| |
@@ -0,0 +1,435 @@
|
| |
+ From 1debd9a68b0f7cbfeef99428b6d9c3dfacdc6976 Mon Sep 17 00:00:00 2001
|
| |
+ From: Valentin Blot <freedesktop-devel@valentinblot.org>
|
| |
+ Date: Thu, 28 Jun 2018 10:28:57 +0200
|
| |
+ Subject: [PATCH 1/2] agent: Unimplement unused interface GAsyncInitable
|
| |
+
|
| |
+ The GAsyncInitable interface that was implemented by the agent was not
|
| |
+ useful. This commit removes this interface implementation to simplify the
|
| |
+ code and allow the use of user_data for other things.
|
| |
+ ---
|
| |
+ demo/agent.c | 25 +-------
|
| |
+ demo/gclue-service-agent.c | 119 ++++++++++---------------------------
|
| |
+ demo/gclue-service-agent.h | 10 +---
|
| |
+ 3 files changed, 37 insertions(+), 117 deletions(-)
|
| |
+
|
| |
+ diff --git a/demo/agent.c b/demo/agent.c
|
| |
+ index 23f9c6d..8e2a3ef 100644
|
| |
+ --- a/demo/agent.c
|
| |
+ +++ b/demo/agent.c
|
| |
+ @@ -44,32 +44,15 @@ static GOptionEntry entries[] =
|
| |
+ { NULL }
|
| |
+ };
|
| |
+
|
| |
+ -GDBusConnection *connection;
|
| |
+ -GMainLoop *main_loop;
|
| |
+ GClueServiceAgent *agent = NULL;
|
| |
+
|
| |
+ -static void
|
| |
+ -on_service_agent_ready (GObject *source_object,
|
| |
+ - GAsyncResult *res,
|
| |
+ - gpointer user_data)
|
| |
+ -{
|
| |
+ - GError *error = NULL;
|
| |
+ -
|
| |
+ - agent = gclue_service_agent_new_finish (res, &error);
|
| |
+ - if (agent == NULL) {
|
| |
+ - g_critical ("Failed to launch agent service: %s", error->message);
|
| |
+ - g_error_free (error);
|
| |
+ -
|
| |
+ - exit (-3);
|
| |
+ - }
|
| |
+ -}
|
| |
+ -
|
| |
+ static void
|
| |
+ on_get_bus_ready (GObject *source_object,
|
| |
+ GAsyncResult *res,
|
| |
+ gpointer user_data)
|
| |
+ {
|
| |
+ GError *error = NULL;
|
| |
+ + GDBusConnection *connection;
|
| |
+
|
| |
+ connection = g_bus_get_finish (res, &error);
|
| |
+ if (connection == NULL) {
|
| |
+ @@ -80,10 +63,7 @@ on_get_bus_ready (GObject *source_object,
|
| |
+ exit (-2);
|
| |
+ }
|
| |
+
|
| |
+ - gclue_service_agent_new_async (connection,
|
| |
+ - NULL,
|
| |
+ - on_service_agent_ready,
|
| |
+ - NULL);
|
| |
+ + agent = gclue_service_agent_new (connection);
|
| |
+ }
|
| |
+
|
| |
+ #define ABS_PATH ABS_SRCDIR "/agent"
|
| |
+ @@ -91,6 +71,7 @@ on_get_bus_ready (GObject *source_object,
|
| |
+ int
|
| |
+ main (int argc, char **argv)
|
| |
+ {
|
| |
+ + GMainLoop *main_loop;
|
| |
+ GError *error = NULL;
|
| |
+ GOptionContext *context;
|
| |
+
|
| |
+ diff --git a/demo/gclue-service-agent.c b/demo/gclue-service-agent.c
|
| |
+ index c4573a7..bd0563c 100644
|
| |
+ --- a/demo/gclue-service-agent.c
|
| |
+ +++ b/demo/gclue-service-agent.c
|
| |
+ @@ -31,18 +31,20 @@
|
| |
+
|
| |
+ #define AGENT_PATH "/org/freedesktop/GeoClue2/Agent"
|
| |
+
|
| |
+ +#define SERVICE "org.freedesktop.GeoClue2"
|
| |
+ +#define MANAGER_PATH "/org/freedesktop/GeoClue2/Manager"
|
| |
+ +#define MANAGER_INTERFACE "org.freedesktop.GeoClue2.Manager"
|
| |
+ +
|
| |
+ static void
|
| |
+ gclue_service_agent_agent_iface_init (GClueAgentIface *iface);
|
| |
+ static void
|
| |
+ -gclue_service_agent_async_initable_init (GAsyncInitableIface *iface);
|
| |
+ +gclue_service_agent_constructed (GObject *object);
|
| |
+
|
| |
+ G_DEFINE_TYPE_WITH_CODE (GClueServiceAgent,
|
| |
+ gclue_service_agent,
|
| |
+ GCLUE_TYPE_AGENT_SKELETON,
|
| |
+ G_IMPLEMENT_INTERFACE (GCLUE_TYPE_AGENT,
|
| |
+ - gclue_service_agent_agent_iface_init)
|
| |
+ - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
| |
+ - gclue_service_agent_async_initable_init))
|
| |
+ + gclue_service_agent_agent_iface_init))
|
| |
+
|
| |
+ struct _GClueServiceAgentPrivate
|
| |
+ {
|
| |
+ @@ -114,6 +116,7 @@ gclue_service_agent_class_init (GClueServiceAgentClass *klass)
|
| |
+ object_class->finalize = gclue_service_agent_finalize;
|
| |
+ object_class->get_property = gclue_service_agent_get_property;
|
| |
+ object_class->set_property = gclue_service_agent_set_property;
|
| |
+ + object_class->constructed = gclue_service_agent_constructed;
|
| |
+
|
| |
+ g_type_class_add_private (object_class, sizeof (GClueServiceAgentPrivate));
|
| |
+
|
| |
+ @@ -141,22 +144,11 @@ on_add_agent_ready (GObject *source_object,
|
| |
+ GAsyncResult *res,
|
| |
+ gpointer user_data)
|
| |
+ {
|
| |
+ - GTask *task = G_TASK (user_data);
|
| |
+ - GVariant *results;
|
| |
+ GError *error = NULL;
|
| |
+
|
| |
+ - results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
|
| |
+ - res,
|
| |
+ - &error);
|
| |
+ - if (results == NULL) {
|
| |
+ - g_task_return_error (task, error);
|
| |
+ - g_object_unref (task);
|
| |
+ - return;
|
| |
+ - }
|
| |
+ -
|
| |
+ - g_task_return_boolean (task, TRUE);
|
| |
+ -
|
| |
+ - g_object_unref (task);
|
| |
+ + g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
|
| |
+ + res,
|
| |
+ + &error);
|
| |
+ }
|
| |
+
|
| |
+ static void
|
| |
+ @@ -201,19 +193,21 @@ on_manager_proxy_ready (GObject *source_object,
|
| |
+ GAsyncResult *res,
|
| |
+ gpointer user_data)
|
| |
+ {
|
| |
+ - GTask *task = G_TASK (user_data);
|
| |
+ GClueAgent *agent;
|
| |
+ GDBusProxy *proxy;
|
| |
+ GError *error = NULL;
|
| |
+
|
| |
+ proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
| |
+ if (proxy == NULL) {
|
| |
+ - g_task_return_error (task, error);
|
| |
+ - g_object_unref (task);
|
| |
+ + g_critical ("Failed to create proxy to %s: %s",
|
| |
+ + MANAGER_PATH,
|
| |
+ + error->message);
|
| |
+ + g_error_free (error);
|
| |
+ +
|
| |
+ return;
|
| |
+ }
|
| |
+
|
| |
+ - agent = GCLUE_AGENT (g_task_get_source_object (task));
|
| |
+ + agent = GCLUE_AGENT (user_data);
|
| |
+ gclue_agent_set_max_accuracy_level (agent, GCLUE_ACCURACY_LEVEL_EXACT);
|
| |
+
|
| |
+ g_dbus_proxy_call (proxy,
|
| |
+ @@ -222,55 +216,37 @@ on_manager_proxy_ready (GObject *source_object,
|
| |
+ "geoclue-demo-agent"),
|
| |
+ G_DBUS_CALL_FLAGS_NONE,
|
| |
+ -1,
|
| |
+ - g_task_get_cancellable (task),
|
| |
+ + NULL,
|
| |
+ on_add_agent_ready,
|
| |
+ - task);
|
| |
+ + NULL);
|
| |
+ print_in_use_info (proxy);
|
| |
+ g_signal_connect (proxy,
|
| |
+ "g-properties-changed",
|
| |
+ G_CALLBACK (on_manager_props_changed),
|
| |
+ - agent);
|
| |
+ + NULL);
|
| |
+ }
|
| |
+
|
| |
+ static void
|
| |
+ -gclue_service_agent_init_async (GAsyncInitable *initable,
|
| |
+ - int io_priority,
|
| |
+ - GCancellable *cancellable,
|
| |
+ - GAsyncReadyCallback callback,
|
| |
+ - gpointer user_data)
|
| |
+ +gclue_service_agent_constructed (GObject *object)
|
| |
+ {
|
| |
+ - GTask *task;
|
| |
+ GError *error = NULL;
|
| |
+ -
|
| |
+ - task = g_task_new (initable, cancellable, callback, user_data);
|
| |
+ -
|
| |
+ if (!g_dbus_interface_skeleton_export
|
| |
+ - (G_DBUS_INTERFACE_SKELETON (initable),
|
| |
+ - GCLUE_SERVICE_AGENT (initable)->priv->connection,
|
| |
+ + (G_DBUS_INTERFACE_SKELETON (object),
|
| |
+ + GCLUE_SERVICE_AGENT (object)->priv->connection,
|
| |
+ AGENT_PATH,
|
| |
+ &error)) {
|
| |
+ - g_task_return_error (task, error);
|
| |
+ - g_object_unref (task);
|
| |
+ return;
|
| |
+ }
|
| |
+
|
| |
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
|
| |
+ G_DBUS_PROXY_FLAGS_NONE,
|
| |
+ NULL,
|
| |
+ - "org.freedesktop.GeoClue2",
|
| |
+ - "/org/freedesktop/GeoClue2/Manager",
|
| |
+ - "org.freedesktop.GeoClue2.Manager",
|
| |
+ - cancellable,
|
| |
+ + SERVICE,
|
| |
+ + MANAGER_PATH,
|
| |
+ + MANAGER_INTERFACE,
|
| |
+ + NULL,
|
| |
+ on_manager_proxy_ready,
|
| |
+ - task);
|
| |
+ -}
|
| |
+ -
|
| |
+ -static gboolean
|
| |
+ -gclue_service_agent_init_finish (GAsyncInitable *initable,
|
| |
+ - GAsyncResult *result,
|
| |
+ - GError **error)
|
| |
+ -{
|
| |
+ - return g_task_propagate_boolean (G_TASK (result), error);
|
| |
+ + object);
|
| |
+ }
|
| |
+
|
| |
+ typedef struct
|
| |
+ @@ -405,42 +381,11 @@ gclue_service_agent_agent_iface_init (GClueAgentIface *iface)
|
| |
+ iface->handle_authorize_app = gclue_service_agent_handle_authorize_app;
|
| |
+ }
|
| |
+
|
| |
+ -static void
|
| |
+ -gclue_service_agent_async_initable_init (GAsyncInitableIface *iface)
|
| |
+ -{
|
| |
+ - iface->init_async = gclue_service_agent_init_async;
|
| |
+ - iface->init_finish = gclue_service_agent_init_finish;
|
| |
+ -}
|
| |
+ -
|
| |
+ -void
|
| |
+ -gclue_service_agent_new_async (GDBusConnection *connection,
|
| |
+ - GCancellable *cancellable,
|
| |
+ - GAsyncReadyCallback callback,
|
| |
+ - gpointer user_data)
|
| |
+ -{
|
| |
+ - g_async_initable_new_async (GCLUE_TYPE_SERVICE_AGENT,
|
| |
+ - G_PRIORITY_DEFAULT,
|
| |
+ - cancellable,
|
| |
+ - callback,
|
| |
+ - user_data,
|
| |
+ - "connection", connection,
|
| |
+ - NULL);
|
| |
+ -}
|
| |
+ -
|
| |
+ GClueServiceAgent *
|
| |
+ -gclue_service_agent_new_finish (GAsyncResult *res,
|
| |
+ - GError **error)
|
| |
+ +gclue_service_agent_new (GDBusConnection *connection)
|
| |
+ {
|
| |
+ - GObject *object;
|
| |
+ - GObject *source_object;
|
| |
+ -
|
| |
+ - source_object = g_async_result_get_source_object (res);
|
| |
+ - object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
|
| |
+ - res,
|
| |
+ - error);
|
| |
+ - g_object_unref (source_object);
|
| |
+ - if (object != NULL)
|
| |
+ - return GCLUE_SERVICE_AGENT (object);
|
| |
+ - else
|
| |
+ - return NULL;
|
| |
+ + return g_object_new (GCLUE_TYPE_SERVICE_AGENT,
|
| |
+ + "connection",
|
| |
+ + connection,
|
| |
+ + NULL);
|
| |
+ }
|
| |
+ diff --git a/demo/gclue-service-agent.h b/demo/gclue-service-agent.h
|
| |
+ index 019a6a3..a1944a7 100644
|
| |
+ --- a/demo/gclue-service-agent.h
|
| |
+ +++ b/demo/gclue-service-agent.h
|
| |
+ @@ -53,14 +53,8 @@ struct _GClueServiceAgentClass
|
| |
+ GClueAgentSkeletonClass parent_class;
|
| |
+ };
|
| |
+
|
| |
+ -GType gclue_service_agent_get_type (void) G_GNUC_CONST;
|
| |
+ -void gclue_service_agent_new_async (GDBusConnection *connection,
|
| |
+ - GCancellable *cancellable,
|
| |
+ - GAsyncReadyCallback callback,
|
| |
+ - gpointer user_data);
|
| |
+ -GClueServiceAgent * gclue_service_agent_new_finish (GAsyncResult *res,
|
| |
+ - GError **error);
|
| |
+ -
|
| |
+ +GType gclue_service_agent_get_type (void) G_GNUC_CONST;
|
| |
+ +GClueServiceAgent * gclue_service_agent_new (GDBusConnection *connection);
|
| |
+
|
| |
+ G_END_DECLS
|
| |
+
|
| |
+ --
|
| |
+ 2.17.1
|
| |
+
|
| |
+
|
| |
+ From c8d7689687189a4b9b1676dca58e7fcf4ef21783 Mon Sep 17 00:00:00 2001
|
| |
+ From: Valentin Blot <freedesktop-devel@valentinblot.org>
|
| |
+ Date: Thu, 28 Jun 2018 10:50:49 +0200
|
| |
+ Subject: [PATCH 2/2] 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
|
| |
+ ---
|
| |
+ demo/gclue-service-agent.c | 70 ++++++++++++++++++++++++++------------
|
| |
+ 1 file 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
|
| |
+ --
|
| |
+ 2.17.1
|
| |
+
|
| |
It should fix RHBZ#1585970 https://bugzilla.redhat.com/show_bug.cgi?id=1585970