Debian Codegraph @

src/gclue-service-manager.c

raw symbols SCIP
1 /* vim: set et ts=8 sw=8: */
2 /* gclue-service-manager.c
3 *
4 * Copyright 2013 Red Hat, Inc.
5 *
6 * Geoclue is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with Geoclue; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Author: Zeeshan Ali (Khattak) <[email protected]>
21 */
22
23 #include <glib/gi18n.h>
24 #include <glib-unix.h>
25 #include <config.h>
26 #include <signal.h>
27
28 #include "gclue-service-manager.h"
29 #include "gclue-service-client.h"
30 #include "gclue-client-info.h"
31 #include "geoclue-agent-interface.h"
32 #include "gclue-enums.h"
33 #include "gclue-locator.h"
34 #include "gclue-config.h"
35
36 static void
37 gclue_service_manager_manager_iface_init (GClueDBusManagerIface *iface);
38 static void
39 gclue_service_manager_initable_iface_init (GInitableIface *iface);
40
41 struct _GClueServiceManagerPrivate
42 {
43 GDBusConnection *connection;
44 GList *clients;
45 GHashTable *agents;
46 GQueue *clients_waiting_agent;
47
48 guint last_client_id;
49 guint num_clients;
50 guint unix_signal_source;
51
52 GClueLocator *locator;
53 };
54
55 G_DEFINE_TYPE_WITH_CODE (GClueServiceManager,
56 gclue_service_manager,
57 GCLUE_DBUS_TYPE_MANAGER_SKELETON,
58 G_IMPLEMENT_INTERFACE (GCLUE_DBUS_TYPE_MANAGER,
59 gclue_service_manager_manager_iface_init)
60 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
61 gclue_service_manager_initable_iface_init)
62 G_ADD_PRIVATE (GClueServiceManager))
63
64 enum
65 {
66 PROP_0,
67 PROP_CONNECTION,
68 PROP_ACTIVE,
69 LAST_PROP
70 };
71
72 static GParamSpec *gParamSpecs[LAST_PROP];
73
74 typedef struct
75 {
76 GClueDBusManager *manager;
77 GDBusMethodInvocation *invocation;
78 GClueClientInfo *client_info;
79 gboolean reuse_client;
80
81 } OnClientInfoNewReadyData;
82
83 static gboolean
84 log_client_list (gpointer user_data)
85 {
86 GClueServiceManager *manager = GCLUE_SERVICE_MANAGER (user_data);
87 GList *l;
88
89 g_message ("SIGUSR1 received, printing client list:");
90 if (!manager->priv->clients) {
91 g_message (" (No clients)");
92 return G_SOURCE_CONTINUE;
93 }
94 g_message (" System Active UID Id");
95 for (l = manager->priv->clients; l != NULL; l = l->next) {
96 GClueDBusClient *dbus_client = GCLUE_DBUS_CLIENT (l->data);
97 GClueClientInfo *client_info =
98 gclue_service_client_get_client_info (GCLUE_SERVICE_CLIENT (l->data));
99 GClueConfig *config;
100 guint32 uid;
101 const char *system, *active, *id;
102 const char *y = "x";
103 const char *n = "-";
104 id = gclue_dbus_client_get_desktop_id (dbus_client);
105 uid = gclue_client_info_get_user_id (client_info);
106 config = gclue_config_get_singleton ();
107 system = gclue_config_is_system_component (config, id) ? y : n;
108 active = gclue_dbus_client_get_active (dbus_client) ? y : n;
109 g_message (" %s %s %-7d %s", system, active, uid, id);
110 }
111 return G_SOURCE_CONTINUE;
112 }
113
114 static void
115 on_client_info_new_ready_data_free (gpointer data)
116 {
117 g_slice_free (OnClientInfoNewReadyData, data);
118 }
119
120 static void
121 sync_in_use_property (GClueServiceManager *manager)
122 {
123 gboolean in_use = FALSE;
124 GList *l;
125 GClueDBusManager *gdbus_manager;
126
127 for (l = manager->priv->clients; l != NULL; l = l->next) {
128 GClueDBusClient *client = GCLUE_DBUS_CLIENT (l->data);
129 GClueConfig *config;
130 const char *id;
131
132 id = gclue_dbus_client_get_desktop_id (client);
133 config = gclue_config_get_singleton ();
134
135 if (gclue_dbus_client_get_active (client) &&
136 !gclue_config_is_system_component (config, id)) {
137 in_use = TRUE;
138
139 break;
140 }
141 }
142
143 gdbus_manager = GCLUE_DBUS_MANAGER (manager);
144 if (in_use != gclue_dbus_manager_get_in_use (gdbus_manager))
145 gclue_dbus_manager_set_in_use (gdbus_manager, in_use);
146 }
147
148 static int
149 compare_client_bus_name (gconstpointer a,
150 gconstpointer b)
151 {
152 GClueClientInfo *info;
153 const char *bus_name = (const char *) b;
154
155 info = gclue_service_client_get_client_info (GCLUE_SERVICE_CLIENT (a));
156
157 return g_strcmp0 (bus_name, gclue_client_info_get_bus_name (info));
158 }
159
160 static void
161 delete_client (GClueServiceManager *manager,
162 GCompareFunc compare_func,
163 gpointer compare_func_data)
164 {
165 GClueServiceManagerPrivate *priv = manager->priv;
166 GList *l;
167
168 l = priv->clients;
169 while (l != NULL) {
170 GList *next = l->next;
171
172 if (compare_func (l->data, compare_func_data) == 0) {
173 g_object_unref (G_OBJECT (l->data));
174 priv->clients = g_list_delete_link (priv->clients, l);
175 priv->num_clients--;
176 if (priv->num_clients == 0) {
177 g_object_notify (G_OBJECT (manager), "active");
178 }
179 }
180 l = next;
181 }
182
183 g_debug ("Number of connected clients: %u", priv->num_clients);
184 sync_in_use_property (manager);
185 }
186
187 static void
188 on_client_notify_active (GObject *gobject,
189 GParamSpec *pspec,
190 gpointer user_data)
191 {
192 sync_in_use_property (GCLUE_SERVICE_MANAGER (user_data));
193 }
194
195 static void
196 on_peer_vanished (GClueClientInfo *info,
197 gpointer user_data)
198 {
199 const char *bus_name;
200
201 bus_name = gclue_client_info_get_bus_name (info);
202 g_debug ("Client `%s` vanished. Dropping associated client objects",
203 bus_name);
204
205 delete_client (GCLUE_SERVICE_MANAGER (user_data),
206 compare_client_bus_name,
207 (char *) bus_name);
208 }
209
210 static gboolean
211 complete_get_client (OnClientInfoNewReadyData *data)
212 {
213 GClueServiceManagerPrivate *priv = GCLUE_SERVICE_MANAGER (data->manager)->priv;
214 GClueServiceClient *client;
215 GClueClientInfo *info = data->client_info;
216 GClueAgent *agent_proxy = NULL;
217 g_autoptr(GError) error = NULL;
218 g_autofree char *path = NULL;
219 guint32 user_id;
220
221 /* Disconnect on_peer_vanished_before_completion, if it's there */
222 g_signal_handlers_disconnect_by_data (info, data);
223
224 user_id = gclue_client_info_get_user_id (info);
225 agent_proxy = g_hash_table_lookup (priv->agents,
226 GINT_TO_POINTER (user_id));
227
228 if (data->reuse_client) {
229 GList *node;
230 const char *peer;
231
232 peer = g_dbus_method_invocation_get_sender (data->invocation);
233 node = g_list_find_custom (priv->clients,
234 peer,
235 compare_client_bus_name);
236 if (node != NULL) {
237 GClueServiceClient *client;
238
239 client = GCLUE_SERVICE_CLIENT (node->data);
240 path = g_strdup
241 (gclue_service_client_get_path (client));
242
243 goto client_created;
244 }
245 }
246
247 path = g_strdup_printf ("/org/freedesktop/GeoClue2/Client/%u",
248 ++priv->last_client_id);
249
250 client = gclue_service_client_new (info,
251 path,
252 priv->connection,
253 agent_proxy,
254 &error);
255 if (client == NULL)
256 goto error_out;
257
258 priv->clients = g_list_prepend (priv->clients, client);
259 priv->num_clients++;
260 if (priv->num_clients == 1) {
261 g_object_notify (G_OBJECT (data->manager), "active");
262 }
263 g_debug ("Number of connected clients: %u", priv->num_clients);
264
265 g_signal_connect_object (client,
266 "notify::active",
267 G_CALLBACK (on_client_notify_active),
268 data->manager, 0);
269
270 g_signal_connect_object (info,
271 "peer-vanished",
272 G_CALLBACK (on_peer_vanished),
273 data->manager, 0);
274
275 client_created:
276 if (data->reuse_client)
277 gclue_dbus_manager_complete_get_client (data->manager,
278 data->invocation,
279 path);
280 else
281 gclue_dbus_manager_complete_create_client (data->manager,
282 data->invocation,
283 path);
284 goto out;
285
286 error_out:
287 g_dbus_method_invocation_return_error_literal (data->invocation,
288 G_DBUS_ERROR,
289 G_DBUS_ERROR_FAILED,
290 error->message);
291 out:
292 g_clear_object (&info);
293 on_client_info_new_ready_data_free (data);
294
295 return FALSE;
296 }
297
298 static void
299 on_peer_vanished_before_completion (GClueClientInfo *info,
300 gpointer user_data)
301 {
302 OnClientInfoNewReadyData *data = (OnClientInfoNewReadyData *) user_data;
303 GClueServiceManager *self = GCLUE_SERVICE_MANAGER (data->manager);
304 GClueServiceManagerPrivate *priv = self->priv;
305 const char *bus_name;
306
307 bus_name = gclue_client_info_get_bus_name (info);
308 g_debug ("Client `%s` vanished before agent appeared",
309 bus_name);
310 g_signal_handlers_disconnect_by_data (info,
311 user_data);
312 g_dbus_method_invocation_return_error (data->invocation,
313 G_DBUS_ERROR,
314 G_DBUS_ERROR_DISCONNECTED,
315 "%s vanished before completion",
316 bus_name);
317 g_queue_remove (priv->clients_waiting_agent, data);
318 on_client_info_new_ready_data_free (data);
319 g_object_unref (info);
320 }
321
322 static void
323 on_client_info_new_ready (GObject *source_object,
324 GAsyncResult *res,
325 gpointer user_data)
326 {
327 OnClientInfoNewReadyData *data = (OnClientInfoNewReadyData *) user_data;
328 GClueServiceManagerPrivate *priv = GCLUE_SERVICE_MANAGER (data->manager)->priv;
329 GClueClientInfo *info = NULL;
330 GClueAgent *agent_proxy;
331 g_autoptr(GError) error = NULL;
332 guint32 user_id;
333
334 info = gclue_client_info_new_finish (res, &error);
335 if (info == NULL) {
336 g_dbus_method_invocation_return_error_literal (data->invocation,
337 G_DBUS_ERROR,
338 G_DBUS_ERROR_FAILED,
339 error->message);
340 on_client_info_new_ready_data_free (data);
341
342 return;
343 }
344
345 data->client_info = info;
346
347 user_id = gclue_client_info_get_user_id (info);
348 agent_proxy = g_hash_table_lookup (priv->agents,
349 GINT_TO_POINTER (user_id));
350 if (agent_proxy == NULL) {
351 /* Its possible that geoclue was just launched on GetClient
352 * call, in which case agents need some time to register
353 * themselves to us.
354 */
355 g_queue_push_tail (priv->clients_waiting_agent, data);
356 g_signal_connect
357 (info,
358 "peer-vanished",
359 G_CALLBACK (on_peer_vanished_before_completion),
360 user_data);
361 g_debug ("Client `%s` waiting for agent for user ID '%u'",
362 gclue_client_info_get_bus_name (info), user_id);
363
364 return;
365 }
366
367 complete_get_client (data);
368 }
369
370 static void
371 handle_get_client (GClueDBusManager *manager,
372 GDBusMethodInvocation *invocation,
373 gboolean reuse_client)
374 {
375 GClueServiceManager *self = GCLUE_SERVICE_MANAGER (manager);
376 GClueServiceManagerPrivate *priv = self->priv;
377 const char *peer;
378 OnClientInfoNewReadyData *data;
379
380 peer = g_dbus_method_invocation_get_sender (invocation);
381
382 data = g_slice_new (OnClientInfoNewReadyData);
383 data->manager = manager;
384 data->invocation = invocation;
385 data->reuse_client = reuse_client;
386 gclue_client_info_new_async (peer,
387 priv->connection,
388 NULL,
389 on_client_info_new_ready,
390 data);
391 }
392
393 static gboolean
394 gclue_service_manager_handle_get_client (GClueDBusManager *manager,
395 GDBusMethodInvocation *invocation)
396 {
397 handle_get_client (manager, invocation, TRUE);
398
399 return TRUE;
400 }
401
402 static gboolean
403 gclue_service_manager_handle_create_client (GClueDBusManager *manager,
404 GDBusMethodInvocation *invocation)
405 {
406 handle_get_client (manager, invocation, FALSE);
407
408 return TRUE;
409 }
410
411 typedef struct
412 {
413 const char *path;
414 const char *bus_name;
415 } CompareClientPathNBusNameData;
416
417 static int
418 compare_client_path_n_bus_name (gconstpointer a,
419 gconstpointer b)
420 {
421 GClueServiceClient *client = GCLUE_SERVICE_CLIENT (a);
422 CompareClientPathNBusNameData *data =
423 (CompareClientPathNBusNameData *) b;
424 GClueClientInfo *info;
425
426 info = gclue_service_client_get_client_info (client);
427
428 if (g_strcmp0 (data->bus_name,
429 gclue_client_info_get_bus_name (info)) == 0 &&
430 g_strcmp0 (data->path,
431 gclue_service_client_get_path (client)) == 0)
432 return 0;
433 else
434 return 1;
435 }
436
437 static gboolean
438 gclue_service_manager_handle_delete_client (GClueDBusManager *manager,
439 GDBusMethodInvocation *invocation,
440 const char *path)
441 {
442 CompareClientPathNBusNameData data;
443
444 data.path = path;
445 data.bus_name = g_dbus_method_invocation_get_sender (invocation);
446
447 delete_client (GCLUE_SERVICE_MANAGER (manager),
448 compare_client_path_n_bus_name,
449 &data);
450
451 gclue_dbus_manager_complete_delete_client (manager, invocation);
452
453 return TRUE;
454 }
455
456 typedef struct
457 {
458 GClueDBusManager *manager;
459 GDBusMethodInvocation *invocation;
460 GClueClientInfo *info;
461 char *desktop_id;
462 } AddAgentData;
463
464 static void
465 add_agent_data_free (AddAgentData *data)
466 {
467 g_clear_pointer (&data->desktop_id, g_free);
468 g_clear_object (&data->manager);
469 g_slice_free (AddAgentData, data);
470 }
471
472 static void
473 on_agent_vanished (GClueClientInfo *info,
474 gpointer user_data)
475 {
476 GClueServiceManager *manager = GCLUE_SERVICE_MANAGER (user_data);
477 guint32 user_id;
478
479 user_id = gclue_client_info_get_user_id (info);
480 g_debug ("Agent for user '%u' vanished", user_id);
481 g_hash_table_remove (manager->priv->agents, GINT_TO_POINTER (user_id));
482 g_object_unref (info);
483 }
484
485 static void
486 on_agent_proxy_ready (GObject *source_object,
487 GAsyncResult *res,
488 gpointer user_data)
489 {
490 AddAgentData *data = (AddAgentData *) user_data;
491 GClueServiceManagerPrivate *priv = GCLUE_SERVICE_MANAGER (data->manager)->priv;
492 guint32 user_id;
493 GClueAgent *agent;
494 g_autoptr(GError) error = NULL;
495 GList *l;
496
497 agent = gclue_agent_proxy_new_for_bus_finish (res, &error);
498 if (agent == NULL)
499 goto error_out;
500
501 user_id = gclue_client_info_get_user_id (data->info);
502 g_debug ("New agent for user ID '%u'", user_id);
503 g_hash_table_replace (priv->agents, GINT_TO_POINTER (user_id), agent);
504
505 g_signal_connect_object (data->info,
506 "peer-vanished",
507 G_CALLBACK (on_agent_vanished),
508 data->manager, 0);
509
510 gclue_dbus_manager_complete_add_agent (data->manager, data->invocation);
511
512 l = priv->clients_waiting_agent->head;
513 while (l != NULL) {
514 GList *next = l->next;
515 OnClientInfoNewReadyData *d =
516 (OnClientInfoNewReadyData *) l->data;
517
518 if (gclue_client_info_get_user_id(d->client_info) == user_id) {
519 complete_get_client (d);
520 g_queue_delete_link (priv->clients_waiting_agent, l);
521 }
522 l = next;
523 }
524
525 goto out;
526
527 error_out:
528 g_dbus_method_invocation_return_error_literal (data->invocation,
529 G_DBUS_ERROR,
530 G_DBUS_ERROR_FAILED,
531 error->message);
532 out:
533 add_agent_data_free (data);
534 }
535
536 #define AGENT_PATH "/org/freedesktop/GeoClue2/Agent"
537
538 static void
539 on_agent_info_new_ready (GObject *source_object,
540 GAsyncResult *res,
541 gpointer user_data)
542 {
543 AddAgentData *data = (AddAgentData *) user_data;
544 g_autoptr(GError) error = NULL;
545 GClueConfig *config;
546 const char *xdg_id;
547
548 data->info = gclue_client_info_new_finish (res, &error);
549 if (data->info == NULL) {
550 g_dbus_method_invocation_return_error_literal (data->invocation,
551 G_DBUS_ERROR,
552 G_DBUS_ERROR_FAILED,
553 error->message);
554 add_agent_data_free (data);
555
556 return;
557 }
558
559 xdg_id = gclue_client_info_get_xdg_id (data->info);
560 config = gclue_config_get_singleton ();
561 if (xdg_id != NULL ||
562 !gclue_config_is_agent_allowed (config,
563 data->desktop_id,
564 data->info)) {
565 g_dbus_method_invocation_return_error (data->invocation,
566 G_DBUS_ERROR,
567 G_DBUS_ERROR_ACCESS_DENIED,
568 "%s not allowed to act as agent",
569 data->desktop_id);
570 add_agent_data_free (data);
571
572 return;
573 }
574
575 gclue_agent_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
576 G_DBUS_PROXY_FLAGS_NONE,
577 gclue_client_info_get_bus_name (data->info),
578 AGENT_PATH,
579 NULL,
580 on_agent_proxy_ready,
581 user_data);
582 }
583
584 static gboolean
585 gclue_service_manager_handle_add_agent (GClueDBusManager *manager,
586 GDBusMethodInvocation *invocation,
587 const char *id)
588 {
589 GClueServiceManager *self = GCLUE_SERVICE_MANAGER (manager);
590 GClueServiceManagerPrivate *priv = self->priv;
591 const char *peer;
592 AddAgentData *data;
593
594 peer = g_dbus_method_invocation_get_sender (invocation);
595
596 data = g_slice_new0 (AddAgentData);
597 data->manager = g_object_ref (manager);
598 data->invocation = invocation;
599 data->desktop_id = g_strdup (id);
600 gclue_client_info_new_async (peer,
601 priv->connection,
602 NULL,
603 on_agent_info_new_ready,
604 data);
605 return TRUE;
606 }
607
608 static void
609 gclue_service_manager_finalize (GObject *object)
610 {
611 GClueServiceManagerPrivate *priv = GCLUE_SERVICE_MANAGER (object)->priv;
612
613 g_clear_object (&priv->locator);
614 g_clear_object (&priv->connection);
615 if (priv->clients != NULL) {
616 g_list_free_full (priv->clients, g_object_unref);
617 priv->clients = NULL;
618 }
619 g_clear_pointer (&priv->agents, g_hash_table_unref);
620 if (priv->clients_waiting_agent != NULL) {
621 g_queue_free_full (priv->clients_waiting_agent,
622 on_client_info_new_ready_data_free);
623 priv->clients_waiting_agent = NULL;
624 }
625 g_clear_handle_id (&priv->unix_signal_source, g_source_remove);
626
627 /* Chain up to the parent class */
628 G_OBJECT_CLASS (gclue_service_manager_parent_class)->finalize (object);
629 }
630
631 static void
632 gclue_service_manager_get_property (GObject *object,
633 guint prop_id,
634 GValue *value,
635 GParamSpec *pspec)
636 {
637 GClueServiceManager *manager = GCLUE_SERVICE_MANAGER (object);
638
639 switch (prop_id) {
640 case PROP_CONNECTION:
641 g_value_set_object (value, manager->priv->connection);
642 break;
643
644 case PROP_ACTIVE:
645 g_value_set_boolean (value, (manager->priv->num_clients != 0));
646 break;
647
648 default:
649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
650 }
651 }
652
653 static void
654 gclue_service_manager_set_property (GObject *object,
655 guint prop_id,
656 const GValue *value,
657 GParamSpec *pspec)
658 {
659 GClueServiceManager *manager = GCLUE_SERVICE_MANAGER (object);
660
661 switch (prop_id) {
662 case PROP_CONNECTION:
663 manager->priv->connection = g_value_dup_object (value);
664 break;
665
666 default:
667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668 }
669 }
670
671 static void
672 on_avail_accuracy_level_changed (GObject *object,
673 GParamSpec *pspec,
674 gpointer user_data)
675 {
676 GClueServiceManagerPrivate *priv = GCLUE_SERVICE_MANAGER (user_data)->priv;
677 GClueAccuracyLevel level;
678
679 level = gclue_location_source_get_available_accuracy_level
680 (GCLUE_LOCATION_SOURCE (priv->locator));
681 gclue_dbus_manager_set_available_accuracy_level
682 (GCLUE_DBUS_MANAGER (user_data), level);
683 }
684
685 static void
686 gclue_service_manager_constructed (GObject *object)
687 {
688 GClueServiceManager *manager = GCLUE_SERVICE_MANAGER (object);
689 GClueServiceManagerPrivate *priv = manager->priv;
690
691 G_OBJECT_CLASS (gclue_service_manager_parent_class)->constructed (object);
692
693 priv->locator = gclue_locator_new (GCLUE_ACCURACY_LEVEL_EXACT);
694 g_signal_connect_object (G_OBJECT (priv->locator),
695 "notify::available-accuracy-level",
696 G_CALLBACK (on_avail_accuracy_level_changed),
697 object, 0);
698 on_avail_accuracy_level_changed (G_OBJECT (priv->locator),
699 NULL,
700 object);
701 priv->unix_signal_source = g_unix_signal_add (SIGUSR1, log_client_list, manager);
702 }
703
704 static void
705 gclue_service_manager_class_init (GClueServiceManagerClass *klass)
706 {
707 GObjectClass *object_class;
708
709 object_class = G_OBJECT_CLASS (klass);
710 object_class->finalize = gclue_service_manager_finalize;
711 object_class->get_property = gclue_service_manager_get_property;
712 object_class->set_property = gclue_service_manager_set_property;
713 object_class->constructed = gclue_service_manager_constructed;
714
715 gParamSpecs[PROP_CONNECTION] = g_param_spec_object ("connection",
716 "Connection",
717 "DBus Connection",
718 G_TYPE_DBUS_CONNECTION,
719 G_PARAM_READWRITE |
720 G_PARAM_CONSTRUCT_ONLY);
721 g_object_class_install_property (object_class,
722 PROP_CONNECTION,
723 gParamSpecs[PROP_CONNECTION]);
724
725 /**
726 * GClueServiceManager:active:
727 *
728 * Unlike the D-Bus 'InUse' property, this indicates wether or not
729 * currently we have connected clients.
730 */
731 gParamSpecs[PROP_ACTIVE] = g_param_spec_boolean ("active",
732 "Active",
733 "If manager is active",
734 FALSE,
735 G_PARAM_READABLE);
736 g_object_class_install_property (object_class,
737 PROP_ACTIVE,
738 gParamSpecs[PROP_ACTIVE]);
739 }
740
741 static void
742 gclue_service_manager_init (GClueServiceManager *manager)
743 {
744 manager->priv = gclue_service_manager_get_instance_private (manager);
745
746 manager->priv->agents = g_hash_table_new_full (g_direct_hash,
747 g_direct_equal,
748 NULL,
749 g_object_unref);
750 manager->priv->clients_waiting_agent = g_queue_new ();
751 }
752
753 static gboolean
754 gclue_service_manager_initable_init (GInitable *initable,
755 GCancellable *cancellable,
756 GError **error)
757 {
758 return g_dbus_interface_skeleton_export
759 (G_DBUS_INTERFACE_SKELETON (initable),
760 GCLUE_SERVICE_MANAGER (initable)->priv->connection,
761 "/org/freedesktop/GeoClue2/Manager",
762 error);
763 }
764
765 static void
766 gclue_service_manager_manager_iface_init (GClueDBusManagerIface *iface)
767 {
768 iface->handle_get_client = gclue_service_manager_handle_get_client;
769 iface->handle_create_client =
770 gclue_service_manager_handle_create_client;
771 iface->handle_delete_client =
772 gclue_service_manager_handle_delete_client;
773 iface->handle_add_agent = gclue_service_manager_handle_add_agent;
774 }
775
776 static void
777 gclue_service_manager_initable_iface_init (GInitableIface *iface)
778 {
779 iface->init = gclue_service_manager_initable_init;
780 }
781
782 GClueServiceManager *
783 gclue_service_manager_new (GDBusConnection *connection,
784 GError **error)
785 {
786 return g_initable_new (GCLUE_TYPE_SERVICE_MANAGER,
787 NULL,
788 error,
789 "connection", connection,
790 NULL);
791 }
792
793 gboolean
794 gclue_service_manager_get_active (GClueServiceManager *manager)
795 {
796 return (manager->priv->num_clients != 0);
797 }