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