2005-06-27 Colin Walters <walters@verbum.org>
authorColin Walters <walters@verbum.org>
Mon, 27 Jun 2005 18:20:20 +0000 (18:20 +0000)
committerColin Walters <walters@verbum.org>
Mon, 27 Jun 2005 18:20:20 +0000 (18:20 +0000)
* test/glib/test-dbus-glib.c:
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
Test hash table signal emitting.

* glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): Convert
types to their fundamental basis types, since this is what
marshallers operate on.  Also add an entry for VOID__BOXED.
(dbus_g_object_register_marshaller_array): Convert to fundamental.

ChangeLog
glib/dbus-gobject.c
test/glib/test-dbus-glib.c
test/glib/test-service-glib.c
test/glib/test-service-glib.xml

index f8517c6..6253b8f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-06-27  Colin Walters  <walters@verbum.org>
+
+       * test/glib/test-dbus-glib.c: 
+       * test/glib/test-service-glib.c:
+       * test/glib/test-service-glib.xml:
+       Test hash table signal emitting.
+
+       * glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): Convert
+       types to their fundamental basis types, since this is what
+       marshallers operate on.  Also add an entry for VOID__BOXED.
+       (dbus_g_object_register_marshaller_array): Convert to fundamental.
+
 2005-06-26  Havoc Pennington  <hp@redhat.com>
 
        * doc/dbus-tutorial.xml: fix names of interface/service/path, fix
index 0052890..93c65a2 100644 (file)
@@ -1429,10 +1429,18 @@ _dbus_gobject_lookup_marshaller (GType        rettype,
 {
   GClosureMarshal ret;
   DBusGFuncSignature sig;
+  GType *params;
+  guint i;
+
+  /* Convert to fundamental types */
+  rettype = G_TYPE_FUNDAMENTAL (rettype);
+  params = g_new (GType, n_params);
+  for (i = 0; i < n_params; i++)
+    params[i] = G_TYPE_FUNDAMENTAL (param_types[i]);
 
   sig.rettype = rettype;
   sig.n_params = n_params;
-  sig.params = (GType*) param_types;
+  sig.params = params;
   
   g_static_rw_lock_reader_lock (&globals_lock);
 
@@ -1451,7 +1459,7 @@ _dbus_gobject_lookup_marshaller (GType        rettype,
            ret = g_cclosure_marshal_VOID__VOID;
          else if (n_params == 1)
            {
-             switch (param_types[0])
+             switch (params[0])
                {
                case G_TYPE_BOOLEAN:
                  ret = g_cclosure_marshal_VOID__BOOLEAN;
@@ -1471,18 +1479,22 @@ _dbus_gobject_lookup_marshaller (GType        rettype,
                case G_TYPE_STRING:
                  ret = g_cclosure_marshal_VOID__STRING;
                  break;
+               case G_TYPE_BOXED:
+                 ret = g_cclosure_marshal_VOID__BOXED;
+                 break;
                }
            }
        }
       else if (n_params == 3
-              && param_types[0] == G_TYPE_STRING
-              && param_types[1] == G_TYPE_STRING
-              && param_types[2] == G_TYPE_STRING)
+              && params[0] == G_TYPE_STRING
+              && params[1] == G_TYPE_STRING
+              && params[2] == G_TYPE_STRING)
        {
          ret = _dbus_g_marshal_NONE__STRING_STRING_STRING;
        }
     }
 
+  g_free (params);
   return ret;
 }
 
