5 * Copyright (C) 2007-2008 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 GSList *driver_list = NULL;
33 static gboolean match_driver(struct connman_device *device,
34 struct connman_device_driver *driver)
36 if (device->element->subtype == driver->type ||
37 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
43 static int device_probe(struct connman_element *element)
45 struct connman_device *device;
48 DBG("element %p name %s", element, element->name);
50 device = g_try_new0(struct connman_device, 1);
54 device->element = element;
56 for (list = driver_list; list; list = list->next) {
57 struct connman_device_driver *driver = list->data;
59 if (match_driver(device, driver) == FALSE)
62 DBG("driver %p name %s", driver, driver->name);
64 if (driver->probe(device) == 0) {
65 device->driver = driver;
66 connman_element_set_data(element, device);
76 static void device_remove(struct connman_element *element)
78 struct connman_device *device = connman_element_get_data(element);
80 DBG("element %p name %s", element, element->name);
82 if (device->driver && device->driver->remove)
83 device->driver->remove(device);
85 connman_element_set_data(element, NULL);
90 static struct connman_driver device_driver = {
92 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
93 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
94 .probe = device_probe,
95 .remove = device_remove,
99 int __connman_device_init(void)
103 //return connman_driver_register(&device_driver);
107 void __connman_device_cleanup(void)
111 //connman_driver_unregister(&device_driver);
114 static gint compare_priority(gconstpointer a, gconstpointer b)
116 const struct connman_device_driver *driver1 = a;
117 const struct connman_device_driver *driver2 = b;
119 return driver2->priority - driver1->priority;
123 * connman_device_driver_register:
124 * @driver: device driver definition
126 * Register a new device driver
128 * Returns: %0 on success
130 int connman_device_driver_register(struct connman_device_driver *driver)
132 DBG("driver %p name %s", driver, driver->name);
134 driver_list = g_slist_insert_sorted(driver_list, driver,
137 //__connman_driver_rescan(&device_driver);
143 * connman_device_driver_unregister:
144 * @driver: device driver definition
146 * Remove a previously registered device driver
148 void connman_device_driver_unregister(struct connman_device_driver *driver)
150 DBG("driver %p name %s", driver, driver->name);
152 driver_list = g_slist_remove(driver_list, driver);