Add tracking of oFono startup and termination
[platform/upstream/connman.git] / plugins / ofono.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  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 <errno.h>
27
28 #include <gdbus.h>
29
30 #define CONNMAN_API_SUBJECT_TO_CHANGE
31 #include <connman/plugin.h>
32 #include <connman/dbus.h>
33 #include <connman/log.h>
34
35 #define OFONO_SERVICE                   "org.ofono"
36
37 static DBusConnection *connection;
38
39 static GHashTable *ofono_modems = NULL;
40
41 static void unregister_modem(gpointer data)
42 {
43         DBG("");
44 }
45
46 static void ofono_connect(DBusConnection *connection, void *user_data)
47 {
48         DBG("connection %p", connection);
49
50         ofono_modems = g_hash_table_new_full(g_str_hash, g_str_equal,
51                                                 g_free, unregister_modem);
52 }
53
54 static void ofono_disconnect(DBusConnection *connection, void *user_data)
55 {
56         DBG("connection %p", connection);
57
58         if (ofono_modems == NULL)
59                 return;
60
61         g_hash_table_destroy(ofono_modems);
62         ofono_modems = NULL;
63 }
64
65 static guint watch;
66
67 static int ofono_init(void)
68 {
69         int err;
70
71         connection = connman_dbus_get_connection();
72         if (connection == NULL)
73                 return -EIO;
74
75         watch = g_dbus_add_service_watch(connection, OFONO_SERVICE,
76                         ofono_connect, ofono_disconnect, NULL, NULL);
77         if (watch == 0) {
78                 err = -EIO;
79                 goto unref;
80         }
81
82         return 0;
83
84 unref:
85         dbus_connection_unref(connection);
86
87         return err;
88 }
89
90 static void ofono_exit(void)
91 {
92         g_dbus_remove_watch(connection, watch);
93
94         ofono_disconnect(connection, NULL);
95
96         dbus_connection_unref(connection);
97 }
98
99 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
100                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)