d2d-manager: make capi can support multi-clients.
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 26 Mar 2018 12:31:05 +0000 (21:31 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
capi/demo/comp-manager.c
capi/demo/companion_demo.c
capi/demo/main.c
capi/include/companion.h
capi/src/companion.c
capi/unittest/companion_unit_test.cpp

index 629dd35..fc40042 100644 (file)
@@ -26,6 +26,8 @@
 #include "menu.h"
 #include "common.h"
 
+companion_h handle = NULL;
+
 GList *found_group_list;
 GList *found_device_list;
 GList *my_devices_list;
@@ -79,7 +81,7 @@ int run_get_my_id(MManager *mm, struct menu_data *menu)
 
        int ret;
        char *uuid;
-       ret = companion_device_get_my_uuid(&uuid);
+       ret = companion_device_get_my_uuid(handle, &uuid);
 
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get My Device ID: [%s(0x%X)]", comp_error_to_string(ret), ret);
@@ -141,7 +143,7 @@ static int run_device_eject(MManager *mm, struct menu_data *menu)
                return RET_FAILURE;
        }
 
-       ret = companion_device_eject(group, device, _device_eject_result_cb, NULL);
+       ret = companion_device_eject(handle, group, device, _device_eject_result_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -200,7 +202,7 @@ static int run_device_invite(MManager *mm, struct menu_data *menu)
                return RET_FAILURE;
        }
 
-       ret = companion_device_invite(group, device, pin, _device_invite_result_cb, NULL);
+       ret = companion_device_invite(handle, group, device, pin, _device_invite_result_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to device invite: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -227,7 +229,7 @@ static int run_devices_show(MManager *mm, struct menu_data *menu)
        int i;
        GList *iter = NULL;
 
-       ret = companion_device_get_found_devices(&devices, &count);
+       ret = companion_device_get_found_devices(handle, &devices, &count);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get Found Devices: [%s(0x%X)]",
                         comp_error_to_string(ret), ret);
@@ -377,7 +379,7 @@ static int run_group_merge(MManager *mm, struct menu_data *menu)
        }
 
 
