Added Ecore::FdHandler. Moved DEF_CONST.
[ruby-ecore.git] / src / ecore / rb_ecore.c
1 /*
2  * $Id: rb_ecore.c 109 2004-09-01 20:33:15Z 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_idler.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 c_ev_exe_exit_init (VALUE self, VALUE event)
74 {
75         VALUE c = CLASS_OF (self);
76         Ecore_Event_Exe_Exit *e = (void *) event;
77
78         rb_define_attr (c, "pid", 1, 0);
79         rb_define_attr (c, "exit_code", 1, 0);
80         rb_define_attr (c, "exit_signal", 1, 0);
81         rb_define_attr (c, "exited", 1, 0);
82         rb_define_attr (c, "signalled", 1, 0);
83
84         rb_iv_set (self, "@pid", INT2FIX (e->pid));
85         rb_iv_set (self, "@exit_code", INT2FIX (e->exit_code));
86         rb_iv_set (self, "@exit_signal", INT2FIX (e->exit_signal));
87         rb_iv_set (self, "@exited", e->exited ? Qtrue : Qfalse);
88         rb_iv_set (self, "@signalled", e->signalled ? Qtrue : Qfalse);
89
90         return self;
91 }
92
93 static VALUE c_ev_sig_user_init (VALUE self, VALUE event)
94 {
95         Ecore_Event_Signal_User *e = (void *) event;
96
97         rb_define_attr (CLASS_OF (self), "number", 1, 0);
98
99         rb_iv_set (self, "@number", INT2FIX (e->number));
100
101         return self;
102 }
103
104 static VALUE c_ev_sig_exit_init (VALUE self, VALUE event)
105 {
106         VALUE c = CLASS_OF (self);
107         Ecore_Event_Signal_Exit *e = (void *) event;
108
109         rb_define_attr (c, "interrupt", 1, 0);
110         rb_define_attr (c, "quit", 1, 0);
111         rb_define_attr (c, "terminate", 1, 0);
112
113         rb_iv_set (self, "@interrupt", e->interrupt ? Qtrue : Qfalse);
114         rb_iv_set (self, "@quit", e->quit ? Qtrue : Qfalse);
115         rb_iv_set (self, "@terminate", e->terminate ? Qtrue : Qfalse);
116
117         return self;
118 }
119
120 static VALUE c_ev_sig_rt_init (VALUE self, VALUE event)
121 {
122         Ecore_Event_Signal_Realtime *e = (void *) event;
123
124         rb_define_attr (CLASS_OF (self), "number", 1, 0);
125
126         rb_iv_set (self, "@number", INT2FIX (e->num));
127
128         return self;
129 }
130
131 void Init_ecore (void)
132 {
133         VALUE c;
134
135         mEcore = rb_define_module ("Ecore");
136
137         rb_define_module_function (mEcore, "main_loop_begin",
138                                    m_main_loop_begin, 0);
139         rb_define_module_function (mEcore, "main_loop_iterate",
140                                    m_main_loop_iterate, 0);
141         rb_define_module_function (mEcore, "main_loop_quit",
142                                    m_main_loop_quit, 0);
143
144         Init_Timer ();
145         Init_Idler ();
146         Init_EventHandler ();
147         Init_FdHandler ();
148
149         /* SIGNAL_HUP */
150         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
151                    "SignalHup", c);
152         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
153
154         /* SIGNAL_POWER */
155         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_POWER,
156                    "SignalPower", c);
157         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
158
159         /* EXE_EXIT */
160         ADD_EVENT (mEcore, ECORE_EVENT_, EXE_EXIT, "ExeExit", c);
161         rb_define_private_method (c, "initialize", c_ev_exe_exit_init, 1);
162
163         /* SIGNAL_USER */
164         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_USER,
165                    "SignalUser", c);
166         rb_define_private_method (c, "initialize", c_ev_sig_user_init, 1);
167
168         /* SIGNAL_EXIT */
169         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_EXIT,
170                    "SignalExit", c);
171         rb_define_private_method (c, "initialize", c_ev_sig_exit_init, 1);
172
173         /* SIGNAL_REALTIME */
174         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_REALTIME,
175                    "SignalRealtime", c);
176         rb_define_private_method (c, "initialize", c_ev_sig_rt_init, 1);
177 }
178