2 * $Id: rb_messages.c 153 2004-12-09 18:40:44Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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.
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.
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
25 #define __RB_MESSAGES_C
26 #include "rb_edje_main.h"
28 #include "rb_messages.h"
30 #define DEF_CONST(mod, prefix, name) \
31 rb_define_const ((mod), #name, \
32 INT2FIX (prefix##name));
34 VALUE cMsg, cStrMsg, cIntMsg, cFloatMsg;
36 static VALUE c_msg_init (VALUE self)
38 rb_iv_set (self, "@id", UINT2NUM (0));
43 static VALUE c_str_msg_init (VALUE self, VALUE str)
45 Check_Type (str, T_STRING);
47 rb_call_super (0, NULL);
49 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING));
50 rb_iv_set (self, "@value", str);
55 static VALUE c_str_msg_serialize (VALUE self)
57 static volatile Edje_Message_String ret;
60 s = rb_iv_get (self, "@value");
61 ret.str = StringValuePtr (s);
66 static VALUE c_int_msg_init (VALUE self, VALUE val)
68 Check_Type (val, T_FIXNUM);
70 rb_call_super (0, NULL);
72 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_INT));
73 rb_iv_set (self, "@value", val);
78 static VALUE c_int_msg_serialize (VALUE self)
80 static volatile Edje_Message_Int ret;
83 i = rb_iv_get (self, "@value");
84 ret.val = NUM2INT (i);
89 static VALUE c_float_msg_init (VALUE self, VALUE val)
91 Check_Type (val, T_FLOAT);
93 rb_call_super (0, NULL);
95 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_FLOAT));
96 rb_iv_set (self, "@value", val);
101 static VALUE c_float_msg_serialize (VALUE self)
103 static volatile Edje_Message_Float ret;
106 f = rb_iv_get (self, "@value");
107 ret.val = NUM2DBL (f);
112 void Init_Messages (void)
114 cMsg = rb_define_class_under (mEdje, "Message", rb_cObject);
116 rb_define_method (cMsg, "initialize", c_msg_init, 0);
118 rb_define_attr (cMsg, "type", 1, 0);
119 rb_define_attr (cMsg, "id", 1, 1);
120 rb_define_attr (cMsg, "value", 1, 1);
123 cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg);
124 rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1);
125 rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0);
128 cIntMsg = rb_define_class_under (mEdje, "IntMessage", cMsg);
129 rb_define_method (cIntMsg, "initialize", c_int_msg_init, 1);
130 rb_define_method (cIntMsg, "serialize", c_int_msg_serialize, 0);
133 cFloatMsg = rb_define_class_under (mEdje, "FloatMessage", cMsg);
134 rb_define_method (cFloatMsg, "initialize", c_float_msg_init, 1);
135 rb_define_method (cFloatMsg, "serialize", c_float_msg_serialize, 0);