5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
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.
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.
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
30 static DBusConnection *connection = NULL;
32 static GSList *notifier_list = NULL;
34 static gint compare_priority(gconstpointer a, gconstpointer b)
36 const struct connman_notifier *notifier1 = a;
37 const struct connman_notifier *notifier2 = b;
39 return notifier2->priority - notifier1->priority;
43 * connman_notifier_register:
44 * @notifier: notifier module
46 * Register a new notifier module
48 * Returns: %0 on success
50 int connman_notifier_register(struct connman_notifier *notifier)
52 DBG("notifier %p name %s", notifier, notifier->name);
54 notifier_list = g_slist_insert_sorted(notifier_list, notifier,
61 * connman_notifier_unregister:
62 * @notifier: notifier module
64 * Remove a previously registered notifier module
66 void connman_notifier_unregister(struct connman_notifier *notifier)
68 DBG("notifier %p name %s", notifier, notifier->name);
70 notifier_list = g_slist_remove(notifier_list, notifier);
73 #define MAX_TECHNOLOGIES 10
75 static volatile gint registered[MAX_TECHNOLOGIES];
76 static volatile gint enabled[MAX_TECHNOLOGIES];
77 static volatile gint connected[MAX_TECHNOLOGIES];
79 void __connman_notifier_list_registered(DBusMessageIter *iter, void *user_data)
83 for (i = 0; i < 10; i++) {
84 const char *type = __connman_service_type2string(i);
89 if (g_atomic_int_get(®istered[i]) > 0)
90 dbus_message_iter_append_basic(iter,
91 DBUS_TYPE_STRING, &type);
95 void __connman_notifier_list_enabled(DBusMessageIter *iter, void *user_data)
99 for (i = 0; i < 10; i++) {
100 const char *type = __connman_service_type2string(i);
105 if (g_atomic_int_get(&enabled[i]) > 0)
106 dbus_message_iter_append_basic(iter,
107 DBUS_TYPE_STRING, &type);
111 void __connman_notifier_list_connected(DBusMessageIter *iter, void *user_data)
115 for (i = 0; i < 10; i++) {
116 const char *type = __connman_service_type2string(i);
121 if (g_atomic_int_get(&connected[i]) > 0)
122 dbus_message_iter_append_basic(iter,
123 DBUS_TYPE_STRING, &type);
127 static void technology_registered(enum connman_service_type type,
128 connman_bool_t registered)
130 DBG("type %d registered %d", type, registered);
132 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
133 CONNMAN_MANAGER_INTERFACE, "AvailableTechnologies",
134 DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL);
137 static void technology_enabled(enum connman_service_type type,
138 connman_bool_t enabled)
142 DBG("type %d enabled %d", type, enabled);
144 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
145 CONNMAN_MANAGER_INTERFACE, "EnabledTechnologies",
146 DBUS_TYPE_STRING, __connman_notifier_list_enabled, NULL);
148 for (list = notifier_list; list; list = list->next) {
149 struct connman_notifier *notifier = list->data;
151 if (notifier->service_enabled)
152 notifier->service_enabled(type, enabled);
156 static void technology_connected(enum connman_service_type type,
157 connman_bool_t connected)
159 DBG("type %d connected %d", type, connected);
161 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
162 CONNMAN_MANAGER_INTERFACE, "ConnectedTechnologies",
163 DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
166 void __connman_notifier_register(enum connman_service_type type)
168 DBG("type %d", type);
171 case CONNMAN_SERVICE_TYPE_UNKNOWN:
172 case CONNMAN_SERVICE_TYPE_SYSTEM:
173 case CONNMAN_SERVICE_TYPE_VPN:
175 case CONNMAN_SERVICE_TYPE_ETHERNET:
176 case CONNMAN_SERVICE_TYPE_WIFI:
177 case CONNMAN_SERVICE_TYPE_WIMAX:
178 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
179 case CONNMAN_SERVICE_TYPE_CELLULAR:
183 if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0)
184 technology_registered(type, TRUE);
187 void __connman_notifier_unregister(enum connman_service_type type)
189 DBG("type %d", type);
192 case CONNMAN_SERVICE_TYPE_UNKNOWN:
193 case CONNMAN_SERVICE_TYPE_SYSTEM:
194 case CONNMAN_SERVICE_TYPE_VPN:
196 case CONNMAN_SERVICE_TYPE_ETHERNET:
197 case CONNMAN_SERVICE_TYPE_WIFI:
198 case CONNMAN_SERVICE_TYPE_WIMAX:
199 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
200 case CONNMAN_SERVICE_TYPE_CELLULAR:
204 if (g_atomic_int_dec_and_test(®istered[type]) == TRUE)
205 technology_registered(type, FALSE);
208 void __connman_notifier_enable(enum connman_service_type type)
210 DBG("type %d", type);
213 case CONNMAN_SERVICE_TYPE_UNKNOWN:
214 case CONNMAN_SERVICE_TYPE_SYSTEM:
215 case CONNMAN_SERVICE_TYPE_VPN:
217 case CONNMAN_SERVICE_TYPE_ETHERNET:
218 case CONNMAN_SERVICE_TYPE_WIFI:
219 case CONNMAN_SERVICE_TYPE_WIMAX:
220 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
221 case CONNMAN_SERVICE_TYPE_CELLULAR:
225 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
226 technology_enabled(type, TRUE);
229 void __connman_notifier_disable(enum connman_service_type type)
231 DBG("type %d", type);
234 case CONNMAN_SERVICE_TYPE_UNKNOWN:
235 case CONNMAN_SERVICE_TYPE_SYSTEM:
236 case CONNMAN_SERVICE_TYPE_VPN:
238 case CONNMAN_SERVICE_TYPE_ETHERNET:
239 case CONNMAN_SERVICE_TYPE_WIFI:
240 case CONNMAN_SERVICE_TYPE_WIMAX:
241 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
242 case CONNMAN_SERVICE_TYPE_CELLULAR:
246 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
247 technology_enabled(type, FALSE);
250 void __connman_notifier_connect(enum connman_service_type type)
252 DBG("type %d", type);
255 case CONNMAN_SERVICE_TYPE_UNKNOWN:
256 case CONNMAN_SERVICE_TYPE_SYSTEM:
257 case CONNMAN_SERVICE_TYPE_VPN:
259 case CONNMAN_SERVICE_TYPE_ETHERNET:
260 case CONNMAN_SERVICE_TYPE_WIFI:
261 case CONNMAN_SERVICE_TYPE_WIMAX:
262 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
263 case CONNMAN_SERVICE_TYPE_CELLULAR:
267 if (g_atomic_int_exchange_and_add(&connected[type], 1) == 0)
268 technology_connected(type, TRUE);
271 void __connman_notifier_disconnect(enum connman_service_type type)
273 DBG("type %d", type);
276 case CONNMAN_SERVICE_TYPE_UNKNOWN:
277 case CONNMAN_SERVICE_TYPE_SYSTEM:
278 case CONNMAN_SERVICE_TYPE_VPN:
280 case CONNMAN_SERVICE_TYPE_ETHERNET:
281 case CONNMAN_SERVICE_TYPE_WIFI:
282 case CONNMAN_SERVICE_TYPE_WIMAX:
283 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
284 case CONNMAN_SERVICE_TYPE_CELLULAR:
288 if (g_atomic_int_dec_and_test(&connected[type]) == TRUE)
289 technology_connected(type, FALSE);
292 static void technology_default(enum connman_service_type type)
296 str = __connman_service_type2string(type);
300 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
301 CONNMAN_MANAGER_INTERFACE, "DefaultTechnology",
302 DBUS_TYPE_STRING, &str);
305 void __connman_notifier_default_changed(struct connman_service *service)
307 enum connman_service_type type = connman_service_get_type(service);
310 technology_default(type);
312 for (list = notifier_list; list; list = list->next) {
313 struct connman_notifier *notifier = list->data;
315 if (notifier->default_changed)
316 notifier->default_changed(service);
320 static void offlinemode_changed(dbus_bool_t enabled)
322 DBG("enabled %d", enabled);
324 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
325 CONNMAN_MANAGER_INTERFACE, "OfflineMode",
326 DBUS_TYPE_BOOLEAN, &enabled);
329 void __connman_notifier_offlinemode(connman_bool_t enabled)
333 DBG("enabled %d", enabled);
335 __connman_profile_changed(FALSE);
337 offlinemode_changed(enabled);
339 for (list = notifier_list; list; list = list->next) {
340 struct connman_notifier *notifier = list->data;
342 if (notifier->offline_mode)
343 notifier->offline_mode(enabled);
347 connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type)
349 DBG("type %d", type);
352 case CONNMAN_SERVICE_TYPE_UNKNOWN:
353 case CONNMAN_SERVICE_TYPE_SYSTEM:
354 case CONNMAN_SERVICE_TYPE_VPN:
356 case CONNMAN_SERVICE_TYPE_ETHERNET:
357 case CONNMAN_SERVICE_TYPE_WIFI:
358 case CONNMAN_SERVICE_TYPE_WIMAX:
359 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
360 case CONNMAN_SERVICE_TYPE_CELLULAR:
364 if (g_atomic_int_get(&enabled[type]) > 0)
370 int __connman_notifier_init(void)
374 connection = connman_dbus_get_connection();
379 void __connman_notifier_cleanup(void)
383 dbus_connection_unref(connection);