[seed] Add seed_closure_invoke_with_context to the PI
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Add seed_closure_invoke_with_context to the PI
- Date: Sat, 9 May 2009 18:23:54 -0400 (EDT)
commit 4caea71acf3741bf40ba54734b7e121586863dc5
Author: Robert Carr <racarr svn gnome org>
Date: Sat May 9 18:23:45 2009 -0400
Add seed_closure_invoke_with_context to the PI
---
libseed/seed-closure.c | 16 +++++++++++++
libseed/seed-closure.h | 2 +
libseed/seed.h | 3 ++
modules/dbus/module.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index 978669e..9ef21a9 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -359,6 +359,22 @@ seed_closure_invoke (GClosure *closure, JSValueRef *args, guint argc, JSValueRef
return ret;
}
+JSValueRef
+seed_closure_invoke_with_context (JSContextRef ctx, GClosure *closure, JSValueRef *args, guint argc, JSValueRef *exception)
+{
+ JSValueRef *real_args = g_newa (JSValueRef, argc +1);
+ JSValueRef ret;
+ guint i;
+
+ for (i = 0; i < argc; i++)
+ real_args[i] = args[i];
+ args[argc] = ((SeedClosure *)closure)->user_data ? ((SeedClosure *)closure)->user_data : JSValueMakeNull (ctx);
+
+ ret = JSObjectCallAsFunction (ctx, ((SeedClosure *)closure)->function, NULL, argc+1, real_args, exception);
+
+ return ret;
+}
+
GClosure *
seed_make_gclosure (JSContextRef ctx, JSObjectRef function, JSObjectRef user_data)
{
diff --git a/libseed/seed-closure.h b/libseed/seed-closure.h
index 59bfcfd..3b403ef 100644
--- a/libseed/seed-closure.h
+++ b/libseed/seed-closure.h
@@ -62,6 +62,8 @@ seed_closure_get_callable (GClosure *c);
JSValueRef
seed_closure_invoke (GClosure *closure, JSValueRef *args, guint argc, JSValueRef *exception);
+JSValueRef
+seed_closure_invoke_with_context (JSContextRef ctx, GClosure *closure, JSValueRef *args, guint argc, JSValueRef *exception);
diff --git a/libseed/seed.h b/libseed/seed.h
index 28353fb..9ff63a1 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -400,5 +400,8 @@ seed_closure_get_callable (GClosure *c);
SeedValue
seed_closure_invoke (GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
+SeedValue
+seed_closure_invoke_with_context (SeedContext ctx, GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
+
#endif
diff --git a/modules/dbus/module.c b/modules/dbus/module.c
index b0cf493..89daeff 100644
--- a/modules/dbus/module.c
+++ b/modules/dbus/module.c
@@ -214,6 +214,63 @@ complete_call(SeedContext ctx,
return TRUE;
}
+static void
+pending_notify(DBusPendingCall *pending,
+ void *user_data)
+{
+ SeedException exception;
+ SeedContext ctx;
+ GClosure *closure;
+ SeedValue argv[2];
+ DBusMessage *reply;
+ DBusError derror;
+
+ closure = user_data;
+
+// big_debug(BIG_DEBUG_JS_DBUS,
+ // "Notified of reply to async call closure %p context %p",
+ // closure, context);
+
+// if (context == NULL) {
+ // big_debug(BIG_DEBUG_JS_DBUS,
+ // "Closure destroyed before we could complete pending call");
+ // return;
+// }
+
+ /* reply may be NULL if none received? I think it may never be if
+ * we've already been notified, but be safe here.
+ */
+
+ ctx = seed_context_create (group, NULL);
+ seed_prepare_global_context (ctx);
+ reply = dbus_pending_call_steal_reply(pending);
+
+ dbus_error_init(&derror);
+ /* argv[0] will be the return value if any, argv[1] we fill with exception if any */
+ 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);
+
+ seed_closure_invoke_with_context(ctx, closure, &argv[0], 2, &exception);
+ seed_context_unref (ctx);
+ // TODO: Do something with exception
+}
+
+static void
+pending_free_closure(void *data)
+{
+ GClosure *closure;
+
+ closure = data;
+
+ g_closure_invalidate(data);
+ g_closure_unref(data);
+}
+
+
+
static SeedValue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]