5 * Copyright (C) 2007-2009 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
28 static GSList *notifier_list = NULL;
30 static gint compare_priority(gconstpointer a, gconstpointer b)
32 const struct connman_notifier *notifier1 = a;
33 const struct connman_notifier *notifier2 = b;
35 return notifier2->priority - notifier1->priority;
39 * connman_notifier_register:
40 * @notifier: notifier module
42 * Register a new notifier module
44 * Returns: %0 on success
46 int connman_notifier_register(struct connman_notifier *notifier)
48 DBG("notifier %p name %s", notifier, notifier->name);
50 notifier_list = g_slist_insert_sorted(notifier_list, notifier,
57 * connman_notifier_unregister:
58 * @notifier: notifier module
60 * Remove a previously registered notifier module
62 void connman_notifier_unregister(struct connman_notifier *notifier)
64 DBG("notifier %p name %s", notifier, notifier->name);
66 notifier_list = g_slist_remove(notifier_list, notifier);
69 static void device_enabled(enum connman_device_type type,
70 connman_bool_t enabled)
74 for (list = notifier_list; list; list = list->next) {
75 struct connman_notifier *notifier = list->data;
77 if (notifier->device_enabled)
78 notifier->device_enabled(type, enabled);
83 static volatile gint enabled[10];
85 void __connman_notifier_device_type_increase(enum connman_device_type type)
90 case CONNMAN_DEVICE_TYPE_UNKNOWN:
91 case CONNMAN_DEVICE_TYPE_HSO:
92 case CONNMAN_DEVICE_TYPE_NOZOMI:
93 case CONNMAN_DEVICE_TYPE_HUAWEI:
94 case CONNMAN_DEVICE_TYPE_NOVATEL:
95 case CONNMAN_DEVICE_TYPE_VENDOR:
97 case CONNMAN_DEVICE_TYPE_ETHERNET:
98 case CONNMAN_DEVICE_TYPE_WIFI:
99 case CONNMAN_DEVICE_TYPE_WIMAX:
100 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
101 case CONNMAN_DEVICE_TYPE_GPS:
102 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
103 device_enabled(type, TRUE);
108 void __connman_notifier_device_type_decrease(enum connman_device_type type)
110 DBG("type %d", type);
113 case CONNMAN_DEVICE_TYPE_UNKNOWN:
114 case CONNMAN_DEVICE_TYPE_HSO:
115 case CONNMAN_DEVICE_TYPE_NOZOMI:
116 case CONNMAN_DEVICE_TYPE_HUAWEI:
117 case CONNMAN_DEVICE_TYPE_NOVATEL:
118 case CONNMAN_DEVICE_TYPE_VENDOR:
120 case CONNMAN_DEVICE_TYPE_ETHERNET:
121 case CONNMAN_DEVICE_TYPE_WIFI:
122 case CONNMAN_DEVICE_TYPE_WIMAX:
123 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
124 case CONNMAN_DEVICE_TYPE_GPS:
125 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
126 device_enabled(type, FALSE);
131 void __connman_notifier_offline_mode(connman_bool_t enabled)
135 DBG("enabled %d", enabled);
137 for (list = notifier_list; list; list = list->next) {
138 struct connman_notifier *notifier = list->data;
140 if (notifier->offline_mode)
141 notifier->offline_mode(enabled);
145 int __connman_notifier_init(void)
152 void __connman_notifier_cleanup(void)