[seed] Add dbus example
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Add dbus example
- Date: Sat, 9 May 2009 23:52:48 -0400 (EDT)
commit a9ed1ce65a4887142a3926094147d04b2c5f6559
Author: Robert Carr <racarr svn gnome org>
Date: Sat May 9 23:52:42 2009 -0400
Add dbus example
---
examples/Makefile.am | 2 ++
examples/dbus-banshee.js | 30 ++++++++++++++++++++++++++++++
libseed/seed-closure.c | 2 +-
modules/dbus/dbus-values.c | 2 +-
modules/dbus/dbus.js | 1 +
modules/dbus/module.c | 9 ++++++---
6 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0850d09..00d097f 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -17,6 +17,7 @@ examplesdir=$(datadir)/doc/seed/examples
examples_DATA = \
actions.js \
Gnio.js \
+ dbus-banshee.js \
gdkpixbufloader.js \
gtktreeview.js \
gtktextview.js \
@@ -50,6 +51,7 @@ endif
EXTRA_DIST = \
COPYING \
actions.js \
+ dbus-banshee.js \
clutter-cogl.js \
gtktreeview.js \
gdkpixbufloader.js \
diff --git a/examples/dbus-banshee.js b/examples/dbus-banshee.js
new file mode 100755
index 0000000..f3dfa3f
--- /dev/null
+++ b/examples/dbus-banshee.js
@@ -0,0 +1,30 @@
+#!/usr/local/bin/seed
+DBus = imports.dbus;
+GLib = imports.gi.GLib;
+
+function PlayerEngine() {
+ this._init();
+}
+
+PlayerEngine.prototype = {
+ _init: function() {
+ DBus.session.proxifyObject (this, 'org.bansheeproject.Banshee','/org/bansheeproject/Banshee/PlayerEngine');
+ }
+};
+
+var PlayerEngineIface = {
+ name: 'org.bansheeproject.Banshee.PlayerEngine',
+ methods: [{name:'Play', inSignature: ''},
+ {name:'Open', inSignature: 's'}],
+};
+
+DBus.proxifyPrototype (PlayerEngine.prototype, PlayerEngineIface);
+
+proxy = new PlayerEngine();
+proxy.OpenRemote("file:///home/racarr/morning.mp3");
+proxy.PlayRemote(function(){
+ Seed.print("proxy.PlayRemote returned");
+});
+
+mainloop = GLib.main_loop_new();
+GLib.main_loop_run(mainloop);
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index 9ef21a9..522222f 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -394,7 +394,7 @@ seed_make_gclosure (JSContextRef ctx, JSObjectRef function, JSObjectRef user_dat
else
((SeedClosure *) closure)->user_data = NULL;
- JSValueProtect (ctx, function);
+ JSValueProtect (eng->context, function);
return closure;
}
diff --git a/modules/dbus/dbus-values.c b/modules/dbus/dbus-values.c
index 14def6c..a9e3684 100644
--- a/modules/dbus/dbus-values.c
+++ b/modules/dbus/dbus-values.c
@@ -938,7 +938,7 @@ seed_js_add_dbus_props (SeedContext ctx, DBusMessage * message, SeedValue value,
{
gchar *sender;
- if (!seed_value_is_object (ctx, value))
+ if (seed_value_is_null (ctx, value) || !seed_value_is_object (ctx, value))
return TRUE;
sender = (gchar *)dbus_message_get_sender (message);
diff --git a/modules/dbus/dbus.js b/modules/dbus/dbus.js
index 645a33c..17b5707 100644
--- a/modules/dbus/dbus.js
+++ b/modules/dbus/dbus.js
@@ -92,6 +92,7 @@ function _logReply(result, exc) {
log("Ignored reply to dbus method: " + result.toSource());
}
if (exc != null) {
+ Seed.print(exc);
log("Ignored exception from dbus method: " + exc.toString());
}
}
diff --git a/modules/dbus/module.c b/modules/dbus/module.c
index b3a1d93..131a9f8 100644
--- a/modules/dbus/module.c
+++ b/modules/dbus/module.c
@@ -123,7 +123,6 @@ prepare_call (SeedContext ctx,
/* FIXME should validate the bus_name, path, interface, method really, but
* we should just not write buggy JS ;-)
*/
-
message = dbus_message_new_method_call (bus_name, path, interface, method);
if (message == NULL)
{
@@ -219,7 +218,7 @@ complete_call (SeedContext ctx,
g_array_free (ret_values, TRUE);
- seed_js_add_dbus_props (ctx, reply, retval, exception);
+ seed_js_add_dbus_props (ctx, reply, *retval, exception);
return TRUE;
}
@@ -227,7 +226,7 @@ complete_call (SeedContext ctx,
static void
pending_notify (DBusPendingCall * pending, void *user_data)
{
- SeedException exception;
+ SeedException exception = NULL;
SeedContext ctx;
GClosure *closure;
SeedValue argv[2];
@@ -256,12 +255,16 @@ pending_notify (DBusPendingCall * pending, void *user_data)
dbus_error_init (&derror);
/* argv[0] will be the return value if any, argv[1] we fill with exception if any */
+ argv[0] = seed_make_null (ctx);
+ argv[1] = seed_make_null (ctx);
complete_call (ctx, &argv[0], reply, &derror, &exception);
g_assert (!dbus_error_is_set (&derror)); /* not supposed to be left set by complete_call() */
if (reply)
dbus_message_unref (reply);
+ if (exception)
+ argv[1] = exception;
seed_closure_invoke_with_context (ctx, closure, &argv[0], 2, &exception);
seed_context_unref (ctx);
// TODO: Do something with exception
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]