Implement wifi_aware_deinitialize
authorCheoleun Moon <chleun.moon@samsung.com>
Wed, 26 Feb 2020 08:36:09 +0000 (17:36 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Wed, 26 Feb 2020 08:36:09 +0000 (17:36 +0900)
src/include/wifi-aware-peer.h
src/include/wifi-aware-private.h
src/wifi-aware-gdbus.c
src/wifi-aware-peer.c
src/wifi-aware-private.c
src/wifi-aware.c

index 34c3ccf..bbe035e 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 #endif
 
 int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id);
+void _wifi_aware_peer_destroy(wifi_aware_peer_h peer);
 int _wifi_aware_peer_add(GHashTable *peer_map, wifi_aware_peer_h peer);
 int _wifi_aware_peer_remove(GHashTable *peer_map, wifi_aware_peer_h peer);
 wifi_aware_peer_h _wifi_aware_get_peer(GHashTable *peer_map, unsigned int peer_id);
index 83fa149..50861af 100644 (file)
@@ -31,13 +31,14 @@ const char *_wifi_aware_convert_error_type_to_string(wifi_aware_error_e err);
 
 bool _wifi_aware_is_initialized();
 int _wifi_aware_init();
+int _wifi_aware_deinit();
 void _add_enabled_callback(wifi_aware_enabled_cb callback, void *user_data);
 int _wifi_aware_enable_request();
 int _wifi_aware_is_enabled();
 int _wifi_aware_disable_request();
 
 int _wifi_aware_session_handle_create(wifi_aware_session_type_e session_type, wifi_aware_session_h *session_handle);
-int _wifi_aware_session_handle_destroy(wifi_aware_session_h session_handle);
+void _wifi_aware_session_handle_destroy(wifi_aware_session_h session_handle);
 wifi_aware_session_type_e _wifi_aware_session_get_type(wifi_aware_session_h session_handle);
 
 int _wifi_aware_publish_handle_create(wifi_aware_publish_h *publish);
index 3648fb0..b52ff19 100644 (file)
@@ -115,8 +115,10 @@ int wifi_aware_gdbus_deinit()
                return WIFI_AWARE_ERROR_OPERATION_FAILED;
        }
 
+       g_object_unref(gdbus_data.cancellable);
+       gdbus_data.cancellable = NULL;
 
-       /* TODO: unsubscribe signal */
+       // TODO: How to unsubscribe all signals
 
        g_object_unref(gdbus_data.connection);
        gdbus_data.connection = NULL;
index b1a8400..8feb9d1 100644 (file)
@@ -37,6 +37,11 @@ int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id)
        return WIFI_AWARE_ERROR_NONE;
 }
 
+void _wifi_aware_peer_destroy(wifi_aware_peer_h peer)
+{
+       g_free((wifi_aware_peer_s *)peer);
+}
+
 int _wifi_aware_peer_add(GHashTable *peer_map, wifi_aware_peer_h peer)
 {
        wifi_aware_peer_s *peer_handle = (wifi_aware_peer_s *)peer;
index 0cf7df0..cbf9484 100644 (file)
@@ -122,6 +122,10 @@ const char *_wifi_aware_convert_error_type_to_string(wifi_aware_error_e err)
                return "Not supported";
        case WIFI_AWARE_ERROR_OPERATION_FAILED:
                return "Operation failed";
+       case WIFI_AWARE_ERROR_NOT_INITIALIZED:
+               return "Not Initialized";
+       case WIFI_AWARE_ERROR_ALREADY_INITIALIZED:
+               return "Already Initialized";
        default:
                return "Unknown error";
        }
@@ -427,12 +431,21 @@ static int __wifi_aware_create()
                return WIFI_AWARE_ERROR_OUT_OF_MEMORY;
        }
 
-       g_wifi_aware->peer_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+       g_wifi_aware->peer_map =
+               g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _wifi_aware_peer_destroy);
 
        WIFI_AWARE_LOGI("Create wifi_aware_s [%p]", g_wifi_aware);
        return WIFI_AWARE_ERROR_NONE;
 }
 
+static void __wifi_aware_destroy()
+{
+       g_hash_table_remove_all(g_wifi_aware->peer_map);
+       g_hash_table_unref(g_wifi_aware->peer_map);
+       g_free(g_wifi_aware);
+       g_wifi_aware = NULL;
+}
+
 bool _wifi_aware_is_initialized()
 {
        return __is_init;
@@ -458,6 +471,21 @@ int _wifi_aware_init()
        return WIFI_AWARE_ERROR_NONE;
 }
 
+int _wifi_aware_deinit()
+{
+       if (!__is_init) {
+               WIFI_AWARE_LOGE("Already initialized");
+               return WIFI_AWARE_ERROR_NOT_INITIALIZED;
+       }
+
+       __wifi_aware_destroy();
+       wifi_aware_gdbus_deinit();
+
+       __is_init = false;
+
+       return WIFI_AWARE_ERROR_NONE;
+}
+
 void _add_enabled_callback(wifi_aware_enabled_cb callback, void *user_data)
 {
        g_wifi_aware->enabled_cb = callback;
@@ -508,11 +536,12 @@ int _wifi_aware_session_handle_create(wifi_aware_session_type_e session_type,
        return WIFI_AWARE_ERROR_NONE;
 }
 
-int _wifi_aware_session_handle_destroy(wifi_aware_session_h session_handle)
+void _wifi_aware_session_handle_destroy(wifi_aware_session_h session_handle)
 {
        // TODO
+       // publish_config and subscribe_config should be destroyed by
+       // wifi_aware_publish_destroy and wifi_aware_subscribe_destroy
        g_free(session_handle);
-       return WIFI_AWARE_ERROR_NONE;
 }
 
 int _wifi_aware_publish_handle_create(wifi_aware_publish_h *publish)
index 35eb41d..ece88b8 100644 (file)
@@ -51,11 +51,14 @@ API int wifi_aware_initialize()
 
 API int wifi_aware_deinitialize()
 {
+       int ret = WIFI_AWARE_ERROR_NONE;
+
        __WIFI_AWARE_FUNC_ENTER__;
        CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE);
-       RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized");
 
-       // TODO
+       ret = _wifi_aware_deinit();
+       RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_deinit failed [%s]",
+                       _wifi_aware_convert_error_type_to_string(ret));
 
        __WIFI_AWARE_FUNC_EXIT__;
        return WIFI_AWARE_ERROR_NONE;
@@ -116,15 +119,12 @@ API int wifi_aware_session_create(wifi_aware_session_type_e session_type, wifi_a
 
 API int wifi_aware_session_destroy(wifi_aware_session_h session)
 {
-       int ret = WIFI_AWARE_ERROR_NONE;
-
        __WIFI_AWARE_FUNC_ENTER__;
        CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE);
        RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized");
        RET_VAL_IF(session == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_session_h is NULL");
 
-       ret = _wifi_aware_session_handle_destroy(session);
-       RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to destroy session handle");
+       _wifi_aware_session_handle_destroy(session);
        return WIFI_AWARE_ERROR_NONE;
 }