From 2fd1633a6fa61e177cef414c0421d0ebba1d2839 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Aug 2013 22:22:14 +0100 Subject: [PATCH] Added all ruby hooks --- plugins/RubyTest.rb | 14 +++++++++- src/plugins/ruby_plugins.c | 54 +++++++------------------------------- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/plugins/RubyTest.rb b/plugins/RubyTest.rb index d6389ac7..d41b94d8 100644 --- a/plugins/RubyTest.rb +++ b/plugins/RubyTest.rb @@ -1,5 +1,17 @@ module RubyTest def RubyTest.prof_init(version, status) - Prof::cons_show("RubyTest: " + version + " " + status) + Prof::cons_show("RubyTest: init, " + version + ", " + status) + end + + def RubyTest.prof_on_start() + Prof::cons_show("RubyTest: on_start") + end + + def RubyTest.prof_on_connect() + Prof::cons_show("RubyTest: on_connect") + end + + def RubyTest.prof_on_message_received(jid, message) + Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message) end end diff --git a/src/plugins/ruby_plugins.c b/src/plugins/ruby_plugins.c index d8f5a4dd..d591e3fc 100644 --- a/src/plugins/ruby_plugins.c +++ b/src/plugins/ruby_plugins.c @@ -79,59 +79,25 @@ ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * cons void ruby_on_start_hook(ProfPlugin *plugin) { -/* - PyObject *p_function; - - PyObject *p_module = plugin->module; - if (PyObject_HasAttrString(p_module, "prof_on_start")) { - p_function = PyObject_GetAttrString(p_module, "prof_on_start"); - ruby_check_error(); - if (p_function && PyCallable_Check(p_function)) { - PyObject_CallObject(p_function, NULL); - ruby_check_error(); - Py_XDECREF(p_function); - } - } -*/ + VALUE module = (VALUE) plugin->module; + rb_funcall(module, rb_intern("prof_on_start"), 0); } void ruby_on_connect_hook(ProfPlugin *plugin) { -/* - PyObject *p_function; - - PyObject *p_module = plugin->module; - if (PyObject_HasAttrString(p_module, "prof_on_connect")) { - p_function = PyObject_GetAttrString(p_module, "prof_on_connect"); - ruby_check_error(); - if (p_function && PyCallable_Check(p_function)) { - PyObject_CallObject(p_function, NULL); - ruby_check_error(); - Py_XDECREF(p_function); - } - } -*/ + VALUE module = (VALUE) plugin->module; + rb_funcall(module, rb_intern("prof_on_connect"), 0); } void ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message) { -/* TODO - PyObject *p_args = Py_BuildValue("ss", jid, message); - PyObject *p_function; + VALUE v_jid = rb_str_new2(jid); + VALUE v_message = rb_str_new2(message); - PyObject *p_module = plugin->module; - if (PyObject_HasAttrString(p_module, "prof_on_message_received")) { - p_function = PyObject_GetAttrString(p_module, "prof_on_message_received"); - ruby_check_error(); - if (p_function && PyCallable_Check(p_function)) { - PyObject_CallObject(p_function, p_args); - ruby_check_error(); - Py_XDECREF(p_function); - } - } -*/ + VALUE module = (VALUE) plugin->module; + rb_funcall(module, rb_intern("prof_on_message_received"), 2, v_jid, v_message); } void @@ -148,7 +114,5 @@ ruby_check_error(void) void ruby_shutdown(void) { -/* TODO - Py_Finalize(); -*/ + ruby_finalize(); }