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 DBG("type %d enabled %d", type, enabled);
76 for (list = notifier_list; list; list = list->next) {
77 struct connman_notifier *notifier = list->data;
79 if (notifier->device_enabled)
80 notifier->device_enabled(type, enabled);
84 static void device_registered(enum connman_device_type type,
85 connman_bool_t registered)
87 DBG("type %d registered %d", type, registered);
90 static const char *type2string(enum connman_device_type type)
93 case CONNMAN_DEVICE_TYPE_UNKNOWN:
94 case CONNMAN_DEVICE_TYPE_MBM:
95 case CONNMAN_DEVICE_TYPE_HSO:
96 case CONNMAN_DEVICE_TYPE_NOZOMI:
97 case CONNMAN_DEVICE_TYPE_HUAWEI:
98 case CONNMAN_DEVICE_TYPE_NOVATEL:
99 case CONNMAN_DEVICE_TYPE_VENDOR:
101 case CONNMAN_DEVICE_TYPE_ETHERNET:
103 case CONNMAN_DEVICE_TYPE_WIFI:
105 case CONNMAN_DEVICE_TYPE_WIMAX:
107 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
109 case CONNMAN_DEVICE_TYPE_GPS:
116 static volatile gint registered[20];
117 static volatile gint enabled[20];
119 void __connman_notifier_device_type_list(gboolean powered,
120 DBusMessageIter *iter)
124 for (i = 0; i < 10; i++) {
125 const char *type = type2string(i);
132 count = g_atomic_int_get(&enabled[i]);
134 count = g_atomic_int_get(®istered[i]);
137 dbus_message_iter_append_basic(iter,
138 DBUS_TYPE_STRING, &type);
142 void __connman_notifier_device_type_register(enum connman_device_type type)
144 DBG("type %d", type);
147 case CONNMAN_DEVICE_TYPE_UNKNOWN:
148 case CONNMAN_DEVICE_TYPE_MBM:
149 case CONNMAN_DEVICE_TYPE_HSO:
150 case CONNMAN_DEVICE_TYPE_NOZOMI:
151 case CONNMAN_DEVICE_TYPE_HUAWEI:
152 case CONNMAN_DEVICE_TYPE_NOVATEL:
153 case CONNMAN_DEVICE_TYPE_VENDOR:
155 case CONNMAN_DEVICE_TYPE_ETHERNET:
156 case CONNMAN_DEVICE_TYPE_WIFI:
157 case CONNMAN_DEVICE_TYPE_WIMAX:
158 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
159 case CONNMAN_DEVICE_TYPE_GPS:
160 if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0)
161 device_registered(type, TRUE);
166 void __connman_notifier_device_type_unregister(enum connman_device_type type)
168 DBG("type %d", type);
171 case CONNMAN_DEVICE_TYPE_UNKNOWN:
172 case CONNMAN_DEVICE_TYPE_MBM:
173 case CONNMAN_DEVICE_TYPE_HSO:
174 case CONNMAN_DEVICE_TYPE_NOZOMI:
175 case CONNMAN_DEVICE_TYPE_HUAWEI:
176 case CONNMAN_DEVICE_TYPE_NOVATEL:
177 case CONNMAN_DEVICE_TYPE_VENDOR:
179 case CONNMAN_DEVICE_TYPE_ETHERNET:
180 case CONNMAN_DEVICE_TYPE_WIFI:
181 case CONNMAN_DEVICE_TYPE_WIMAX:
182 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
183 case CONNMAN_DEVICE_TYPE_GPS:
184 if (g_atomic_int_dec_and_test(®istered[type]) == TRUE)
185 device_registered(type, FALSE);
190 void __connman_notifier_device_type_increase(enum connman_device_type type)
192 DBG("type %d", type);
195 case CONNMAN_DEVICE_TYPE_UNKNOWN:
196 case CONNMAN_DEVICE_TYPE_MBM:
197 case CONNMAN_DEVICE_TYPE_HSO:
198 case CONNMAN_DEVICE_TYPE_NOZOMI:
199 case CONNMAN_DEVICE_TYPE_HUAWEI:
200 case CONNMAN_DEVICE_TYPE_NOVATEL:
201 case CONNMAN_DEVICE_TYPE_VENDOR:
203 case CONNMAN_DEVICE_TYPE_ETHERNET:
204 case CONNMAN_DEVICE_TYPE_WIFI:
205 case CONNMAN_DEVICE_TYPE_WIMAX:
206 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
207 case CONNMAN_DEVICE_TYPE_GPS:
208 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
209 device_enabled(type, TRUE);
214 void __connman_notifier_device_type_decrease(enum connman_device_type type)
216 DBG("type %d", type);
219 case CONNMAN_DEVICE_TYPE_UNKNOWN:
220 case CONNMAN_DEVICE_TYPE_MBM:
221 case CONNMAN_DEVICE_TYPE_HSO:
222 case CONNMAN_DEVICE_TYPE_NOZOMI:
223 case CONNMAN_DEVICE_TYPE_HUAWEI:
224 case CONNMAN_DEVICE_TYPE_NOVATEL:
225 case CONNMAN_DEVICE_TYPE_VENDOR:
227 case CONNMAN_DEVICE_TYPE_ETHERNET:
228 case CONNMAN_DEVICE_TYPE_WIFI:
229 case CONNMAN_DEVICE_TYPE_WIMAX:
230 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
231 case CONNMAN_DEVICE_TYPE_GPS:
232 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
233 device_enabled(type, FALSE);
238 void __connman_notifier_offline_mode(connman_bool_t enabled)
242 DBG("enabled %d", enabled);
244 for (list = notifier_list; list; list = list->next) {
245 struct connman_notifier *notifier = list->data;
247 if (notifier->offline_mode)
248 notifier->offline_mode(enabled);
252 int __connman_notifier_init(void)
259 void __connman_notifier_cleanup(void)