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
28 struct connman_location {
30 struct connman_service *service;
31 enum connman_location_result result;
33 struct connman_location_driver *driver;
38 * connman_location_ref:
39 * @location: Location structure
41 * Increase reference counter of location
43 struct connman_location *connman_location_ref(struct connman_location *location)
45 g_atomic_int_inc(&location->refcount);
51 * connman_location_unref:
52 * @location: Location structure
54 * Decrease reference counter of location
56 void connman_location_unref(struct connman_location *location)
58 if (g_atomic_int_dec_and_test(&location->refcount) == FALSE)
61 if (location->driver) {
62 location->driver->finish(location);
63 location->driver = NULL;
70 * connman_location_get_type:
71 * @location: Location structure
73 * Get the service type of location
75 enum connman_service_type connman_location_get_type(struct connman_location *location)
78 return CONNMAN_SERVICE_TYPE_UNKNOWN;
80 return connman_service_get_type(location->service);
84 * connman_location_get_interface:
85 * @location: location structure
87 * Get network interface of location
89 char *connman_location_get_interface(struct connman_location *location)
94 return connman_service_get_interface(location->service);
98 * connman_location_get_data:
99 * @location: Location structure
101 * Get private location data pointer
103 void *connman_location_get_data(struct connman_location *location)
105 return location->driver_data;
109 * connman_location_set_data:
110 * @location: Location structure
111 * @data: data pointer
113 * Set private location data pointer
115 void connman_location_set_data(struct connman_location *location, void *data)
117 location->driver_data = data;
120 static GSList *driver_list = NULL;
122 static gint compare_priority(gconstpointer a, gconstpointer b)
124 const struct connman_location_driver *driver1 = a;
125 const struct connman_location_driver *driver2 = b;
127 return driver2->priority - driver1->priority;
131 * connman_location_driver_register:
132 * @driver: Location driver definition
134 * Register a new Location driver
136 * Returns: %0 on success
138 int connman_location_driver_register(struct connman_location_driver *driver)
140 DBG("driver %p name %s", driver, driver->name);
142 driver_list = g_slist_insert_sorted(driver_list, driver,
149 * connman_location_driver_unregister:
150 * @driver: Location driver definition
152 * Remove a previously registered Location driver
154 void connman_location_driver_unregister(struct connman_location_driver *driver)
156 DBG("driver %p name %s", driver, driver->name);
158 driver_list = g_slist_remove(driver_list, driver);
162 * connman_location_report_result:
163 * @location: location structure
164 * @result: result information
166 * Report result of a location detection
168 void connman_location_report_result(struct connman_location *location,
169 enum connman_location_result result)
171 DBG("location %p result %d", location, result);
173 if (location == NULL)
176 if (location->result == result)
179 location->result = result;
181 switch (location->result) {
182 case CONNMAN_LOCATION_RESULT_UNKNOWN:
184 case CONNMAN_LOCATION_RESULT_PORTAL:
185 //__connman_service_indicate_state(location->service,
186 // CONNMAN_SERVICE_STATE_LOGIN);
188 case CONNMAN_LOCATION_RESULT_ONLINE:
189 //__connman_service_indicate_state(location->service,
190 // CONNMAN_SERVICE_STATE_ONLINE);
195 struct connman_location *__connman_location_create(struct connman_service *service)
197 struct connman_location *location;
199 DBG("service %p", service);
204 location = g_try_new0(struct connman_location, 1);
205 if (location == NULL)
208 DBG("location %p", location);
210 location->refcount = 1;
212 location->service = service;
213 location->result = CONNMAN_LOCATION_RESULT_UNKNOWN;
218 int __connman_location_detect(struct connman_service *service)
220 struct connman_location *location;
223 DBG("service %p", service);
225 location = __connman_service_get_location(service);
226 if (location == NULL)
229 if (location->driver)
232 for (list = driver_list; list; list = list->next) {
233 struct connman_location_driver *driver = list->data;
235 DBG("driver %p name %s", driver, driver->name);
237 if (driver->detect(location) == 0) {
238 location->driver = driver;
243 if (location->driver == NULL)
244 connman_location_report_result(location,
245 CONNMAN_LOCATION_RESULT_ONLINE);
250 int __connman_location_finish(struct connman_service *service)
252 struct connman_location *location;
254 DBG("service %p", service);
256 location = __connman_service_get_location(service);
257 if (location == NULL)
260 if (location->driver) {
261 location->driver->finish(location);
262 location->driver = NULL;
268 int __connman_location_init(void)
273 void __connman_location_cleanup(void)