More work on the bindings
authorMikael Hallendal <micke@imendio.com>
Tue, 08 Apr 2008 21:45:10 +0200
changeset 352 5e3371477a70
parent 351 7066461a5f79
child 353 999be9e7fad7
More work on the bindings
bindings/ruby/rlm-connection.c
bindings/ruby/rlm-message.c
bindings/ruby/rloudmouth.h
--- a/bindings/ruby/rlm-connection.c	Tue Apr 08 18:07:47 2008 +0200
+++ b/bindings/ruby/rlm-connection.c	Tue Apr 08 21:45:10 2008 +0200
@@ -20,7 +20,7 @@
 }
 
 VALUE
-conn_initialize(VALUE self, VALUE server)
+conn_initialize(VALUE self, VALUE server, VALUE context)
 {
 	LmConnection *conn;
 
@@ -33,13 +33,34 @@
 		lm_connection_set_server (conn, StringValuePtr (str_val));
 	}
 
+	/* Set context */
+
 	return self;
 }
 
+static void
+open_callback (LmConnection *conn, gboolean success, gpointer user_data)
+{
+	rb_funcall((VALUE)user_data, rb_intern ("call"), 1,
+		   GBOOL2RVAL (success));
+}
+
 VALUE
-conn_open (VALUE block)
+conn_open (int argc, VALUE *argv, VALUE self)
 {
-	return Qtrue;
+	LmConnection *conn;
+	VALUE         ret_val;
+	VALUE         func;
+
+	Data_Get_Struct (self, LmConnection, conn);
+
+	rb_scan_args (argc, argv, "&", &func);
+	if (NIL_P (func)) {
+		func = rb_block_proc ();
+	}
+
+	return GBOOL2RVAL (lm_connection_open (conn, open_callback, 
+					       (gpointer) func, NULL, NULL));
 }
 
 void
@@ -51,6 +72,7 @@
 						rb_cObject);
 
 	rb_define_alloc_func (lm_mConnection, conn_allocate);
+
 	rb_define_method (lm_mConnection, "initialize", conn_initialize, 1);
 	rb_define_method (lm_mConnection, "open", conn_open, 1);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/ruby/rlm-message.c	Tue Apr 08 21:45:10 2008 +0200
@@ -0,0 +1,20 @@
+#include "rloudmouth.h"
+
+VALUE
+msg_allocate (VALUE klass)
+{
+}
+
+extern void 
+Init_lm_message (VALUE lm_mLM)
+{
+	VALUE lm_mConnection;
+
+	lm_mMessage = rb_define_class_under (lm_mLM, "Message", 
+					     rb_cObject);
+
+	rb_define_alloc_func (lm_mMessage, msg_allocate);
+	
+	rb_define_method (lm_mMessage, "initialize", msg_initialize, 1);
+}
+
--- a/bindings/ruby/rloudmouth.h	Tue Apr 08 18:07:47 2008 +0200
+++ b/bindings/ruby/rloudmouth.h	Tue Apr 08 21:45:10 2008 +0200
@@ -5,8 +5,11 @@
 #include <loudmouth/loudmouth.h> 
 #include <glib.h>
 
-extern void Init_loudmouth     (void);
-extern void Init_lm_connection (VALUE lm_mLM);
+#define GBOOL2RVAL(x) (x == TRUE ? Qtrue : Qfalse)
+
+extern void Init_loudmouth          (void);
+extern void Init_lm_connection      (VALUE lm_mLM);
+extern void Init_lm_message         (VALUE lm_mLM);
 
 #endif /* __RLM_H__ */