Add device type for Ericsson MBM hardware
[platform/upstream/connman.git] / src / notifier.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 "connman.h"
27
28 static GSList *notifier_list = NULL;
29
30 static gint compare_priority(gconstpointer a, gconstpointer b)
31 {
32         const struct connman_notifier *notifier1 = a;
33         const struct connman_notifier *notifier2 = b;
34
35         return notifier2->priority - notifier1->priority;
36 }
37
38 /**
39  * connman_notifier_register:
40  * @notifier: notifier module
41  *
42  * Register a new notifier module
43  *
44  * Returns: %0 on success
45  */
46 int connman_notifier_register(struct connman_notifier *notifier)
47 {
48         DBG("notifier %p name %s", notifier, notifier->name);
49
50         notifier_list = g_slist_insert_sorted(notifier_list, notifier,
51                                                         compare_priority);
52
53         return 0;
54 }
55
56 /**
57  * connman_notifier_unregister:
58  * @notifier: notifier module
59  *
60  * Remove a previously registered notifier module
61  */
62 void connman_notifier_unregister(struct connman_notifier *notifier)
63 {
64         DBG("notifier %p name %s", notifier, notifier->name);
65
66         notifier_list = g_slist_remove(notifier_list, notifier);
67 }
68
69 static void device_enabled(enum connman_device_type type,
70                                                 connman_bool_t enabled)
71 {
72         GSList *list;
73
74         for (list = notifier_list; list; list = list->next) {
75                 struct connman_notifier *notifier = list->data;
76
77                 if (notifier->device_enabled)
78                         notifier->device_enabled(type, enabled);
79         }
80
81 }
82
83 static volatile gint enabled[10];
84
85 void __connman_notifier_device_type_increase(enum connman_device_type type)
86 {
87         DBG("type %d", type);
88
89         switch (type) {
90         case CONNMAN_DEVICE_TYPE_UNKNOWN:
91         case CONNMAN_DEVICE_TYPE_MBM:
92         case CONNMAN_DEVICE_TYPE_HSO:
93         case CONNMAN_DEVICE_TYPE_NOZOMI:
94         case CONNMAN_DEVICE_TYPE_HUAWEI:
95         case CONNMAN_DEVICE_TYPE_NOVATEL:
96         case CONNMAN_DEVICE_TYPE_VENDOR:
97                 return;
98         case CONNMAN_DEVICE_TYPE_ETHERNET:
99         case CONNMAN_DEVICE_TYPE_WIFI:
100         case CONNMAN_DEVICE_TYPE_WIMAX:
101         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
102         case CONNMAN_DEVICE_TYPE_GPS:
103                 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
104                         device_enabled(type, TRUE);
105                 break;
106         }
107 }
108
109 void __connman_notifier_device_type_decrease(enum connman_device_type type)
110 {
111         DBG("type %d", type);
112
113         switch (type) {
114         case CONNMAN_DEVICE_TYPE_UNKNOWN:
115         case CONNMAN_DEVICE_TYPE_MBM:
116         case CONNMAN_DEVICE_TYPE_HSO:
117         case CONNMAN_DEVICE_TYPE_NOZOMI:
118         case CONNMAN_DEVICE_TYPE_HUAWEI:
119         case CONNMAN_DEVICE_TYPE_NOVATEL:
120         case CONNMAN_DEVICE_TYPE_VENDOR:
121                 return;
122         case CONNMAN_DEVICE_TYPE_ETHERNET:
123         case CONNMAN_DEVICE_TYPE_WIFI:
124         case CONNMAN_DEVICE_TYPE_WIMAX:
125         case CONNMAN_DEVICE_TYPE_BLUETOOTH:
126         case CONNMAN_DEVICE_TYPE_GPS:
127                 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
128                         device_enabled(type, FALSE);
129                 break;
130         }
131 }
132
133 void __connman_notifier_offline_mode(connman_bool_t enabled)
134 {
135         GSList *list;
136
137         DBG("enabled %d", enabled);
138
139         for (list = notifier_list; list; list = list->next) {
140                 struct connman_notifier *notifier = list->data;
141
142                 if (notifier->offline_mode)
143                         notifier->offline_mode(enabled);
144         }
145 }
146
147 int __connman_notifier_init(void)
148 {
149         DBG("");
150
151         return 0;
152 }
153
154 void __connman_notifier_cleanup(void)
155 {
156         DBG("");
157 }