[gjs] support signals with G_TYPE_POINTER argument



commit 6fed5321c2111ef0737ed2788b3bcfd08ebc4dd5
Author: Maxim Ermilov <zaspire rambler ru>
Date:   Wed Oct 27 18:10:06 2010 +0400

    support signals with G_TYPE_POINTER argument
    
    get information about type of argument from gobject-introspection
    Example of such signal:
    evolution-data-server.libecal
    ECalView::objects-added
    https://bugzilla.gnome.org/show_bug.cgi?id=632626

 gi/value.c |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/gi/value.c b/gi/value.c
index 5999bd0..a180cdb 100644
--- a/gi/value.c
+++ b/gi/value.c
@@ -44,7 +44,9 @@ static GType _ptr_array_type = G_TYPE_INVALID;
 static JSBool gjs_value_from_g_value_internal(JSContext    *context,
                                               jsval        *value_p,
                                               const GValue *gvalue,
-                                              gboolean      no_copy);
+                                              gboolean      no_copy,
+                                              GSignalQuery *signal_query,
+                                              gint          arg_n);
 
 static void
 closure_marshal(GClosure        *closure,
@@ -114,7 +116,7 @@ closure_marshal(GClosure        *closure,
             no_copy = (signal_query.param_types[i - 1] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0;
         }
 
-        if (!gjs_value_from_g_value_internal(context, &argv[i], gval, no_copy)) {
+        if (!gjs_value_from_g_value_internal(context, &argv[i], gval, no_copy, &signal_query, i)) {
             gjs_debug(GJS_DEBUG_GCLOSURE,
                       "Unable to convert arg %d in order to invoke closure",
                       i);
@@ -516,7 +518,9 @@ static JSBool
 gjs_value_from_g_value_internal(JSContext    *context,
                                 jsval        *value_p,
                                 const GValue *gvalue,
-                                gboolean      no_copy)
+                                gboolean      no_copy,
+                                GSignalQuery *signal_query,
+                                gint          arg_n)
 {
     GType gtype;
 
@@ -637,6 +641,39 @@ gjs_value_from_g_value_internal(JSContext    *context,
 
         obj = gjs_param_from_g_param(context, gparam);
         *value_p = OBJECT_TO_JSVAL(obj);
+    } else if (signal_query && g_type_is_a(gtype, G_TYPE_POINTER)) {
+        JSBool res;
+        GArgument arg;
+        GIArgInfo *arg_info;
+        GIBaseInfo *obj;
+        GISignalInfo *signal_info;
+        GITypeInfo type_info;
+
+        obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
+        if (!obj) {
+            gjs_throw(context, "Signal argument with GType %s isn't introspectable",
+                      g_type_name(signal_query->itype));
+            return JS_FALSE;
+        }
+
+        signal_info = g_object_info_find_signal((GIObjectInfo*)obj, signal_query->signal_name);
+
+        if (!signal_info) {
+            gjs_throw(context, "Unknown signal.");
+            g_base_info_unref((GIBaseInfo*)obj);
+            return JS_FALSE;
+        }
+        arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
+        g_arg_info_load_type(arg_info, &type_info);
+
+        arg.v_pointer = g_value_get_pointer(gvalue);
+
+        res = gjs_value_from_g_argument(context, value_p, &type_info, &arg);
+
+        g_base_info_unref((GIBaseInfo*)arg_info);
+        g_base_info_unref((GIBaseInfo*)signal_info);
+        g_base_info_unref((GIBaseInfo*)obj);
+        return res;
     } else if (g_type_is_a(gtype, G_TYPE_POINTER)) {
         gpointer pointer;
 
@@ -678,7 +715,7 @@ gjs_value_from_g_value(JSContext    *context,
                        jsval        *value_p,
                        const GValue *gvalue)
 {
-    return gjs_value_from_g_value_internal(context, value_p, gvalue, FALSE);
+    return gjs_value_from_g_value_internal(context, value_p, gvalue, FALSE, NULL, 0);
 }
 
 __attribute__((constructor)) static void



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