X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmanager.c;h=2b34ea6f4bf8849d853ea9959f82ae6d31bd3ebe;hb=079495237ccad5c98a5fab36ad89eb921b4c884b;hp=9705b055d19218c251006e9e1538badc6c864088;hpb=db075ce314d647680cce30d97fc174a3aee02f77;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/manager.c b/src/manager.c index 9705b05..2b34ea6 100644 --- a/src/manager.c +++ b/src/manager.c @@ -23,16 +23,21 @@ #include #endif +#include + #include #include "connman.h" +connman_bool_t connman_state_idle; +DBusMessage *session_mode_pending = NULL; + static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; DBusMessageIter array, dict; - connman_bool_t offlinemode, tethering; + connman_bool_t offlinemode, sessionmode; const char *str; DBG("conn %p", conn); @@ -45,13 +50,6 @@ static DBusMessage *get_properties(DBusConnection *conn, connman_dbus_dict_open(&array, &dict); - str = __connman_profile_active_path(); - if (str != NULL) - 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", @@ -61,14 +59,10 @@ static DBusMessage *get_properties(DBusConnection *conn, connman_dbus_dict_append_basic(&dict, "State", DBUS_TYPE_STRING, &str); - offlinemode = __connman_profile_get_offlinemode(); + offlinemode = __connman_technology_get_offlinemode(); connman_dbus_dict_append_basic(&dict, "OfflineMode", DBUS_TYPE_BOOLEAN, &offlinemode); - tethering = __connman_tethering_get_status(); - connman_dbus_dict_append_basic(&dict, "Tethering", - DBUS_TYPE_BOOLEAN, &tethering); - connman_dbus_dict_append_array(&dict, "AvailableTechnologies", DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL); connman_dbus_dict_append_array(&dict, "EnabledTechnologies", @@ -86,6 +80,11 @@ static DBusMessage *get_properties(DBusConnection *conn, connman_dbus_dict_append_array(&dict, "EnabledDebugs", DBUS_TYPE_STRING, __connman_debug_list_enabled, NULL); + sessionmode = __connman_session_mode(); + connman_dbus_dict_append_basic(&dict, "SessionMode", + DBUS_TYPE_BOOLEAN, + &sessionmode); + connman_dbus_dict_close(&array, &dict); return reply; @@ -117,29 +116,25 @@ static DBusMessage *set_property(DBusConnection *conn, dbus_message_iter_get_basic(&value, &offlinemode); - __connman_profile_set_offlinemode(offlinemode, TRUE); - - __connman_profile_save_default(); - } else if (g_str_equal(name, "Tethering") == TRUE) { - connman_bool_t tethering; + __connman_technology_set_offlinemode(offlinemode); + } else if (g_str_equal(name, "SessionMode") == TRUE) { + connman_bool_t sessionmode; if (type != DBUS_TYPE_BOOLEAN) return __connman_error_invalid_arguments(msg); - dbus_message_iter_get_basic(&value, &tethering); + dbus_message_iter_get_basic(&value, &sessionmode); - if (__connman_tethering_set_status(tethering) < 0) - return __connman_error_invalid_arguments(msg); + if (session_mode_pending != NULL) + return __connman_error_in_progress(msg); - connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH, - CONNMAN_MANAGER_INTERFACE, "Tethering", - DBUS_TYPE_BOOLEAN, &tethering); - } else if (g_str_equal(name, "ActiveProfile") == TRUE) { - const char *str; + __connman_session_set_mode(sessionmode); - dbus_message_iter_get_basic(&value, &str); + if (sessionmode == TRUE && connman_state_idle == FALSE) { + session_mode_pending = msg; + return NULL; + } - return __connman_error_not_supported(msg); } else return __connman_error_invalid_property(msg); @@ -159,43 +154,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) { @@ -235,7 +193,7 @@ static DBusMessage *request_scan(DBusConnection *conn, else return __connman_error_invalid_arguments(msg); - err = __connman_element_request_scan(type); + err = __connman_device_request_scan(type); if (err < 0) { if (err == -EINPROGRESS) { connman_error("Invalid return code from scan"); @@ -250,63 +208,34 @@ static DBusMessage *request_scan(DBusConnection *conn, static DBusConnection *connection = NULL; -static enum connman_service_type technology_type; -static connman_bool_t technology_enabled; -static DBusMessage *technology_pending = NULL; -static guint technology_timeout = 0; - -static void technology_reply(int error) +static void session_mode_notify(void) { - DBG(""); - - if (technology_timeout > 0) { - g_source_remove(technology_timeout); - technology_timeout = 0; - } - - if (technology_pending != NULL) { - if (error > 0) { - DBusMessage *reply; - - reply = __connman_error_failed(technology_pending, - error); - if (reply != NULL) - g_dbus_send_message(connection, reply); - } else - g_dbus_send_reply(connection, technology_pending, - DBUS_TYPE_INVALID); + DBusMessage *reply; - dbus_message_unref(technology_pending); - technology_pending = NULL; - } + reply = g_dbus_create_reply(session_mode_pending, DBUS_TYPE_INVALID); + g_dbus_send_message(connection, reply); - technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN; + dbus_message_unref(session_mode_pending); + session_mode_pending = NULL; } -static gboolean technology_abort(gpointer user_data) +static void idle_state(connman_bool_t idle) { - DBG(""); - - technology_timeout = 0; - technology_reply(ETIMEDOUT); + DBG("idle %d", idle); - return FALSE; -} + connman_state_idle = idle; -static void technology_notify(enum connman_service_type type, - connman_bool_t enabled) -{ - DBG("type %d enabled %d", type, enabled); + if (connman_state_idle == FALSE || session_mode_pending == NULL) + return; - if (type == technology_type && enabled == technology_enabled) - technology_reply(0); + session_mode_notify(); } static struct connman_notifier technology_notifier = { .name = "manager", .priority = CONNMAN_NOTIFIER_PRIORITY_HIGH, - .service_enabled= technology_notify, + .idle_state = idle_state, }; static DBusMessage *enable_technology(DBusConnection *conn, @@ -314,13 +243,9 @@ static DBusMessage *enable_technology(DBusConnection *conn, { enum connman_service_type type; const char *str; - int err; DBG("conn %p", conn); - if (technology_pending != NULL) - return __connman_error_in_progress(msg); - dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); @@ -343,16 +268,7 @@ static DBusMessage *enable_technology(DBusConnection *conn, if (__connman_notifier_is_enabled(type) == TRUE) return __connman_error_already_enabled(msg); - technology_type = type; - technology_enabled = TRUE; - technology_pending = dbus_message_ref(msg); - - err = __connman_element_enable_technology(type); - if (err < 0 && err != -EINPROGRESS) - technology_reply(-err); - else - technology_timeout = g_timeout_add_seconds(15, - technology_abort, NULL); + __connman_technology_enable(type, msg); return NULL; } @@ -362,13 +278,9 @@ static DBusMessage *disable_technology(DBusConnection *conn, { enum connman_service_type type; const char *str; - int err; DBG("conn %p", conn); - if (technology_pending != NULL) - return __connman_error_in_progress(msg); - dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); @@ -391,16 +303,7 @@ static DBusMessage *disable_technology(DBusConnection *conn, if (__connman_notifier_is_enabled(type) == FALSE) return __connman_error_already_disabled(msg); - technology_type = type; - technology_enabled = FALSE; - technology_pending = dbus_message_ref(msg); - - err = __connman_element_disable_technology(type); - if (err < 0 && err != -EINPROGRESS) - technology_reply(-err); - else - technology_timeout = g_timeout_add_seconds(10, - technology_abort, NULL); + __connman_technology_disable(type, msg); return NULL; } @@ -460,6 +363,13 @@ static DBusMessage *connect_service(DBusConnection *conn, DBG("conn %p", conn); + if (__connman_session_mode() == TRUE) { + connman_info("Session mode enabled: " + "direct service connect disabled"); + + return __connman_error_failed(msg, -EINVAL); + } + err = __connman_service_create_and_connect(msg); if (err < 0) { if (err == -EINPROGRESS) { @@ -473,6 +383,19 @@ static DBusMessage *connect_service(DBusConnection *conn, return NULL; } +static DBusMessage *provision_service(DBusConnection *conn, DBusMessage *msg, + void *data) +{ + int err; + + DBG("conn %p", conn); + + err = __connman_service_provision(msg); + if (err < 0) + return __connman_error_failed(msg, -err); + + return NULL; +} static DBusMessage *connect_provider(DBusConnection *conn, DBusMessage *msg, void *data) @@ -481,6 +404,13 @@ static DBusMessage *connect_provider(DBusConnection *conn, DBG("conn %p", conn); + if (__connman_session_mode() == TRUE) { + connman_info("Session mode enabled: " + "direct provider connect disabled"); + + return __connman_error_failed(msg, -EINVAL); + } + err = __connman_provider_create_and_connect(msg); if (err < 0) { if (err == -EINPROGRESS) { @@ -579,40 +509,63 @@ static DBusMessage *unregister_counter(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -static DBusMessage *request_session(DBusConnection *conn, +static DBusMessage *create_session(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *bearer, *sender, *service_path; - struct connman_service *service; + int err; DBG("conn %p", conn); - sender = dbus_message_get_sender(msg); + err = __connman_session_create(msg); + if (err < 0) + return __connman_error_failed(msg, -err); - dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &bearer, - DBUS_TYPE_INVALID); + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} - service = __connman_session_request(bearer, sender); - if (service == NULL) - return __connman_error_failed(msg, EINVAL); +static DBusMessage *destroy_session(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + int err; - service_path = __connman_service_get_path(service); + DBG("conn %p", conn); - return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &service_path, - DBUS_TYPE_INVALID); + err = __connman_session_destroy(msg); + if (err < 0) + return __connman_error_failed(msg, -err); + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -static DBusMessage *release_session(DBusConnection *conn, +static DBusMessage *request_private_network(DBusConnection *conn, DBusMessage *msg, void *data) { const char *sender; - int err; + int err; DBG("conn %p", conn); sender = dbus_message_get_sender(msg); - err = __connman_session_release(sender); + err = __connman_private_network_request(msg, sender); + if (err < 0) + return __connman_error_failed(msg, -err); + + return NULL; +} + +static DBusMessage *release_private_network(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_private_network_release(path); if (err < 0) return __connman_error_failed(msg, -err); @@ -621,10 +574,9 @@ static DBusMessage *release_session(DBusConnection *conn, static GDBusMethodTable manager_methods[] = { { "GetProperties", "", "a{sv}", get_properties }, - { "SetProperty", "sv", "", set_property }, + { "SetProperty", "sv", "", set_property, + G_DBUS_METHOD_FLAG_ASYNC }, { "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, @@ -635,14 +587,21 @@ static GDBusMethodTable manager_methods[] = { { "LookupService", "s", "o", lookup_service, }, { "ConnectService", "a{sv}", "o", connect_service, G_DBUS_METHOD_FLAG_ASYNC }, + { "ProvisionService", "s", "", provision_service, + G_DBUS_METHOD_FLAG_ASYNC }, { "ConnectProvider", "a{sv}", "o", connect_provider, G_DBUS_METHOD_FLAG_ASYNC }, { "RegisterAgent", "o", "", register_agent }, { "UnregisterAgent", "o", "", unregister_agent }, { "RegisterCounter", "ouu", "", register_counter }, { "UnregisterCounter", "o", "", unregister_counter }, - { "RequestSession", "s", "o", request_session }, - { "ReleaseSession", "s", "", release_session }, + { "CreateSession", "a{sv}o", "o", create_session }, + { "DestroySession", "o", "", destroy_session }, + { "RequestPrivateNetwork", "", "oa{sv}h", + request_private_network, + G_DBUS_METHOD_FLAG_ASYNC }, + { "ReleasePrivateNetwork", "o", "", + release_private_network }, { }, }; @@ -668,6 +627,8 @@ int __connman_manager_init(void) manager_methods, manager_signals, NULL, NULL, NULL); + connman_state_idle = TRUE; + return 0; } @@ -675,11 +636,11 @@ void __connman_manager_cleanup(void) { DBG(""); - connman_notifier_unregister(&technology_notifier); - if (connection == NULL) return; + connman_notifier_unregister(&technology_notifier); + g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE);