append_path, &filter);
}
-struct count_data {
- enum connman_element_type type;
- int count;
-};
-
-static gboolean count_element(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct count_data *data = user_data;
-
- DBG("element %p name %s", element, element->name);
-
- if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
- return FALSE;
-
- if (data->type != CONNMAN_ELEMENT_TYPE_UNKNOWN &&
- data->type != element->type)
- return FALSE;
-
- data->count++;
-
- return FALSE;
-}
-
-int __connman_element_count(struct connman_element *element,
- enum connman_element_type type)
-{
- struct count_data data = { type, 0 };
- GNode *node;
-
- DBG("");
-
- if (element != NULL) {
- node = g_node_find(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, element);
- if (node == NULL)
- return 0;
- } else
- node = element_root;
-
- g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
- count_element, &data);
-
- return data.count;
-}
-
static struct connman_network *__connman_element_get_network(struct connman_element *element)
{
if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
g_free(property);
}
+static void unregister_child(gpointer data)
+{
+ struct connman_element *element = data;
+
+ DBG("element %p", element);
+
+ connman_element_unref(element);
+}
+
void __connman_element_initialize(struct connman_element *element)
{
DBG("element %p", element);
element->index = -1;
element->enabled = FALSE;
- element->configuring = FALSE;
+ element->children = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, unregister_child);
element->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, unregister_property);
element->properties = NULL;
}
+static void free_children(struct connman_element *element)
+{
+ DBG("element %p name %s", element, element->name);
+
+ g_hash_table_destroy(element->children);
+ element->children = NULL;
+}
+
void connman_element_unref(struct connman_element *element)
{
DBG("element %p name %s refcount %d", element, element->name,
if (g_atomic_int_dec_and_test(&element->refcount) == TRUE) {
if (element->destruct)
element->destruct(element);
+ free_children(element);
free_properties(element);
g_free(element->ipv4.address);
g_free(element->ipv4.netmask);
return value;
}
-static void emit_state_change(DBusConnection *conn, const char *state)
-{
- DBusMessage *signal;
- DBusMessageIter iter;
-
- connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "State",
- DBUS_TYPE_STRING, &state);
-
- signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "StateChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &state);
-
- g_dbus_send_message(conn, signal);
-}
-
static void probe_element(struct connman_element *element)
{
GSList *list;
g_node_append_data(node, element);
- if (element->type == CONNMAN_ELEMENT_TYPE_DHCP) {
- element->parent->configuring = TRUE;
-
-#if 0
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
- emit_state_change(connection, "connecting");
-#endif
- }
-
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- struct connman_element *parent = element->parent;
-
- while (parent) {
- parent->configuring = FALSE;
- parent = parent->parent;
- }
-
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 1)
- emit_state_change(connection, "online");
- }
-
if (started == FALSE)
return;
if (element->devname == NULL)
element->devname = g_strdup(element->name);
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
goto setup;
if (__connman_element_device_isfiltered(element->devname) == TRUE)
if (node != NULL)
g_node_destroy(node);
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
- emit_state_change(connection, "offline");
- }
-
connman_element_unref(element);
return FALSE;
connman_dbus_dict_append_array(&dict, "Devices",
DBUS_TYPE_OBJECT_PATH, __connman_device_list, NULL);
- if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
- str = "online";
- else
- str = "offline";
-
+ str = __connman_notifier_get_state();
connman_dbus_dict_append_basic(&dict, "State",
DBUS_TYPE_STRING, &str);
CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
return __connman_error_permission_denied(msg);
- if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
- str = "online";
- else
- str = "offline";
+ str = __connman_notifier_get_state();
return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &str,
DBUS_TYPE_INVALID);
if (reply == NULL)
return NULL;
- if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
+ if (__connman_notifier_count_connected() > 0)
state = NM_STATE_CONNECTED;
else
state = NM_STATE_DISCONNECTED;
{
int i;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < MAX_TECHNOLOGIES; i++) {
const char *type = __connman_service_type2string(i);
if (type == NULL)
{
int i;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < MAX_TECHNOLOGIES; i++) {
const char *type = __connman_service_type2string(i);
if (type == NULL)
{
int i;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < MAX_TECHNOLOGIES; i++) {
const char *type = __connman_service_type2string(i);
if (type == NULL)
}
}
+unsigned int __connman_notifier_count_connected(void)
+{
+ unsigned int i, count = 0;
+
+ for (i = 0; i < MAX_TECHNOLOGIES; i++) {
+ if (g_atomic_int_get(&connected[i]) > 0)
+ count++;
+ }
+
+ return count;
+}
+
+const char *__connman_notifier_get_state(void)
+{
+ unsigned int count = __connman_notifier_count_connected();
+
+ if (count > 0)
+ return "online";
+
+ return "offline";
+}
+
+static void state_changed(void)
+{
+ unsigned int count = __connman_notifier_count_connected();
+ char *state = "offline";
+ DBusMessage *signal;
+
+ if (count > 1)
+ return;
+
+ if (count > 0)
+ state = "online";
+
+ connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "State",
+ DBUS_TYPE_STRING, &state);
+
+ signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "StateChanged");
+ if (signal == NULL)
+ return;
+
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &state, NULL);
+
+ g_dbus_send_message(connection, signal);
+}
+
static void technology_connected(enum connman_service_type type,
connman_bool_t connected)
{
connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE, "ConnectedTechnologies",
DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
+
+ state_changed();
}
void __connman_notifier_register(enum connman_service_type type)