-       ret = companion_group_merge(group_a, group_b);
+       ret = companion_group_merge(handle, group_a, group_b);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Merge Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -411,7 +413,7 @@ static int run_group_delete(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_group_delete(group);
+       ret = companion_group_delete(handle, group);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -427,7 +429,7 @@ int run_device_show_found(MManager *mm, struct menu_data *menu)
        int count;
        companion_device_h *devices = NULL;
 
-       ret = companion_device_get_found_devices(&devices, &count);
+       ret = companion_device_get_found_devices(handle, &devices, &count);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get Found Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -515,7 +517,7 @@ static int run_devices_find(MManager *mm, struct menu_data *menu)
        if (strlen(timeout))
                duration = (unsigned short)strtol(timeout, NULL, 10);
 
-       ret = companion_device_find(duration, _device_found_cb, _device_finish_cb, NULL);
+       ret = companion_device_find(handle, duration, _device_found_cb, _device_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Find Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -537,7 +539,7 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu)
 
        msg("Get My Device");
 
-       ret = companion_device_get_my_device(&device);
+       ret = companion_device_get_my_device(handle, &device);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get My Device: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -595,7 +597,7 @@ static int run_group_leave(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_group_leave(group, _group_leave_finish_cb, NULL);
+       ret = companion_group_leave(handle, group, _group_leave_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Leave Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -673,7 +675,7 @@ static int run_group_join(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_group_join(group, _group_join_finish_cb, NULL);
+       ret = companion_group_join(handle, group, _group_join_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Join Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -696,7 +698,7 @@ static int run_group_show_found(MManager *mm, struct menu_data *menu)
 
        msg("Show Found Group(s)");
 
-       ret = companion_group_get_found_groups(&groups, &count);
+       ret = companion_group_get_found_groups(handle, &groups, &count);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get Found Groups: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -761,7 +763,7 @@ static int run_group_find(MManager *mm, struct menu_data *menu)
        if (strlen(timeout))
                duration = (unsigned short)strtol(timeout, NULL, 10);
 
-       ret = companion_group_find(duration, _group_found_cb, _group_finish_cb, NULL);
+       ret = companion_group_find(handle, duration, _group_found_cb, _group_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Find Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -781,7 +783,7 @@ static int run_group_create(MManager *mm, struct menu_data *menu)
        int ret;
        msg("Create Group");
 
-       ret = companion_group_create(groupid);
+       ret = companion_group_create(handle, groupid);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Create Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -826,7 +828,7 @@ static int __send_data(int idx)
                address = NULL;
        }
 
-       ret = companion_send_data(device, message, strlen(message), _send_data_finish_cb, NULL);
+       ret = companion_send_data(handle, device, message, strlen(message), _send_data_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret)
                msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
 
@@ -908,7 +910,8 @@ static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu)
        if (strlen(timeout))
                duration = (unsigned short)strtol(timeout, NULL, 10);
 
-       ret = companion_device_find_mowned_device(duration, _mowned_device_found_cb, _mowned_device_finish_cb, NULL);
+       ret = companion_device_find_mowned_device(handle, duration, _mowned_device_found_cb,
+               _mowned_device_finish_cb, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Find My Owned Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -929,7 +932,7 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
        int count;
        companion_device_h *devices = NULL;
 
-       ret = companion_device_get_found_mowned_devices(&devices, &count);
+       ret = companion_device_get_found_mowned_devices(handle, &devices, &count);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get Found Mowned Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -989,7 +992,7 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_create_group(device, request_groupid);
+       ret = companion_request_create_group(handle, device, request_groupid);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Create Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -1050,7 +1053,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_invite(group, device, pin);
+       ret = companion_request_invite(handle, group, device, pin);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Invite: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -1111,7 +1114,7 @@ static int run_request_eject(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_eject(group, device);
+       ret = companion_request_eject(handle, group, device);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Eject: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -1152,7 +1155,7 @@ static int run_request_delete_group(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_delete_group(group);
+       ret = companion_request_delete_group(handle, group);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
index 9f5df94..9fd72a2 100644 (file)
@@ -44,6 +44,8 @@ typedef struct {
 GList *found_group_list;
 GList *found_device_list;
 
+companion_h handle = NULL;
+
 static bool test_get_user_int(const char *msg, int *num)
 {
        if (msg == NULL || num == NULL)
@@ -88,7 +90,7 @@ int companion_initialize_test(void)
 
        BEGIN();
 
-       ret = companion_initialize();
+       ret = companion_initialize(&handle);
 
        if (ret == 0)
                TC_PRT("Initialize successful");
@@ -103,6 +105,7 @@ int companion_group_create_test(void)
 {
        int ret = 0;
        char input_str[50] = {0, };
+       companion_h handle = NULL;
 
        BEGIN();
 
@@ -115,7 +118,7 @@ int companion_group_create_test(void)
                return -1;
        }
 
-       ret = companion_group_create(input_str);
+       ret = companion_group_create(handle, input_str);
 
        if (ret == 0)
                TC_PRT("Group create successful");
@@ -156,7 +159,7 @@ int companion_group_find_test(void)
                TC_PRT("default timeout value [%d]", input_int);
        }
 
-       companion_group_find(input_int, _group_found_cb, _group_finish_cb, NULL);
+       companion_group_find(handle, input_int, _group_found_cb, _group_finish_cb, NULL);
 
        if (ret == 0)
                TC_PRT("group find successful");
@@ -177,7 +180,7 @@ int companion_group_get_found_groups_test(void)
 
        found_group_list = NULL;
 
-       ret = companion_group_get_found_groups(&groups, &count);
+       ret = companion_group_get_found_groups(handle, &groups, &count);
 
        if (ret == 0)
                TC_PRT("group find successful");
@@ -228,7 +231,7 @@ int companion_device_find_test(void)
                TC_PRT("default timeout value [%d]", input_int);
        }
 
-       companion_device_find(input_int, _device_found_cb, _group_finish_cb, NULL);
+       companion_device_find(handle, input_int, _device_found_cb, _group_finish_cb, NULL);
 
        if (ret == 0)
                TC_PRT("device find successful");
@@ -249,7 +252,7 @@ int companion_device_get_found_devices_test(void)
 
        found_device_list = NULL;
 
-       ret = companion_device_get_found_devices(&devices, &count);
+       ret = companion_device_get_found_devices(hadnle, &devices, &count);
 
        if (ret == 0)
                TC_PRT("device find successful");
@@ -291,7 +294,7 @@ int companion_device_invite_test(void)
                companion_group_h group = (companion_group_h)(found_group_list[0].data);
                companion_device_h device = (companion_device_h)(found_device_list[0].data);
 
-               companion_device_invite(group, device, "12341234", _device_invite_result_cb, NULL);
+               companion_device_invite(handle, group, device, "12341234", _device_invite_result_cb, NULL);
 
        } else {
                TC_PRT("not exist found group or device list");
@@ -318,7 +321,7 @@ int companion_device_eject_test(void)
                companion_device_h device = (companion_device_h)(found_device_list[0].data);
 
                /* using stored group list and device list */
-               companion_device_eject(group, device, _device_eject_result_cb, NULL);
+               companion_device_eject(handle, group, device, _device_eject_result_cb, NULL);
        } else {
                TC_PRT("not exist found group or device list");
        }
@@ -338,7 +341,7 @@ int companion_send_data_to_remote_device_test(void)
 
        if (g_list_length(found_device_list) > 0) {
                companion_device_h device = (companion_device_h)(found_device_list[0].data);
-               ret = companion_send_data(device, "123", NULL, NULL);
+               ret = companion_send_data(handle, device, "123", NULL, NULL);
        } else {
                TC_PRT("not exist found device list");
        }
@@ -353,7 +356,7 @@ int companion_deinitialize_test(void)
 
        BEGIN();
 
-       ret = companion_deinitialize();
+       ret = companion_deinitialize(handle);
 
        if (ret == 0)
                TC_PRT("Initialize successful");
index 48fa104..79677b0 100644 (file)
@@ -33,6 +33,7 @@ extern struct menu_data menu_comp_manager[];
 
 extern GList *found_group_list;
 extern GList *found_device_list;
+extern companion_h handle;
 
 #define CASE_TO_STR(x) case x: return #x;
 
@@ -63,13 +64,13 @@ static int __init_func(MManager *mm, struct menu_data *menu)
 {
        int ret = -1;
 
-       ret = companion_initialize();
+       ret = companion_initialize(&handle);
        if (ret != 0) {
                msg("Failed to initialize companion-manager: [%s(0x%X)]",
                                comp_error_to_string(ret), ret);
                return RET_FAILURE;
        }
-       companion_request_result_callback(receive_request_result, NULL);
+       companion_request_result_callback(handle, receive_request_result, NULL);
 
        return RET_SUCCESS;
 }
@@ -130,7 +131,7 @@ OUT:
        if (found_device_list)
                g_list_free_full(found_device_list, _free_device);
 
-       companion_deinitialize();
+       companion_deinitialize(handle);
 
        g_main_loop_unref(mainloop);
        msg("******* Bye bye *******");
index 01960e4..9e7bb33 100644 (file)
@@ -34,12 +34,18 @@ extern "C" {
  * @{
  */
 
-#ifndef TIZEN_ERROR_COMP
+/**
+ * @brief The companion-manager handle.
+ * @since_tizen 5.0
+ */
+typedef void *companion_h;
+
 /**
  * @brief Base error codes for companion-manager.
  *
  * @since_tizen 5.0
  */
+#ifndef TIZEN_ERROR_COMP
 #define TIZEN_ERROR_COMP -0x02F50000 /**< Base error code */
 #endif
 
@@ -251,7 +257,7 @@ typedef void (*companion_request_result_cb)(char *cmd, char *arg, int ret,
  * @retval #COMP_ERROR_PERMISSION_DENIED Permission Denied
  * @retval #COMP_ERROR_OUT_OF_MEMORY Out of memory
  */
-int companion_initialize();
+int companion_initialize(companion_h *handle);
 
 /**
  * @brief Deinitializes the companion-manager.
@@ -265,7 +271,7 @@ int companion_initialize();
  * @retval #COMP_ERROR_INVALID_OPERATION Invalid operation
  * @retval #COMP_ERROR_OPERATION_FAILED Operation failed
  */
-int companion_deinitialize();
+int companion_deinitialize(companion_h handle);
 
 /* Group Module APIs*/
 
@@ -277,6 +283,7 @@ int companion_deinitialize();
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group_name Group name
  *
  * @return 0 on success, otherwise a negative error value.
@@ -287,7 +294,7 @@ int companion_deinitialize();
  * @see companion_group_get_found_groups()
  *
  */
-int companion_group_create(char *group_name);
+int companion_group_create(companion_h handle, char *group_name);
 
 /**
  * @brief Finds group resources in local and the network.
@@ -295,6 +302,7 @@ int companion_group_create(char *group_name);
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] timeout Time to find
  * @param[in] found_cb Callback handler to retrieve the found group resource
  * @param[in] finish_cb Callback handler to know finding process finished
@@ -308,10 +316,8 @@ int companion_group_create(char *group_name);
  * @see companion_group_get_found_groups()
  *
  */
-int companion_group_find(
-               int timeout,
-               companion_group_found_cb found_cb,
-               companion_group_find_finish_cb finish_cb,
+int companion_group_find(companion_h handle, int timeout,
+               companion_group_found_cb found_cb, companion_group_find_finish_cb finish_cb,
                void *user_data);
 
 /**
@@ -320,6 +326,7 @@ int companion_group_find(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] groups Group resource list
  * @param[out] count Number of groups
  *
@@ -332,8 +339,8 @@ int companion_group_find(
  * @see companion_group_find()
  *
  */
-int companion_group_get_found_groups(companion_group_h **groups,
-               int *count);
+int companion_group_get_found_groups(companion_h handle,
+               companion_group_h **groups, int *count);
 
 /**
  * @brief Joins the remote group.
@@ -342,6 +349,7 @@ int companion_group_get_found_groups(companion_group_h **groups,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group resource list
  * @param[in] callback Callback handler to retrieve the found group resource
  * @param[in] user_data User data poiter
@@ -358,7 +366,7 @@ int companion_group_get_found_groups(companion_group_h **groups,
  * @see companion_group_get_member_devices()
  *
  */
-int companion_group_join(companion_group_h group,
+int companion_group_join(companion_h handle, companion_group_h group,
                companion_group_find_finish_cb callback, void *user_data);
 
 /**
@@ -367,6 +375,7 @@ int companion_group_join(companion_group_h group,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  * @param[in] callback Callback handler to retrieve the found group resource
  * @param[in] user_data User data poiter
@@ -383,7 +392,7 @@ int companion_group_join(companion_group_h group,
  * @see companion_group_get_member_devices()
  *
  */
-int companion_group_leave(companion_group_h group,
+int companion_group_leave(companion_h handle, companion_group_h group,
                companion_group_find_finish_cb callback, void *user_data);
 
 /**
@@ -392,6 +401,7 @@ int companion_group_leave(companion_group_h group,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  *
  *
@@ -406,7 +416,7 @@ int companion_group_leave(companion_group_h group,
  * @see companion_group_get_member_devices()
  *
  */
-int companion_group_delete(companion_group_h group);
+int companion_group_delete(companion_h handle, companion_group_h group);
 
 /**
  * @brief Combines both groups to one.
@@ -414,6 +424,7 @@ int companion_group_delete(companion_group_h group);
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] dest_group Group handle to be united
  * @param[in] src_group Group handle to be merged
  *
@@ -429,7 +440,7 @@ int companion_group_delete(companion_group_h group);
  * @see companion_group_get_member_devices()
  *
  */
-int companion_group_merge(companion_group_h dest_group,
+int companion_group_merge(companion_h handle, companion_group_h dest_group,
                companion_group_h src_group);
 
 /**
@@ -440,6 +451,7 @@ int companion_group_merge(companion_group_h dest_group,
  *
  * @remarks The @devices should be released using companion_device_destroy().
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group resource list
  * @param[out] devices Device list
  * @param[out] count Number of devices in a group
@@ -456,8 +468,8 @@ int companion_group_merge(companion_group_h dest_group,
  * @see companion_group_merge()
  *
  */
-int companion_group_get_member_devices(companion_group_h group,
-               companion_device_h **devices, int *count);
+int companion_group_get_member_devices(companion_h handle,
+               companion_group_h group, companion_device_h **devices, int *count);
 
 
 /* Device Module */
@@ -468,6 +480,7 @@ int companion_group_get_member_devices(companion_group_h group,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] timeout Time to find
  * @param[in] found_cb Callback handler to retrieve the found device
  * @param[in] finish_cb Callback handler to know finding process finished
@@ -481,10 +494,8 @@ int companion_group_get_member_devices(companion_group_h group,
  * @see companion_device_get_found_devices()
  *
  */
-int companion_device_find(
-               int timeout,
-               companion_device_found_cb found_cb,
-               companion_device_find_finish_cb finish_cb,
+int companion_device_find(companion_h handle, int timeout,
+               companion_device_found_cb found_cb, companion_device_find_finish_cb finish_cb,
                void *user_data);
 
 /**
@@ -493,6 +504,7 @@ int companion_device_find(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] devices Device list
  * @param[in] count Number of devices
  *
@@ -504,9 +516,8 @@ int companion_device_find(
  * @see companion_device_find_mowned_device()
  *
  */
-int companion_device_get_found_devices(
-               companion_device_h **devices,
-               int *count);
+int companion_device_get_found_devices(companion_h handle,
+               companion_device_h **devices, int *count);
 
 /**
  * @brief Finds my owned devices in the network.
@@ -515,6 +526,7 @@ int companion_device_get_found_devices(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] timeout Time to find
  * @param[in] found_cb Callback handler to retrieve the found device
  * @param[in] finish_cb Callback handler to know finding process finished
@@ -528,10 +540,8 @@ int companion_device_get_found_devices(
  * @see companion_device_get_found_mowned_devices()
  *
  */
-int companion_device_find_mowned_device(
-               int timeout,
-               companion_device_found_cb found_cb,
-               companion_device_find_finish_cb finish_cb,
+int companion_device_find_mowned_device(companion_h handle, int timeout,
+               companion_device_found_cb found_cb, companion_device_find_finish_cb finish_cb,
                void *user_data);
 
 /**
@@ -540,6 +550,7 @@ int companion_device_find_mowned_device(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] devices Device list
  * @param[in] count Number of devices
  *
@@ -551,7 +562,7 @@ int companion_device_find_mowned_device(
  * @see companion_device_find_mowned_device()
  *
  */
-int companion_device_get_found_mowned_devices(
+int companion_device_get_found_mowned_devices(companion_h handle,
                companion_device_h **devices, int *count);
 
 /* companion_group_device_invite : Invite a remote group device to my local group. */
@@ -581,11 +592,8 @@ int companion_device_get_found_mowned_devices(
  * @see companion_send_data()
  *
  */
-int companion_device_invite(
-               companion_group_h group,
-               companion_device_h device,
-               char *PIN,
-               companion_device_invite_result_cb callback,
+int companion_device_invite(companion_h handle, companion_group_h group,
+               companion_device_h device, char *PIN, companion_device_invite_result_cb callback,
                void *user_data);
 
 /* companion_group_device_eject : Eject a remote group device from my group. */
@@ -596,6 +604,7 @@ int companion_device_invite(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  * @param[in] device Device handle
  * @param[in] callback Callback handler to receive the result
@@ -613,10 +622,8 @@ int companion_device_invite(
  * @see companion_send_data()
  *
  */
-int companion_device_eject(
-               companion_group_h group,
-               companion_device_h device,
-               companion_device_eject_result_cb callback,
+int companion_device_eject(companion_h handle, companion_group_h group,
+               companion_device_h device, companion_device_eject_result_cb callback,
                void *user_data);
 
 /**
@@ -625,6 +632,8 @@ int companion_device_eject(
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
+ * @param[in] handle The companion manager handle
  * @param[in] device Local device handle
  *
  * @return 0 on success, otherwise a negative error value.
@@ -634,7 +643,8 @@ int companion_device_eject(
  * @see companion_device_get_my_uuid()
  *
  */
-int companion_device_get_my_device(companion_device_h *device);
+int companion_device_get_my_device(companion_h handle,
+               companion_device_h *device);
 
 /**
  * @brief Gets my local device ID.
@@ -644,6 +654,7 @@ int companion_device_get_my_device(companion_device_h *device);
  *
  * @remarks The @uuid should not be released.
  *
+ * @param[in] handle The companion manager handle
  * @param[in] uuid Local device UUID
  *
  * @return 0 on success, otherwise a negative error value.
@@ -653,7 +664,7 @@ int companion_device_get_my_device(companion_device_h *device);
  * @see companion_device_get_my_device()
  *
  */
-int companion_device_get_my_uuid(char **uuid);
+int companion_device_get_my_uuid(companion_h handle, char **uuid);
 
 /* Group Information Module */
 
@@ -1004,6 +1015,7 @@ int companion_device_information_get_device_type(companion_device_h device,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] device Device handle
  * @param[in] data Data to send
  * @param[in] len What length to send
@@ -1022,8 +1034,8 @@ int companion_device_information_get_device_type(companion_device_h device,
  * @see companion_request_result_callback()
  *
  */
-int companion_send_data(companion_device_h device, char *data, int len,
-               companion_send_data_finish_cb finish_cb, void *user_data);
+int companion_send_data(companion_h handle, companion_device_h device, char *data,
+               int len, companion_send_data_finish_cb finish_cb, void *user_data);
 
 /**
  * @brief Requests to create a group.
@@ -1032,6 +1044,7 @@ int companion_send_data(companion_device_h device, char *data, int len,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] device Device handle
  * @param[in] group_name Group name
  *
@@ -1047,7 +1060,8 @@ int companion_send_data(companion_device_h device, char *data, int len,
  * @see companion_send_data()
  *
  */
-int companion_request_create_group(companion_device_h device, char *group_name);
+int companion_request_create_group(companion_h handle,
+       companion_device_h device, char *group_name);
 
 /**
  * @brief Requests to invite a device to the group.
@@ -1056,6 +1070,7 @@ int companion_request_create_group(companion_device_h device, char *group_name);
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  * @param[in] device Device handle
  * @param[in] PIN PIN number
@@ -1072,8 +1087,8 @@ int companion_request_create_group(companion_device_h device, char *group_name);
  * @see companion_send_data()
  *
  */
-int companion_request_invite(companion_group_h group, companion_device_h device,
-               char *PIN);
+int companion_request_invite(companion_h handle, companion_group_h group,
+               companion_device_h device, char *PIN);
 
 /**
  * @brief Requests to eject a device.
@@ -1081,6 +1096,7 @@ int companion_request_invite(companion_group_h group, companion_device_h device,
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  * @param[in] device Device handle
  *
@@ -1096,7 +1112,8 @@ int companion_request_invite(companion_group_h group, companion_device_h device,
  * @see companion_send_data()
  *
  */
-int companion_request_eject(companion_group_h group, companion_device_h device);
+int companion_request_eject(companion_h handle, companion_group_h group,
+               companion_device_h device);
 
 /**
  * @brief Requests to delete the group.
@@ -1104,6 +1121,7 @@ int companion_request_eject(companion_group_h group, companion_device_h device);
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] group Group handle
  *
  *
@@ -1118,7 +1136,7 @@ int companion_request_eject(companion_group_h group, companion_device_h device);
  * @see companion_send_data()
  *
  */
-int companion_request_delete_group(companion_group_h group);
+int companion_request_delete_group(companion_h handle, companion_group_h group);
 
 /**
  * @brief Registers request result callback funtion.
@@ -1127,6 +1145,7 @@ int companion_request_delete_group(companion_group_h group);
  *
  * @since_tizen 5.0
  *
+ * @param[in] handle The companion manager handle
  * @param[in] callback Callback function pointer
  * @param[in] user_data User data pointer
  *
@@ -1142,8 +1161,8 @@ int companion_request_delete_group(companion_group_h group);
  * @see companion_send_data()
  *
  */
-int companion_request_result_callback(companion_request_result_cb callback,
-               void *user_data);
+int companion_request_result_callback(companion_h handle,
+               companion_request_result_cb callback, void *user_data);
 
 /**
  * @}
index 14e0d22..58f7f57 100644 (file)
@@ -46,92 +46,104 @@ do { \
 #define COMP_DBUS_GROUP_PATH "/org/tizen/companion/group" /**< For group dbus */
 #define COMP_DBUS_ENABLER_PATH "/org/tizen/companion/enabler" /**< dbus auto-activation */
 
-Group *group_proxy = NULL; /**< To receive signal from companion-manager */
-Enabler *enabler_proxy = NULL; /**< Enbler proxy */
-
-int ref_count = 0;
-bool __is_initialized = false;
+int ref_count = 0; /**< How many clients are alive */
+bool __is_initialized = false; /**< Initialize or not */
 
 typedef struct _companion_group_t {
-       char *uri_path;
-       char *device_id;
-       char *group_name;
-       char *host_addr;
-       char *resource_type;
-       companion_group_type_e type;
+       char *uri_path; /**< URI Path for group resource */
+       char *device_id; /**< Device ID of the device has this group resource */
+       char *group_name; /**< Group Name (Friendly name) */
+       char *host_addr; /**< Host address */
+       char *resource_type; /**< Resource type */
+       companion_group_type_e type; /**< Mine or Remote */
 } companion_group_t;
 
 typedef struct _companion_device_t {
-       char *device_id;
-       char *ip;
-       char *device_type;
-       int port;
+       char *device_id; /**< Device ID */
+       char *ip; /**< Device IP */
+       char *device_type; /**< Device Type */
+       int port; /**< Port Number */
 } companion_device_t;
 
 typedef struct _group_found_cb_t {
        companion_group_found_cb found_cb;
        void *user_data;
 } group_found_cb_t;
-group_found_cb_t group_found_cb;
 
 typedef struct _device_found_cb_t {
        companion_device_found_cb found_cb;
        void *user_data;
 } device_found_cb_t;
-device_found_cb_t device_found_cb;
 
 typedef struct _group_find_finish_cb_t {
        companion_group_find_finish_cb finish_cb;
        void *user_data;
 } group_find_finish_cb_t;
-group_find_finish_cb_t group_find_finish_cb;
 
 typedef struct _device_find_finish_cb_t {
        companion_device_find_finish_cb finish_cb;
        void *user_data;
 } device_find_finish_cb_t;
-device_find_finish_cb_t device_find_finish_cb;
 
 typedef struct _mowned_device_found_cb_t {
        companion_device_found_cb found_cb;
        void *user_data;
 } mowned_device_found_cb_t;
-mowned_device_found_cb_t mowned_device_found_cb;
 
 typedef struct _mowned_device_find_finish_cb_t {
        companion_device_find_finish_cb finish_cb;
        void *user_data;
 } mowned_device_find_finish_cb_t;
-mowned_device_find_finish_cb_t mowned_device_find_finish_cb;
 
 typedef struct _device_invite_result_cb_t {
        companion_device_invite_result_cb result_cb;
        void *user_data;
 } device_invite_result_cb_t;
-device_invite_result_cb_t device_invite_result_cb;
 
 typedef struct _device_eject_result_cb_t {
        companion_device_eject_result_cb result_cb;
        void *user_data;
 } device_eject_result_cb_t;
-device_eject_result_cb_t device_eject_result_cb;
 
 typedef struct _send_data_finish_cb_t {
        companion_send_data_finish_cb finish_cb;
        void *user_data;
 } send_data_finish_cb_t;
-send_data_finish_cb_t send_data_finish_cb;
 
 typedef struct _request_result_cb_t {
        companion_request_result_cb result_cb;
        void *user_data;
 } request_result_cb_t;
-request_result_cb_t request_result_cb;
+
+typedef struct _comp_manager_s {
+       gpointer dbus_connection;
+       GCancellable *ca;
+
+       Group *group_proxy; /**< To receive signal from companion-manager */
+       Enabler *enabler_proxy; /**< Enbler proxy */
+
+       group_found_cb_t group_found_cb;
+       device_found_cb_t device_found_cb;
+       group_find_finish_cb_t group_find_finish_cb;
+       device_find_finish_cb_t device_find_finish_cb;
+       mowned_device_found_cb_t mowned_device_found_cb;
+       mowned_device_find_finish_cb_t mowned_device_find_finish_cb;
+       device_invite_result_cb_t device_invite_result_cb;
+       device_eject_result_cb_t device_eject_result_cb;
+       send_data_finish_cb_t send_data_finish_cb;
+       request_result_cb_t request_result_cb;
+} comp_manager_s;
 
 static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
        char *group_name, char *host_addr, char *resource_type, companion_group_type_e type)
 {
-       companion_group_t *group = g_new0(companion_group_t, 1);
+       companion_group_t *group = calloc(1, sizeof(companion_group_t));
+       if (NULL == group) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation failed");
+               goto CREATE_GROUP_HANDLER_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
 
        group->uri_path = g_strdup(uri_path);
        group->device_id = g_strdup(device_id);
@@ -140,20 +152,90 @@ static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
        group->resource_type = g_strdup(resource_type);
        group->type = type;
 
+       if (!group->uri_path || !group->device_id ||
+               !group->host_addr || !group->resource_type) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation failed");
+               goto CREATE_GROUP_HANDLER_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
        return group;
+
+CREATE_GROUP_HANDLER_ERROR:
+       /* LCOV_EXCL_START */
+       if (group) {
+               if (group->uri_path) {
+                       free(group->uri_path);
+                       group->uri_path = NULL;
+               }
+               if (group->device_id) {
+                       free(group->device_id);
+                       group->device_id = NULL;
+               }
+               if (group->group_name) {
+                       free(group->group_name);
+                       group->group_name = NULL;
+               }
+               if (group->host_addr) {
+                       free(group->host_addr);
+                       group->host_addr = NULL;
+               }
+               if (group->resource_type) {
+                       free(group->resource_type);
+                       group->resource_type = NULL;
+               }
+               free(group);
+               group = NULL;
+       }
+       return NULL;
+       /* LCOV_EXCL_STOP */
 }
 
 static companion_device_t *_create_device_handle(char *device_id, char *ip,
        char *device_type, int port)
 {
-       companion_device_t *device = g_new0(companion_device_t, 1);
+       companion_device_t *device = calloc(1, sizeof(companion_device_t));
+       if (NULL == device) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation failed");
+               goto CREATE_DEVICE_HANDLER_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
 
        device->device_id = g_strdup(device_id);
        device->ip = g_strdup(ip);
        device->device_type = g_strdup(device_type);
        device->port = port;
 
+       if (!device->device_id || !device->ip || !device->device_type) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation failed");
+               goto CREATE_DEVICE_HANDLER_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
        return device;
+
+CREATE_DEVICE_HANDLER_ERROR:
+       /* LCOV_EXCL_START */
+       if (device) {
+               if (device->device_id) {
+                       free(device->device_id);
+                       device->device_id = NULL;
+               }
+               if (device->ip) {
+                       free(device->ip);
+                       device->ip = NULL;
+               }
+               if (device->device_type) {
+                       free(device->device_type);
+                       device->device_type = NULL;
+               }
+               free(device);
+               device = NULL;
+       }
+       return NULL;
+       /* LCOV_EXCL_STOP */
 }
 
 static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
@@ -169,6 +251,16 @@ static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
        char *resource_type = NULL;
        companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
 
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+
        g_variant_get(va, "a{sv}", &iter);
        while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
                if (g_strcmp0(key, "URI") == 0)
@@ -189,14 +281,24 @@ static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
 
        group = _create_group_handle(uri_path, device_id, group_name, host_addr,
                resource_type, type);
-       if (group_found_cb.found_cb)
-               group_found_cb.found_cb(type, group, group_found_cb.user_data);
+       if (handle->group_found_cb.found_cb)
+               handle->group_found_cb.found_cb(type, group, handle->group_found_cb.user_data);
 }
 
 static void _group_find_finish_cb(Group *object, gint ret, gpointer user_data)
 {
-       if (group_find_finish_cb.finish_cb)
-               group_find_finish_cb.finish_cb(ret, group_find_finish_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->group_find_finish_cb.finish_cb)
+               handle->group_find_finish_cb.finish_cb(ret,
+                       handle->group_find_finish_cb.user_data);
 }
 
 static void __device_found_cb(Group *object, gint count, GVariant *va,
@@ -208,6 +310,16 @@ static void __device_found_cb(Group *object, gint count, GVariant *va,
        GVariant *key_value;
        companion_device_t *device = NULL;
 
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+
        g_variant_get(va, "aa{sv}", &iter);
        while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
                char *device_id = NULL;
@@ -228,16 +340,26 @@ static void __device_found_cb(Group *object, gint count, GVariant *va,
                g_variant_iter_free(iter_row);
 
                device = _create_device_handle(device_id, ip, device_type, port);
-               if (device_found_cb.found_cb)
-                       device_found_cb.found_cb(device, device_found_cb.user_data);
+               if (handle->device_found_cb.found_cb)
+                       handle->device_found_cb.found_cb(device, handle->device_found_cb.user_data);
        }
        g_variant_iter_free(iter);
 }
 
 static void _device_find_finish_cb(Group *object, gint ret, gpointer user_data)
 {
-       if (device_find_finish_cb.finish_cb)
-               device_find_finish_cb.finish_cb(ret, device_find_finish_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->device_find_finish_cb.finish_cb)
+               handle->device_find_finish_cb.finish_cb(ret,
+                       handle->device_find_finish_cb.user_data);
 }
 
 static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
@@ -249,6 +371,16 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
        GVariant *key_value;
        companion_device_t *device = NULL;
 
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+
        g_variant_get(va, "aa{sv}", &iter);
        while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
                char *device_id = NULL;
@@ -270,8 +402,9 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                g_variant_iter_free(iter_row);
 
                device = _create_device_handle(device_id, ip, device_type, port);
-               if (mowned_device_found_cb.found_cb)
-                       mowned_device_found_cb.found_cb(device, mowned_device_found_cb.user_data);
+               if (handle->mowned_device_found_cb.found_cb)
+                       handle->mowned_device_found_cb.found_cb(device,
+                               handle->mowned_device_found_cb.user_data);
        }
        g_variant_iter_free(iter);
 }
@@ -279,152 +412,290 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
 static void _mowned_device_find_finish_cb(Group *object, gint ret,
        gpointer user_data)
 {
-       if (mowned_device_find_finish_cb.finish_cb)
-               mowned_device_find_finish_cb.finish_cb(ret, mowned_device_find_finish_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->mowned_device_find_finish_cb.finish_cb)
+               handle->mowned_device_find_finish_cb.finish_cb(ret,
+                       handle->mowned_device_find_finish_cb.user_data);
 }
 
 static void __device_invite_result_cb(Group *object, gint ret, gpointer user_data)
 {
-       if (device_invite_result_cb.result_cb)
-               device_invite_result_cb.result_cb(ret, device_invite_result_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->device_invite_result_cb.result_cb)
+               handle->device_invite_result_cb.result_cb(ret,
+                       handle->device_invite_result_cb.user_data);
 }
 
 static void __device_eject_result_cb(Group *object, gint ret, gpointer user_data)
 {
-       if (device_eject_result_cb.result_cb)
-               device_eject_result_cb.result_cb(ret, device_eject_result_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->device_eject_result_cb.result_cb)
+               handle->device_eject_result_cb.result_cb(ret,
+                       handle->device_eject_result_cb.user_data);
 }
 
 static void __send_data_finish_cb(Group *object, gchar *resp_data, gint ret,
        gpointer user_data)
 {
-       if (send_data_finish_cb.finish_cb)
-               send_data_finish_cb.finish_cb(ret, resp_data, send_data_finish_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->send_data_finish_cb.finish_cb)
+               handle->send_data_finish_cb.finish_cb(ret, resp_data,
+                       handle->send_data_finish_cb.user_data);
 }
 
 static void __request_result_cb(Group *object, gchar *cmd, gchar *arg, gint ret,
        gpointer user_data)
 {
-       if (request_result_cb.result_cb)
-               request_result_cb.result_cb(cmd, arg, ret, request_result_cb.user_data);
+       NOTUSED(object);
+
+       comp_manager_s *handle = user_data;
+       if (!handle) {
+               /* LCOV_EXCL_START */
+               _ERR("handle is null");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+       if (handle->request_result_cb.result_cb)
+               handle->request_result_cb.result_cb(cmd, arg, ret,
+                       handle->request_result_cb.user_data);
 }
 
-static void _group_proxy_init(void)
+static int _group_proxy_init(comp_manager_s *handle);
+static int _enabler_proxy_init(comp_manager_s *handle);
+static void _group_proxy_deinit(comp_manager_s *handle);
+static void _enabler_proxy_deinit(comp_manager_s *handle);
+
+static int _gdbus_initialize(comp_manager_s *handle)
 {
-       GError *error = NULL;
+       int ret = COMP_ERROR_NONE;
 
-       group_proxy = group_proxy_new_for_bus_sync(
-                                       G_BUS_TYPE_SYSTEM,
-                                       G_DBUS_PROXY_FLAGS_NONE,
-                                       COMP_DBUS_SERVICE,
-                                       COMP_DBUS_GROUP_PATH,
-                                       NULL,
-                                       &error);
+       _group_proxy_init(handle);
+       _enabler_proxy_init(handle);
 
-       g_signal_connect(group_proxy,
-               "group-found", G_CALLBACK(__group_found_cb), NULL);
-       g_signal_connect(group_proxy,
-               "group-find-finish", G_CALLBACK(_group_find_finish_cb), NULL);
-       g_signal_connect(group_proxy,
-               "device-found", G_CALLBACK(__device_found_cb), NULL);
-       g_signal_connect(group_proxy,
-               "device-find-finish", G_CALLBACK(_device_find_finish_cb), NULL);
-       g_signal_connect(group_proxy,
-               "mowned-device-found", G_CALLBACK(__mowned_device_found_cb), NULL);
-       g_signal_connect(group_proxy,
-               "mowned-device-find-finish", G_CALLBACK(_mowned_device_find_finish_cb), NULL);
-       g_signal_connect(group_proxy,
-               "device-invite-result", G_CALLBACK(__device_invite_result_cb), NULL);
-       g_signal_connect(group_proxy,
-               "device-eject-result", G_CALLBACK(__device_eject_result_cb), NULL);
-       g_signal_connect(group_proxy,
-               "send-data-finish", G_CALLBACK(__send_data_finish_cb), NULL);
-       g_signal_connect(group_proxy,
-               "request-result", G_CALLBACK(__request_result_cb), NULL);
+       if (handle->group_proxy == NULL)
+               ret = -1; /* LCOV_EXCL_LINE */
+
+       if (handle->enabler_proxy == NULL)
+               ret = -1; /* LCOV_EXCL_LINE */
+
+       handle->ca = g_cancellable_new();
+
+       return ret;
 }
 
-static void _enabler_proxy_init(void)
+static int _gdbus_deinitialize(comp_manager_s *handle)
 {
-       GError *error = NULL;
+       int ret = COMP_ERROR_NONE;
+
+       _group_proxy_deinit(handle);
+       _enabler_proxy_deinit(handle);
+
+       g_cancellable_cancel(handle->ca);
+       g_object_unref(handle->ca);
+       handle->ca = NULL;
+
+       return ret;
+}
 
-       enabler_proxy = enabler_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+static int _enabler_proxy_init(comp_manager_s *handle)
+{
+       int ret = COMP_ERROR_NONE;
+       GError *error = NULL;
+       handle->enabler_proxy = enabler_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
                                                   G_DBUS_PROXY_FLAGS_NONE, COMP_DBUS_SERVICE,
                                                   COMP_DBUS_ENABLER_PATH, NULL, &error);
+       if (NULL == handle->enabler_proxy) {
+               /* LCOV_EXCL_START */
+               if (error != NULL) {
+                       _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
+                       g_error_free(error);
+               }
+               return COMP_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+       return ret;
 }
 
-static void _group_proxy_deinit(void)
+static void _group_proxy_deinit(comp_manager_s *handle)
 {
-       group_proxy = NULL;
+       g_object_unref(handle->group_proxy);
+       handle->group_proxy = NULL;
 }
 
-static void _enabler_proxy_deinit(void)
+static void _enabler_proxy_deinit(comp_manager_s *handle)
 {
        int ret;
 
-       enabler_call_disable_sync(enabler_proxy, &ret, NULL, NULL);
-       enabler_proxy = NULL;
+       enabler_call_disable_sync(handle->enabler_proxy, &ret, NULL, NULL);
+       g_object_unref(handle->enabler_proxy);
+       handle->enabler_proxy = NULL;
 }
 
-static int _gdbus_initialize(void)
+/* LCOV_EXCL_START */
+static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
+               gpointer *user_data)
 {
-       int ret = 0;
-
-       _group_proxy_init();
-       _enabler_proxy_init();
+       GDBusProxy *proxy = G_DBUS_PROXY(object);
+       gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
+       comp_manager_s *handle = (comp_manager_s *)user_data;
+       if (!handle) {
+               _ERR("handle is null");
+               return;
+       }
 
-       if (group_proxy == NULL)
-               ret = -1; /* LCOV_EXCL_LINE */
+       LOGD("Name owner notify [%s]", name_owner);
 
-       if (enabler_proxy == NULL)
-               ret = -1; /* LCOV_EXCL_LINE */
+       if (NULL == name_owner)
+               _gdbus_deinitialize(handle);
+       free(name_owner);
 
-       return ret;
 }
+/* LCOV_EXCL_STOP */
 
-static int _gdbus_deinitialize(void)
+static int _group_proxy_init(comp_manager_s *handle)
 {
-       int ret = 0;
+       int id = -1;
+       GError *error = NULL;
+
+       handle->group_proxy = group_proxy_new_for_bus_sync(
+                                       G_BUS_TYPE_SYSTEM,
+                                       G_DBUS_PROXY_FLAGS_NONE,
+                                       COMP_DBUS_SERVICE,
+                                       COMP_DBUS_GROUP_PATH,
+                                       NULL,
+                                       &error);
+       if (NULL == handle->group_proxy) {
+               /* LCOV_EXCL_START */
+               if (error != NULL) {
+                       _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
+                       g_error_free(error);
+               }
+               return COMP_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
 
-       _group_proxy_deinit();
-       _enabler_proxy_deinit();
+       id = g_signal_connect(handle->group_proxy, "notify::g-name-owner",
+                       G_CALLBACK(_dbus_name_owner_notify), handle);
+       if (0 == id) {
+               /* LCOV_EXCL_START */
+               _ERR("g_signal_connect() Fail");
+               g_object_unref(handle->group_proxy);
+               handle->group_proxy = NULL;
+               return COMP_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
 
-       return ret;
+       g_signal_connect(handle->group_proxy,
+               "group-found", G_CALLBACK(__group_found_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "group-find-finish", G_CALLBACK(_group_find_finish_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "device-found", G_CALLBACK(__device_found_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "device-find-finish", G_CALLBACK(_device_find_finish_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "mowned-device-found", G_CALLBACK(__mowned_device_found_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "mowned-device-find-finish", G_CALLBACK(_mowned_device_find_finish_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "device-invite-result", G_CALLBACK(__device_invite_result_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "device-eject-result", G_CALLBACK(__device_eject_result_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "send-data-finish", G_CALLBACK(__send_data_finish_cb), handle);
+       g_signal_connect(handle->group_proxy,
+               "request-result", G_CALLBACK(__request_result_cb), handle);
+
+       return COMP_ERROR_NONE;
 }
 
-EXPORT_API int companion_initialize()
+EXPORT_API int companion_initialize(companion_h *handle)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
+       struct comp_manager_s *comp_manager = NULL;
+
+       if (NULL == handle) {
+               /* LCOV_EXCL_START */
+               _ERR("Invalid parameter");
+               return COMP_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
 
        _BEGIN();
 
-       COMPANION_LOCK;
+       comp_manager = calloc(1, sizeof(comp_manager_s));
+       if (NULL == comp_manager) {
+               /* LCOV_EXCL_START */
+               _ERR("Failed to create handle");
+               return COMP_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+       *handle = comp_manager;
 
-       if (__is_initialized == false) {
-               ret = _gdbus_initialize();
-               __is_initialized = true;
+       if (__is_initialized) {
+               _DBG("Already initialized");
+               return COMP_ERROR_ALREADY_INITIALIZED;
        }
-       ref_count++;
 
+       COMPANION_LOCK;
+       ret = _gdbus_initialize(*handle);
+       __is_initialized = true;
        COMPANION_UNLOCK;
+       ref_count++;
 
        _END();
 
        return ret;
 }
 
-EXPORT_API int companion_deinitialize()
+EXPORT_API int companion_deinitialize(companion_h handle)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
 
        _BEGIN();
 
        COMPANION_LOCK;
 
-       if (ref_count > 0)
-               ref_count--;
+       if (0 > --ref_count) {
+               _DBG("all connections closed\n");
+               ref_count = 0;
+               return ret;
+       }
 
        if (__is_initialized == true && ref_count == 0) {
-               ret = _gdbus_deinitialize();
+               ret = _gdbus_deinitialize(handle);
                __is_initialized = false;
        }
 
@@ -436,13 +707,18 @@ EXPORT_API int companion_deinitialize()
 
 }
 
-EXPORT_API int companion_group_create(char *group_name)
+EXPORT_API int companion_group_create(companion_h handle, char *group_name)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        /* create group to daemon using gdbus */
-       group_call_create_sync(group_proxy, group_name, &ret, NULL, &error);
+       group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error);
 
        return ret;
 }
@@ -475,32 +751,45 @@ EXPORT_API void companion_group_destroy(companion_group_t *group)
        group = NULL;
 }
 
-EXPORT_API int companion_group_find(int timeout, companion_group_found_cb found_cb,
-       companion_group_find_finish_cb finish_cb, void *user_data)
+EXPORT_API int companion_group_find(companion_h handle, int timeout,
+       companion_group_found_cb found_cb, companion_group_find_finish_cb finish_cb,
+       void *user_data)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
 
-       group_found_cb.found_cb = found_cb;
-       group_find_finish_cb.finish_cb = finish_cb;
-       group_found_cb.user_data = user_data;
-       group_find_finish_cb.user_data = user_data;
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
+       _handle->group_found_cb.found_cb = found_cb;
+       _handle->group_find_finish_cb.finish_cb = finish_cb;
+       _handle->group_found_cb.user_data = user_data;
+       _handle->group_find_finish_cb.user_data = user_data;
 
        /* get groups from daemon using gdbus */
-       group_call_find_sync(group_proxy, timeout, &ret, NULL, &error);
+       group_call_find_sync(_handle->group_proxy, timeout, &ret, NULL, &error);
 
        return ret;
 }
 
-EXPORT_API int companion_group_get_found_groups(companion_group_h **groups,
-       int *count)
+EXPORT_API int companion_group_get_found_groups(companion_h handle,
+       companion_group_h **groups, int *count)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GVariant *va = NULL;
        GError *error = NULL;
 
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        /* get groups from daemon using gdbus */
-       group_call_get_found_groups_sync(group_proxy, &ret, &va, NULL, &error);
+       group_call_get_found_groups_sync(_handle->group_proxy, &ret, &va, NULL, &error);
        *count = g_variant_n_children(va);
 
        _DBG("get found groups : %d", *count);
@@ -556,69 +845,94 @@ EXPORT_API int companion_group_get_found_groups(companion_group_h **groups,
        return ret;
 }
 
-EXPORT_API int companion_group_join(companion_group_h group,
+EXPORT_API int companion_group_join(companion_h handle, companion_group_h group,
        companion_group_find_finish_cb callback, void *user_data)
 {
        int ret = COMP_ERROR_NONE;
+
+       NOTUSED(handle);
        NOTUSED(group);
        NOTUSED(callback);
        NOTUSED(user_data);
+
        return ret;
 }
 
-EXPORT_API int companion_group_leave(companion_group_h group,
+EXPORT_API int companion_group_leave(companion_h handle, companion_group_h group,
        companion_group_find_finish_cb callback, void *user_data)
 {
        int ret = COMP_ERROR_NONE;
+
+       NOTUSED(handle);
        NOTUSED(group);
        NOTUSED(callback);
        NOTUSED(user_data);
+
        return ret;
 }
 
-EXPORT_API int companion_device_find(int timeout, companion_device_found_cb found_cb,
-       companion_device_find_finish_cb finish_cb, void *user_data)
+EXPORT_API int companion_device_find(companion_h handle, int timeout,
+       companion_device_found_cb found_cb, companion_device_find_finish_cb finish_cb,
+       void *user_data)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
 
-       device_found_cb.found_cb = found_cb;
-       device_found_cb.user_data = user_data;
-       device_find_finish_cb.finish_cb = finish_cb;
-       device_find_finish_cb.user_data = user_data;
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
+       _handle->device_found_cb.found_cb = found_cb;
+       _handle->device_found_cb.user_data = user_data;
+       _handle->device_find_finish_cb.finish_cb = finish_cb;
+       _handle->device_find_finish_cb.user_data = user_data;
 
        /* get groups from daemon using gdbus */
-       group_call_device_find_sync(group_proxy, timeout, &ret, NULL, &error);
+       group_call_device_find_sync(_handle->group_proxy, timeout, &ret, NULL, &error);
 
        return ret;
 }
 
-EXPORT_API int companion_device_find_mowned_device(int timeout,
-       companion_device_found_cb found_cb,  companion_device_find_finish_cb finish_cb,
-       void *user_data)
+EXPORT_API int companion_device_find_mowned_device(companion_h handle,
+       int timeout, companion_device_found_cb found_cb,
+       companion_device_find_finish_cb finish_cb, void *user_data)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
+       comp_manager_s *_handle = handle;
 
-       mowned_device_found_cb.found_cb = found_cb;
-       mowned_device_found_cb.user_data = user_data;
-       mowned_device_find_finish_cb.finish_cb = finish_cb;
-       mowned_device_find_finish_cb.user_data = user_data;
+       _handle->mowned_device_found_cb.found_cb = found_cb;
+       _handle->mowned_device_found_cb.user_data = user_data;
+       _handle->mowned_device_find_finish_cb.finish_cb = finish_cb;
+       _handle->mowned_device_find_finish_cb.user_data = user_data;
 
        /* get groups from daemon using gdbus */
-       group_call_find_mowned_devices_sync(group_proxy, timeout, &ret, NULL, &error);
+       group_call_find_mowned_devices_sync(_handle->group_proxy, timeout, &ret, NULL, &error);
 
        return ret;
 }
 
-EXPORT_API int companion_send_data(companion_device_h device, char *data, int len,
-       companion_send_data_finish_cb finish_cb, void *user_data)
+EXPORT_API int companion_send_data(companion_h handle, companion_device_h device,
+       char *data, int len, companion_send_data_finish_cb finish_cb, void *user_data)
 {
        int ret = COMP_ERROR_NONE;
 
        char *buf = NULL;
        GError *error = NULL;
+
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        companion_device_t *dev = (companion_device_t *)device;
+       if (!dev) {
+               _ERR("dev is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        buf = g_malloc0(len + 1);
        if (NULL == buf) {
@@ -627,10 +941,10 @@ EXPORT_API int companion_send_data(companion_device_h device, char *data, int le
        }
        memcpy(buf, data, len);
 
-       send_data_finish_cb.finish_cb = finish_cb;
-       send_data_finish_cb.user_data = user_data;
+       _handle->send_data_finish_cb.finish_cb = finish_cb;
+       _handle->send_data_finish_cb.user_data = user_data;
 
-       group_call_send_data_sync(group_proxy, dev->device_id, dev->ip, dev->port,
+       group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->ip, dev->port,
                buf, len, &ret, NULL, &error);
 
        free(buf);
@@ -641,16 +955,22 @@ EXPORT_API int companion_send_data(companion_device_h device, char *data, int le
 
 /* companion_group_join : join to remote group. if group handle is my daemon's,
    then the api return fail error */
-EXPORT_API int companion_device_get_found_devices(companion_device_h **devices,
-       int *count)
+EXPORT_API int companion_device_get_found_devices(companion_h handle,
+       companion_device_h **devices, int *count)
 {
        int ret = 0;
        int num = 0;
        GVariant *va = NULL;
        GError *error = NULL;
+       comp_manager_s *_handle = handle;
+
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        /* get groups from daemon using gdbus */
-       group_call_get_remote_device_sync(group_proxy, &num, &va, NULL, &error);
+       group_call_get_remote_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
        /* *count = g_variant_n_children(va); */
        *count = num;
 
@@ -696,15 +1016,21 @@ EXPORT_API int companion_device_get_found_devices(companion_device_h **devices,
 }
 
 EXPORT_API int companion_device_get_found_mowned_devices(
-       companion_device_h **devices, int *count)
+       companion_h handle, companion_device_h **devices, int *count)
 {
        int ret = 0;
        int num = 0;
        GVariant *va = NULL;
        GError *error = NULL;
+       comp_manager_s *_handle = handle;
+
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        /* get groups from daemon using gdbus */
-       group_call_get_mowned_device_sync(group_proxy, &num, &va, NULL, &error);
+       group_call_get_mowned_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
        /* *count = g_variant_n_children(va); */
        *count = num;
 
@@ -749,7 +1075,8 @@ EXPORT_API int companion_device_get_found_mowned_devices(
        return ret;
 }
 
-EXPORT_API int companion_device_get_my_device(companion_device_h *device)
+EXPORT_API int companion_device_get_my_device(companion_h handle,
+       companion_device_h *device)
 {
        int ret = 0;
        GError *error = NULL;
@@ -761,8 +1088,14 @@ EXPORT_API int companion_device_get_my_device(companion_device_h *device)
        char *addr = NULL;
        char *ver = NULL;
        int port = -1;
+       comp_manager_s *_handle = handle;
+
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
-       group_call_get_my_mowned_device_sync(group_proxy, &va, NULL, &error);
+       group_call_get_my_mowned_device_sync(_handle->group_proxy, &va, NULL, &error);
 
        g_variant_get(va, "a{sv}", &iter);
        while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
@@ -806,74 +1139,117 @@ static void companion_device_destroy(companion_device_t *device)
        device = NULL;
 }
 
-EXPORT_API int companion_device_get_my_uuid(char **uuid)
+EXPORT_API int companion_device_get_my_uuid(companion_h handle, char **uuid)
 {
        int ret = 0;
        GError *error = NULL;
 
-       group_call_get_my_uuid_sync(group_proxy, uuid, NULL, &error);
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
+       group_call_get_my_uuid_sync(_handle->group_proxy, uuid, NULL, &error);
 
        return ret;
 }
 
 /* group merge */
-EXPORT_API int companion_group_merge(companion_group_h dest_group,
-       companion_group_h src_group)
+EXPORT_API int companion_group_merge(companion_h hadnle,
+       companion_group_h dest_group, companion_group_h src_group)
 {
+       NOTUSED(dest_group);
+       NOTUSED(src_group);
        return 0;
 }
 
-EXPORT_API int companion_group_delete(companion_group_h group)
+EXPORT_API int companion_group_delete(companion_h handle, companion_group_h group)
 {
+       NOTUSED(handle);
+       NOTUSED(group);
        return 0;
 }
 
-EXPORT_API int companion_group_get_member_devices(companion_group_h group,
-       companion_device_h **devices, int *count)
+EXPORT_API int companion_group_get_member_devices(companion_h handle,
+       companion_group_h group, companion_device_h **devices, int *count)
 {
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(devices);
+       NOTUSED(count);
+
        return 0;
 }
 
-EXPORT_API int companion_device_invite(companion_group_h group,
-       companion_device_h device, char *PIN, companion_device_invite_result_cb result_cb,
-       void *user_data)
+EXPORT_API int companion_device_invite(companion_h handle,
+       companion_group_h group, companion_device_h device, char *PIN,
+       companion_device_invite_result_cb result_cb, void *user_data)
 {
        int ret = 0;
        GError *error = NULL;
-       companion_device_t *dev = (companion_device_t *)device;
+
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        companion_group_t *grp = (companion_group_t *)group;
+       if (!grp) {
+               _ERR("grp is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
+       companion_device_t *dev = (companion_device_t *)device;
+       if (!dev) {
+               _ERR("dev is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
-       device_invite_result_cb.result_cb = result_cb;
-       device_invite_result_cb.user_data = user_data;
+       _handle->device_invite_result_cb.result_cb = result_cb;
+       _handle->device_invite_result_cb.user_data = user_data;
 
        /* Now, for the sake of convenience, we change 'companion_device_invite' to
           'group_call_invite_sync'. */
 #if 0
        group_call_device_invite_sync(group_proxy, dev->device_id, PIN, &ret, NULL, &error);
 #else
-       group_call_invite_sync(group_proxy, grp->group_name, dev->device_id, PIN, &ret,
+       group_call_invite_sync(_handle->group_proxy, grp->group_name, dev->device_id, PIN, &ret,
                NULL, &error);
 #endif
 
        return ret;
 }
 
-EXPORT_API int companion_device_eject(companion_group_h group,
-       companion_device_h device, companion_device_eject_result_cb result_cb, void *user_data)
+EXPORT_API int companion_device_eject(companion_h handle,
+       companion_group_h group, companion_device_h device,
+       companion_device_eject_result_cb result_cb, void *user_data)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
+
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        companion_device_t *dev = (companion_device_t *)device;
+       if (!dev) {
+               _ERR("dev is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
-       device_eject_result_cb.result_cb = result_cb;
-       device_eject_result_cb.user_data = user_data;
+       _handle->device_eject_result_cb.result_cb = result_cb;
+       _handle->device_eject_result_cb.user_data = user_data;
 
        /* Now, for the sake of convenience, we change 'companion_device_eject' to
          'group_call_eject_sync'. */
 #if 0
        group_call_device_eject_sync(group_proxy, dev->device_id, &ret, NULL, &error);
 #else
-       group_call_eject_sync(group_proxy, dev->device_id, &ret, NULL, &error);
+       group_call_eject_sync(_handle->group_proxy, dev->device_id, &ret, NULL, &error);
 #endif
 
        return ret;
@@ -1072,71 +1448,110 @@ EXPORT_API int companion_device_information_get_device_type(
        return 0;
 }
 
-EXPORT_API int companion_request_create_group(companion_device_h device,
-       char *group_name)
+EXPORT_API int companion_request_create_group(companion_h handle,
+       companion_device_h device, char *group_name)
 {
-       int ret;
+       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
+       comp_manager_s *_handle = handle;
        companion_device_t *dev = (companion_device_t *)device;
 
        _DBG("Device id : %s", dev->device_id);
 
-       group_call_request_create_group_sync(group_proxy, dev->device_id,
+       group_call_request_create_group_sync(_handle->group_proxy, dev->device_id,
                group_name, &ret, NULL, &error);
 
        return ret;
 }
 
-EXPORT_API int companion_request_invite(companion_group_h group,
-       companion_device_h device, char *PIN)
+EXPORT_API int companion_request_invite(companion_h handle,
+       companion_group_h group, companion_device_h device, char *PIN)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
+
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        companion_group_t *grp = (companion_group_t *)group;
+       if (!grp) {
+               _ERR("grp is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        companion_device_t *dev = (companion_device_t *)device;
+       if (!dev) {
+               _ERR("dev is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        _DBG("%s", grp->device_id);
        _DBG("%s", grp->group_name);
        _DBG("%s", dev->device_id);
 
-       group_call_request_invite(group_proxy, grp->device_id, grp->group_name,
+       group_call_request_invite(_handle->group_proxy, grp->device_id, grp->group_name,
                dev->device_id, PIN,
                NULL, NULL, NULL);
 
        return ret;
 }
 
-EXPORT_API int companion_request_eject(companion_group_h group,
-       companion_device_h device)
+EXPORT_API int companion_request_eject(companion_h handle,
+       companion_group_h group, companion_device_h device)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
+
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        companion_group_t *grp = (companion_group_t *)group;
+       if (!grp) {
+               _ERR("grp is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
+
        companion_device_t *dev = (companion_device_t *)device;
+       if (!dev) {
+               _ERR("dev is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
        _DBG("%s", grp->device_id);
        _DBG("%s", grp->group_name);
        _DBG("%s", dev->device_id);
 
-       group_call_request_eject(group_proxy, grp->device_id, grp->group_name, dev->device_id,
-               NULL, NULL, NULL);
+       group_call_request_eject(_handle->group_proxy, grp->device_id, grp->group_name,
+               dev->device_id, NULL, NULL, NULL);
 
        return ret;
 }
 
-EXPORT_API int companion_request_delete_group(companion_group_h group)
+EXPORT_API int companion_request_delete_group(companion_h handle,
+       companion_group_h group)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
+       NOTUSED(handle);
+       NOTUSED(group);
        return ret;
 }
 
-EXPORT_API int companion_request_result_callback(
+EXPORT_API int companion_request_result_callback(companion_h handle,
        companion_request_result_cb result_cb, void *user_data)
 {
-       int ret = 0;
+       int ret = COMP_ERROR_NONE;
+       comp_manager_s *_handle = handle;
+       if (!handle) {
+               _ERR("handle is null");
+               return COMP_ERROR_INVALID_PARAMETER;
+       }
 
-       request_result_cb.result_cb = result_cb;
-       request_result_cb.user_data = user_data;
+       _handle->request_result_cb.result_cb = result_cb;
+       _handle->request_result_cb.user_data = user_data;
 
        return ret;
 }
index 0a8b3e5..2bab208 100644 (file)
@@ -34,6 +34,8 @@ using ::testing::TestInfo;
 using ::testing::TestPartResult;
 using ::testing::UnitTest;
 
+companion_h handle = NULL;
+
 TEST(companion, companion_initialize_p) {
 
 }
@@ -55,8 +57,8 @@ TEST(companion, companion_group_create_p) {
 
        int ret;
 
-       companion_initialize();
-       ret = companion_group_create((char *)"group1");
+       companion_initialize(&handle);
+       ret = companion_group_create(handle, (char *)"group1");
 
        cout << "TEST END :" <<  ret << endl;
 }
@@ -81,7 +83,7 @@ void _companion_finish_cb(int result, void *user_data)
        companion_group_h *groups;
        int count;
 
-       companion_group_get_found_groups(&groups, &count);
+       companion_group_get_found_groups(handle, &groups, &count);
        cout << "Found groups device count : " << count << endl;
 
        for (int i = 0; i < count; i++) {
@@ -95,9 +97,9 @@ void _companion_finish_cb(int result, void *user_data)
 
 TEST(companion, companion_group_find_p) {
        cout << "TEST START" << endl;
-       companion_initialize();
+       companion_initialize(&handle);
        main_loop = g_main_loop_new(NULL, FALSE);
-       companion_group_find(5, _companion_group_found_cb, _companion_finish_cb, main_loop);
+       companion_group_find(handle, 5, _companion_group_found_cb, _companion_finish_cb, main_loop);
        g_main_loop_run(main_loop);
        cout << "TEST END" << endl;
 }