Added Ecore::IdleEnterer.
[ruby-ecore.git] / src / ecore / rb_ecore.c
1 /*
2  * $Id: rb_ecore.c 152 2004-12-09 18: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_animator.h"
29 #include "rb_idler.h"
30 #include "rb_event_handler.h"
31 #include "rb_fd_handler.h"
32
33 VALUE mEcore;
34
35 /*
36  * call-seq:
37  *  Ecore.main_loop_begin
38  *
39  * Starts the Ecore main loop.
40  */
41 static VALUE m_main_loop_begin (VALUE self)
42 {
43         ecore_main_loop_begin ();
44
45         return Qnil;
46 }
47
48 /*
49  * call-seq:
50  *  Ecore.main_loop_iterate
51  *
52  * Run one iteration of the Ecore main loop.
53  */
54 static VALUE m_main_loop_iterate (VALUE self)
55 {
56         ecore_main_loop_iterate ();
57
58         return Qnil;
59 }
60
61 /*
62  * call-seq:
63  *  Ecore.main_loop_quit
64  *
65  * Stops the Ecore main loop.
66  */
67 static VALUE m_main_loop_quit (VALUE self)
68 {
69         ecore_main_loop_quit ();
70
71         return Qnil;
72 }
73
74 static VALUE m_time_get (VALUE self)
75 {
76         return rb_float_new (ecore_time_get ());
77 }
78
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
99 static VALUE c_ev_sig_user_init (VALUE self, VALUE event)
100 {
101         Ecore_Event_Signal_User *e = (void *) event;
102
103         rb_define_attr (CLASS_OF (self), "number", 1, 0);
104
105         rb_iv_set (self, "@number", INT2FIX (e->number));
106
107         return self;
108 }
109
110 static VALUE c_ev_sig_exit_init (VALUE self, VALUE event)
111 {
112         VALUE c = CLASS_OF (self);
113         Ecore_Event_Signal_Exit *e = (void *) event;
114
115         rb_define_attr (c, "interrupt", 1, 0);
116         rb_define_attr (c, "quit", 1, 0);
117         rb_define_attr (c, "terminate", 1, 0);
118
119         rb_iv_set (self, "@interrupt", e->interrupt ? Qtrue : Qfalse);
120         rb_iv_set (self, "@quit", e->quit ? Qtrue : Qfalse);
121         rb_iv_set (self, "@terminate", e->terminate ? Qtrue : Qfalse);
122
123         return self;
124 }
125
126 static VALUE c_ev_sig_rt_init (VALUE self, VALUE event)
127 {
128         Ecore_Event_Signal_Realtime *e = (void *) event;
129
130         rb_define_attr (CLASS_OF (self), "number", 1, 0);
131
132         rb_iv_set (self, "@number", INT2FIX (e->num));
133
134         return self;
135 }
136
137 void Init_ecore (void)
138 {
139         VALUE c;
140
141         mEcore = rb_define_module ("Ecore");
142
143         rb_define_module_function (mEcore, "main_loop_begin",
144                                    m_main_loop_begin, 0);
145         rb_define_module_function (mEcore, "main_loop_iterate",
146                                    m_main_loop_iterate, 0);
147         rb_define_module_function (mEcore, "main_loop_quit",
148                                    m_main_loop_quit, 0);
149         rb_define_module_function (mEcore, "time", m_time_get, 0);
150
151         Init_Timer ();
152         Init_Animator ();
153         Init_Idler ();
154         Init_IdleEnterer ();
155         Init_EventHandler ();
156         Init_FdHandler ();
157
158         /* SIGNAL_HUP */
159         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
160                    "SignalHup", c);
161         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
162
163         /* SIGNAL_POWER */
164         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_POWER,
165                    "SignalPower", c);
166         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
167
168         /* EXE_EXIT */
169         ADD_EVENT (mEcore, ECORE_EVENT_, EXE_EXIT, "ExeExit", c);
170         rb_define_private_method (c, "initialize", c_ev_exe_exit_init, 1);
171
172         /* SIGNAL_USER */
173         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_USER,
174                    "SignalUser", c);
175         rb_define_private_method (c, "initialize", c_ev_sig_user_init, 1);
176
177         /* SIGNAL_EXIT */
178         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_EXIT,
179                    "SignalExit", c);
180         rb_define_private_method (c, "initialize", c_ev_sig_exit_init, 1);
181
182         /* SIGNAL_REALTIME */
183         ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_REALTIME,
184                    "SignalRealtime", c);
185         rb_define_private_method (c, "initialize", c_ev_sig_rt_init, 1);
186 }
187