DBG("property %p", property);
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE))
- g_free(property->value);
-
- g_free(property->name);
+ g_free(property->value);
g_free(property);
}
element->index = -1;
element->enabled = FALSE;
- element->properties = g_hash_table_new_full(g_str_hash, g_direct_equal,
+ element->configuring = FALSE;
+
+ element->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, unregister_property);
}
}
}
-int connman_element_add_static_property(struct connman_element *element,
+static int set_static_property(struct connman_element *element,
const char *name, int type, const void *value)
{
struct connman_property *property;
if (property == NULL)
return -ENOMEM;
- property->flags = CONNMAN_PROPERTY_FLAG_STATIC;
- property->id = CONNMAN_PROPERTY_ID_INVALID;
- property->name = g_strdup(name);
- property->type = type;
+ property->id = CONNMAN_PROPERTY_ID_INVALID;
+ property->type = type;
DBG("name %s type %d value %p", name, type, value);
__connman_element_lock(element);
- g_hash_table_insert(element->properties, g_strdup(name), property);
+ g_hash_table_replace(element->properties, g_strdup(name), property);
__connman_element_unlock(element);
return 0;
}
-int connman_element_set_static_property(struct connman_element *element,
- const char *name, int type, const void *value)
-{
- struct connman_property *property;
-
- DBG("element %p name %s", element, element->name);
-
- if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_BYTE)
- return -EINVAL;
-
- __connman_element_lock(element);
-
- property = g_hash_table_lookup(element->properties, name);
- if (property != NULL) {
- property->flags |= CONNMAN_PROPERTY_FLAG_STATIC;
-
- property->type = type;
- g_free(property->value);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- property->value = g_strdup(*((const char **) value));
- break;
- case DBUS_TYPE_BYTE:
- property->value = g_try_malloc(1);
- if (property->value != NULL)
- memcpy(property->value, value, 1);
- break;
- }
- }
-
- __connman_element_unlock(element);
-
- return 0;
-}
-
-int connman_element_add_static_array_property(struct connman_element *element,
+static int set_static_array_property(struct connman_element *element,
const char *name, int type, const void *value, int len)
{
struct connman_property *property;
if (property == NULL)
return -ENOMEM;
- property->flags = CONNMAN_PROPERTY_FLAG_STATIC;
property->id = CONNMAN_PROPERTY_ID_INVALID;
- property->name = g_strdup(name);
property->type = DBUS_TYPE_ARRAY;
property->subtype = type;
__connman_element_lock(element);
- g_hash_table_insert(element->properties, g_strdup(name), property);
+ g_hash_table_replace(element->properties, g_strdup(name), property);
__connman_element_unlock(element);
return 0;
}
-int connman_element_set_property(struct connman_element *element,
+#if 0
+static int set_property(struct connman_element *element,
enum connman_property_id id, const void *value)
{
switch (id) {
return 0;
}
+#endif
int connman_element_get_value(struct connman_element *element,
enum connman_property_id id, void *value)
return 0;
}
-gboolean connman_element_get_static_property(struct connman_element *element,
+static gboolean get_static_property(struct connman_element *element,
const char *name, void *value)
{
struct connman_property *property;
__connman_element_lock(element);
property = g_hash_table_lookup(element->properties, name);
- if (property != NULL &&
- (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)) {
- if (g_str_equal(property->name, name) == TRUE) {
- switch (property->type) {
- case DBUS_TYPE_STRING:
- *((char **) value) = property->value;
- found = TRUE;
- break;
- case DBUS_TYPE_BYTE:
- memcpy(value, property->value, 1);
- found = TRUE;
- break;
- }
+ if (property != NULL) {
+ switch (property->type) {
+ case DBUS_TYPE_STRING:
+ *((char **) value) = property->value;
+ found = TRUE;
+ break;
+ case DBUS_TYPE_BYTE:
+ memcpy(value, property->value, 1);
+ found = TRUE;
+ break;
}
}
__connman_element_unlock(element);
if (found == FALSE && element->parent != NULL)
- return connman_element_get_static_property(element->parent,
- name, value);
+ return get_static_property(element->parent, name, value);
return found;
}
-gboolean connman_element_get_static_array_property(struct connman_element *element,
- const char *name, void *value, int *len)
+static gboolean get_static_array_property(struct connman_element *element,
+ const char *name, void *value, unsigned int *len)
{
struct connman_property *property;
gboolean found = FALSE;
__connman_element_lock(element);
property = g_hash_table_lookup(element->properties, name);
- if (property != NULL &&
- (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)) {
- if (g_str_equal(property->name, name) == TRUE) {
- *((char **) value) = property->value;
- *len = property->size;
- found = TRUE;
- }
+ if (property != NULL) {
+ *((char **) value) = property->value;
+ *len = property->size;
+ found = TRUE;
}
__connman_element_unlock(element);
return found;
}
-gboolean connman_element_match_static_property(struct connman_element *element,
+#if 0
+static gboolean match_static_property(struct connman_element *element,
const char *name, const void *value)
{
struct connman_property *property;
__connman_element_lock(element);
property = g_hash_table_lookup(element->properties, name);
- if (property != NULL &&
- (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)) {
- if (g_str_equal(property->name, name) == TRUE &&
- property->type == DBUS_TYPE_STRING)
+ if (property != NULL) {
+ if (property->type == DBUS_TYPE_STRING)
result = g_str_equal(property->value,
*((const char **) value));
}
return result;
}
+#endif
-static void append_connections(DBusMessageIter *entry)
+/**
+ * connman_element_set_string:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_element_set_string(struct connman_element *element,
+ const char *key, const char *value)
{
- DBusMessageIter value, iter;
- const char *key = "Connections";
+ return set_static_property(element, key, DBUS_TYPE_STRING, &value);
+}
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
+/**
+ * connman_element_get_string:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_element_get_string(struct connman_element *element,
+ const char *key)
+{
+ const char *value;
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
- &value);
+ if (get_static_property(element, key, &value) == FALSE)
+ return NULL;
- dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
- __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION, &iter);
- dbus_message_iter_close_container(&value, &iter);
+ return value;
+}
- dbus_message_iter_close_container(entry, &value);
+/**
+ * connman_element_set_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: integer value
+ *
+ * Set integer value for specific key
+ */
+int connman_element_set_uint8(struct connman_element *element,
+ const char *key, connman_uint8_t value)
+{
+ return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
}
-static void emit_connections_signal(DBusConnection *conn)
+/**
+ * connman_element_get_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get integer value for specific key
+ */
+connman_uint8_t connman_element_get_uint8(struct connman_element *element,
+ const char *key)
{
- DBusMessage *signal;
- DBusMessageIter entry;
+ connman_uint8_t value;
- DBG("conn %p", conn);
+ if (get_static_property(element, key, &value) == FALSE)
+ return 0;
- signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
+ return value;
+}
- dbus_message_iter_init_append(signal, &entry);
+/**
+ * connman_element_set_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @data: blob data
+ * @size: blob size
+ *
+ * Set binary blob value for specific key
+ */
+int connman_element_set_blob(struct connman_element *element,
+ const char *key, const void *data, unsigned int size)
+{
+ return set_static_array_property(element, key,
+ DBUS_TYPE_BYTE, data, size);
+}
+
+/**
+ * connman_element_get_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @size: pointer to blob size
+ *
+ * Get binary blob value for specific key
+ */
+const void *connman_element_get_blob(struct connman_element *element,
+ const char *key, unsigned int *size)
+{
+ void *value;
- append_connections(&entry);
+ if (get_static_array_property(element, key, &value, size) == FALSE)
+ return NULL;
- g_dbus_send_message(conn, signal);
+ return value;
+}
+
+int __connman_element_append_ipv4(struct connman_element *element,
+ DBusMessageIter *dict)
+{
+ const char *method = NULL;
+ const char *address = NULL, *netmask = NULL, *gateway = NULL;
+
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_METHOD, &method);
+
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_ADDRESS, &address);
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_NETMASK, &netmask);
+ connman_element_get_value(element,
+ CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
+
+ if (method != NULL)
+ connman_dbus_dict_append_variant(dict, "IPv4.Method",
+ DBUS_TYPE_STRING, &method);
+
+ if (address != NULL)
+ connman_dbus_dict_append_variant(dict, "IPv4.Address",
+ DBUS_TYPE_STRING, &address);
+
+ if (netmask != NULL)
+ connman_dbus_dict_append_variant(dict, "IPv4.Netmask",
+ DBUS_TYPE_STRING, &netmask);
+
+ if (gateway != NULL)
+ connman_dbus_dict_append_variant(dict, "IPv4.Gateway",
+ DBUS_TYPE_STRING, &gateway);
+
+ return 0;
+}
+
+int __connman_element_set_ipv4(struct connman_element *element,
+ const char *name, DBusMessageIter *value)
+{
+ int type;
+
+ type = dbus_message_iter_get_arg_type(value);
+
+ if (g_str_equal(name, "IPv4.Method") == TRUE) {
+ enum connman_ipv4_method method;
+ const char *str;
+
+ if (type != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(value, &str);
+ method = __connman_ipv4_string2method(str);
+ if (method == CONNMAN_IPV4_METHOD_UNKNOWN)
+ return -EINVAL;
+
+ if (method == element->ipv4.method)
+ return -EALREADY;
+
+ element->ipv4.method = method;
+
+ connman_element_update(element);
+ } else if (g_str_equal(name, "IPv4.Address") == TRUE) {
+ const char *address;
+
+ if (type != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(value, &address);
+
+ g_free(element->ipv4.address);
+ element->ipv4.address = g_strdup(address);
+
+ connman_element_update(element);
+ } else if (g_str_equal(name, "IPv4.Netmask") == TRUE) {
+ const char *netmask;
+
+ if (type != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(value, &netmask);
+
+ g_free(element->ipv4.netmask);
+ element->ipv4.netmask = g_strdup(netmask);
+
+ connman_element_update(element);
+ } else if (g_str_equal(name, "IPv4.Gateway") == TRUE) {
+ const char *gateway;
+
+ if (type != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(value, &gateway);
+
+ g_free(element->ipv4.gateway);
+ element->ipv4.gateway = g_strdup(gateway);
+
+ connman_element_update(element);
+ }
+
+ return 0;
}
static void append_state(DBusMessageIter *entry, const char *state)
g_node_append_data(node, element);
+ if (element->type == CONNMAN_ELEMENT_TYPE_DHCP) {
+ element->parent->configuring = TRUE;
+
+ if (__connman_element_count(NULL,
+ CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
+ emit_state_change(connection, "connecting");
+ }
+
if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- emit_connections_signal(connection);
- emit_state_change(connection, "online");
+ 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");
}
emit_element_signal(connection, "ElementAdded", element);
if (__connman_element_count(NULL,
CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
emit_state_change(connection, "offline");
- emit_connections_signal(connection);
}
emit_element_signal(connection, "ElementRemoved", element);
element->enabled = enabled;
+ connman_element_update(element);
+
return 0;
}
-int __connman_element_init(DBusConnection *conn, const char *device)
+int __connman_element_init(DBusConnection *conn, const char *device,
+ const char *nodevice)
{
struct connman_element *element;
element_root = g_node_new(element);
+ __connman_notifier_init();
__connman_network_init();
__connman_device_init();
__connman_device_cleanup();
__connman_network_cleanup();
+ __connman_notifier_cleanup();
g_node_traverse(element_root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
free_driver, NULL);