This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 include/Makefile.am |    2 +-
 include/device.h    |   83 ++++++++++++++++++++++++++++
 include/element.h   |    6 ++
 src/Makefile.am     |    3 +-
 src/connman.h       |    8 +++
 src/device.c        |  150 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/element.c       |   35 ++++++++++++
 7 files changed, 285 insertions(+), 2 deletions(-)

New commits:
commit a0035fd5cfe3b29d6098a0310642a59457979a63
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Oct 15 21:45:56 2008 +0200

    Add missing function declaration

commit a95cc3309444678d795e2b29d402c6b0d3b1f059
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Oct 15 21:43:30 2008 +0200

    Fix function declaration

commit 9508e2afee0328fcf3a11775555bb0ffe1b1d3e4
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Oct 15 21:42:40 2008 +0200

    Add set_enabled and rescan funtions

commit eae556dcaff92fc0e7c5915d364839c0c3e52a40
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Oct 15 21:36:00 2008 +0200

    Add init and cleanup calls for device abstraction

commit f99bd377e6e13d163d881b617b5e419658a42f2f
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Oct 15 21:34:40 2008 +0200

    Add string conversion for fake subtype

commit 4fe64c1ea26c8d0d5c2d51c495a83824613cf2e4
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Tue Oct 14 18:05:16 2008 +0200

    Add first step towards providing device abstraction


Diff in this email is a maximum of 400 lines.
diff --git a/include/Makefile.am b/include/Makefile.am
index 76057be..74a8cb7 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -2,7 +2,7 @@
 includedir = @includedir@/connman
 
 include_HEADERS = log.h plugin.h security.h driver.h element.h property.h \
-                                                               rtnl.h dbus.h
+                                                       device.h rtnl.h dbus.h
 
 MAINTAINERCLEANFILES = Makefile.in
 
