summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-07-15 17:42:03 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-07-15 17:42:03 +0200
commite12fa6d28418efd46d85a4c60a122dca5ce105d6 (patch)
treefc43a06cffc1a7e5f4e1f7bc6b8c7c09bc5f1e69
parent171d554c7fe91e9f9c266d466946b2eed43b7e7e (diff)
downloadconnman-e12fa6d28418efd46d85a4c60a122dca5ce105d6.tar.gz
connman-e12fa6d28418efd46d85a4c60a122dca5ce105d6.tar.bz2
connman-e12fa6d28418efd46d85a4c60a122dca5ce105d6.zip
Add support for technology drivers
-rw-r--r--Makefile.am2
-rw-r--r--include/technology.h54
-rw-r--r--src/connman.h4
-rw-r--r--src/technology.c67
4 files changed, 125 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index aa30177b..2f20476b 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 00000000..56350406
--- /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 <connman/service.h>
+
+#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 7482d5bc..1f4be8d3 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 <connman/device.h>
+#include <connman/technology.h>
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 <connman/device.h>
+
int __connman_device_init(void);
void __connman_device_cleanup(void);
diff --git a/src/technology.c b/src/technology.c
index e1dc5753..feaa95e1 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();