diff options
author | Valentin Blot <freedesktop-devel@valentinblot.org> | 2018-06-28 10:50:49 +0200 |
---|---|---|
committer | Zeeshan Ali <zeenix@collabora.co.uk> | 2018-06-29 16:03:58 +0200 |
commit | c8d7689687189a4b9b1676dca58e7fcf4ef21783 (patch) | |
tree | 5399d524001511fd3bc17c0ccebd6702274b5b59 /demo/gclue-service-agent.c | |
parent | 1debd9a68b0f7cbfeef99428b6d9c3dfacdc6976 (diff) | |
download | geoclue-c8d7689687189a4b9b1676dca58e7fcf4ef21783.tar.gz |
agent: Register the agent whenever geoclue starts
The agent watches on d-bus and registers whenever it sees geoclue getting
alive.
https://gitlab.freedesktop.org/geoclue/geoclue/issues/68
Diffstat (limited to 'demo/gclue-service-agent.c')
-rw-r--r-- | demo/gclue-service-agent.c | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/demo/gclue-service-agent.c b/demo/gclue-service-agent.c index bd0563c..6f2e227 100644 --- a/demo/gclue-service-agent.c +++ b/demo/gclue-service-agent.c @@ -49,6 +49,7 @@ G_DEFINE_TYPE_WITH_CODE (GClueServiceAgent, struct _GClueServiceAgentPrivate { GDBusConnection *connection; + GDBusProxy *manager_proxy; }; enum @@ -193,24 +194,21 @@ on_manager_proxy_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GClueAgent *agent; - GDBusProxy *proxy; + GClueServiceAgent *agent; GError *error = NULL; + agent = GCLUE_SERVICE_AGENT (user_data); - proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - if (proxy == NULL) { + agent->priv->manager_proxy = g_dbus_proxy_new_for_bus_finish (res, + &error); + if (agent->priv->manager_proxy == NULL) { g_critical ("Failed to create proxy to %s: %s", MANAGER_PATH, error->message); g_error_free (error); - return; } - agent = GCLUE_AGENT (user_data); - gclue_agent_set_max_accuracy_level (agent, GCLUE_ACCURACY_LEVEL_EXACT); - - g_dbus_proxy_call (proxy, + g_dbus_proxy_call (agent->priv->manager_proxy, "AddAgent", g_variant_new ("(s)", "geoclue-demo-agent"), @@ -219,25 +217,19 @@ on_manager_proxy_ready (GObject *source_object, NULL, on_add_agent_ready, NULL); - print_in_use_info (proxy); - g_signal_connect (proxy, + print_in_use_info (agent->priv->manager_proxy); + g_signal_connect (agent->priv->manager_proxy, "g-properties-changed", G_CALLBACK (on_manager_props_changed), NULL); } static void -gclue_service_agent_constructed (GObject *object) +on_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) { - GError *error = NULL; - if (!g_dbus_interface_skeleton_export - (G_DBUS_INTERFACE_SKELETON (object), - GCLUE_SERVICE_AGENT (object)->priv->connection, - AGENT_PATH, - &error)) { - return; - } - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -246,7 +238,41 @@ gclue_service_agent_constructed (GObject *object) MANAGER_INTERFACE, NULL, on_manager_proxy_ready, - object); + user_data); +} + +static void +on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + GClueServiceAgent *agent = GCLUE_SERVICE_AGENT (user_data); + + g_clear_object (&agent->priv->manager_proxy); +} + +static void +gclue_service_agent_constructed (GObject *object) +{ + GError *error = NULL; + GClueServiceAgent *agent = GCLUE_SERVICE_AGENT (object); + if (!g_dbus_interface_skeleton_export + (G_DBUS_INTERFACE_SKELETON (agent), + agent->priv->connection, + AGENT_PATH, + &error)) { + return; + } + gclue_agent_set_max_accuracy_level (GCLUE_AGENT (agent), + GCLUE_ACCURACY_LEVEL_EXACT); + g_bus_watch_name (G_BUS_TYPE_SYSTEM, + SERVICE, + G_BUS_NAME_WATCHER_FLAGS_NONE, + on_name_appeared, + on_name_vanished, + agent, + NULL); + } typedef struct |