[seed] Implement on_name_acquire and on_name_lost handlers



commit 7470ca852345ed81cbab68ceccc052972ddcbdde
Author: Robert Carr <racarr svn gnome org>
Date:   Sat May 9 19:46:00 2009 -0400

    Implement on_name_acquire and on_name_lost handlers
---
 libseed/seed.h        |    2 +-
 modules/dbus/module.c |   72 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/libseed/seed.h b/libseed/seed.h
index 41176f0..f57a128 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -218,7 +218,7 @@ SeedValue seed_value_from_double (SeedContext ctx,
 gchar *seed_value_to_string (SeedContext ctx,
 			     SeedValue val, SeedException * exception);
 SeedValue seed_value_from_string (SeedContext ctx,
-				  gchar * val, SeedException * exception);
+				  const gchar * val, SeedException * exception);
 
 gchar *seed_value_to_filename (SeedContext ctx,
 			       SeedValue val, SeedValue * exception);
diff --git a/modules/dbus/module.c b/modules/dbus/module.c
index 4d3d71a..9d5404f 100644
--- a/modules/dbus/module.c
+++ b/modules/dbus/module.c
@@ -860,6 +860,78 @@ seed_js_dbus_call(SeedContext ctx,
     return retval;
 }
 
+typedef struct {
+    BigDBusNameOwnerFuncs funcs;
+    GClosure *acquired_closure;
+    GClosure *lost_closure;
+    DBusBusType bus_type;
+} BigJSDBusNameOwner;
+
+static void
+on_name_acquired(DBusConnection *connection,
+                 const char     *name,
+                 void           *data)
+{
+    int argc;
+    SeedValue argv[1];
+    SeedContext ctx;
+    BigJSDBusNameOwner *owner;
+    SeedException exception; // TODO: Do something with this...
+
+    owner = data;
+
+    ctx = seed_context_create (group, NULL);
+    seed_prepare_global_context (ctx);
+    if (ctx == NULL)
+      {
+	//        big_debug(BIG_DEBUG_JS_DBUS,
+	//          "Closure destroyed before we could notify name acquired");
+        return;
+      }
+
+    argc = 1;
+
+    argv[0] = seed_value_from_string (ctx, name, &exception);
+
+    seed_closure_invoke_with_context(ctx, owner->acquired_closure,
+				     argv, argc, &exception);
+    
+    seed_context_unref (ctx);
+}
+
+
+static void
+on_name_lost(DBusConnection *connection,
+                 const char     *name,
+                 void           *data)
+{
+    int argc;
+    SeedValue argv[1];
+    SeedContext ctx;
+    BigJSDBusNameOwner *owner;
+    SeedException exception; // TODO: Do something with this...
+
+    owner = data;
+
+    ctx = seed_context_create (group, NULL);
+    seed_prepare_global_context (ctx);
+    if (ctx == NULL)
+      {
+	//        big_debug(BIG_DEBUG_JS_DBUS,
+	//          "Closure destroyed before we could notify name acquired");
+        return;
+      }
+
+    argc = 1;
+
+    argv[0] = seed_value_from_string (ctx, name, &exception);
+
+    seed_closure_invoke_with_context(ctx, owner->lost_closure,
+				     argv, argc, &exception);
+    
+    seed_context_unref (ctx);
+}
+
 static SeedValue
 seed_js_dbus_signature_length (SeedContext ctx,
 			       SeedObject function,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]