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