@@ -1536,6 +1548,7 @@ dbus_g_object_register_marshaller_array (GClosureMarshal  marshaller,
                                         const GType*     types)
 {
   DBusGFuncSignature *sig;
+  guint i;
 
   g_static_rw_lock_writer_lock (&globals_lock);
 
@@ -1545,10 +1558,11 @@ dbus_g_object_register_marshaller_array (GClosureMarshal  marshaller,
                                           g_free,
                                           NULL);
   sig = g_new0 (DBusGFuncSignature, 1);
-  sig->rettype = rettype;
+  sig->rettype = G_TYPE_FUNDAMENTAL (rettype);
   sig->n_params = n_types;
   sig->params = g_new (GType, n_types);
-  memcpy (sig->params, types, n_types * sizeof (GType));
+  for (i = 0; i < n_types; i++)
+    sig->params[i] = G_TYPE_FUNDAMENTAL (types[i]);
 
   g_hash_table_insert (marshal_table, sig, marshaller);
 
index 94aeaeb..5928491 100644 (file)
@@ -14,6 +14,7 @@ static int n_times_foo_received = 0;
 static int n_times_frobnicate_received = 0;
 static int n_times_sig0_received = 0;
 static int n_times_sig1_received = 0;
+static int n_times_sig2_received = 0;
 static guint exit_timeout = 0;
 
 static gboolean
@@ -84,6 +85,24 @@ sig1_signal_handler (DBusGProxy  *proxy,
   g_source_remove (exit_timeout);
 }
 
+static void
+sig2_signal_handler (DBusGProxy  *proxy,
+                    GHashTable  *table,
+                    void        *user_data)
+{
+  n_times_sig2_received += 1;
+
+  g_assert (g_hash_table_size (table) == 2);
+
+  g_assert (g_hash_table_lookup (table, "baz") != NULL);
+  g_assert (!strcmp (g_hash_table_lookup (table, "baz"), "cow"));
+  g_assert (g_hash_table_lookup (table, "bar") != NULL);
+  g_assert (!strcmp (g_hash_table_lookup (table, "bar"), "foo"));
+
+  g_main_loop_quit (loop);
+  g_source_remove (exit_timeout);
+}
+
 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
 static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
 
@@ -721,7 +740,8 @@ main (int argc, char **argv)
                                     G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
 
   dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID);
-  dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE);
+  dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
+  dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID);
   
   dbus_g_proxy_connect_signal (proxy, "Sig0",
                                G_CALLBACK (sig0_signal_handler),
@@ -729,6 +749,9 @@ main (int argc, char **argv)
   dbus_g_proxy_connect_signal (proxy, "Sig1",
                                G_CALLBACK (sig1_signal_handler),
                                NULL, NULL);
+  dbus_g_proxy_connect_signal (proxy, "Sig2",
+                               G_CALLBACK (sig2_signal_handler),
+                               NULL, NULL);
 
   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
 
@@ -743,6 +766,15 @@ main (int argc, char **argv)
   if (n_times_sig1_received != 1)
     lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received);
 
+  dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID);
+  dbus_g_connection_flush (connection);
+
+  exit_timeout = g_timeout_add (5000, timed_exit, loop);
+  g_main_loop_run (loop);
+
+  if (n_times_sig2_received != 1)
+    lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received);
+
   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
   dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID);
 
index 21c4458..46421d7 100644 (file)
@@ -79,6 +79,7 @@ gboolean my_object_get_val (MyObject *obj, guint *ret, GError **error);
 gboolean my_object_get_value (MyObject *obj, guint *ret, GError **error);
 
 gboolean my_object_emit_signals (MyObject *obj, GError **error);
+gboolean my_object_emit_signal2 (MyObject *obj, GError **error);
 
 gboolean my_object_emit_frobnicate (MyObject *obj, GError **error);
 
@@ -98,6 +99,7 @@ enum
   FROBNICATE,
   SIG0,
   SIG1,
+  SIG2,
   LAST_SIGNAL
 };
 
@@ -206,6 +208,15 @@ my_object_class_init (MyObjectClass *mobject_class)
                   NULL, NULL,
                   my_object_marshal_VOID__STRING_BOXED,
                   G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
+
+  signals[SIG2] =
+    g_signal_new ("sig2",
+                 G_OBJECT_CLASS_TYPE (mobject_class),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__BOXED,
+                  G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE);
 }
 
 GQuark
@@ -438,6 +449,19 @@ my_object_emit_signals (MyObject *obj, GError **error)
   return TRUE;
 }
 
+gboolean
+my_object_emit_signal2 (MyObject *obj, GError **error)
+{
+  GHashTable *table;
+
+  table = g_hash_table_new (g_str_hash, g_str_equal);
+  g_hash_table_insert (table, "baz", "cow");
+  g_hash_table_insert (table, "bar", "foo");
+  g_signal_emit (obj, signals[SIG2], 0, table);
+  g_hash_table_destroy (table);
+  return TRUE;
+}
+
 static GMainLoop *loop;
 
 #define TEST_SERVICE_NAME "org.freedesktop.DBus.TestSuiteGLibService"
index 05cb5ab..e2197ec 100644 (file)
 
     <signal name="Sig1"/>
 
+    <method name="EmitSignal2">
+    </method>
+
+    <signal name="Sig2"/>
+
   </interface>
 
 </node>