From: Samuel Ortiz Date: Mon, 4 Apr 2011 19:55:31 +0000 (+0200) Subject: manager: Remove the Create/RemoveProfile D-Bus API X-Git-Tag: 0.73~58 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0061d5a986c7f23f4a97e6b3d46b4e041e77007a;p=platform%2Fupstream%2Fconnman.git manager: Remove the Create/RemoveProfile D-Bus API Provisioning is done through configuration files, not profiles (naming could be changed as well). There is no need for multiple profiles files. --- diff --git a/doc/manager-api.txt b/doc/manager-api.txt index f07e185..2c7aa07 100644 --- a/doc/manager-api.txt +++ b/doc/manager-api.txt @@ -29,26 +29,6 @@ Methods dict GetProperties() Possible Errors: [service].Error.InvalidArguments - object CreateProfile(string name) - - Create and add new profile with the specified - identifier name. - - Possible Errors: [service].Error.InvalidArguments - - void RemoveProfile(object path) - - Remove profile with specified object path. - - It is not possible to remove the current active - profile. To remove the active profile a different - one must be selected via ActiveProfile property - first. - - At minimum one profile must be available all the time. - - Possible Errors: [service].Error.InvalidArguments - void RequestScan(string type) Request to trigger a scan for the specified @@ -254,10 +234,6 @@ Properties string State [readonly] Object path of the current active profile. - array{object} Profiles [readonly] - - List of profile object paths. - array{object} Technologies [readonly] List of technology object paths. diff --git a/src/manager.c b/src/manager.c index 349ddb4..047d26d 100644 --- a/src/manager.c +++ b/src/manager.c @@ -50,8 +50,6 @@ static DBusMessage *get_properties(DBusConnection *conn, connman_dbus_dict_append_basic(&dict, "ActiveProfile", DBUS_TYPE_OBJECT_PATH, &str); - connman_dbus_dict_append_array(&dict, "Profiles", - DBUS_TYPE_OBJECT_PATH, __connman_profile_list, NULL); connman_dbus_dict_append_array(&dict, "Services", DBUS_TYPE_OBJECT_PATH, __connman_service_list, NULL); connman_dbus_dict_append_array(&dict, "Technologies", @@ -155,43 +153,6 @@ static DBusMessage *get_state(DBusConnection *conn, DBUS_TYPE_INVALID); } -static DBusMessage *create_profile(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *name, *path; - int err; - - DBG("conn %p", conn); - - dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name, - DBUS_TYPE_INVALID); - - err = __connman_profile_create(name, &path); - if (err < 0) - return __connman_error_failed(msg, -err); - - return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID); -} - -static DBusMessage *remove_profile(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *path; - int err; - - DBG("conn %p", conn); - - dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID); - - err = __connman_profile_remove(path); - if (err < 0) - return __connman_error_failed(msg, -err); - - return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); -} - static DBusMessage *remove_provider(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -621,8 +582,6 @@ static GDBusMethodTable manager_methods[] = { { "GetProperties", "", "a{sv}", get_properties }, { "SetProperty", "sv", "", set_property }, { "GetState", "", "s", get_state }, - { "CreateProfile", "s", "o", create_profile }, - { "RemoveProfile", "o", "", remove_profile }, { "RemoveProvider", "o", "", remove_provider }, { "RequestScan", "s", "", request_scan }, { "EnableTechnology", "s", "", enable_technology, diff --git a/src/profile.c b/src/profile.c index e0d9994..fd72e8b 100644 --- a/src/profile.c +++ b/src/profile.c @@ -39,32 +39,10 @@ struct connman_profile { connman_bool_t offlinemode; }; -static GHashTable *profile_hash = NULL; static struct connman_profile *default_profile = NULL; static DBusConnection *connection = NULL; -static void append_path(gpointer key, gpointer value, gpointer user_data) -{ - struct connman_profile *profile = value; - DBusMessageIter *iter = user_data; - - dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, - &profile->path); -} - -void __connman_profile_list(DBusMessageIter *iter, void *user_data) -{ - g_hash_table_foreach(profile_hash, append_path, iter); -} - -static void profiles_changed(void) -{ - connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH, - CONNMAN_MANAGER_INTERFACE, "Profiles", - DBUS_TYPE_OBJECT_PATH, __connman_profile_list, NULL); -} - static void name_changed(struct connman_profile *profile) { connman_dbus_property_changed_basic(profile->path, @@ -147,25 +125,20 @@ static guint changed_timeout = 0; static gboolean services_changed(gpointer user_data) { - struct connman_profile *profile = default_profile; - connman_dbus_append_cb_t function = NULL; - changed_timeout = 0; - if (profile == NULL) + if (default_profile == NULL) return FALSE; - if (g_strcmp0(profile->ident, PROFILE_DEFAULT_IDENT) == 0) { - function = __connman_service_list; - - connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH, + connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "Services", - DBUS_TYPE_OBJECT_PATH, function, NULL); - } + DBUS_TYPE_OBJECT_PATH, __connman_service_list, + NULL); - connman_dbus_property_changed_array(profile->path, + connman_dbus_property_changed_array(default_profile->path, CONNMAN_PROFILE_INTERFACE, "Services", - DBUS_TYPE_OBJECT_PATH, function, NULL); + DBUS_TYPE_OBJECT_PATH, __connman_service_list, + NULL); return FALSE; } @@ -298,171 +271,36 @@ static void free_profile(struct connman_profile *profile) g_free(profile); } -static void unregister_profile(gpointer data) -{ - struct connman_profile *profile = data; - - DBG("profile %p", profile); - - connman_info("Removing profile %s", profile->ident); - - g_dbus_unregister_interface(connection, profile->path, - CONNMAN_PROFILE_INTERFACE); - - if (g_strcmp0(profile->ident, PROFILE_DEFAULT_IDENT) == 0) - default_profile = NULL; - - free_profile(profile); -} - -static int create_profile(const char *ident, const char *name, - const char **path) +static int profile_init(void) { - struct connman_profile *profile; - - DBG("ident %s name %s", ident, name); + DBG(""); - profile = g_try_new0(struct connman_profile, 1); - if (profile == NULL) + default_profile = g_try_new0(struct connman_profile, 1); + if (default_profile == NULL) return -ENOMEM; - profile->ident = g_strdup(ident); - profile->path = g_strdup_printf("/profile/%s", ident); + default_profile->ident = g_strdup(PROFILE_DEFAULT_IDENT); + default_profile->path = g_strdup_printf("/profile/%s", + PROFILE_DEFAULT_IDENT); - if (profile->ident == NULL || profile->path == NULL) { - free_profile(profile); + if (default_profile->ident == NULL || default_profile->path == NULL) { + free_profile(default_profile); return -ENOMEM; } - if (g_hash_table_lookup(profile_hash, profile->path) != NULL) { - free_profile(profile); - return -EEXIST; - } - - profile->name = g_strdup(name); + default_profile->name = g_strdup("Default"); - __connman_storage_load_profile(profile); + __connman_storage_load_profile(default_profile); - g_hash_table_insert(profile_hash, g_strdup(profile->path), profile); + connman_info("Adding default profile"); - connman_info("Adding profile %s", ident); - - if (g_strcmp0(ident, PROFILE_DEFAULT_IDENT) == 0) - default_profile = profile; - - g_dbus_register_interface(connection, profile->path, + g_dbus_register_interface(connection, default_profile->path, CONNMAN_PROFILE_INTERFACE, profile_methods, profile_signals, - NULL, profile, NULL); + NULL, default_profile, NULL); - if (path != NULL) - *path = profile->path; - DBG("profile %p path %s", profile, profile->path); - - return 0; -} - -int __connman_profile_create(const char *name, const char **path) -{ - struct connman_profile *profile; - int err; - - DBG("name %s", name); - - if (connman_dbus_validate_ident(name) == FALSE) - return -EINVAL; - - err = create_profile(name, NULL, path); - if (err < 0) - return err; - - profile = g_hash_table_lookup(profile_hash, *path); - if (profile == NULL) - return -EIO; - - __connman_storage_save_profile(profile); - - profiles_changed(); - - return 0; -} - -int __connman_profile_remove(const char *path) -{ - struct connman_profile *profile; - - DBG("path %s", path); - - if (default_profile != NULL && - g_strcmp0(path, default_profile->path) == 0) - return -EINVAL; - - profile = g_hash_table_lookup(profile_hash, path); - if (profile == NULL) - return -ENXIO; - - __connman_storage_delete_profile(profile->ident); - - g_hash_table_remove(profile_hash, path); - - profiles_changed(); - - return 0; -} - -static int profile_init(void) -{ - GDir *dir; - const gchar *file; - - DBG(""); - - dir = g_dir_open(STORAGEDIR, 0, NULL); - if (dir != NULL) { - while ((file = g_dir_read_name(dir)) != NULL) { - GString *str; - gchar *ident; - - if (g_str_has_suffix(file, ".profile") == FALSE) - continue; - - ident = g_strrstr(file, ".profile"); - if (ident == NULL) - continue; - - /* - * If there is no non-extension portion to the file - * (i.e. it is precisely named ".profile"), then ignore - * it. Passing such files to create_profile will result - * in a SIGABRT. - */ - - if (file == ident) { - connman_info("Ignoring malformed profile %s\n", - file); - continue; - } - - str = g_string_new_len(file, ident - file); - if (str == NULL) - continue; - - ident = g_string_free(str, FALSE); - - if (connman_dbus_validate_ident(ident) == TRUE) - create_profile(ident, NULL, NULL); - - g_free(ident); - } - - g_dir_close(dir); - } - - if (default_profile == NULL) - create_profile(PROFILE_DEFAULT_IDENT, "Default", NULL); - - profiles_changed(); + DBG("profile %p path %s", default_profile, default_profile->path); return 0; } @@ -538,9 +376,6 @@ int __connman_profile_init(void) if (connman_storage_register(&profile_storage) < 0) connman_error("Failed to register profile storage"); - profile_hash = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, unregister_profile); - return 0; } @@ -551,9 +386,6 @@ void __connman_profile_cleanup(void) if (connection == NULL) return; - g_hash_table_destroy(profile_hash); - profile_hash = NULL; - connman_storage_unregister(&profile_storage); dbus_connection_unref(connection);