From e061175d100cbb068b572030b88981f83984287c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 5 Jan 2009 00:23:29 +0100 Subject: [PATCH] Add support for more device and network properties --- include/device.h | 7 ++++-- include/network.h | 4 ++-- src/device.c | 68 +++++++++++++++++++++++++++++++++++++++---------------- src/network.c | 56 +++++++++++++++++++++++++++++---------------- 4 files changed, 93 insertions(+), 42 deletions(-) diff --git a/include/device.h b/include/device.h index b14b9b1..8af7d28 100644 --- a/include/device.h +++ b/include/device.h @@ -70,8 +70,6 @@ extern struct connman_device *connman_device_create(const char *node, extern struct connman_device *connman_device_ref(struct connman_device *device); extern void connman_device_unref(struct connman_device *device); -extern void connman_device_set_path(struct connman_device *device, - const char *path); extern const char *connman_device_get_path(struct connman_device *device); extern void connman_device_set_index(struct connman_device *device, int index); @@ -92,6 +90,11 @@ extern int connman_device_set_carrier(struct connman_device *device, extern int connman_device_set_scanning(struct connman_device *device, connman_bool_t scanning); +extern int connman_device_set_string(struct connman_device *device, + const char *key, const char *value); +extern const char *connman_device_get_string(struct connman_device *device, + const char *key); + extern int connman_device_add_network(struct connman_device *device, struct connman_network *network); extern struct connman_network *connman_device_get_network(struct connman_device *device, diff --git a/include/network.h b/include/network.h index 7249264..14e9d87 100644 --- a/include/network.h +++ b/include/network.h @@ -59,8 +59,6 @@ extern void connman_network_unref(struct connman_network *network); extern const char *connman_network_get_identifier(struct connman_network *network); -extern void connman_network_set_path(struct connman_network *network, - const char *path); extern const char *connman_network_get_path(struct connman_network *network); extern void connman_network_set_index(struct connman_network *network, int index); @@ -74,6 +72,8 @@ extern int connman_network_set_connected(struct connman_network *network, extern int connman_network_set_string(struct connman_network *network, const char *key, const char *value); +extern const char *connman_network_get_string(struct connman_network *network, + const char *key); extern int connman_network_set_uint8(struct connman_network *network, const char *key, connman_uint8_t value); extern int connman_network_set_blob(struct connman_network *network, diff --git a/src/device.c b/src/device.c index f481175..48f3f7d 100644 --- a/src/device.c +++ b/src/device.c @@ -36,7 +36,8 @@ struct connman_device { gboolean powered; gboolean carrier; gboolean scanning; - char *path; + char *name; + char *node; char *interface; struct connman_device_driver *driver; @@ -656,7 +657,8 @@ static void device_destruct(struct connman_element *element) DBG("element %p name %s", element, element->name); - g_free(device->path); + g_free(device->node); + g_free(device->name); g_free(device->interface); g_hash_table_destroy(device->networks); @@ -747,22 +749,6 @@ void connman_device_unref(struct connman_device *device) } /** - * connman_device_set_path: - * @device: device structure - * @path: path name - * - * Set path name of device - */ -void connman_device_set_path(struct connman_device *device, const char *path) -{ - g_free(device->element.devpath); - device->element.devpath = g_strdup(path); - - g_free(device->path); - device->path = g_strdup(path); -} - -/** * connman_device_get_path: * @device: device structure * @@ -770,7 +756,7 @@ void connman_device_set_path(struct connman_device *device, const char *path) */ const char *connman_device_get_path(struct connman_device *device) { - return device->path; + return device->element.path; } /** @@ -979,6 +965,50 @@ int connman_device_set_scanning(struct connman_device *device, } /** + * connman_device_set_string: + * @device: device structure + * @key: unique identifier + * @value: string value + * + * Set string value for specific key + */ +int connman_device_set_string(struct connman_device *device, + const char *key, const char *value) +{ + DBG("device %p key %s value %s", device, key, value); + + if (g_str_equal(key, "Name") == TRUE) { + g_free(device->name); + device->name = g_strdup(value); + } else if (g_str_equal(key, "Node") == TRUE) { + g_free(device->node); + device->node = g_strdup(value); + } + + return 0; +} + +/** + * connman_device_get_string: + * @device: device structure + * @key: unique identifier + * + * Get string value for specific key + */ +const char *connman_device_get_string(struct connman_device *device, + const char *key) +{ + DBG("device %p key %s", device); + + if (g_str_equal(key, "Name") == TRUE) + return device->name; + else if (g_str_equal(key, "Node") == TRUE) + return device->node; + + return NULL; +} + +/** * connman_device_add_network: * @device: device structure * @network: network structure diff --git a/src/network.c b/src/network.c index cd0bb75..898bed5 100644 --- a/src/network.c +++ b/src/network.c @@ -37,7 +37,7 @@ struct connman_network { connman_uint8_t strength; char *identifier; char *name; - char *path; + char *node; struct connman_network_driver *driver; void *driver_data; @@ -73,6 +73,13 @@ static DBusMessage *get_properties(DBusConnection *conn, DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + if (network->device) { + const char *path = connman_device_get_path(network->device); + if (path != NULL) + connman_dbus_dict_append_variant(&dict, "Device", + DBUS_TYPE_OBJECT_PATH, &path); + } + if (network->name != NULL) connman_dbus_dict_append_variant(&dict, "Name", DBUS_TYPE_STRING, &network->name); @@ -261,7 +268,7 @@ static void network_destruct(struct connman_element *element) g_free(network->wifi.security); g_free(network->wifi.passphrase); - g_free(network->path); + g_free(network->node); g_free(network->name); g_free(network->identifier); } @@ -356,22 +363,6 @@ const char *connman_network_get_identifier(struct connman_network *network) } /** - * connman_network_set_path: - * @network: network structure - * @path: path name - * - * Set path name of network - */ -void connman_network_set_path(struct connman_network *network, const char *path) -{ - g_free(network->element.devpath); - network->element.devpath = g_strdup(path); - - g_free(network->path); - network->path = g_strdup(path); -} - -/** * connman_network_get_path: * @network: network structure * @@ -379,7 +370,7 @@ void connman_network_set_path(struct connman_network *network, const char *path) */ const char *connman_network_get_path(struct connman_network *network) { - return network->path; + return network->element.path; } /** @@ -482,6 +473,9 @@ int connman_network_set_string(struct connman_network *network, if (g_str_equal(key, "Name") == TRUE) { g_free(network->name); network->name = g_strdup(value); + } else if (g_str_equal(key, "Node") == TRUE) { + g_free(network->node); + network->node = g_strdup(value); } else if (g_str_equal(key, "WiFi.Mode") == TRUE) { g_free(network->wifi.mode); network->wifi.mode = g_strdup(value); @@ -494,6 +488,30 @@ int connman_network_set_string(struct connman_network *network, } /** + * connman_network_get_string: + * @network: network structure + * @key: unique identifier + * + * Get string value for specific key + */ +const char *connman_network_get_string(struct connman_network *network, + const char *key) +{ + DBG("network %p key %s", network); + + if (g_str_equal(key, "Name") == TRUE) + return network->name; + else if (g_str_equal(key, "Node") == TRUE) + return network->node; + else if (g_str_equal(key, "WiFi.Mode") == TRUE) + return network->wifi.mode; + else if (g_str_equal(key, "WiFi.Security") == TRUE) + return network->wifi.security; + + return NULL; +} + +/** * connman_network_set_uint8: * @network: network structure * @key: unique identifier -- 2.7.4