Add initial support for LookupService helper method
[framework/connectivity/connman.git] / src / manager.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <gdbus.h>
27
28 #include "connman.h"
29
30 static DBusMessage *get_properties(DBusConnection *conn,
31                                         DBusMessage *msg, void *data)
32 {
33         DBusMessage *reply;
34         DBusMessageIter array, dict;
35         connman_bool_t offlinemode;
36         const char *str;
37
38         DBG("conn %p", conn);
39
40         if (__connman_security_check_privilege(msg,
41                                         CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
42                 return __connman_error_permission_denied(msg);
43
44         reply = dbus_message_new_method_return(msg);
45         if (reply == NULL)
46                 return NULL;
47
48         dbus_message_iter_init_append(reply, &array);
49
50         connman_dbus_dict_open(&array, &dict);
51
52         str = __connman_profile_active_path();
53         if (str != NULL)
54                 connman_dbus_dict_append_basic(&dict, "ActiveProfile",
55                                                 DBUS_TYPE_OBJECT_PATH, &str);
56
57         connman_dbus_dict_append_array(&dict, "Profiles",
58                         DBUS_TYPE_OBJECT_PATH, __connman_profile_list, NULL);
59         connman_dbus_dict_append_array(&dict, "Services",
60                         DBUS_TYPE_OBJECT_PATH, __connman_service_list, NULL);
61         connman_dbus_dict_append_array(&dict, "Providers",
62                         DBUS_TYPE_OBJECT_PATH, __connman_provider_list, NULL);
63         connman_dbus_dict_append_array(&dict, "Technologies",
64                         DBUS_TYPE_OBJECT_PATH, __connman_technology_list, NULL);
65
66         str = __connman_notifier_get_state();
67         connman_dbus_dict_append_basic(&dict, "State",
68                                                 DBUS_TYPE_STRING, &str);
69
70         offlinemode = __connman_profile_get_offlinemode();
71         connman_dbus_dict_append_basic(&dict, "OfflineMode",
72                                         DBUS_TYPE_BOOLEAN, &offlinemode);
73
74         connman_dbus_dict_append_array(&dict, "AvailableTechnologies",
75                 DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL);
76         connman_dbus_dict_append_array(&dict, "EnabledTechnologies",
77                 DBUS_TYPE_STRING, __connman_notifier_list_enabled, NULL);
78         connman_dbus_dict_append_array(&dict, "ConnectedTechnologies",
79                 DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
80
81         str = __connman_service_default();
82         if (str != NULL)
83                 connman_dbus_dict_append_basic(&dict, "DefaultTechnology",
84                                                 DBUS_TYPE_STRING, &str);
85
86         connman_dbus_dict_append_array(&dict, "AvailableDebugs",
87                         DBUS_TYPE_STRING, __connman_debug_list_available, NULL);
88         connman_dbus_dict_append_array(&dict, "EnabledDebugs",
89                         DBUS_TYPE_STRING, __connman_debug_list_enabled, NULL);
90
91         connman_dbus_dict_close(&array, &dict);
92
93         return reply;
94 }
95
96 static DBusMessage *set_property(DBusConnection *conn,
97                                         DBusMessage *msg, void *data)
98 {
99         DBusMessageIter iter, value;
100         const char *name;
101         int type;
102
103         DBG("conn %p", conn);
104
105         if (dbus_message_iter_init(msg, &iter) == FALSE)
106                 return __connman_error_invalid_arguments(msg);
107
108         dbus_message_iter_get_basic(&iter, &name);
109         dbus_message_iter_next(&iter);
110         dbus_message_iter_recurse(&iter, &value);
111
112         if (__connman_security_check_privilege(msg,
113                                         CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
114                 return __connman_error_permission_denied(msg);
115
116         type = dbus_message_iter_get_arg_type(&value);
117
118         if (g_str_equal(name, "OfflineMode") == TRUE) {
119                 connman_bool_t offlinemode;
120
121                 if (type != DBUS_TYPE_BOOLEAN)
122                         return __connman_error_invalid_arguments(msg);
123
124                 dbus_message_iter_get_basic(&value, &offlinemode);
125
126                 __connman_profile_set_offlinemode(offlinemode);
127
128                 __connman_profile_save_default();
129         } else if (g_str_equal(name, "ActiveProfile") == TRUE) {
130                 const char *str;
131
132                 dbus_message_iter_get_basic(&value, &str);
133
134                 return __connman_error_not_supported(msg);
135         } else
136                 return __connman_error_invalid_property(msg);
137
138         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
139 }
140
141 static DBusMessage *get_state(DBusConnection *conn,
142                                         DBusMessage *msg, void *data)
143 {
144         const char *str;
145
146         DBG("conn %p", conn);
147
148         if (__connman_security_check_privilege(msg,
149                                         CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
150                 return __connman_error_permission_denied(msg);
151
152         str = __connman_notifier_get_state();
153
154         return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &str,
155                                                 DBUS_TYPE_INVALID);
156 }
157
158 static DBusMessage *create_profile(DBusConnection *conn,
159                                         DBusMessage *msg, void *data)
160 {
161         const char *name, *path;
162         int err;
163
164         DBG("conn %p", conn);
165
166         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
167                                                         DBUS_TYPE_INVALID);
168
169         if (__connman_security_check_privilege(msg,
170                                         CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
171                 return __connman_error_permission_denied(msg);
172
173         err = __connman_profile_create(name, &path);
174         if (err < 0)
175                 return __connman_error_failed(msg, -err);
176
177         return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path,
178                                                         DBUS_TYPE_INVALID);
179 }
180
181 static DBusMessage *remove_profile(DBusConnection *conn,
182                                         DBusMessage *msg, void *data)
183 {
184         const char *path;
185         int err;
186
187         DBG("conn %p", conn);
188
189         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
190                                                         DBUS_TYPE_INVALID);
191
192         if (__connman_security_check_privilege(msg,
193                                         CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
194                 return __connman_error_permission_denied(msg);
195
196         err = __connman_profile_remove(path);
197         if (err < 0)
198                 return __connman_error_failed(msg, -err);
199
200         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
201 }
202
203 static DBusMessage *remove_provider(DBusConnection *conn,
204                                     DBusMessage *msg, void *data)
205 {
206         const char *path;
207         int err;
208
209         DBG("conn %p", conn);
210
211         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path,
212                               DBUS_TYPE_INVALID);
213
214         if (__connman_security_check_privilege(msg,
215                                 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
216                 return __connman_error_permission_denied(msg);
217
218         err = __connman_provider_remove(path);
219         if (err < 0)
220                 return __connman_error_failed(msg, -err);
221
222         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
223 }
224
225 static DBusMessage *request_scan(DBusConnection *conn,
226                                         DBusMessage *msg, void *data)
227 {
228         enum connman_service_type type;
229         const char *str;
230         int err;
231
232         DBG("conn %p", conn);
233
234         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
235                                                         DBUS_TYPE_INVALID);
236
237         if (g_strcmp0(str, "") == 0)
238                 type = CONNMAN_SERVICE_TYPE_UNKNOWN;
239         else if (g_strcmp0(str, "wifi") == 0)
240                 type = CONNMAN_SERVICE_TYPE_WIFI;
241         else if (g_strcmp0(str, "wimax") == 0)
242                 type = CONNMAN_SERVICE_TYPE_WIMAX;
243         else
244                 return __connman_error_invalid_arguments(msg);
245
246         err = __connman_element_request_scan(type);
247         if (err < 0) {
248                 if (err == -EINPROGRESS) {
249                         connman_error("Invalid return code from scan");
250                         err = -EINVAL;
251                 }
252
253                 return __connman_error_failed(msg, -err);
254         }
255
256         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
257 }
258
259 static DBusConnection *connection = NULL;
260
261 static enum connman_service_type technology_type;
262 static connman_bool_t technology_enabled;
263 static DBusMessage *technology_pending = NULL;
264 static guint technology_timeout = 0;
265
266 static void technology_reply(int error)
267 {
268         DBG("");
269
270         if (technology_timeout > 0) {
271                 g_source_remove(technology_timeout);
272                 technology_timeout = 0;
273         }
274
275         if (technology_pending != NULL) {
276                 if (error > 0) {
277                         DBusMessage *reply;
278
279                         reply = __connman_error_failed(technology_pending,
280                                                                 error);
281                         if (reply != NULL)
282                                 g_dbus_send_message(connection, reply);
283                 } else
284                         g_dbus_send_reply(connection, technology_pending,
285                                                         DBUS_TYPE_INVALID);
286
287                 dbus_message_unref(technology_pending);
288                 technology_pending = NULL;
289         }
290
291         technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
292 }
293
294 static gboolean technology_abort(gpointer user_data)
295 {
296         DBG("");
297
298         technology_timeout = 0;
299
300         technology_reply(ETIMEDOUT);
301
302         return FALSE;
303 }
304
305 static void technology_notify(enum connman_service_type type,
306                                                 connman_bool_t enabled)
307 {
308         DBG("type %d enabled %d", type, enabled);
309
310         if (type == technology_type && enabled == technology_enabled)
311                 technology_reply(0);
312 }
313
314 static struct connman_notifier technology_notifier = {
315         .name           = "manager",
316         .priority       = CONNMAN_NOTIFIER_PRIORITY_HIGH,
317         .service_enabled= technology_notify,
318 };
319
320 static DBusMessage *enable_technology(DBusConnection *conn,
321                                         DBusMessage *msg, void *data)
322 {
323         enum connman_service_type type;
324         const char *str;
325         int err;
326
327         DBG("conn %p", conn);
328
329         if (technology_pending != NULL)
330                 return __connman_error_in_progress(msg);
331
332         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
333                                                         DBUS_TYPE_INVALID);
334
335         if (g_strcmp0(str, "ethernet") == 0)
336                 type = CONNMAN_SERVICE_TYPE_ETHERNET;
337         else if (g_strcmp0(str, "wifi") == 0)
338                 type = CONNMAN_SERVICE_TYPE_WIFI;
339         else if (g_strcmp0(str, "wimax") == 0)
340                 type = CONNMAN_SERVICE_TYPE_WIMAX;
341         else if (g_strcmp0(str, "bluetooth") == 0)
342                 type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
343         else if (g_strcmp0(str, "cellular") == 0)
344                 type = CONNMAN_SERVICE_TYPE_CELLULAR;
345         else
346                 return __connman_error_invalid_arguments(msg);
347
348         if (__connman_notifier_is_registered(type) == FALSE)
349                 return __connman_error_not_registered(msg);
350
351         if (__connman_notifier_is_enabled(type) == TRUE)
352                 return __connman_error_already_enabled(msg);
353
354         technology_type = type;
355         technology_enabled = TRUE;
356         technology_pending = dbus_message_ref(msg);
357
358         err = __connman_element_enable_technology(type);
359         if (err < 0 && err != -EINPROGRESS)
360                 technology_reply(-err);
361         else
362                 technology_timeout = g_timeout_add_seconds(15,
363                                                 technology_abort, NULL);
364
365         return NULL;
366 }
367
368 static DBusMessage *disable_technology(DBusConnection *conn,
369                                         DBusMessage *msg, void *data)
370 {
371         enum connman_service_type type;
372         const char *str;
373         int err;
374
375         DBG("conn %p", conn);
376
377         if (technology_pending != NULL)
378                 return __connman_error_in_progress(msg);
379
380         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
381                                                         DBUS_TYPE_INVALID);
382
383         if (g_strcmp0(str, "ethernet") == 0)
384                 type = CONNMAN_SERVICE_TYPE_ETHERNET;
385         else if (g_strcmp0(str, "wifi") == 0)
386                 type = CONNMAN_SERVICE_TYPE_WIFI;
387         else if (g_strcmp0(str, "wimax") == 0)
388                 type = CONNMAN_SERVICE_TYPE_WIMAX;
389         else if (g_strcmp0(str, "bluetooth") == 0)
390                 type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
391         else if (g_strcmp0(str, "cellular") == 0)
392                 type = CONNMAN_SERVICE_TYPE_CELLULAR;
393         else
394                 return __connman_error_invalid_arguments(msg);
395
396         if (__connman_notifier_is_registered(type) == FALSE)
397                 return __connman_error_not_registered(msg);
398
399         if (__connman_notifier_is_enabled(type) == FALSE)
400                 return __connman_error_already_disabled(msg);
401
402         technology_type = type;
403         technology_enabled = FALSE;
404         technology_pending = dbus_message_ref(msg);
405
406         err = __connman_element_disable_technology(type);
407         if (err < 0 && err != -EINPROGRESS)
408                 technology_reply(-err);
409         else
410                 technology_timeout = g_timeout_add_seconds(10,
411                                                 technology_abort, NULL);
412
413         return NULL;
414 }
415
416 static DBusMessage *lookup_service(DBusConnection *conn,
417                                         DBusMessage *msg, void *data)
418 {
419         const char *pattern, *path;
420         int err;
421
422         DBG("conn %p", conn);
423
424         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
425                                                         DBUS_TYPE_INVALID);
426
427         err = __connman_service_lookup(pattern, &path);
428         if (err < 0)
429                 return __connman_error_failed(msg, -err);
430
431         return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &path,
432                                                         DBUS_TYPE_INVALID);
433 }
434
435 static DBusMessage *connect_service(DBusConnection *conn,
436                                         DBusMessage *msg, void *data)
437 {
438         int err;
439
440         DBG("conn %p", conn);
441
442         if (__connman_security_check_privilege(msg,
443                                         CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
444                 return __connman_error_permission_denied(msg);
445
446         err = __connman_service_create_and_connect(msg);
447         if (err < 0) {
448                 if (err == -EINPROGRESS) {
449                         connman_error("Invalid return code from connect");
450                         err = -EINVAL;
451                 }
452
453                 return __connman_error_failed(msg, -err);
454         }
455
456         return NULL;
457 }
458
459
460 static DBusMessage *connect_provider(DBusConnection *conn,
461                                      DBusMessage *msg, void *data)
462 {
463         int err;
464
465         DBG("conn %p", conn);
466
467         if (__connman_security_check_privilege(msg,
468                                 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
469                 return __connman_error_permission_denied(msg);
470
471         err = __connman_provider_create_and_connect(msg);
472         if (err < 0) {
473                 if (err == -EINPROGRESS) {
474                         connman_error("Invalid return code from connect");
475                         err = -EINVAL;
476                 }
477
478                 return __connman_error_failed(msg, -err);
479         }
480
481         return NULL;
482 }
483
484 static DBusMessage *register_agent(DBusConnection *conn,
485                                         DBusMessage *msg, void *data)
486 {
487         const char *sender, *path;
488         int err;
489
490         DBG("conn %p", conn);
491
492         sender = dbus_message_get_sender(msg);
493
494         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
495                                                         DBUS_TYPE_INVALID);
496
497         err = __connman_agent_register(sender, path);
498         if (err < 0)
499                 return __connman_error_failed(msg, -err);
500
501         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
502 }
503
504 static DBusMessage *unregister_agent(DBusConnection *conn,
505                                         DBusMessage *msg, void *data)
506 {
507         const char *sender, *path;
508         int err;
509
510         DBG("conn %p", conn);
511
512         sender = dbus_message_get_sender(msg);
513
514         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
515                                                         DBUS_TYPE_INVALID);
516
517         err = __connman_agent_unregister(sender, path);
518         if (err < 0)
519                 return __connman_error_failed(msg, -err);
520
521         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
522 }
523
524 static DBusMessage *register_counter(DBusConnection *conn,
525                                         DBusMessage *msg, void *data)
526 {
527         const char *sender, *path;
528         unsigned int interval;
529         int err;
530
531         DBG("conn %p", conn);
532
533         sender = dbus_message_get_sender(msg);
534
535         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
536                                                 DBUS_TYPE_UINT32, &interval,
537                                                         DBUS_TYPE_INVALID);
538
539         err = __connman_counter_register(sender, path, interval);
540         if (err < 0)
541                 return __connman_error_failed(msg, -err);
542
543         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
544 }
545
546 static DBusMessage *unregister_counter(DBusConnection *conn,
547                                         DBusMessage *msg, void *data)
548 {
549         const char *sender, *path;
550         int err;
551
552         DBG("conn %p", conn);
553
554         sender = dbus_message_get_sender(msg);
555
556         dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
557                                                         DBUS_TYPE_INVALID);
558
559         err = __connman_counter_unregister(sender, path);
560         if (err < 0)
561                 return __connman_error_failed(msg, -err);
562
563         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
564 }
565
566 static DBusMessage *request_session(DBusConnection *conn,
567                                         DBusMessage *msg, void *data)
568 {
569         const char *bearer, *sender, *service_path;
570         struct connman_service *service;
571
572         DBG("conn %p", conn);
573
574         sender = dbus_message_get_sender(msg);
575
576         dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &bearer,
577                                                         DBUS_TYPE_INVALID);
578
579         service = __connman_session_request(bearer, sender);
580         if (service == NULL)
581                 return __connman_error_failed(msg, EINVAL);
582
583         service_path = __connman_service_get_path(service);
584
585         return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &service_path,
586                                                 DBUS_TYPE_INVALID);
587 }
588
589 static DBusMessage *release_session(DBusConnection *conn,
590                                         DBusMessage *msg, void *data)
591 {
592         const char *sender;
593         int err;
594
595         DBG("conn %p", conn);
596
597         sender = dbus_message_get_sender(msg);
598
599         err = __connman_session_release(sender);
600         if (err < 0)
601                 return __connman_error_failed(msg, -err);
602
603         return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
604 }
605
606 static GDBusMethodTable manager_methods[] = {
607         { "GetProperties",     "",      "a{sv}", get_properties     },
608         { "SetProperty",       "sv",    "",      set_property       },
609         { "GetState",          "",      "s",     get_state          },
610         { "CreateProfile",     "s",     "o",     create_profile     },
611         { "RemoveProfile",     "o",     "",      remove_profile     },
612         { "RemoveProvider",    "s",     "",      remove_provider    },
613         { "RequestScan",       "s",     "",      request_scan       },
614         { "EnableTechnology",  "s",     "",      enable_technology,
615                                                 G_DBUS_METHOD_FLAG_ASYNC },
616         { "DisableTechnology", "s",     "",      disable_technology,
617                                                 G_DBUS_METHOD_FLAG_ASYNC },
618         { "LookupService",     "s",     "o",     lookup_service,    },
619         { "ConnectService",    "a{sv}", "o",     connect_service,
620                                                 G_DBUS_METHOD_FLAG_ASYNC },
621         { "ConnectProvider",   "a{sv}", "o",     connect_provider,
622                                                 G_DBUS_METHOD_FLAG_ASYNC },
623         { "RegisterAgent",     "o",     "",      register_agent     },
624         { "UnregisterAgent",   "o",     "",      unregister_agent   },
625         { "RegisterCounter",   "ou",    "",      register_counter   },
626         { "UnregisterCounter", "o",     "",      unregister_counter },
627         { "RequestSession",    "s",     "o",     request_session    },
628         { "ReleaseSession",    "s",     "",      release_session    },
629         { },
630 };
631
632 static GDBusSignalTable manager_signals[] = {
633         { "PropertyChanged", "sv" },
634         { "StateChanged",    "s"  },
635         { },
636 };
637
638 static DBusMessage *nm_sleep(DBusConnection *conn,
639                                         DBusMessage *msg, void *data)
640 {
641         DBusMessage *reply;
642
643         DBG("conn %p", conn);
644
645         reply = dbus_message_new_method_return(msg);
646         if (reply == NULL)
647                 return NULL;
648
649         dbus_message_append_args(reply, DBUS_TYPE_INVALID);
650
651         return reply;
652 }
653
654 static DBusMessage *nm_wake(DBusConnection *conn,
655                                         DBusMessage *msg, void *data)
656 {
657         DBusMessage *reply;
658
659         DBG("conn %p", conn);
660
661         reply = dbus_message_new_method_return(msg);
662         if (reply == NULL)
663                 return NULL;
664
665         dbus_message_append_args(reply, DBUS_TYPE_INVALID);
666
667         return reply;
668 }
669
670 enum {
671         NM_STATE_UNKNOWN = 0,
672         NM_STATE_ASLEEP,
673         NM_STATE_CONNECTING,
674         NM_STATE_CONNECTED,
675         NM_STATE_DISCONNECTED
676 };
677
678 static DBusMessage *nm_state(DBusConnection *conn,
679                                         DBusMessage *msg, void *data)
680 {
681         DBusMessage *reply;
682         dbus_uint32_t state;
683
684         DBG("conn %p", conn);
685
686         reply = dbus_message_new_method_return(msg);
687         if (reply == NULL)
688                 return NULL;
689
690         if (__connman_notifier_count_connected() > 0)
691                 state = NM_STATE_CONNECTED;
692         else
693                 state = NM_STATE_DISCONNECTED;
694
695         dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
696                                                         DBUS_TYPE_INVALID);
697
698         return reply;
699 }
700
701 static GDBusMethodTable nm_methods[] = {
702         { "sleep", "",  "",   nm_sleep        },
703         { "wake",  "",  "",   nm_wake         },
704         { "state", "",  "u",  nm_state        },
705         { },
706 };
707
708 static gboolean nm_compat = FALSE;
709
710 int __connman_manager_init(gboolean compat)
711 {
712         DBG("");
713
714         connection = connman_dbus_get_connection();
715         if (connection == NULL)
716                 return -1;
717
718         if (connman_notifier_register(&technology_notifier) < 0)
719                 connman_error("Failed to register technology notifier");
720
721         g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
722                                         CONNMAN_MANAGER_INTERFACE,
723                                         manager_methods,
724                                         manager_signals, NULL, NULL, NULL);
725
726         if (compat == TRUE) {
727                 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
728                                         nm_methods, NULL, NULL, NULL, NULL);
729
730                 nm_compat = TRUE;
731         }
732
733         return 0;
734 }
735
736 void __connman_manager_cleanup(void)
737 {
738         DBG("");
739
740         connman_notifier_unregister(&technology_notifier);
741
742         if (connection == NULL)
743                 return;
744
745         if (nm_compat == TRUE) {
746                 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
747         }
748
749         g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
750                                                 CONNMAN_MANAGER_INTERFACE);
751
752         dbus_connection_unref(connection);
753 }