X-Git-Url: http://git.code-monkey.de/?p=ruby-edje.git;a=blobdiff_plain;f=src%2Frb_messages.c;fp=src%2Frb_messages.c;h=b5c4f5be71802372e9b0e34240818dcbf2ca4bf3;hp=0000000000000000000000000000000000000000;hb=887790d08e623c56ce01230fb2889b2555f21ed2;hpb=2a5118f22e227a5ce2c2a46e6a4bdc4f6bc86ca2 diff --git a/src/rb_messages.c b/src/rb_messages.c new file mode 100644 index 0000000..b5c4f5b --- /dev/null +++ b/src/rb_messages.c @@ -0,0 +1,80 @@ +/* + * $Id: rb_messages.c 139 2004-10-30 09:41:17Z tilman $ + * + * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include + +#define __RB_MESSAGES_C +#include "rb_edje_main.h" +#include "rb_edje.h" +#include "rb_messages.h" + +#define DEF_CONST(mod, prefix, name) \ + rb_define_const ((mod), #name, \ + INT2FIX (prefix##name)); + +VALUE cMsg, cStrMsg; + +static VALUE c_msg_init (VALUE self) +{ + rb_iv_set (self, "@id", UINT2NUM (0)); + + return self; +} + +static VALUE c_str_msg_init (VALUE self, VALUE str) +{ + Check_Type (str, T_STRING); + + rb_call_super (0, NULL); + + rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING)); + rb_iv_set (self, "@string", str); + + return self; +} + +static VALUE c_str_msg_serialize (VALUE self) +{ + static volatile Edje_Message_String ret; + VALUE s; + + s = rb_iv_get (self, "@string"); + ret.str = StringValuePtr (s); + + return (VALUE) &ret; +} + +void Init_Messages (void) +{ + cMsg = rb_define_class_under (mEdje, "Message", rb_cObject); + + rb_define_method (cMsg, "initialize", c_msg_init, 0); + + rb_define_attr (cMsg, "type", 1, 0); + rb_define_attr (cMsg, "id", 1, 1); + + cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg); + rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1); + rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0); + + rb_define_attr (cStrMsg, "string", 1, 1); +}