Fixed class instantiation.
[ruby-ecore.git] / src / ecore / rb_ecore.c
1 /*
2  * $Id: rb_ecore.c 349 2006-01-29 09:17:44Z tilman $
3  *
4  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <ruby.h>
22
23 #include <Ecore.h>
24
25 #define __RB_ECORE_C
26 #include "rb_ecore.h"
27 #include "rb_timer.h"
28 #include "rb_animator.h"
29 #include "rb_idler.h"
30 #include "rb_idle_enterer.h"
31 #include "rb_event_handler.h"
32 #include "rb_fd_handler.h"
33
34 VALUE mEcore;
35
36 /*
37  * call-seq:
38  *  Ecore.main_loop_begin
39  *
40  * Starts the Ecore main loop.
41  */
42 static VALUE m_main_loop_begin (VALUE self)
43 {
44         ecore_main_loop_begin ();
45
46         return Qnil;
47 }
48
49 /*
50  * call-seq:
51  *  Ecore.main_loop_iterate
52  *
53  * Run one iteration of the Ecore main loop.
54  */
55 static VALUE m_main_loop_iterate (VALUE self)
56 {
57         ecore_main_loop_iterate ();
58
59         return Qnil;
60 }
61
62 /*
63  * call-seq:
64  *  Ecore.main_loop_quit
65  *
66  * Stops the Ecore main loop.
67  */
68 static VALUE m_main_loop_quit (VALUE self)
69 {
70         ecore_main_loop_quit ();
71
72         return Qnil;
73 }
74
75 static VALUE m_time_get (VALUE self)
76 {
77         return rb_float_new (ecore_time_get ());
78 }
79
80 #if 0
81 static VALUE c_ev_exe_exit_init (VALUE self, VALUE event)
82 {
83         VALUE c = CLASS_OF (self);
84         Ecore_Event_Exe_Exit *e = (void *) event;
85
86         rb_define_attr (c, "pid", 1, 0);
87         rb_define_attr (c, "exit_code", 1, 0);
88         rb_define_attr (c, "exit_signal", 1, 0);
89         rb_define_attr (c, "exited", 1, 0);
90         rb_define_attr (c, "signalled", 1, 0);
91
92         rb_iv_set (self, "@pid", INT2FIX (e->pid));
93         rb_iv_set (self, "@exit_code", INT2FIX (e->exit_code));
94         rb_iv_set (self, "@exit_signal", INT2FIX (e->exit_signal));
95         rb_iv_set (self, "@exited", e->exited ? Qtrue : Qfalse);
96         rb_iv_set (self, "@signalled", e->signalled ? Qtrue : Qfalse);
97
98         return self;
99 }
100 #endif
101
102 static VALUE c_ev_sig_user_init (VALUE self, VALUE event)
103 {
104         Ecore_Event_Signal_User *e = (void *) event;
105
106         rb_define_attr (CLASS_OF (self), "number", 1, 0);
107
108         rb_iv_set (self, "@number", INT2FIX (e->number));
109
110         return self;
111 }
112
113 static VALUE c_ev_sig_exit_init (VALUE self, VALUE event)
114 {
115         VALUE c = CLASS_OF (self);
116         Ecore_Event_Signal_Exit *e = (void *) event;
117
118         rb_define_attr (c, "interrupt", 1, 0);
119         rb_define_attr (c, "quit", 1, 0);
120         rb_define_attr (c, "terminate", 1, 0);
121
122         rb_iv_set (self, "@interrupt", e->interrupt ? Qtrue : Qfalse);
123         rb_iv_set (self, "@quit", e->quit ? Qtrue : Qfalse);
124         rb_iv_set (self, "@terminate", e->terminate ? Qtrue : Qfalse);
125
126         return self;
127 }
128
129 static VALUE c_ev_sig_rt_init (VALUE self, VALUE event)
130 {
131         Ecore_Event_Signal_Realtime *e = (void *) event;
132
133         rb_define_attr (CLASS_OF (self), "number", 1, 0);
134
135         rb_iv_set (self, "@number", INT2FIX (e->num));
136
137         return self;
138 }
139
140 static void at_exit ()
141 {
142         ecore_shutdown ();
143 }
144
145 void Init_ecore (void)
146 {
147         VALUE c;
148
149         ecore_init ();
150
151         atexit (at_exit);
152
153         mEcore = rb_define_module ("Ecore");
154
155         rb_define_module_function (mEcore, "main_loop_begin",
156                                    m_main_loop_begin, 0);
157         rb_define_module_function (mEcore, "main_loop_iterate",
158                                    m_main_loop_iterate, 0);
159         rb_define_module_function (mEcore, "main_loop_quit",
160                                    m_main_loop_quit, 0);
161         rb_define_module_function (mEcore, "time", m_time_get, 0);
162
163         Init_Timer ();
164         Init_Animator ();
165         Init_Idler ();
166         Init_IdleEnterer ();
167         Init_EventHandler ();
168         Init_FdHandler ();
169
170         /* SIGNAL_HUP */
171         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
172                    "SignalHup", c);
173         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
174
175         /* SIGNAL_POWER */
176         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_POWER,
177                    "SignalPower", c);
178         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
179
180 #if 0
181         /* EXE_EXIT */
182         ADD_EVENT (mEcore, ECORE_EVENT_, EXE_EXIT, "ExeExit", c);
183         rb_define_private_method (c, "initialize", c_ev_exe_exit_init, 1);
184 #endif
185
186         /* SIGNAL_USER */
187         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_USER,
188                    "SignalUser", c);
189         rb_define_private_method (c, "initialize", c_ev_sig_user_init, 1);
190
191         /* SIGNAL_EXIT */
192         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_EXIT,
193                    "SignalExit", c);
194         rb_define_private_method (c, "initialize", c_ev_sig_exit_init, 1);
195
196         /* SIGNAL_REALTIME */
197         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_REALTIME,
198                    "SignalRealtime", c);
199         rb_define_private_method (c, "initialize", c_ev_sig_rt_init, 1);
200 }
201