#include "gdbusconnection.h"
#include "glibintl.h"
-#include "gioalias.h"
/**
* SECTION:gdbusnamewatching
}
g_free (client->name);
g_free (client->name_owner);
- if (client->main_context != NULL)
- g_main_context_unref (client->main_context);
+ g_main_context_unref (client->main_context);
if (client->user_data_free_func != NULL)
client->user_data_free_func (client->user_data);
g_free (client);
static void
do_call (Client *client, CallType call_type)
{
+ GMainContext *current_context;
+
/* only schedule in idle if we're not in the right thread */
- if (g_main_context_get_thread_default () != client->main_context)
+ current_context = g_main_context_ref_thread_default ();
+ if (current_context != client->main_context)
schedule_call_in_idle (client, call_type);
else
actually_do_call (client, client->connection, client->name_owner, call_type);
+ g_main_context_unref (current_context);
}
static void
"org.freedesktop.DBus", /* interface name */
"GetNameOwner", /* method name */
g_variant_new ("(s)", client->name),
+ G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
"NameOwnerChanged", /* signal */
"/org/freedesktop/DBus", /* path */
client->name,
+ G_DBUS_SIGNAL_FLAGS_NONE,
on_name_owner_changed,
client,
NULL);
"org.freedesktop.DBus", /* interface name */
"StartServiceByName", /* method name */
g_variant_new ("(su)", client->name, 0),
+ G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
client->name_vanished_handler = name_vanished_handler;
client->user_data = user_data;
client->user_data_free_func = user_data_free_func;
- client->main_context = g_main_context_get_thread_default ();
- if (client->main_context != NULL)
- g_main_context_ref (client->main_context);
+ client->main_context = g_main_context_ref_thread_default ();
if (map_id_to_client == NULL)
{
/**
* g_bus_watch_name_on_connection:
- * @connection: A #GDBusConnection that is not closed.
+ * @connection: A #GDBusConnection.
* @name: The name (well-known or unique) to watch.
* @flags: Flags from the #GBusNameWatcherFlags enumeration.
* @name_appeared_handler: Handler to invoke when @name is known to exist or %NULL.
client->name_vanished_handler = name_vanished_handler;
client->user_data = user_data;
client->user_data_free_func = user_data_free_func;
- client->main_context = g_main_context_get_thread_default ();
- if (client->main_context != NULL)
- g_main_context_ref (client->main_context);
+ client->main_context = g_main_context_ref_thread_default ();
if (map_id_to_client == NULL)
- {
- map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
- }
+ map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
+
g_hash_table_insert (map_id_to_client,
GUINT_TO_POINTER (client->id),
client);
return client->id;
}
+typedef struct {
+ GClosure *name_appeared_closure;
+ GClosure *name_vanished_closure;
+} WatchNameData;
+
+static WatchNameData *
+watch_name_data_new (GClosure *name_appeared_closure,
+ GClosure *name_vanished_closure)
+{
+ WatchNameData *data;
+
+ data = g_new0 (WatchNameData, 1);
+
+ if (name_appeared_closure != NULL)
+ {
+ data->name_appeared_closure = g_closure_ref (name_appeared_closure);
+ g_closure_sink (name_appeared_closure);
+ if (G_CLOSURE_NEEDS_MARSHAL (name_appeared_closure))
+ g_closure_set_marshal (name_appeared_closure, g_cclosure_marshal_generic);
+ }
+
+ if (name_vanished_closure != NULL)
+ {
+ data->name_vanished_closure = g_closure_ref (name_vanished_closure);
+ g_closure_sink (name_vanished_closure);
+ if (G_CLOSURE_NEEDS_MARSHAL (name_vanished_closure))
+ g_closure_set_marshal (name_vanished_closure, g_cclosure_marshal_generic);
+ }
+
+ return data;
+}
+
+static void
+watch_with_closures_on_name_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ WatchNameData *data = user_data;
+ GValue params[3] = { G_VALUE_INIT, G_VALUE_INIT, G_VALUE_INIT };
+
+ g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
+ g_value_set_object (¶ms[0], connection);
+
+ g_value_init (¶ms[1], G_TYPE_STRING);
+ g_value_set_string (¶ms[1], name);
+
+ g_value_init (¶ms[2], G_TYPE_STRING);
+ g_value_set_string (¶ms[2], name_owner);
+
+ g_closure_invoke (data->name_appeared_closure, NULL, 3, params, NULL);
+
+ g_value_unset (params + 0);
+ g_value_unset (params + 1);
+ g_value_unset (params + 2);
+}
+
+static void
+watch_with_closures_on_name_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ WatchNameData *data = user_data;
+ GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
+
+ g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
+ g_value_set_object (¶ms[0], connection);
+
+ g_value_init (¶ms[1], G_TYPE_STRING);
+ g_value_set_string (¶ms[1], name);
+
+ g_closure_invoke (data->name_vanished_closure, NULL, 2, params, NULL);
+
+ g_value_unset (params + 0);
+ g_value_unset (params + 1);
+}
+
+static void
+bus_watch_name_free_func (gpointer user_data)
+{
+ WatchNameData *data = user_data;
+
+ if (data->name_appeared_closure != NULL)
+ g_closure_unref (data->name_appeared_closure);
+
+ if (data->name_vanished_closure != NULL)
+ g_closure_unref (data->name_vanished_closure);
+
+ g_free (data);
+}
+
+/**
+ * g_bus_watch_name_with_closures:
+ * @bus_type: The type of bus to watch a name on.
+ * @name: The name (well-known or unique) to watch.
+ * @flags: Flags from the #GBusNameWatcherFlags enumeration.
+ * @name_appeared_closure: (allow-none): #GClosure to invoke when @name is known
+ * to exist or %NULL.
+ * @name_vanished_closure: (allow-none): #GClosure to invoke when @name is known
+ * to not exist or %NULL.
+ *
+ * Version of g_bus_watch_name() using closures instead of callbacks for
+ * easier binding in other languages.
+ *
+ * Returns: An identifier (never 0) that an be used with
+ * g_bus_unwatch_name() to stop watching the name.
+ *
+ * Rename to: g_bus_watch_name
+ *
+ * Since: 2.26
+ */
+guint
+g_bus_watch_name_with_closures (GBusType bus_type,
+ const gchar *name,
+ GBusNameWatcherFlags flags,
+ GClosure *name_appeared_closure,
+ GClosure *name_vanished_closure)
+{
+ return g_bus_watch_name (bus_type,
+ name,
+ flags,
+ name_appeared_closure != NULL ? watch_with_closures_on_name_appeared : NULL,
+ name_vanished_closure != NULL ? watch_with_closures_on_name_vanished : NULL,
+ watch_name_data_new (name_appeared_closure, name_vanished_closure),
+ bus_watch_name_free_func);
+}
+
+/**
+ * g_bus_watch_name_on_connection_with_closures:
+ * @connection: A #GDBusConnection.
+ * @name: The name (well-known or unique) to watch.
+ * @flags: Flags from the #GBusNameWatcherFlags enumeration.
+ * @name_appeared_closure: (allow-none): #GClosure to invoke when @name is known
+ * to exist or %NULL.
+ * @name_vanished_closure: (allow-none): #GClosure to invoke when @name is known
+ * to not exist or %NULL.
+ *
+ * Version of g_bus_watch_name_on_connection() using closures instead of callbacks for
+ * easier binding in other languages.
+ *
+ * Returns: An identifier (never 0) that an be used with
+ * g_bus_unwatch_name() to stop watching the name.
+ *
+ * Rename to: g_bus_watch_name_on_connection
+ *
+ * Since: 2.26
+ */
+guint g_bus_watch_name_on_connection_with_closures (
+ GDBusConnection *connection,
+ const gchar *name,
+ GBusNameWatcherFlags flags,
+ GClosure *name_appeared_closure,
+ GClosure *name_vanished_closure)
+{
+ return g_bus_watch_name_on_connection (connection,
+ name,
+ flags,
+ name_appeared_closure != NULL ? watch_with_closures_on_name_appeared : NULL,
+ name_vanished_closure != NULL ? watch_with_closures_on_name_vanished : NULL,
+ watch_name_data_new (name_appeared_closure, name_vanished_closure),
+ bus_watch_name_free_func);
+}
+
/**
* g_bus_unwatch_name:
* @watcher_id: An identifier obtained from g_bus_watch_name()
client_unref (client);
}
}
-
-#define __G_DBUS_NAME_WATCHING_C__
-#include "gioaliasdef.c"