+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
{
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);
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;
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;
}
const GType* types)
{
DBusGFuncSignature *sig;
+ guint i;
g_static_rw_lock_writer_lock (&globals_lock);
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);
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
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;
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),
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);
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);
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);
FROBNICATE,
SIG0,
SIG1,
+ SIG2,
LAST_SIGNAL
};
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
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"
<signal name="Sig1"/>
+ <method name="EmitSignal2">
+ </method>
+
+ <signal name="Sig2"/>
+
</interface>
</node>