dundee: Watch service on D-Bus
[platform/upstream/connman.git] / plugins / dundee.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2012  BMW Car IT GmbH. 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/device.h>
33 #include <connman/network.h>
34 #include <connman/dbus.h>
35
36 #define DUNDEE_SERVICE                  "org.ofono.dundee"
37
38 static DBusConnection *connection;
39
40 static GHashTable *dundee_devices = NULL;
41
42 struct dundee_data {
43 };
44
45 static void device_destroy(gpointer data)
46 {
47         struct dundee_data *info = data;
48
49         g_free(info);
50 }
51
52 static int network_probe(struct connman_network *network)
53 {
54         DBG("network %p", network);
55
56         return 0;
57 }
58
59 static void network_remove(struct connman_network *network)
60 {
61         DBG("network %p", network);
62 }
63
64 static int network_connect(struct connman_network *network)
65 {
66         DBG("network %p", network);
67
68         return 0;
69 }
70
71 static int network_disconnect(struct connman_network *network)
72 {
73         DBG("network %p", network);
74
75         return 0;
76 }
77
78 static struct connman_network_driver network_driver = {
79         .name           = "network",
80         .type           = CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN,
81         .probe          = network_probe,
82         .remove         = network_remove,
83         .connect        = network_connect,
84         .disconnect     = network_disconnect,
85 };
86
87 static int dundee_probe(struct connman_device *device)
88 {
89         DBG("device %p", device);
90
91         return 0;
92 }
93
94 static void dundee_remove(struct connman_device *device)
95 {
96         DBG("device %p", device);
97 }
98
99 static int dundee_enable(struct connman_device *device)
100 {
101         DBG("device %p", device);
102
103         return 0;
104 }
105
106 static int dundee_disable(struct connman_device *device)
107 {
108         DBG("device %p", device);
109
110         return 0;
111 }
112
113 static struct connman_device_driver dundee_driver = {
114         .name           = "dundee",
115         .type           = CONNMAN_DEVICE_TYPE_BLUETOOTH,
116         .probe          = dundee_probe,
117         .remove         = dundee_remove,
118         .enable         = dundee_enable,
119         .disable        = dundee_disable,
120 };
121
122 static void dundee_connect(DBusConnection *connection, void *user_data)
123 {
124         DBG("connection %p", connection);
125
126         dundee_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
127                                         g_free, device_destroy);
128 }
129
130 static void dundee_disconnect(DBusConnection *connection, void *user_data)
131 {
132         DBG("connection %p", connection);
133
134         g_hash_table_destroy(dundee_devices);
135         dundee_devices = NULL;
136 }
137
138 static guint watch;
139
140 static int dundee_init(void)
141 {
142         int err;
143
144         connection = connman_dbus_get_connection();
145         if (connection == NULL)
146                 return -EIO;
147
148         watch = g_dbus_add_service_watch(connection, DUNDEE_SERVICE,
149                         dundee_connect, dundee_disconnect, NULL, NULL);
150
151         if (watch == 0) {
152                 err = -EIO;
153                 goto remove;
154         }
155
156         err = connman_network_driver_register(&network_driver);
157         if (err < 0)
158                 goto remove;
159
160         err = connman_device_driver_register(&dundee_driver);
161         if (err < 0) {
162                 connman_network_driver_unregister(&network_driver);
163                 goto remove;
164         }
165
166         return 0;
167
168 remove:
169         g_dbus_remove_watch(connection, watch);
170
171         dbus_connection_unref(connection);
172
173         return err;
174 }
175
176 static void dundee_exit(void)
177 {
178         g_dbus_remove_watch(connection, watch);
179
180         connman_device_driver_unregister(&dundee_driver);
181         connman_network_driver_unregister(&network_driver);
182
183         dbus_connection_unref(connection);
184 }
185
186 CONNMAN_PLUGIN_DEFINE(dundee, "Dundee plugin", VERSION,
187                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, dundee_init, dundee_exit)