initial code for ruby bindings
authorMikael Hallendal <micke@imendio.com>
Tue, 08 Apr 2008 18:07:06 +0200
changeset 350 de2e3f3631c9
parent 349 3dafc8376e9b
child 351 7066461a5f79
initial code for ruby bindings
bindings/ruby/extconf.rb
bindings/ruby/rlm-connection.c
bindings/ruby/rloudmouth.c
bindings/ruby/rloudmouth.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/ruby/extconf.rb	Tue Apr 08 18:07:06 2008 +0200
@@ -0,0 +1,13 @@
+require 'pkg-config'
+
+PACKAGE_NAME = "loudmouth"
+PACKAGE_ID = "loudmouth"
+
+# SRCDIR = File.expand_path(File.dirname(__FILE__) + '/src')
+
+require 'mkmf'
+
+PKGConfig.have_package("loudmouth-1.0", 1, 3, 4) or exit 1
+PKGConfig.have_package("glib-2.0", 2, 4, 0) or exit 1
+
+create_makefile("loudmouth")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/ruby/rlm-connection.c	Tue Apr 08 18:07:06 2008 +0200
@@ -0,0 +1,56 @@
+#include "rloudmouth.h"
+
+void
+conn_mark (LmConnection *self)
+{
+}
+
+void
+conn_free (LmConnection *self)
+{
+	lm_connection_unref (self);
+}
+
+VALUE
+conn_allocate(VALUE klass)
+{
+	LmConnection *conn = lm_connection_new (NULL);
+
+	return Data_Wrap_Struct (klass, conn_mark, conn_free, conn);
+}
+
+VALUE
+conn_initialize(VALUE self, VALUE server)
+{
+	LmConnection *conn;
+
+	Data_Get_Struct (self, LmConnection, conn);
+
+	if (!rb_respond_to (server, rb_intern ("to_s"))) {
+		rb_raise (rb_eArgError, "server should respond to to_s");
+	} else {
+		VALUE str_val = rb_funcall (server, rb_intern ("to_s"), 0);
+		lm_connection_set_server (conn, StringValuePtr (str_val));
+	}
+
+	return self;
+}
+
+VALUE
+conn_open (VALUE block)
+{
+	return Qtrue;
+}
+
+void
+Init_lm_connection (VALUE lm_mLM)
+{
+	VALUE lm_mConnection;
+	
+	lm_mConnection = rb_define_class_under (lm_mLM, "Connection", 
+						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/rloudmouth.c	Tue Apr 08 18:07:06 2008 +0200
@@ -0,0 +1,12 @@
+#include "rloudmouth.h"
+
+void
+Init_loudmouth (void)
+{
+	VALUE lm_mLM;
+	
+	lm_mLM = rb_define_module ("LM");
+
+	Init_lm_connection (lm_mLM);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/ruby/rloudmouth.h	Tue Apr 08 18:07:06 2008 +0200
@@ -0,0 +1,12 @@
+#ifndef __RLM_H__
+#define __RLM_H__
+
+#include <ruby.h>
+#include <loudmouth/loudmouth.h> 
+#include <glib.h>
+
+extern void Init_loudmouth     (void);
+extern void Init_lm_connection (VALUE lm_mLM);
+
+#endif /* __RLM_H__ */
+