2 * $Id: rb_messages.c 329 2005-04-28 10:41:17Z 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));
35 static VALUE cStrMsg, cIntMsg, cFloatMsg;
37 static VALUE c_msg_init (VALUE self)
39 rb_iv_set (self, "@id", UINT2NUM (0));
44 static VALUE c_str_msg_init (VALUE self, VALUE str)
46 Check_Type (str, T_STRING);
48 rb_call_super (0, NULL);
50 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING));
51 rb_iv_set (self, "@value", str);
56 static VALUE c_str_msg_serialize (VALUE self)
58 static volatile Edje_Message_String ret;
61 s = rb_iv_get (self, "@value");
62 ret.str = StringValuePtr (s);
67 static VALUE c_int_msg_init (VALUE self, VALUE val)
69 Check_Type (val, T_FIXNUM);
71 rb_call_super (0, NULL);
73 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_INT));
74 rb_iv_set (self, "@value", val);
79 static VALUE c_int_msg_serialize (VALUE self)
81 static volatile Edje_Message_Int ret;
84 i = rb_iv_get (self, "@value");
85 ret.val = NUM2INT (i);
90 static VALUE c_float_msg_init (VALUE self, VALUE val)
92 Check_Type (val, T_FLOAT);
94 rb_call_super (0, NULL);
96 rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_FLOAT));
97 rb_iv_set (self, "@value", val);
102 static VALUE c_float_msg_serialize (VALUE self)
104 static volatile Edje_Message_Float ret;
107 f = rb_iv_get (self, "@value");
108 ret.val = NUM2DBL (f);
113 void Init_Messages (void)
115 cMsg = rb_define_class_under (mEdje, "Message", rb_cObject);
117 rb_define_method (cMsg, "initialize", c_msg_init, 0);
119 rb_define_attr (cMsg, "type", 1, 0);
120 rb_define_attr (cMsg, "id", 1, 1);
121 rb_define_attr (cMsg, "value", 1, 1);
124 cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg);
125 rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1);
126 rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0);
129 cIntMsg = rb_define_class_under (mEdje, "IntMessage", cMsg);
130 rb_define_method (cIntMsg, "initialize", c_int_msg_init, 1);
131 rb_define_method (cIntMsg, "serialize", c_int_msg_serialize, 0);
134 cFloatMsg = rb_define_class_under (mEdje, "FloatMessage", cMsg);
135 rb_define_method (cFloatMsg, "initialize", c_float_msg_init, 1);
136 rb_define_method (cFloatMsg, "serialize", c_float_msg_serialize, 0);