From b6f52b052e6bf83a520cb0241e61bc894653b79f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 31 Mar 2009 20:09:19 -0700 Subject: [PATCH] Add initial support for service properties --- include/dbus.h | 1 + src/profile.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/include/dbus.h b/include/dbus.h index 277e69a..4007a14 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -38,6 +38,7 @@ extern "C" { #define CONNMAN_MANAGER_PATH "/" #define CONNMAN_PROFILE_INTERFACE CONNMAN_SERVICE ".Profile" +#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" #define CONNMAN_DEVICE_INTERFACE CONNMAN_SERVICE ".Device" #define CONNMAN_NETWORK_INTERFACE CONNMAN_SERVICE ".Network" #define CONNMAN_CONNECTION_INTERFACE CONNMAN_SERVICE ".Connection" diff --git a/src/profile.c b/src/profile.c index 4300520..5115aad 100644 --- a/src/profile.c +++ b/src/profile.c @@ -31,18 +31,59 @@ #define PROFILE_DEFAULT "/profile/default" struct connman_group { + char *type; char *path; GSList *networks; }; static GHashTable *groups = NULL; +static DBusConnection *connection = NULL; + +static DBusMessage *get_properties(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct connman_group *group = data; + DBusMessage *reply; + DBusMessageIter array, dict; + + DBG("conn %p", conn); + + reply = dbus_message_new_method_return(msg); + if (reply == NULL) + return NULL; + + dbus_message_iter_init_append(reply, &array); + + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + if (group->type != NULL) + connman_dbus_dict_append_variant(&dict, "Type", + DBUS_TYPE_STRING, &group->type); + + dbus_message_iter_close_container(&array, &dict); + + return reply; +} + +static GDBusMethodTable service_methods[] = { + { "GetProperties", "", "a{sv}", get_properties }, + { }, +}; + static void free_group(gpointer data) { struct connman_group *group = data; DBG("group %p", group); + g_dbus_unregister_interface(connection, group->path, + CONNMAN_SERVICE_INTERFACE); + + g_free(group->type); g_free(group->path); g_free(group); } @@ -64,10 +105,16 @@ static struct connman_group *lookup_group(const char *name) if (group == NULL) return NULL; + group->type = CONNMAN_ELEMENT_TYPE_UNKNOWN; group->path = g_strdup_printf("%s/%s", PROFILE_DEFAULT, name); g_hash_table_insert(groups, g_strdup(name), group); + g_dbus_register_interface(connection, group->path, + CONNMAN_SERVICE_INTERFACE, + service_methods, + NULL, NULL, group, NULL); + done: DBG("group %p", group); @@ -88,6 +135,8 @@ int __connman_profile_add_device(struct connman_device *device) if (group == NULL) return -EINVAL; + group->type = g_strdup(__connman_device_get_type(device)); + return 0; } @@ -118,6 +167,10 @@ int __connman_profile_add_network(struct connman_network *network) if (group == NULL) return -EINVAL; + g_free(group->type); + + group->type = g_strdup(__connman_network_get_type(network)); + return 0; } @@ -190,7 +243,7 @@ static void append_services(DBusMessageIter *dict) dbus_message_iter_close_container(dict, &entry); } -static DBusMessage *get_properties(DBusConnection *conn, +static DBusMessage *profile_properties(DBusConnection *conn, DBusMessage *msg, void *data) { const char *name = "Default"; @@ -221,12 +274,10 @@ static DBusMessage *get_properties(DBusConnection *conn, } static GDBusMethodTable profile_methods[] = { - { "GetProperties", "", "a{sv}", get_properties }, + { "GetProperties", "", "a{sv}", profile_properties }, { }, }; -static DBusConnection *connection = NULL; - int __connman_profile_init(DBusConnection *conn) { DBG("conn %p", conn); -- 1.7.9.5