b5c4f5be71802372e9b0e34240818dcbf2ca4bf3
[ruby-edje.git] / src / rb_messages.c
1 /*
2  * $Id: rb_messages.c 139 2004-10-30 09:41:17Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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 <Edje.h>
24
25 #define __RB_MESSAGES_C
26 #include "rb_edje_main.h"
27 #include "rb_edje.h"
28 #include "rb_messages.h"
29
30 #define DEF_CONST(mod, prefix, name) \
31         rb_define_const ((mod), #name, \
32                          INT2FIX (prefix##name));
33
34 VALUE cMsg, cStrMsg;
35
36 static VALUE c_msg_init (VALUE self)
37 {
38         rb_iv_set (self, "@id", UINT2NUM (0));
39
40         return self;
41 }
42
43 static VALUE c_str_msg_init (VALUE self, VALUE str)
44 {
45         Check_Type (str, T_STRING);
46
47         rb_call_super (0, NULL);
48
49         rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING));
50         rb_iv_set (self, "@string", str);
51
52         return self;
53 }
54
55 static VALUE c_str_msg_serialize (VALUE self)
56 {
57         static volatile Edje_Message_String ret;
58         VALUE s;
59
60         s = rb_iv_get (self, "@string");
61         ret.str = StringValuePtr (s);
62
63         return (VALUE) &ret;
64 }
65
66 void Init_Messages (void)
67 {
68         cMsg = rb_define_class_under (mEdje, "Message", rb_cObject);
69
70         rb_define_method (cMsg, "initialize", c_msg_init, 0);
71
72         rb_define_attr (cMsg, "type", 1, 0);
73         rb_define_attr (cMsg, "id", 1, 1);
74
75         cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg);
76         rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1);
77         rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0);
78
79         rb_define_attr (cStrMsg, "string", 1, 1);
80 }