diff --git a/include/device.h b/include/device.h
new file mode 100644
index 0000000..09d2856
--- /dev/null
+++ b/include/device.h
@@ -0,0 +1,83 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  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_DEVICE_H
+#define __CONNMAN_DEVICE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <connman/element.h>
+
+/**
+ * SECTION:driver
+ * @title: Driver premitives
+ * @short_description: Functions for registering drivers
+ */
+
+enum connman_device_type {
+       CONNMAN_DEVICE_TYPE_UNKNOWN   = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN,
+       CONNMAN_DEVICE_TYPE_FAKE      = CONNMAN_ELEMENT_SUBTYPE_FAKE,
+       CONNMAN_DEVICE_TYPE_ETHERNET  = CONNMAN_ELEMENT_SUBTYPE_ETHERNET,
+       CONNMAN_DEVICE_TYPE_WIFI      = CONNMAN_ELEMENT_SUBTYPE_WIFI,
+       CONNMAN_DEVICE_TYPE_WIMAX     = CONNMAN_ELEMENT_SUBTYPE_WIMAX,
+       CONNMAN_DEVICE_TYPE_MODEM     = CONNMAN_ELEMENT_SUBTYPE_MODEM,
+       CONNMAN_DEVICE_TYPE_BLUETOOTH = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH,
+};
+
+enum connman_device_state {
+       CONNMAN_DEVICE_STATE_UNKNOWN = 0,
+       CONNMAN_DEVICE_STATE_OFF     = 1,
+};
+
+struct connman_device_driver;
+
+struct connman_device {
+       struct connman_element *element;
+       enum connman_device_state state;
+
+       struct connman_device_driver *driver;
+       void *driver_data;
+
+       GSList *networks;
+};
+
+extern int connman_device_set_enabled(struct connman_device *device,
+                                                       gboolean enabled);
+
+struct connman_device_driver {
+       const char *name;
+       enum connman_device_type type;
+       int priority;
+       int (*probe) (struct connman_device *device);
+       void (*remove) (struct connman_device *device);
+       int (*scan) (struct connman_device *device);
+};
+
+extern int connman_device_driver_register(struct connman_device_driver 
*driver);
+extern void connman_device_driver_unregister(struct connman_device_driver 
*driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_DEVICE_H */
diff --git a/include/element.h b/include/element.h
index 4669332..b731d44 100644
--- a/include/element.h
+++ b/include/element.h
@@ -128,6 +128,12 @@ extern void connman_element_unregister(struct 
connman_element *element);
 extern void connman_element_unregister_children(struct connman_element 
*element);
 extern void connman_element_update(struct connman_element *element);
 
+extern int connman_element_set_enabled(struct connman_element *element,
+                                                       gboolean enabled);
+
+extern int connman_element_set_enabled(struct connman_element *element,
+                                                       gboolean enabled);
+
 static inline void *connman_element_get_data(struct connman_element *element)
 {
        return element->driver_data;
diff --git a/src/Makefile.am b/src/Makefile.am
index 52082cd..afa1ce9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,7 +12,8 @@ DISTCLEANFILES = $(service_DATA)
 sbin_PROGRAMS = connmand
 
 connmand_SOURCES = main.c connman.h log.c error.c plugin.c profile.c \
-               element.c security.c storage.c manager.c agent.c rtnl.c
+                               element.c device.c security.c storage.c \
+                                               manager.c agent.c rtnl.c
 
 connmand_LDADD = @GDBUS_LIBS@ @GLIB_LIBS@ @GTHREAD_LIBS@ -ldl
 
diff --git a/src/connman.h b/src/connman.h
index 8b1e6fd..57f97bf 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -62,6 +62,9 @@ void __connman_plugin_cleanup(void);
 int __connman_security_check_privileges(DBusMessage *message);
 
 #include <connman/driver.h>
+
+void __connman_driver_rescan(struct connman_driver *driver);
+
 #include <connman/element.h>
 
 int __connman_element_init(DBusConnection *conn, const char *device);
@@ -76,6 +79,11 @@ const char *__connman_element_subtype2string(enum 
connman_element_subtype type);
 int __connman_element_load(struct connman_element *element);
 int __connman_element_store(struct connman_element *element);
 
+#include <connman/device.h>
+
+int __connman_device_init(void);
+void __connman_device_cleanup(void);
+
 #include <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
diff --git a/src/device.c b/src/device.c
new file mode 100644
index 0000000..0e2cf59
--- /dev/null
+++ b/src/device.c
@@ -0,0 +1,150 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+
+#include "connman.h"
+
+static GSList *driver_list = NULL;
+
+static gboolean match_driver(struct connman_device *device,
+                                       struct connman_device_driver *driver)
+{
+       if (device->element->subtype == driver->type ||
+                       driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
+               return TRUE;
+
+       return FALSE;
+}
+
+static int device_probe(struct connman_element *element)
+{
+       struct connman_device *device;
+       GSList *list;
+
+       DBG("element %p name %s", element, element->name);
+
+       device = g_try_new0(struct connman_device, 1);
+       if (device == NULL)
+               return -ENOMEM;
+
+       device->element = element;
+
+       for (list = driver_list; list; list = list->next) {
+               struct connman_device_driver *driver = list->data;
+
+               if (match_driver(device, driver) == FALSE)
+                       continue;
+
+               DBG("driver %p name %s", driver, driver->name);
+
+               if (driver->probe(device) == 0) {
+                       device->driver = driver;
+                       connman_element_set_data(element, device);
+                       return 0;
+               }
+       }
+
+       g_free(device);
+
+       return -ENODEV;
+}
+
+static void device_remove(struct connman_element *element)
+{
+       struct connman_device *device = connman_element_get_data(element);
+
+       DBG("element %p name %s", element, element->name);
+
+       if (device->driver && device->driver->remove)
+               device->driver->remove(device);
+
+       connman_element_set_data(element, NULL);
+
+       g_free(device);
+}
+
+static struct connman_driver device_driver = {
+       .name           = "device",
+       .type           = CONNMAN_ELEMENT_TYPE_DEVICE,
+       .priority       = CONNMAN_DRIVER_PRIORITY_LOW,
+       .probe          = device_probe,
+       .remove         = device_remove,
+};
+
+int __connman_device_init(void)
+{
+       DBG("");
+
+       return connman_driver_register(&device_driver);
+}
+
+void __connman_device_cleanup(void)
+{
+       DBG("");
+
+       connman_driver_unregister(&device_driver);
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+       const struct connman_device_driver *driver1 = a;
+       const struct connman_device_driver *driver2 = b;
+
+       return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_device_driver_register:
+ * @driver: device driver definition
+ *
+ * Register a new device driver
+ *
+ * Returns: %0 on success
+ */
+int connman_device_driver_register(struct connman_device_driver *driver)
+{
+       DBG("driver %p name %s", driver, driver->name);
+
+       driver_list = g_slist_insert_sorted(driver_list, driver,
+                                                       compare_priority);
+
+       __connman_driver_rescan(&device_driver);
+
+       return 0;
+}
+
+/**
+ * connman_device_driver_unregister:
+ * @driver: device driver definition
+ *
+ * Remove a previously registered device driver
+ */
+void connman_device_driver_unregister(struct connman_device_driver *driver)
+{
+       DBG("driver %p name %s", driver, driver->name);
+
+       driver_list = g_slist_remove(driver_list, driver);
+}
diff --git a/src/element.c b/src/element.c
index d3b2cc5..dd78c69 100644
--- a/src/element.c
+++ b/src/element.c
@@ -122,6 +122,8 @@ static const char *subtype2string(enum 
connman_element_subtype type)
        switch (type) {
        case CONNMAN_ELEMENT_SUBTYPE_UNKNOWN:
                return "unknown";
+       case CONNMAN_ELEMENT_SUBTYPE_FAKE:
+               return "fake";
        case CONNMAN_ELEMENT_SUBTYPE_NETWORK:
                return "network";
        case CONNMAN_ELEMENT_SUBTYPE_ETHERNET:
@@ -516,6 +518,22 @@ static gboolean probe_driver(GNode *node, gpointer data)
        return FALSE;
 }
 
+void __connman_driver_rescan(struct connman_driver *driver)
+{
+       DBG("driver %p name %s", driver, driver->name);
+
+       if (!driver->probe)
+               return;
+
+       g_static_rw_lock_writer_lock(&element_lock);
+
+       if (element_root != NULL)
+               g_node_traverse(element_root, G_PRE_ORDER,
+                               G_TRAVERSE_ALL, -1, probe_driver, driver);
+
+       g_static_rw_lock_writer_unlock(&element_lock);
+}
+
 /**
  * connman_driver_register:
  * @driver: driver definition
@@ -1051,6 +1069,19 @@ void connman_element_update(struct connman_element 
*element)
        g_static_rw_lock_reader_unlock(&element_lock);
 }
 
+int connman_element_set_enabled(struct connman_element *element,
+                                                       gboolean enabled)
+{
+       if (element->enabled == enabled)
+               return 0;
+
+       element->enabled = enabled;
+
+       connman_element_update(element);
+
+       return 0;
+}
+
 static void register_element(gpointer data, gpointer user_data)
 {
        struct connman_element *element = data;
@@ -1227,6 +1258,8 @@ int __connman_element_init(DBusConnection *conn, const 
char *device)
        thread_unregister_children = g_thread_pool_new(unregister_children,
                                                        NULL, 1, FALSE, NULL);
 
+       __connman_device_init();
+
        return 0;
 }
 
@@ -1264,6 +1297,8 @@ void __connman_element_cleanup(void)
 {
        DBG("");
 
+       __connman_device_cleanup();
+
        g_thread_pool_free(thread_register, TRUE, TRUE);
        thread_register = NULL;
 
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to