Implemented Edje#send_message.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sat, 30 Oct 2004 09:41:17 +0000 (09:41 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sat, 30 Oct 2004 09:41:17 +0000 (09:41 +0000)
src/Makefile.am
src/rb_edje.c
src/rb_edje_main.c
src/rb_messages.c [new file with mode: 0644]
src/rb_messages.h [new file with mode: 0644]

index 29cd3c58a1e8e3b2fd21b37759ac4f3ccc5b4b30..06d777c6661f819cc4c0acffdb80a41c5afd3ea1 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 119 2004-10-18 20:17:53Z tilman $
+## $Id: Makefile.am 139 2004-10-30 09:41:17Z tilman $
 
 AM_CFLAGS = $(EVAS_CFLAGS) $(EDJE_CFLAGS)
 INCLUDES = -I$(RUBYDIR) -I$(RUBYSITEDIR)
@@ -8,7 +8,8 @@ extdir = $(RUBYSITEDIR)
 
 edje_la_SOURCES = rb_edje_main.c rb_edje_main.h \
                   rb_edje.c rb_edje.h \
-                  rb_part.c rb_part.h
+                  rb_part.c rb_part.h \
+                  rb_messages.c rb_messages.h
 
 edje_la_LIBADD = -L$(RUBYLIBDIR) $(RUBYLIB) $(EVAS_LIBS) $(EDJE_LIBS)
 edje_la_LDFLAGS = -module -avoid-version
index 711df113b0d1a4bf259242d1d1dd55477f2ff7b1..25be7482d724d756ebbf58dc1341c14b0edd8308 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_edje.c 129 2004-10-22 17:03:35Z tilman $
+ * $Id: rb_edje.c 139 2004-10-30 09:41:17Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -28,6 +28,7 @@
 #include "rb_edje.h"
 #include "rb_edje_main.h"
 #include "rb_part.h"
+#include "rb_messages.h"
 
 VALUE cEdje;
 
@@ -395,6 +396,25 @@ static VALUE c_data_get (VALUE self, VALUE key)
        return s ? rb_str_new2 (s) : Qnil;
 }
 
+static VALUE c_send_message (VALUE self, VALUE msg)
+{
+       VALUE m;
+       Edje_Message_Type type;
+       int id;
+
+       GET_OBJ (self, RbEdje, e);
+
+       CHECK_CLASS (msg, cMsg);
+
+       type = NUM2INT (rb_iv_get (msg, "@type"));
+       id = NUM2INT (rb_iv_get (msg, "@id"));
+       m = rb_funcall (msg, rb_intern ("serialize"), 0, NULL);
+
+       edje_object_message_send (e->real.real, type, id, (void *) m);
+
+       return Qnil;
+}
+
 void Init_Edje (void)
 {
        cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
@@ -415,4 +435,5 @@ void Init_Edje (void)
        rb_define_method (cEdje, "animation?", c_animation_get, 0);
        rb_define_method (cEdje, "animation=", c_animation_set, 1);
        rb_define_method (cEdje, "data", c_data_get, 1);
+       rb_define_method (cEdje, "send_message", c_send_message, 1);
 }
index a553b54703202fbb8aff456105bd27cd599bda10..9c075de74727125961e28f6945efe61e8d342454 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_edje_main.c 59 2004-08-10 14:10:31Z tilman $
+ * $Id: rb_edje_main.c 139 2004-10-30 09:41:17Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -25,6 +25,7 @@
 #include "rb_edje_main.h"
 #include "rb_edje.h"
 #include "rb_part.h"
+#include "rb_messages.h"
 
 /*
  * call-seq:
@@ -91,5 +92,6 @@ void Init_edje (void)
 
        Init_Edje ();
        Init_Part ();
+       Init_Messages ();
 }
 
diff --git a/src/rb_messages.c b/src/rb_messages.c
new file mode 100644 (file)
index 0000000..b5c4f5b
--- /dev/null
@@ -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 <ruby.h>
+
+#include <Edje.h>
+
+#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);
+}
diff --git a/src/rb_messages.h b/src/rb_messages.h
new file mode 100644 (file)
index 0000000..992b88d
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * $Id: rb_messages.h 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
+ */
+
+#ifndef __RB_MESSAGES_H
+#define __RB_MESSAGES_H
+
+void Init_Messages (void);
+
+#ifndef __RB_MESSAGES_C
+extern VALUE cMsg, cStrMsg;
+#endif
+
+#endif