From: Marcel Holtmann Date: Thu, 15 Jul 2010 15:42:03 +0000 (+0200) Subject: Add support for technology drivers X-Git-Tag: 0.55~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e12fa6d28418efd46d85a4c60a122dca5ce105d6;p=platform%2Fupstream%2Fconnman.git Add support for technology drivers --- diff --git a/Makefile.am b/Makefile.am index aa30177..2f20476 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ noinst_HEADERS = include/driver.h include/element.h include/property.h \ include/dbus.h include/rfkill.h include/option.h \ include/profile.h include/provider.h include/dhcp.h \ include/utsname.h include/timeserver.h \ - include/location.h + include/location.h include/technology.h local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \ $(noinst_HEADERS), include/connman/$(notdir $(file))) diff --git a/include/technology.h b/include/technology.h new file mode 100644 index 0000000..5635040 --- /dev/null +++ b/include/technology.h @@ -0,0 +1,54 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007-2010 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CONNMAN_TECHNOLOGY_H +#define __CONNMAN_TECHNOLOGY_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * SECTION:technology + * @title: technology premitives + * @short_description: Functions for handling technology details + */ + +struct connman_technology; + +struct connman_technology_driver { + const char *name; + enum connman_service_type type; + int priority; + int (*probe) (struct connman_technology *technology); + void (*remove) (struct connman_technology *technology); +}; + +int connman_technology_driver_register(struct connman_technology_driver *driver); +void connman_technology_driver_unregister(struct connman_technology_driver *driver); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMAN_TECHNOLOGY_H */ diff --git a/src/connman.h b/src/connman.h index 7482d5b..1f4be8d 100644 --- a/src/connman.h +++ b/src/connman.h @@ -284,7 +284,7 @@ char *__connman_udev_get_devtype(const char *ifname); void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked); connman_bool_t __connman_udev_get_blocked(int phyindex); -#include +#include void __connman_technology_list(DBusMessageIter *iter, void *user_data); @@ -301,6 +301,8 @@ int __connman_technology_update_rfkill(unsigned int index, connman_bool_t hardblock); int __connman_technology_remove_rfkill(unsigned int index); +#include + int __connman_device_init(void); void __connman_device_cleanup(void); diff --git a/src/technology.c b/src/technology.c index e1dc575..feaa95e 100644 --- a/src/technology.c +++ b/src/technology.c @@ -54,8 +54,52 @@ struct connman_technology { GHashTable *rfkill_list; GSList *device_list; gint enabled; + + struct connman_technology_driver *driver; + void *driver_data; }; +static GSList *driver_list = NULL; + +static gint compare_priority(gconstpointer a, gconstpointer b) +{ + const struct connman_technology_driver *driver1 = a; + const struct connman_technology_driver *driver2 = b; + + return driver2->priority - driver1->priority; +} + +/** + * connman_technology_driver_register: + * @driver: Technology driver definition + * + * Register a new technology driver + * + * Returns: %0 on success + */ +int connman_technology_driver_register(struct connman_technology_driver *driver) +{ + DBG("driver %p name %s", driver, driver->name); + + driver_list = g_slist_insert_sorted(driver_list, driver, + compare_priority); + + return 0; +} + +/** + * connman_technology_driver_unregister: + * @driver: Technology driver definition + * + * Remove a previously registered technology driver + */ +void connman_technology_driver_unregister(struct connman_technology_driver *driver) +{ + DBG("driver %p name %s", driver, driver->name); + + driver_list = g_slist_remove(driver_list, driver); +} + static void free_rfkill(gpointer data) { struct connman_rfkill *rfkill = data; @@ -233,6 +277,7 @@ static struct connman_technology *technology_get(enum connman_service_type type) { struct connman_technology *technology; const char *str; + GSList *list; DBG("type %d", type); @@ -275,6 +320,23 @@ static struct connman_technology *technology_get(enum connman_service_type type) technologies_changed(); + if (technology->driver != NULL) + goto done; + + for (list = driver_list; list; list = list->next) { + struct connman_technology_driver *driver = list->data; + + DBG("driver %p name %s", driver, driver->name); + + if (driver->type != technology->type) + continue; + + if (driver->probe(technology) == 0) { + technology->driver = driver; + break; + } + } + done: DBG("technology %p", technology); @@ -288,6 +350,11 @@ static void technology_put(struct connman_technology *technology) if (g_atomic_int_dec_and_test(&technology->refcount) == FALSE) return; + if (technology->driver) { + technology->driver->remove(technology); + technology->driver = NULL; + } + technology_list = g_slist_remove(technology_list, technology); technologies_changed();