From: Marcel Holtmann Date: Fri, 5 Dec 2008 20:39:16 +0000 (+0100) Subject: Do policy based enabling/disabling of devices X-Git-Tag: 2.0_alpha~4533 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7bb1bc293ccdb0d8fb95ae8ef25080ab13656769;p=framework%2Fconnectivity%2Fconnman.git Do policy based enabling/disabling of devices --- diff --git a/src/element.c b/src/element.c index 370713a..c9fd08a 100644 --- a/src/element.c +++ b/src/element.c @@ -795,6 +795,20 @@ static gboolean match_driver(struct connman_element *element, return FALSE; } +static void enable_element(struct connman_element *element) +{ + if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE) + return; + + if (element->policy != CONNMAN_ELEMENT_POLICY_AUTO) + return; + + if (element->driver && element->driver->enable) { + if (element->driver->enable(element) == 0) + element->enabled = TRUE; + } +} + static gboolean probe_driver(GNode *node, gpointer data) { struct connman_element *element = node->data; @@ -809,6 +823,8 @@ static gboolean probe_driver(GNode *node, gpointer data) __connman_element_lock(element); element->driver = driver; __connman_element_unlock(element); + + enable_element(element); } return FALSE; @@ -862,6 +878,20 @@ int connman_driver_register(struct connman_driver *driver) return 0; } +static void disable_element(struct connman_element *element) +{ + if (element->policy != CONNMAN_ELEMENT_POLICY_AUTO) + return; + + if (element->enabled == FALSE) + return; + + if (element->driver && element->driver->disable) { + if (element->driver->disable(element) == 0) + element->enabled = FALSE; + } +} + static gboolean remove_driver(GNode *node, gpointer data) { struct connman_element *element = node->data; @@ -870,6 +900,8 @@ static gboolean remove_driver(GNode *node, gpointer data) DBG("element %p name %s", element, element->name); if (element->driver == driver) { + disable_element(element); + if (driver->remove) driver->remove(element); @@ -1662,6 +1694,8 @@ static void register_element(gpointer data, gpointer user_data) __connman_element_lock(element); element->driver = driver; __connman_element_unlock(element); + + enable_element(element); break; } }