Moved the rb_define_attr calls. Implemented more events and enums.
[ruby-ecore.git] / src / ecore / rb_ecore.c
1 /*
2  * $Id: rb_ecore.c 83 2004-08-21 19:55:35Z 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
31 VALUE mEcore;
32
33 /*
34  * call-seq:
35  *  Ecore.main_loop_begin
36  *
37  * Starts the Ecore main loop.
38  */
39 static VALUE m_main_loop_begin (VALUE self)
40 {
41         ecore_main_loop_begin ();
42
43         return Qnil;
44 }
45
46 /*
47  * call-seq:
48  *  Ecore.main_loop_iterate
49  *
50  * Run one iteration of the Ecore main loop.
51  */
52 static VALUE m_main_loop_iterate (VALUE self)
53 {
54         ecore_main_loop_iterate ();
55
56         return Qnil;
57 }
58
59 /*
60  * call-seq:
61  *  Ecore.main_loop_quit
62  *
63  * Stops the Ecore main loop.
64  */
65 static VALUE m_main_loop_quit (VALUE self)
66 {
67         ecore_main_loop_quit ();
68
69         return Qnil;
70 }
71
72 static VALUE c_ev_exe_exit_init (VALUE self, VALUE event)
73 {
74         VALUE c = CLASS_OF (self);
75         Ecore_Event_Exe_Exit *e = (void *) event;
76
77         rb_define_attr (c, "pid", 1, 0);
78         rb_define_attr (c, "exit_code", 1, 0);
79         rb_define_attr (c, "exit_signal", 1, 0);
80         rb_define_attr (c, "exited", 1, 0);
81         rb_define_attr (c, "signalled", 1, 0);
82
83         rb_iv_set (self, "@pid", INT2FIX (e->pid));
84         rb_iv_set (self, "@exit_code", INT2FIX (e->exit_code));
85         rb_iv_set (self, "@exit_signal", INT2FIX (e->exit_signal));
86         rb_iv_set (self, "@exited", e->exited ? Qtrue : Qfalse);
87         rb_iv_set (self, "@signalled", e->signalled ? Qtrue : Qfalse);
88
89         return self;
90 }
91
92 static VALUE c_ev_sig_user_init (VALUE self, VALUE event)
93 {
94         Ecore_Event_Signal_User *e = (void *) event;
95
96         rb_define_attr (CLASS_OF (self), "number", 1, 0);
97
98         rb_iv_set (self, "@number", INT2FIX (e->number));
99
100         return self;
101 }
102
103 static VALUE c_ev_sig_exit_init (VALUE self, VALUE event)
104 {
105         VALUE c = CLASS_OF (self);
106         Ecore_Event_Signal_Exit *e = (void *) event;
107
108         rb_define_attr (c, "interrupt", 1, 0);
109         rb_define_attr (c, "quit", 1, 0);
110         rb_define_attr (c, "terminate", 1, 0);
111
112         rb_iv_set (self, "@interrupt", e->interrupt ? Qtrue : Qfalse);
113         rb_iv_set (self, "@quit", e->quit ? Qtrue : Qfalse);
114         rb_iv_set (self, "@terminate", e->terminate ? Qtrue : Qfalse);
115
116         return self;
117 }
118
119 static VALUE c_ev_sig_rt_init (VALUE self, VALUE event)
120 {
121         Ecore_Event_Signal_Realtime *e = (void *) event;
122
123         rb_define_attr (CLASS_OF (self), "number", 1, 0);
124
125         rb_iv_set (self, "@number", INT2FIX (e->num));
126
127         return self;
128 }
129
130 void Init_ecore (void)
131 {
132         VALUE c;
133
134         mEcore = rb_define_module ("Ecore");
135
136         rb_define_module_function (mEcore, "main_loop_begin",
137                                    m_main_loop_begin, 0);
138         rb_define_module_function (mEcore, "main_loop_iterate",
139                                    m_main_loop_iterate, 0);
140         rb_define_module_function (mEcore, "main_loop_quit",
141                                    m_main_loop_quit, 0);
142
143         Init_Timer ();
144         Init_Idler ();
145         Init_EventHandler ();
146
147         /* SIGNAL_HUP */
148         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
149                    "SignalHup", c);
150         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
151
152         /* SIGNAL_POWER */
153         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_POWER,
154                    "SignalPower", c);
155         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
156
157         /* EXE_EXIT */
158         ADD_EVENT (mEcore, ECORE_EVENT_, EXE_EXIT, "ExeExit", c);
159         rb_define_private_method (c, "initialize", c_ev_exe_exit_init, 1);
160
161         /* SIGNAL_USER */
162         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_USER,
163                    "SignalUser", c);
164         rb_define_private_method (c, "initialize", c_ev_sig_user_init, 1);
165
166         /* SIGNAL_EXIT */
167         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_EXIT,
168                    "SignalExit", c);
169         rb_define_private_method (c, "initialize", c_ev_sig_exit_init, 1);
170
171         /* SIGNAL_REALTIME */
172         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_REALTIME,
173                    "SignalRealtime", c);
174         rb_define_private_method (c, "initialize", c_ev_sig_rt_init, 1);
175 }
176