#include "connman.h"
+#define PROFILE_DEFAULT "/profile/default"
+
+struct connman_group {
+ char *path;
+ GSList *networks;
+};
+
+static GHashTable *groups = NULL;
+
+static void free_group(gpointer data)
+{
+ struct connman_group *group = data;
+
+ DBG("group %p", group);
+
+ g_free(group->path);
+ g_free(group);
+}
+
+static struct connman_group *lookup_group(const char *name)
+{
+ struct connman_group *group;
+
+ DBG("name %s", name);
+
+ if (name == NULL)
+ return NULL;
+
+ group = g_hash_table_lookup(groups, name);
+ if (group != NULL)
+ goto done;
+
+ group = g_try_new0(struct connman_group, 1);
+ if (group == NULL)
+ return NULL;
+
+ group->path = g_strdup_printf("%s/%s", PROFILE_DEFAULT, name);
+
+ g_hash_table_insert(groups, g_strdup(name), group);
+
+done:
+ DBG("group %p", group);
+
+ return group;
+}
+
int __connman_profile_add_device(struct connman_device *device)
{
+ struct connman_group *group;
+ char *name;
+
DBG("device %p", device);
+ name = g_strdup_printf("device%d", connman_device_get_index(device));
+ group = lookup_group(name);
+ g_free(name);
+
+ if (group == NULL)
+ return -EINVAL;
+
return 0;
}
int __connman_profile_remove_device(struct connman_device *device)
{
+ struct connman_group *group;
+ char *name;
+
DBG("device %p", device);
+ name = g_strdup_printf("device%d", connman_device_get_index(device));
+ group = lookup_group(name);
+ g_free(name);
+
+ if (group == NULL)
+ return -EINVAL;
+
return 0;
}
int __connman_profile_add_network(struct connman_network *network)
{
+ struct connman_group *group;
+
DBG("network %p", network);
+ group = lookup_group(__connman_network_get_group(network));
+ if (group == NULL)
+ return -EINVAL;
+
return 0;
}
int __connman_profile_remove_network(struct connman_network *network)
{
+ struct connman_group *group;
+
DBG("network %p", network);
+ group = lookup_group(__connman_network_get_group(network));
+ if (group == NULL)
+ return -EINVAL;
+
return 0;
}
{
DBG("");
- return "/profile/default";
+ return PROFILE_DEFAULT;
}
void __connman_profile_list(DBusMessageIter *iter)
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
}
+static void append_path(gpointer key, gpointer value, gpointer user_data)
+{
+ struct connman_group *group = value;
+ DBusMessageIter *iter = user_data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+ &group->path);
+}
+
void __connman_profile_list_services(DBusMessageIter *iter)
{
DBG("");
+
+ g_hash_table_foreach(groups, append_path, iter);
+}
+
+static void append_services(DBusMessageIter *dict)
+{
+ DBusMessageIter entry, value, iter;
+ const char *key = "Services";
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
+ &value);
+
+ dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
+ __connman_profile_list_services(&iter);
+ dbus_message_iter_close_container(&value, &iter);
+
+ dbus_message_iter_close_container(&entry, &value);
+
+ dbus_message_iter_close_container(dict, &entry);
}
static DBusMessage *get_properties(DBusConnection *conn,
connman_dbus_dict_append_variant(&dict, "Name",
DBUS_TYPE_STRING, &name);
+ append_services(&dict);
+
dbus_message_iter_close_container(&array, &dict);
return reply;
if (connection == NULL)
return -1;
- g_dbus_register_interface(connection, "/profile/default",
+ groups = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, free_group);
+
+ g_dbus_register_interface(connection, PROFILE_DEFAULT,
CONNMAN_PROFILE_INTERFACE,
profile_methods,
NULL, NULL, NULL, NULL);
{
DBG("conn %p", connection);
- g_dbus_unregister_interface(connection, "/profile/default",
+ g_dbus_unregister_interface(connection, PROFILE_DEFAULT,
CONNMAN_PROFILE_INTERFACE);
+ g_hash_table_destroy(groups);
+ groups = NULL;
+
if (connection == NULL)
return;