Change prefix from 'companion' to 'mdg'
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 23 Apr 2018 11:48:34 +0000 (20:48 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:50 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
109 files changed:
CMakeLists.txt
capi/CMakeLists.txt
capi/capi-network-companion.pc.in [deleted file]
capi/capi-network-mdg.pc.in [new file with mode: 0644]
capi/demo/CMakeLists.txt [deleted file]
capi/demo/common.h [deleted file]
capi/demo/comp-manager.c [deleted file]
capi/demo/companion_demo.c [deleted file]
capi/demo/main.c [deleted file]
capi/demo/menu.c [deleted file]
capi/demo/menu.h [deleted file]
capi/doc/companion_doc.h [deleted file]
capi/doc/mdg_doc.h [new file with mode: 0644]
capi/include/companion.h [deleted file]
capi/include/companion_internal.h [deleted file]
capi/include/mdg.h [new file with mode: 0644]
capi/include/mdg_internal.h [new file with mode: 0644]
capi/src/companion.c [deleted file]
capi/src/companion_dbus.c [deleted file]
capi/src/companion_dbus.h [deleted file]
capi/src/companion_debug.h [deleted file]
capi/src/companion_gdbus.xml [deleted file]
capi/src/companion_private.h [deleted file]
capi/src/companion_util.c [deleted file]
capi/src/companion_util.h [deleted file]
capi/src/gen.sh
capi/src/mdg.c [new file with mode: 0644]
capi/src/mdg_dbus.c [new file with mode: 0644]
capi/src/mdg_dbus.h [new file with mode: 0644]
capi/src/mdg_debug.h [new file with mode: 0644]
capi/src/mdg_gdbus.xml [new file with mode: 0644]
capi/src/mdg_private.h [new file with mode: 0644]
capi/src/mdg_util.c [new file with mode: 0644]
capi/src/mdg_util.h [new file with mode: 0644]
capi/test/CMakeLists.txt [new file with mode: 0644]
capi/test/common.h [new file with mode: 0644]
capi/test/main.c [new file with mode: 0644]
capi/test/mdg-manager.c [new file with mode: 0644]
capi/test/mdg-test.c [new file with mode: 0644]
capi/test/menu.c [new file with mode: 0644]
capi/test/menu.h [new file with mode: 0644]
capi/unittest/CMakeLists.txt
capi/unittest/companion_unit_test.cpp [deleted file]
capi/unittest/mdg_unit_test.cpp [new file with mode: 0644]
packaging/capi-network-companion.manifest [deleted file]
packaging/capi-network-mdg.manifest [new file with mode: 0644]
packaging/compmanager.service [deleted file]
packaging/d2d-manager.spec [changed mode: 0755->0644]
packaging/mdgd.service [new file with mode: 0644]
packaging/net.compmanager.service [deleted file]
packaging/net.mdgd.service [new file with mode: 0644]
src/companion-manager/CMakeLists.txt [deleted file]
src/companion-manager/include/comp_context.h [deleted file]
src/companion-manager/include/comp_db.h [deleted file]
src/companion-manager/include/comp_enum.h [deleted file]
src/companion-manager/include/comp_gdbus.h [deleted file]
src/companion-manager/include/comp_gdbus_group.h [deleted file]
src/companion-manager/include/comp_group.h [deleted file]
src/companion-manager/include/comp_iot.h [deleted file]
src/companion-manager/include/comp_log.h [deleted file]
src/companion-manager/include/comp_manager.h [deleted file]
src/companion-manager/include/comp_mot_agent.h [deleted file]
src/companion-manager/include/comp_resource.h [deleted file]
src/companion-manager/include/comp_util.h [deleted file]
src/companion-manager/oic_svr_db_comp_manager.dat [deleted file]
src/companion-manager/oic_svr_db_comp_manager.json [deleted file]
src/companion-manager/src/comp_context.c [deleted file]
src/companion-manager/src/comp_db.c [deleted file]
src/companion-manager/src/comp_gdbus.c [deleted file]
src/companion-manager/src/comp_gdbus_group.c [deleted file]
src/companion-manager/src/comp_group.c [deleted file]
src/companion-manager/src/comp_iot.cpp [deleted file]
src/companion-manager/src/comp_log.c [deleted file]
src/companion-manager/src/comp_manager.c [deleted file]
src/companion-manager/src/comp_mot_agent.c [deleted file]
src/companion-manager/src/comp_resource.c [deleted file]
src/companion-manager/src/comp_util.c [deleted file]
src/companion-manager/src/companion_gdbus.xml [deleted file]
src/companion-manager/src/gen.sh [deleted file]
src/include/d2d-log.h [deleted file]
src/mdg-manager/CMakeLists.txt [new file with mode: 0644]
src/mdg-manager/include/mdgd_context.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_db.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_enum.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_gdbus.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_gdbus_group.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_group.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_iot.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_log.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_manager.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_mot_agent.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_resource.h [new file with mode: 0644]
src/mdg-manager/include/mdgd_util.h [new file with mode: 0644]
src/mdg-manager/oic_svr_db_mdg_manager.dat [new file with mode: 0644]
src/mdg-manager/oic_svr_db_mdg_manager.json [new file with mode: 0644]
src/mdg-manager/src/gen.sh [new file with mode: 0755]
src/mdg-manager/src/mdg_gdbus.xml [new file with mode: 0644]
src/mdg-manager/src/mdgd_context.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_db.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_gdbus.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_gdbus_group.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_group.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_iot.cpp [new file with mode: 0644]
src/mdg-manager/src/mdgd_log.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_manager.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_mot_agent.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_resource.c [new file with mode: 0644]
src/mdg-manager/src/mdgd_util.c [new file with mode: 0644]
src/mot-agent/CMakeLists.txt

index 639ea9555969182a8f8f5708f45d623d056a84dc..1f091014d2d157474d5e57c595e4477b6bbd7328 100644 (file)
@@ -42,5 +42,5 @@ ADD_DEFINITIONS("-DTCP_ADAPTER")
 
 MESSAGE(" - Start building src directories")
 ADD_SUBDIRECTORY(src/mot-agent)
-ADD_SUBDIRECTORY(src/companion-manager)
+ADD_SUBDIRECTORY(src/mdg-manager)
 ADD_SUBDIRECTORY(capi)
index 683a370fab11b38d483d69200248f7721b73ba79..3bc8e603b0cf0e786d3dd68ae1e956fb442f6ee8 100644 (file)
@@ -1,44 +1,43 @@
-SET(CAPI_FN "capi-network-companion")
+SET(CAPI_MDG "capi-network-mdg")
 
 FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
 EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
                 " \\
-                --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/src/companion_gdbus \\
-                --interface-prefix org.tizen.companion. \\
-                ${CMAKE_CURRENT_SOURCE_DIR}/src/companion_gdbus.xml \\
+                --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/src/mdg_gdbus \\
+                --interface-prefix org.tizen.mdg. \\
+                ${CMAKE_CURRENT_SOURCE_DIR}/src/mdg_gdbus.xml \\
                 ")
 
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
 
-SET(SOURCES src/companion.c
-            src/companion_gdbus.c
-            src/companion_util.c
-            src/companion_dbus.c)
+SET(SOURCES src/mdg.c
+            src/mdg_gdbus.c
+            src/mdg_util.c
+            src/mdg_dbus.c)
 
-ADD_LIBRARY(${CAPI_FN} SHARED ${SOURCES})
+ADD_LIBRARY(${CAPI_MDG} SHARED ${SOURCES})
 
-TARGET_LINK_LIBRARIES(${CAPI_FN} ${daemon_pkgs_LDFLAGS} pthread)
+TARGET_LINK_LIBRARIES(${CAPI_MDG} ${daemon_pkgs_LDFLAGS} pthread)
 
-INSTALL(TARGETS ${CAPI_FN} DESTINATION lib)
+INSTALL(TARGETS ${CAPI_MDG} DESTINATION lib)
 INSTALL(
         DIRECTORY include/ DESTINATION include
         FILES_MATCHING
         PATTERN "include/*.h"
         )
 
-SET(PC_NAME ${CAPI_FN})
 SET(PC_REQUIRED capi-base-common)
-SET(PC_LDFLAGS -l${CAPI_FN})
+SET(PC_LDFLAGS -l${CAPI_MDG})
 
 CONFIGURE_FILE(
-    ${CAPI_FN}.pc.in
-    ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_FN}.pc
+    ${CAPI_MDG}.pc.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_MDG}.pc
     @ONLY
 )
 
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_FN}.pc DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_MDG}.pc DESTINATION lib/pkgconfig)
 
-ADD_SUBDIRECTORY(demo)
+ADD_SUBDIRECTORY(test)
 ADD_SUBDIRECTORY(unittest)
diff --git a/capi/capi-network-companion.pc.in b/capi/capi-network-companion.pc.in
deleted file mode 100644 (file)
index c45e5b2..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=/usr
-libdir=@libdir@
-includedir=/usr/include/
-
-Name: @PC_NAME@
-Description: @PACKAGE_DESCRIPTION@
-Version: @VERSION@
-Requires: @PC_REQUIRED@
-Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir}
-
diff --git a/capi/capi-network-mdg.pc.in b/capi/capi-network-mdg.pc.in
new file mode 100644 (file)
index 0000000..c45e5b2
--- /dev/null
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@libdir@
+includedir=/usr/include/
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/capi/demo/CMakeLists.txt b/capi/demo/CMakeLists.txt
deleted file mode 100644 (file)
index c46601a..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-SET(COMP_DEMO "companion_demo")
-
-SET(COMP_DEMO_SOURCES
-       main.c
-       menu.c
-       comp-manager.c
-)
-
-ADD_EXECUTABLE(${COMP_DEMO} ${COMP_DEMO_SOURCES})
-
-TARGET_LINK_LIBRARIES(${COMP_DEMO}
-        ${daemon_pkgs_LIBRARIES} capi-network-companion)
-
-INSTALL(TARGETS ${COMP_DEMO} DESTINATION bin/)
diff --git a/capi/demo/common.h b/capi/demo/common.h
deleted file mode 100644 (file)
index dd29976..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMMON_H__
-#define __COMMON_H__
-
-#include <companion.h>
-
-__BEGIN_DECLS
-
-const char* comp_error_to_string(comp_error_e err);
-const char *comp_group_type_to_string(companion_group_type_e e);
-
-__END_DECLS
-
-#endif /** __COMMON_H__ */
diff --git a/capi/demo/comp-manager.c b/capi/demo/comp-manager.c
deleted file mode 100755 (executable)
index 64798a2..0000000
+++ /dev/null
@@ -1,1370 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "menu.h"
-#include "common.h"
-
-companion_h handle = NULL;
-
-GList *found_group_list;
-GList *found_device_list;
-GList *my_devices_list;
-
-static char groupid[MENU_DATA_SIZE + 1] = "mygroup";
-static char request_groupid[MENU_DATA_SIZE + 1] = "subgroup";
-static char timeout[MENU_DATA_SIZE + 1] = "2";
-static char group_idx[MENU_DATA_SIZE + 1] = "1";
-static char group_idx_a[MENU_DATA_SIZE + 1] = "1";
-static char group_idx_b[MENU_DATA_SIZE + 1] = "2";
-static char device_idx[MENU_DATA_SIZE + 1] = "1";
-static char pin[MENU_DATA_SIZE + 1] = "12341234";
-static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
-static char monitor[MENU_DATA_SIZE + 1] = "1";
-
-static int run_group_find(MManager *mm, struct menu_data *menu);
-static int run_devices_find(MManager *mm, struct menu_data *menu);
-
-static const char* __device_type_to_string(companion_device_type_e type)
-{
-       switch (type) {
-       /* CHECK: List all enum values here */
-       case COMPANION_DEVICE_TYPE_LOCAL:
-               return "Local";
-       case COMPANION_DEVICE_TYPE_REMOTE:
-               return "Remote";
-       default :
-               return "Unknown";
-       }
-}
-
-void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
-                                                       int len, int ret, void *user_data)
-{
-       msg("_request_result_cb is called command %s Requester id %s", cmd,
-                               device_id);
-
-       if (cmd == NULL) {
-               msgp("cmd is null [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return;
-       }
-
-       if (strcmp("COMP_REQ_CREATE_GROUP", cmd) == 0) {
-               msgp("[CMD] Request Create Group [%s(0x%X)]", comp_error_to_string(ret),
-                        ret);
-               if (ret == COMP_ERROR_NONE && arg != NULL) {
-                       msgb("Created Group name is %s", arg);
-                       run_group_find(NULL, NULL);
-                       run_devices_find(NULL, NULL);
-               }
-       } else if (strcmp("COMP_REQ_INVITE_DEVICE", cmd) == 0) {
-               msgp("[CMD] Request Invite [%s(0x%X)]", comp_error_to_string(ret), ret);
-               if (ret == COMP_ERROR_NONE && arg != NULL)
-                       msgb("Invited Device ID is %s", arg);
-       } else if (strcmp("COMP_REQ_EJECT_DEVICE", cmd) == 0) {
-               msgp("[CMD] Request Eject [%s(0x%X)]", comp_error_to_string(ret), ret);
-               if (ret == COMP_ERROR_NONE && arg != NULL)
-                       msgb("Ejected Device ID is %s", arg);
-       } else if (strcmp("COMP_REQ_DELETE_GROUP", cmd) == 0) {
-               msgp("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret),
-                        ret);
-               if (ret == COMP_ERROR_NONE && arg != NULL)
-                       msgb("Deleted Group name is %s", arg);
-       } else if (strcmp("COMP_REQ_SEND_DATA", cmd) == 0) {
-               msgp("Received data [%d] %s", strlen((char *)arg), arg);
-       } else {
-               msgp("[Recv][%d] %s", strlen((char *) arg), arg);
-       }
-}
-
-int run_get_my_id(MManager *mm, struct menu_data *menu)
-{
-       msg("Get Device ID of my device");
-
-       int ret;
-       char *uuid;
-       ret = companion_device_information_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);
-               return RET_FAILURE;
-       }
-
-       msg(" - companion_device_my_deviceid() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-       msgb("[ID] : [%s]", uuid);
-
-       return RET_SUCCESS;
-}
-
-void _device_eject_result_cb(int result, void *user_data)
-{
-       msgb("\rEject Device Complete [%s]", comp_error_to_string(result));
-}
-
-static int run_device_eject(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       companion_group_h group = NULL;
-       companion_device_h device = NULL;
-
-       msg("Eject Device");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       if (strlen(device_idx)) {
-               idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (NULL == found_device_list) {
-               msgr("Find device first");
-               return RET_FAILURE;
-       }
-
-       device = g_list_nth_data(found_device_list, idx - 1);
-       if (NULL == device) {
-               msgr("Failed to g_hash_table_find");
-               return RET_FAILURE;
-       }
-
-       ret = companion_group_eject_device(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;
-       }
-       msg(" - companion_group_eject_device() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-void _device_invite_result_cb(int result, void *user_data)
-{
-       msgb("\rInvite Device Finished [%s]", comp_error_to_string(result));
-}
-
-static int run_device_invite(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       companion_group_h group = NULL;
-       companion_device_h device = NULL;
-
-       msg("Invite Device");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       if (strlen(device_idx)) {
-               idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (NULL == found_device_list) {
-               msgr("Find device first");
-               return RET_FAILURE;
-       }
-
-       device = g_list_nth_data(found_device_list, idx - 1);
-       if (NULL == device) {
-               msgr("Failed to g_hash_table_find");
-               return RET_FAILURE;
-       }
-
-       ret = companion_group_invite_device(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;
-       }
-       msg(" - companion_group_invite_device() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static void _destroy_comp_device_info(gpointer data)
-{
-       companion_device_information_destroy((companion_device_h)data);
-}
-
-static int run_devices_show(MManager *mm, struct menu_data *menu)
-{
-       char *deviceid = NULL;
-       char *ip = NULL;
-       companion_device_type_e devicetype;
-       companion_device_h device;
-       int ret;
-       int count;
-       companion_device_h *devices = NULL;
-       int i;
-       GList *iter = NULL;
-
-       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;
-       } else {
-               if (found_device_list) {
-                       g_list_free_full(found_device_list, _destroy_comp_device_info);
-                       found_device_list = NULL;
-               }
-
-               for (i = 0; i < count; i++)
-                       found_device_list = g_list_append(found_device_list, devices[i]);
-       }
-
-       /* Get a first item */
-       i = 0;
-       iter = g_list_first(found_device_list);
-       while (NULL != iter) {
-               device = iter->data;
-               if (!device) {
-                       msgr("device list is null");
-                       break;
-               }
-               companion_device_information_get_device_id(device, &deviceid);
-               companion_device_information_get_ip(device, &ip);
-               companion_device_information_get_device_type(device, &devicetype);
-               msgp("[%d] deviceid: %s, IP: %s type: %s", i+1, deviceid, ip,
-                        __device_type_to_string(devicetype));
-
-               if (deviceid) {
-                       free(deviceid);
-                       deviceid = NULL;
-               }
-               if (ip) {
-                       free(ip);
-                       ip  = NULL;
-               }
-               /* Next item */
-               iter = g_list_next(iter);
-               i++;
-       }
-
-       return RET_SUCCESS;
-}
-
-#if 0
-static int run_group_get_members(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       int count;
-       companion_group_h group = NULL;
-       companion_device_h **devices = NULL;
-
-       msg("Get Group Members");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_group_get_member_devices(group, devices, &count);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-       msg(" - companion_group_get_member_devices() ret: [0x%X] [%s]", ret,
-               comp_error_to_string(ret));
-
-       for (int i = 0; i < count; i++) {
-
-               char *device_id = NULL;
-               char *ip = NULL;
-               companion_device_type_e device_type;
-
-               companion_device_information_get_device_id(devices[i], &device_id);
-               companion_device_information_get_ip(devices[i], &ip);
-               companion_device_information_get_device_type(devices[i], &device_type);
-
-               msgp("device_id : %s, name : %s, type : %s", device_id, ip,
-                       __device_type_to_string(device_type));
-
-               if (device_id)
-                       free(device_id);
-               if (ip)
-                       free(ip);
-       }
-
-       return RET_SUCCESS;
-}
-#endif
-
-static int run_group_merge(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int a, b;
-       companion_group_h group_a;
-       companion_group_h group_b;
-
-       msg("Merge Group");
-
-       if (strlen(group_idx_a)) {
-               a = (unsigned short)strtol(group_idx_a, NULL, 10);
-               if (0 >= a) {
-                       msgp("Invalid index. set to 1");
-                       a = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group_a = g_list_nth_data(found_group_list, a - 1);
-               if (NULL == group_a) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       if (strlen(group_idx_b)) {
-               b = (unsigned short)strtol(group_idx_b, NULL, 10);
-               if (0 >= b) {
-                       msgp("Invalid index. set to 2");
-                       b = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group_b = g_list_nth_data(found_group_list, b - 1);
-               if (NULL == group_b) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-
-       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;
-       }
-       msg(" - companion_group_merge() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_group_delete(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       companion_group_h group;
-
-       msg("Delete Group");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       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;
-       }
-       msg(" - companion_group_delete() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-int run_device_show_found(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int count;
-       companion_device_h *devices = NULL;
-
-       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;
-       }
-       msg(" - companion_device_get_found_devices() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       for (int i = 0; i < count; i++) {
-               char *device_id = NULL;
-               char *ip = NULL;
-               companion_device_type_e device_type;
-
-               companion_device_information_get_device_id(devices[i], &device_id);
-               companion_device_information_get_ip(devices[i], &ip);
-               companion_device_information_get_device_type(devices[i], &device_type);
-
-               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
-                       __device_type_to_string(device_type));
-
-               if (device_id)
-                       free(device_id);
-               if (ip)
-                       free(ip);
-       }
-
-       return RET_SUCCESS;
-}
-
-void _device_finish_cb(int result, void *user_data)
-{
-       msgb("\rFind Device Finished ret: [0x%X] [%s]", result, comp_error_to_string(result));
-}
-
-bool _device_found_cb(companion_device_h device, void *user_data)
-{
-       char *ip = NULL;
-       char *device_id = NULL;
-       char *model_name = NULL;
-       companion_device_type_e device_type;
-       GList *iter = NULL;
-       gboolean is_exist = FALSE;
-
-       companion_device_information_get_device_id(device, &device_id);
-       companion_device_information_get_ip(device, &ip);
-       companion_device_information_get_device_type(device, &device_type);
-       companion_device_information_get_model_name(device, &model_name);
-
-       iter = found_device_list;
-       while (iter != NULL) {
-               companion_device_h temp = (companion_device_h)iter->data;
-               char *temp_device_id;
-
-               companion_device_information_get_device_id(temp, &temp_device_id);
-
-               if (g_strcmp0(device_id, temp_device_id) == 0) {
-                       is_exist = TRUE;
-                       free(temp_device_id);
-                       companion_device_information_destroy(device);
-                       break;
-               }
-
-               free(temp_device_id);
-               iter = g_list_next(iter);
-       }
-
-       if (is_exist == FALSE) {
-               found_device_list = g_list_append(found_device_list, device);
-               msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, ip,
-                       __device_type_to_string(device_type), model_name);
-       }
-
-       if (device_id)
-               free(device_id);
-       if (ip)
-               free(ip);
-
-       return TRUE;
-}
-
-static int run_devices_find(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int duration;
-       msg("Find Devices");
-
-       if (strlen(timeout))
-               duration = (unsigned short)strtol(timeout, NULL, 10);
-
-       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;
-       }
-       msg(" - companion_device_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       if (found_device_list) {
-               g_list_free_full(found_device_list, _destroy_comp_device_info);
-               found_device_list = NULL;
-       }
-
-       return RET_SUCCESS;
-}
-
-int run_device_show_my_device(MManager *mm, struct menu_data *menu)
-{
-       int ret = 0;
-       companion_device_h device = NULL;
-
-       msg("Get My Device");
-
-       ret = companion_device_information_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;
-       }
-       msg(" - companion_device_information_get_my_device() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       if (ret == 0) {
-               char *device_id = NULL;
-               char *ip = NULL;
-               companion_device_type_e device_type;
-
-               companion_device_information_get_device_id(device, &device_id);
-               companion_device_information_get_ip(device, &ip);
-               companion_device_information_get_device_type(device, &device_type);
-
-               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
-                       __device_type_to_string(device_type));
-
-               if (device_id)
-                       free(device_id);
-               if (ip)
-                       free(ip);
-
-               companion_device_information_destroy(device);
-               device = NULL;
-       }
-
-       return RET_SUCCESS;
-}
-
-static int run_group_leave(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       companion_group_h group;
-
-       msg("Leave Group");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_leave_group (handle, group, receive_request_result, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Leave Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-       msg(" - companion_request_leave_group () ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_group_show(MManager *mm, struct menu_data *menu)
-{
-       char *rt;
-       char *uri;
-       companion_group_type_e type;
-       companion_group_h group;
-
-       int i;
-       GList *iter = NULL;
-
-       /* Get a first item */
-       i = 0;
-       iter = g_list_first(found_group_list);
-       while (NULL != iter) {
-               group = iter->data;
-               if (!group) {
-                       msgr("groups is null");
-                       break;
-               }
-               companion_group_information_get_type(group, &type);
-               companion_group_information_get_uri_path(group, &uri);
-               companion_group_information_get_resource_type(group, &rt);
-               msgp("[%d] type: %s, URI: %s RT: %s", i+1, comp_group_type_to_string(type), uri, rt);
-               if (uri) {
-                       free(uri);
-                       uri = NULL;
-               }
-               if (rt) {
-                       free(rt);
-                       rt = NULL;
-               }
-               /* Next item */
-               iter = g_list_next(iter);
-               i++;
-       }
-
-       return RET_SUCCESS;
-}
-
-static int run_group_join(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int idx;
-       companion_group_h group;
-
-       msg("Join Group");
-
-       if (strlen(group_idx)) {
-               idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_join_group(handle, group, receive_request_result, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Join Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-       msg(" - companion_request_join_group() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static void _destroy_comp_group_info(gpointer data)
-{
-       companion_group_information_destroy((companion_group_h)data);
-}
-
-static int run_group_show_found(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int count;
-       companion_group_h *groups;
-
-       msg("Show Found Group(s)");
-
-       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;
-       }
-       msg(" - companion_group_get_found_groups() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       if (found_group_list) {
-               g_list_free_full(found_group_list, _destroy_comp_group_info);
-               found_group_list = NULL;
-       }
-
-       for (int i = 0; i < count; i++) {
-               companion_group_type_e type;
-               char *uri_path;
-               char *group_name;
-
-               companion_group_information_get_type(groups[i], &type);
-               companion_group_information_get_uri_path(groups[i], &uri_path);
-               companion_group_information_get_name(groups[i], &group_name);
-
-               if (type == COMPANION_GROUP_TYPE_MINE)
-                       msgb("%d. type : MINE, name : %s, uri : %s", i+1, group_name, uri_path);
-               else
-                       msgb("%d. type : REMOTE, name : %s, uri : %s", i+1, group_name, uri_path);
-
-               found_group_list = g_list_append(found_group_list, groups[i]);
-
-               g_free(uri_path);
-               g_free(group_name);
-       }
-
-       return RET_SUCCESS;
-}
-
-bool _group_found_cb(companion_group_type_e type, companion_group_h group, void *user_data)
-{
-       char *group_name;
-
-       companion_group_information_get_name(group, &group_name);
-
-       if (type == COMPANION_GROUP_TYPE_MINE)
-               msgp("\rfound group type : MINE, name : %s", group_name);
-       else
-               msgp("\rfound group type : REMOTE, name : %s", group_name);
-
-       found_group_list = g_list_append(found_group_list, group);
-
-       return TRUE;
-}
-
-void _group_finish_cb(int result, void *user_data)
-{
-       msgb("\rFind Group Finished ret: [0x%X] [%s]", result, comp_error_to_string(result));
-}
-
-static int run_group_find(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int duration;
-       msg("Find Group");
-
-       if (strlen(timeout))
-               duration = (unsigned short)strtol(timeout, NULL, 10);
-
-       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;
-       }
-       msg(" - companion_group_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       if (found_group_list) {
-               g_list_free_full(found_group_list, _destroy_comp_group_info);
-               found_group_list = NULL;
-       }
-
-       return RET_SUCCESS;
-}
-
-static int run_group_create(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       msg("Create Group");
-
-       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;
-       }
-       msg(" - companion_group_create() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-       msgb("Create Group Successfully");
-
-       return RET_SUCCESS;
-}
-
-void _send_data_finish_cb(int result, char *resp_data, void *user_data)
-{
-       msgb("\rFind Send Data Finished = %d", result);
-       if (resp_data != NULL && strlen(resp_data) > 0)
-               msgp("Response from %s", resp_data);
-}
-
-static int __send_data(int idx)
-{
-       int ret = 0;
-       char *deviceid = NULL;
-       char *address = NULL;
-       companion_device_h device = NULL;
-
-       if (found_device_list) {
-               device = g_list_nth_data(found_device_list, idx - 1);
-               if (NULL == device) {
-                       msgr("Find my device first");
-                       return RET_FAILURE;
-               }
-       }
-
-       companion_device_information_get_device_id(device, &deviceid);
-       companion_device_information_get_ip(device, &address);
-       msgp("Sent to [ID] %s [IP] %s", deviceid, address);
-       if (deviceid) {
-               free(deviceid);
-               deviceid = NULL;
-       }
-       if (address) {
-               free(address);
-               address = NULL;
-       }
-
-       ret = companion_device_send_data(handle, device, (unsigned char *) message,
-                                                strlen(message), _send_data_finish_cb, NULL);
-       if (COMP_ERROR_NONE != ret)
-               msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
-
-       return ret;
-}
-
-static int run_send_data(MManager *mm, struct menu_data *menu)
-{
-       int idx = 0;
-       int count = g_list_length(found_device_list);
-
-       if (0 >= count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       if (strlen(device_idx)) {
-               idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= idx) {
-                       msgp("Invalid index. set to 1");
-                       idx = 1;
-               }
-       }
-       return __send_data(idx);
-}
-
-static int run_send_data_all(MManager *mm, struct menu_data *menu)
-{
-       int count = 0;
-
-       count = g_list_length(found_device_list);
-
-       if (0 >= count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       for (int i = 1; i <= count; i++)
-               __send_data(i);
-
-       return RET_SUCCESS;
-}
-
-void _mowned_device_finish_cb(int result, void *user_data)
-{
-       msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
-               comp_error_to_string(result));
-}
-
-bool _mowned_device_found_cb(companion_device_h device, void *user_data)
-{
-       char *ip = NULL;
-       char *device_id = NULL;
-       companion_device_type_e device_type;
-
-       companion_device_information_get_device_id(device, &device_id);
-       companion_device_information_get_ip(device, &ip);
-       companion_device_information_get_device_type(device, &device_type);
-
-       msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
-               __device_type_to_string(device_type));
-
-       if (device_id)
-               free(device_id);
-       if (ip)
-               free(ip);
-
-       my_devices_list = g_list_append(my_devices_list, device);
-
-       return TRUE;
-}
-
-static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int duration;
-       msg("Find My Owned Devices");
-
-       if (strlen(timeout))
-               duration = (unsigned short)strtol(timeout, NULL, 10);
-
-       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;
-       }
-       msg(" - companion_device_find_mowned_device() ret: [0x%X] [%s]",
-               ret, comp_error_to_string(ret));
-
-       if (my_devices_list) {
-               g_list_free_full(my_devices_list, _destroy_comp_device_info);
-               my_devices_list = NULL;
-       }
-
-       return RET_SUCCESS;
-}
-
-int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int count;
-       companion_device_h *devices = NULL;
-
-       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;
-       }
-       msg(" - companion_device_get_found_mowned_devices() ret: [0x%X] [%s]", ret,
-               comp_error_to_string(ret));
-
-       for (int i = 0; i < count; i++) {
-               char *device_id = NULL;
-               char *ip = NULL;
-               companion_device_type_e device_type;
-
-               companion_device_information_get_device_id(devices[i], &device_id);
-               companion_device_information_get_ip(devices[i], &ip);
-               companion_device_information_get_device_type(devices[i], &device_type);
-
-               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
-                       __device_type_to_string(device_type));
-
-               if (device_id)
-                       free(device_id);
-               if (ip)
-                       free(ip);
-       }
-
-       return RET_SUCCESS;
-}
-
-static int run_request_create_group(MManager *mm, struct menu_data *menu)
-{
-       int ret = 0;
-       int dev_count = 0;
-       companion_device_h device = NULL;
-
-       msg("Request create group");
-
-       dev_count = g_list_length(found_device_list);
-
-       if (0 >= dev_count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       int dev_idx;
-       if (device_idx != NULL && strlen(device_idx)) {
-               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= dev_idx) {
-                       msgp("Invalid index. set to 1");
-                       dev_idx = 1;
-               }
-       }
-
-       if (found_device_list) {
-               device = g_list_nth_data(found_device_list, dev_idx - 1);
-               if (NULL == device) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_create_group(handle, device, request_groupid,
-               receive_request_result, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Request Create Group: [%s(0x%X)]",
-                       comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-
-       msg(" - companion_request_create_group() ret: [0x%X] [%s]",
-               ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_request_invite(MManager *mm, struct menu_data *menu)
-{
-       int ret = 0;
-       int grp_count = 0;
-       int dev_count = 0;
-       companion_device_h device = NULL;
-       companion_group_h group = NULL;
-
-       dev_count = g_list_length(found_device_list);
-       grp_count = g_list_length(found_group_list);
-
-       if (0 >= dev_count || 0 >= grp_count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       int grp_idx;
-       if (group_idx != NULL && strlen(group_idx)) {
-               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= grp_idx) {
-                       msgp("Invalid index. set to 1");
-                       grp_idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, grp_idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       int dev_idx;
-       if (device_idx != NULL && strlen(device_idx)) {
-               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= dev_idx) {
-                       msgp("Invalid index. set to 1");
-                       dev_idx = 1;
-               }
-       }
-
-       if (found_device_list) {
-               device = g_list_nth_data(found_device_list, dev_idx - 1);
-               if (NULL == device) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_invite_device(handle, group, device, pin,
-               receive_request_result, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Request Invite: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-
-       msg(" - companion_request_invite_device() ret: [0x%X] [%s]",
-               ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_request_eject(MManager *mm, struct menu_data *menu)
-{
-       int ret = 0;
-       int grp_count = 0;
-       int dev_count = 0;
-       companion_device_h device = NULL;
-       companion_group_h group = NULL;
-
-       dev_count = g_list_length(found_device_list);
-       grp_count = g_list_length(found_group_list);
-
-       if (0 >= dev_count || 0 >= grp_count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       int grp_idx;
-       if (group_idx != NULL && strlen(group_idx)) {
-               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= grp_idx) {
-                       msgp("Invalid index. set to 1");
-                       grp_idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, grp_idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       int dev_idx;
-       if (device_idx != NULL && strlen(device_idx)) {
-               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
-               if (0 >= dev_idx) {
-                       msgp("Invalid index. set to 1");
-                       dev_idx = 1;
-               }
-       }
-
-       if (found_device_list) {
-               device = g_list_nth_data(found_device_list, dev_idx - 1);
-               if (NULL == device) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_eject_device(handle, group, device, receive_request_result,
-               NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Request Eject: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-
-       msg(" - companion_request_eject_device() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_request_delete_group(MManager *mm, struct menu_data *menu)
-{
-       int ret = 0;
-       int grp_count = 0;
-       companion_group_h group = NULL;
-
-       grp_count = g_list_length(found_group_list);
-
-       if (0 >= grp_count) {
-               msgr("No Device");
-               return RET_SUCCESS;
-       }
-
-       int grp_idx;
-       if (group_idx != NULL && strlen(group_idx)) {
-               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
-               if (0 >= grp_idx) {
-                       msgp("Invalid index. set to 1");
-                       grp_idx = 1;
-               }
-       }
-
-       if (found_group_list) {
-               group = g_list_nth_data(found_group_list, grp_idx - 1);
-               if (NULL == group) {
-                       msgr("Failed to g_hash_table_find");
-                       return RET_FAILURE;
-               }
-       }
-
-       ret = companion_request_delete_group(handle, group, receive_request_result, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Request Delete Group: [%s(0x%X)]",
-                       comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-
-       msg(" - companion_request_delete_group() ret: [0x%X] [%s]",
-               ret, comp_error_to_string(ret));
-
-       return RET_SUCCESS;
-}
-
-static void device_monitor_result(char *uuid, char *group_name,
-                                                 companion_device_status_e status, void *user_data)
-{
-       msgp("device monitor result uuid %s group_name %s status %s", uuid,
-                group_name, status == COMPANION_DEVICE_ADDED ? "ADDED" : "REMOVED");
-}
-
-static int run_start_device_monitor(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-
-       if (g_strcmp0(monitor, "1") == 0) {
-               msg(" - Start device monitor");
-               ret = companion_device_monitor_start(handle, device_monitor_result,
-                                                                                        NULL);
-               if (COMP_ERROR_NONE != ret) {
-                       msgr("Failed to Start Monitor: [%s(0x%X)]",
-                                comp_error_to_string(ret), ret);
-                       return RET_FAILURE;
-               }
-       } else {
-               msg(" - Stop device monitor");
-               ret = companion_device_monitor_stop(handle);
-               if (COMP_ERROR_NONE != ret) {
-                       msgr("Failed to Stop Monitor: [%s(0x%X)]",
-                                comp_error_to_string(ret), ret);
-                       return RET_FAILURE;
-               }
-       }
-       return RET_SUCCESS;
-}
-
-
-static struct menu_data menu_group_create[] = {
-       { "0", "Group Name", NULL, NULL, groupid },
-       { "1", "Run", NULL, run_group_create, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_find[] = {
-       { "0", "Timeout", NULL, NULL, timeout },
-       { "1", "Run", NULL, run_group_find, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_join[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Index", NULL, NULL, group_idx },
-       { "2", "Run", NULL, run_group_join, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_leave[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Index", NULL, NULL, group_idx },
-       { "2", "Run", NULL, run_group_leave, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_delete[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Index", NULL, NULL, group_idx },
-       { "2", "Run", NULL, run_group_delete, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_merge[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "A Index", NULL, NULL, group_idx_a },
-       { "2", "B Index", NULL, NULL, group_idx_b },
-       { "3", "Run", NULL, run_group_merge, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_devices_find[] = {
-       { "0", "Timeout", NULL, NULL, timeout },
-       { "1", "Run", NULL, run_devices_find, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_invite_device[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
-       { "2", "Group Index", NULL, NULL, group_idx },
-       { "3", "Device Index", NULL, NULL, device_idx },
-       { "4", "PIN", NULL, NULL, pin },
-       { "5", "Run", NULL, run_device_invite, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_group_eject_device[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
-       { "2", "Group Index", NULL, NULL, group_idx },
-       { "3", "Device Index", NULL, NULL, device_idx },
-       { "4", "Run", NULL, run_device_eject, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_send_data[] = {
-       { "0", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL },
-       { "1", "Message", NULL, NULL, message },
-       { "2", "Device Index", NULL, NULL, device_idx },
-       { "3", "Send (Unicast)", NULL, run_send_data, NULL },
-       { "4", "Send (Broadcast)", NULL, run_send_data_all, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_devices_find_mownd_device[] = {
-       { "0", "Timeout", NULL, NULL, timeout },
-       { "1", "Run", NULL, run_devices_find_mowned_device, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_request_create_group[] = {
-       { "0", "Show Found Device(s)", NULL, run_devices_show, NULL },
-       { "1", "Device Index", NULL, NULL, device_idx },
-       { "2", "Request Group Name", NULL, NULL, request_groupid },
-       { "3", "Run", NULL, run_request_create_group, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_request_invite[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
-       { "2", "Group Index", NULL, NULL, group_idx },
-       { "3", "Device Index", NULL, NULL, device_idx },
-       { "4", "PIN", NULL, NULL, pin },
-       { "5", "Run", NULL, run_request_invite, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_request_eject[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
-       { "2", "Group Index", NULL, NULL, group_idx },
-       { "3", "Device Index", NULL, NULL, device_idx },
-       { "4", "Run", NULL, run_request_eject, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_request_delete_group[] = {
-       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
-       { "1", "Group Index", NULL, NULL, group_idx },
-       { "2", "Run", NULL, run_request_delete_group, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_monitor[] = {
-       { "1", "Input 1 to Start and 2 to Stop Monitor", NULL, NULL,  monitor },
-       { "2", "Start/Stop Device Monitor", NULL, run_start_device_monitor, NULL },
-       { NULL, NULL, },
-};
-
-struct menu_data menu_comp_manager[] = {
-       { "0", "Show My Device ID", NULL, run_get_my_id, NULL },
-       { "1", "Show My Device", NULL, run_device_show_my_device, NULL },
-       { "2", "Create Group", menu_group_create, NULL, NULL },
-       { "3", "Find Group(s)", menu_group_find, NULL, NULL },
-       { "4", "Show Found Group(s)", NULL, run_group_show_found , NULL },
-       { "5", "Join Group (Not yet developed)", menu_group_join, NULL, NULL },
-       { "6", "Leave Group (Not yet developed)", menu_group_leave, NULL, NULL },
-       { "7", "Delete Group (Not yet developed)", menu_group_delete, NULL, NULL },
-       { "8", "Find Device(s)", menu_devices_find, NULL, NULL },
-       { "9", "Show Found Device(s)", NULL, run_device_show_found, NULL },
-       { "10", "Invite Device", menu_group_invite_device, NULL, NULL },
-       { "11", "Eject Device", menu_group_eject_device, NULL, NULL },
-       { "12", "Find My Owned Device(s)", menu_devices_find_mownd_device, NULL, NULL },
-       { "13", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL},
-       { "14", "Send Message", menu_send_data, NULL, NULL },
-       { "15", "Request Create Group", menu_request_create_group, NULL, NULL },
-       { "16", "Request Invite", menu_request_invite, NULL, NULL },
-       { "17", "Request Eject", menu_request_eject, NULL, NULL },
-       { "18", "Request Delete Group (Not yet developed)", menu_request_delete_group,
-               NULL, NULL },
-       { "19", "Start/Stop Device Monitor", menu_monitor, NULL, NULL },
-       { NULL, NULL, },
-};
diff --git a/capi/demo/companion_demo.c b/capi/demo/companion_demo.c
deleted file mode 100644 (file)
index ade3d06..0000000
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <glib.h>
-#include <sys/time.h>
-
-#include <companion.h>
-
-#define BUFFER_LEN 100
-#define TEST_CASE_MAX 10
-
-#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
-#define TC_PRT(format, args...) PRT(format"\n", ##args)
-
-#define BEGIN() TC_PRT("BEGIN");
-#define END() TC_PRT("END");
-
-GMainLoop *main_loop = NULL;
-
-typedef struct {
-       const char *tc_name;
-       int tc_code;
-       int (*tc_func)(void);
-} tc_table_t;
-
-GList *found_group_list;
-GList *found_device_list;
-
-companion_h handle = NULL;
-
-#define CASE_TO_STR(x) case x: return #x;
-static const char* __device_type_to_string(companion_device_type_e type)
-{
-       switch (type) {
-       /* CHECK: List all enum values here */
-       CASE_TO_STR(COMPANION_DEVICE_TYPE_LOCAL)
-       CASE_TO_STR(COMPANION_DEVICE_TYPE_REMOTE)
-       default :
-               return "COMPANION_DEVICE_TYPE_ERROR";
-       }
-}
-
-static bool test_get_user_int(const char *msg, int *num)
-{
-       if (msg == NULL || num == NULL)
-               return false;
-
-       int rv;
-       char buf[32] = { 0, };
-       printf("%s\n", msg);
-       rv = read(0, buf, 32);
-
-       if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
-               return false;
-
-       *num = atoi(buf);
-       return true;
-}
-
-static bool test_get_user_string(const char *msg, char *buf, int buf_size)
-{
-       if (msg == NULL || buf == NULL || buf_size < 2)
-               return false;
-
-       int rv;
-       printf("%s\n", msg);
-       memset(buf, 0, buf_size);
-       rv = read(0, buf, buf_size - 1);
-
-       if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
-               buf[0] = '\0';
-               return false;
-       }
-
-       if (rv >= 0)
-               buf[rv] = '\0';
-
-       return true;
-}
-
-int companion_initialize_test(void)
-{
-       int ret = 0;
-
-       BEGIN();
-
-       ret = companion_initialize(&handle);
-
-       if (ret == 0)
-               TC_PRT("Initialize successful");
-       else
-               TC_PRT("Initialize failed, ret [%d]", ret);
-
-       END();
-       return ret;
-}
-
-int companion_group_create_test(void)
-{
-       int ret = 0;
-       char input_str[50] = {0, };
-       companion_h handle = NULL;
-
-       BEGIN();
-
-       if (test_get_user_string("Input group name(ex - GROUP123)"
-                                                " - (Enter for skip) :", input_str, 50)) {
-               g_strstrip(input_str);
-       } else {
-               TC_PRT("Invalid Input !!![%s]", input_str);
-               END();
-               return -1;
-       }
-
-       ret = companion_group_create(handle, input_str);
-
-       if (ret == 0)
-               TC_PRT("Group create successful");
-       else
-               TC_PRT("Group create failed, ret [%d]", ret);
-
-       END();
-       return ret;
-}
-
-bool _group_found_cb(companion_group_type_e type, companion_group_h group, void *user_data)
-{
-       char *uri_path;
-
-       companion_group_information_get_uri_path(group, &uri_path);
-
-       TC_PRT("found group type : %d, uri : %s", type, uri_path);
-
-       found_group_list = g_list_append(found_group_list, group);
-}
-
-void _group_finish_cb(int result, void *user_data)
-{
-       TC_PRT("find operation finished");
-}
-
-int companion_group_find_test(void)
-{
-       int ret = 0;
-       int input_int = 0;
-
-       BEGIN();
-       found_group_list = NULL;
-
-       if (!test_get_user_int("==> Input timeout value (sec)"
-                                                " - (Enter for skip) :", &input_int)) {
-               input_int = 5;
-               TC_PRT("default timeout value [%d]", input_int);
-       }
-
-       companion_group_find(handle, input_int, _group_found_cb, _group_finish_cb, NULL);
-
-       if (ret == 0)
-               TC_PRT("group find successful");
-       else
-               TC_PRT("group find failed, ret [%d]", ret);
-
-       END();
-       return ret;
-}
-
-int companion_group_get_found_groups_test(void)
-{
-       int ret = 0;
-       int count;
-       companion_group_h *groups;
-
-       BEGIN();
-
-       found_group_list = NULL;
-
-       ret = companion_group_get_found_groups(handle, &groups, &count);
-
-       if (ret == 0)
-               TC_PRT("group find successful");
-       else
-               TC_PRT("group find failed, ret [%d]", ret);
-
-       TC_PRT("Found group count : %d", count);
-
-       for (int i = 0; i < count; i++) {
-               companion_group_type_e type;
-               char *uri_path;
-               companion_group_information_get_type(groups[i], &type);
-               companion_group_information_get_uri_path(groups[i], &uri_path);
-               TC_PRT("%d. type : %d, uri path : %s", i+1, type, uri_path);
-               found_group_list = g_list_append(found_group_list, groups[i]);
-       }
-
-       END();
-       return ret;
-}
-
-bool _device_found_cb(companion_device_h device, void *user_data)
-{
-       char *device_id;
-       char *ip;
-       companion_device_type_e device_type;
-
-       companion_device_information_get_device_id(device, &device_id);
-       companion_device_information_get_ip(device, &ip);
-       companion_device_information_get_device_type(device, &device_type);
-
-       TC_PRT("found device device_id : %s, ip : %s, device_type : %s", device_id, ip,
-               __device_type_to_string(device_type));
-
-       found_device_list = g_list_append(found_device_list, device);
-}
-
-int companion_device_find_test(void)
-{
-       int ret = 0;
-       int input_int = 0;
-
-       BEGIN();
-       found_device_list = NULL;
-
-       if (!test_get_user_int("==> Input timeout value (sec)"
-                                                " - (Enter for skip) :", &input_int)) {
-               input_int = 5;
-               TC_PRT("default timeout value [%d]", input_int);
-       }
-
-       companion_device_find(handle, input_int, _device_found_cb, _group_finish_cb, NULL);
-
-       if (ret == 0)
-               TC_PRT("device find successful");
-       else
-               TC_PRT("device find failed, ret [%d]", ret);
-
-       END();
-       return ret;
-}
-
-int companion_device_get_found_devices_test(void)
-{
-       int ret = 0;
-       int count = 0;
-       companion_device_h *devices;
-
-       BEGIN();
-
-       found_device_list = NULL;
-
-       ret = companion_device_get_found_devices(hadnle, &devices, &count);
-
-       if (ret == 0)
-               TC_PRT("device find successful");
-       else
-               TC_PRT("device find failed, ret [%d]", ret);
-
-       TC_PRT("Found device count : ", count);
-
-       for (int i = 0; i < count; i++) {
-               char *uuid;
-               char *ip;
-               companion_device_type_e device_type;
-
-               companion_device_information_get_device_id(devices[i], &uuid);
-               companion_device_information_get_ip(devices[i], &ip);
-               companion_device_information_get_device_type(devices[i], &device_type);
-
-               TC_PRT("%d. uuid : %s, ip : %s, device_type : %s", i+1, uuid, ip,
-                       __device_type_to_string(device_type));
-               found_device_list = g_list_append(found_device_list, devices[i]);
-       }
-
-       END();
-       return ret;
-}
-
-void _device_invite_result_cb(int result, void *user_data)
-{
-       TC_PRT("Invite complete !!!! ret : %d", result);
-}
-
-int companion_device_invite_test(void)
-{
-       int ret = 0;
-       BEGIN();
-
-       /* using stored group list and device list */
-       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
-               TC_PRT("Invite Test Start");
-               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_group_invite_device(handle, group, device, "12341234", _device_invite_result_cb, NULL);
-
-       } else {
-               TC_PRT("not exist found group or device list");
-       }
-
-       END();
-       return ret;
-}
-
-void _device_eject_result_cb(int result, void *user_data)
-{
-       TC_PRT("eject complete !!!! ret : %d", result);
-}
-
-int companion_device_eject_test(void)
-{
-       int ret = 0;
-       BEGIN();
-
-       /* using stored group list and device list */
-       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
-               TC_PRT("Invite Test Start");
-               companion_group_h group = (companion_group_h)(found_group_list[0].data);
-               companion_device_h device = (companion_device_h)(found_device_list[0].data);
-
-               /* using stored group list and device list */
-               companion_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
-       } else {
-               TC_PRT("not exist found group or device list");
-       }
-
-
-       END();
-       return ret;
-}
-
-//send_data_callback : if the remote device not invited, then callback is called include result failed.
-//send_data_callback : if the remote device invited, then callback result successful.
-
-int companion_send_data_to_remote_device_test(void)
-{
-       int ret = 0;
-       BEGIN();
-
-       if (g_list_length(found_device_list) > 0) {
-               companion_device_h device = (companion_device_h)(found_device_list[0].data);
-               ret = companion_device_send_data(handle, device, "123", NULL, NULL);
-       } else {
-               TC_PRT("not exist found device list");
-       }
-
-       END();
-       return ret;
-}
-
-int companion_deinitialize_test(void)
-{
-       int ret = 0;
-
-       BEGIN();
-
-       ret = companion_deinitialize(handle);
-
-       if (ret == 0)
-               TC_PRT("Initialize successful");
-       else
-               TC_PRT("Initialize failed, ret [%d]", ret);
-
-       END();
-       return ret;
-}
-
-tc_table_t tc_table[] = {
-       /* manager api */
-       {"companion_initialize_test",  1,       companion_initialize_test},
-       {"companion_group_create_test",  2,     companion_group_create_test},
-       {"companion_group_find_test",  3,       companion_group_find_test},
-       {"companion_group_get_found_groups_test",  4,   companion_group_get_found_groups_test},
-       {"companion_device_find_test",  5,      companion_device_find_test},
-       {"companion_device_get_found_devices_test",  6, companion_device_get_found_devices_test},
-       {"companion_device_invite_test",  7,    companion_device_invite_test},
-       {"companion_device_eject_test",  8,     companion_device_eject_test},
-       {"companion_send_data_to_remote_device_test",  9,       companion_send_data_to_remote_device_test},
-       {"companion_deinitialize_test",  TEST_CASE_MAX, companion_deinitialize_test},
-
-       /*-----------*/
-       {"Finish",                                                                      0x0000, NULL},
-       {NULL,                                                                          0x00ff, NULL},
-};
-
-static void tc_usage_print(void)
-{
-       int i = 0;
-
-       while (tc_table[i].tc_name) {
-               if (tc_table[i].tc_code != 0x00ff)
-                       printf("Key [%2d] : usage %s\n", tc_table[i].tc_code, tc_table[i].tc_name);
-               else
-                       printf("Key [%2d] : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
-
-               i++;
-       }
-}
-
-static int test_input_callback(void *data)
-{
-       long test_id = (long)data;
-       int ret = 0;
-
-       if ((test_id >= 1) && (test_id <= TEST_CASE_MAX)) {
-               TC_PRT("test_input_callback test_id : %ld", test_id);
-
-               if (tc_table[test_id-1].tc_func != NULL) {
-                       ret = tc_table[test_id-1].tc_func();
-
-                       if (ret != 0)
-                               TC_PRT(">>>>> Test Error Returned !!! : %d", ret);
-               }
-       }
-
-       return 0;
-}
-
-static int test_terminate(void)
-{
-       int ret = 0;
-
-       TC_PRT("Finished");
-
-       companion_deinitialize_test();
-       g_main_loop_quit(main_loop);
-
-       return ret;
-}
-
-static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
-{
-       char buf[BUFFER_LEN] = {0,};
-       long test_id;
-       int rv = 0;
-
-       memset(buf, 0, sizeof(buf));
-
-       rv = read(0, buf, 100);
-
-       if (rv < 0 || buf[0] == '0') {
-               test_terminate();
-               exit(1);
-       }
-
-       if (*buf == '\n' || *buf == '\r')
-               tc_usage_print();
-
-       test_id = atoi(buf);
-
-       test_input_callback((void *)test_id);
-
-       return TRUE;
-}
-
-
-int main(int argc, char ** argv)
-{
-       GIOChannel *key_io;
-
-       main_loop = g_main_loop_new(NULL, FALSE);
-       key_io = g_io_channel_unix_new(0);
-
-       printf("Test Thread created...\n");
-
-       g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL);
-       g_main_loop_run(main_loop);
-
-       g_io_channel_unref(key_io);
-       g_main_loop_unref(main_loop);
-
-       return 0;
-}
diff --git a/capi/demo/main.c b/capi/demo/main.c
deleted file mode 100644 (file)
index a7f1f43..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <glib.h>
-#include <gio/gio.h>
-
-#include <companion_internal.h>
-#include "menu.h"
-#include "common.h"
-
-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;
-
-void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
-                                                       int len, int ret, void *user_data);
-
-const char* comp_error_to_string(comp_error_e err)
-{
-       switch (err) {
-       /* CHECK: List all enum values here */
-       CASE_TO_STR(COMP_ERROR_NONE)
-       CASE_TO_STR(COMP_ERROR_IO_ERROR)
-       CASE_TO_STR(COMP_ERROR_INVALID_PARAMETER)
-       CASE_TO_STR(COMP_ERROR_OUT_OF_MEMORY)
-       CASE_TO_STR(COMP_ERROR_PERMISSION_DENIED)
-       CASE_TO_STR(COMP_ERROR_NOT_SUPPORTED)
-       CASE_TO_STR(COMP_ERROR_COMM_ERROR)
-       CASE_TO_STR(COMP_ERROR_RX)
-       CASE_TO_STR(COMP_ERROR_TX)
-       CASE_TO_STR(COMP_ERROR_OPERATION_FAILED)
-       CASE_TO_STR(COMP_ERROR_ALREADY_IN_PROGRESS)
-       CASE_TO_STR(COMP_ERROR_ALREADY_INITIALIZED)
-       default :
-               return "COMP_ERROR_GENERAL";
-       }
-}
-
-const char *comp_group_type_to_string(companion_group_type_e e)
-{
-       switch (e) {
-       CASE_TO_STR(COMPANION_GROUP_TYPE_MINE)
-       CASE_TO_STR(COMPANION_GROUP_TYPE_REMOTE)
-       default :
-               return "Unknown station type";
-       }
-}
-
-
-static int __init_func(MManager *mm, struct menu_data *menu)
-{
-       int ret = -1;
-
-       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;
-       }
-
-       ret = companion_request_result_callback(handle, receive_request_result,
-                                       NULL);
-       if (ret != 0) {
-               msg("Failed to request result callback: [%s(0x%X)]",
-                               comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-
-       return RET_SUCCESS;
-}
-
-static struct menu_data menu_main[] = {
-       { "1", "Comp-Manager", menu_comp_manager, NULL, NULL },
-       { NULL, NULL, },
-};
-
-static gboolean __create_init_menu(struct menu_data init_menu[1])
-{
-       init_menu[0].key = "1";
-       init_menu[0].title = "Init";
-       init_menu[0].sub_menu = menu_main;
-       init_menu[0].callback = __init_func;
-       init_menu[0].data = NULL;
-
-       return TRUE;
-}
-
-void _free_device(gpointer data)
-{
-       companion_device_information_destroy(data);
-}
-
-int main(int arg, char **argv)
-{
-       GMainLoop *mainloop = NULL;
-       GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
-       MManager *manager;
-       struct menu_data init_menu[1+1] = { {NULL, NULL, } };
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
-       g_type_init();
-#endif
-       mainloop = g_main_loop_new(NULL, FALSE);
-
-       msg("");
-       msg("* Companion-Manager Test application ");
-       msg("* Build On: %s  %s", __DATE__, __TIME__);
-
-       if (__create_init_menu(init_menu) == FALSE)
-               goto OUT;
-
-       manager = menu_manager_new(init_menu, mainloop);
-       if (!manager)
-               goto OUT;
-
-       menu_manager_run(manager);
-
-       g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
-                               on_menu_manager_keyboard, manager);
-       g_main_loop_run(mainloop);
-
-OUT:
-       if (found_group_list)
-               g_list_free_full(found_group_list, _free_device);
-       if (found_device_list)
-               g_list_free_full(found_device_list, _free_device);
-
-       companion_deinitialize(handle);
-
-       g_main_loop_unref(mainloop);
-       msg("******* Bye bye *******");
-
-       return 0;
-}
diff --git a/capi/demo/menu.c b/capi/demo/menu.c
deleted file mode 100644 (file)
index c217f6b..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <glib.h>
-#include <asm/unistd.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#include "menu.h"
-
-#define DEFAULT_MENU_MENU      "m"
-#define DEFAULT_MENU_PREV      "p"
-#define DEFAULT_MENU_QUIT      "q"
-#define DEFAULT_MENU_NONE      "-"
-#define TAB_SPACE     "  "
-
-struct menu_manager {
-       GQueue *stack;
-       GQueue *title_stack;
-
-       struct menu_data *menu;
-
-       char *buf;
-
-       void *user_data;
-       GMainLoop *mainloop;
-};
-
-
-char key_buffer[MENU_DATA_SIZE];
-int flag_pid_display = 1;
-
-extern unsigned short dest_addr16;
-extern struct menu_data menu_sel_device[];
-
-static void _show_prompt(void)
-{
-       msgn("(%5d) >> ", get_tid());
-}
-
-static void _show_reserved_menu(void)
-{
-       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
-       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
-       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
-                       " ] " ANSI_COLOR_NORMAL "Previous menu " , DEFAULT_MENU_PREV);
-       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
-                       " ] " ANSI_COLOR_NORMAL "Show Menu " , DEFAULT_MENU_MENU);
-       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
-                       " ] " ANSI_COLOR_NORMAL "Quit " , DEFAULT_MENU_QUIT);
-}
-
-static void _show_input_ok(void)
-{
-       msg("OK.");
-}
-
-static void _show_menu(MManager *m, struct menu_data menu[])
-{
-       int i = 0;
-       int len = 0;
-       struct menu_data *item;
-       char title_buf[256] = { 0, };
-
-       if (!menu)
-               return;
-
-       msg("");
-       msg(HR_DOUBLE);
-
-       len = g_queue_get_length(m->title_stack);
-       msgn(ANSI_COLOR_YELLOW " Main");
-       if (len > 0) {
-               for (i = 0; i < len; i++) {
-                       msgn(ANSI_COLOR_NORMAL " >> " ANSI_COLOR_YELLOW "%s",
-                                       (char *)g_queue_peek_nth(m->title_stack, i));
-               }
-       }
-       msg(ANSI_COLOR_NORMAL);
-       msg(HR_SINGLE);
-
-       hide_pid();
-       i = 0;
-
-       while (1) {
-               item = menu + i;
-               if (item->key == NULL)
-                       break;
-
-               if (!g_strcmp0(item->key, "-")) {
-                       msgn("       ");
-               } else if (!g_strcmp0(item->key, "_")) {
-                       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
-
-                       if (item->callback)
-                               item->callback(m, item);
-
-                       i++;
-
-                       continue;
-               } else if (!g_strcmp0(item->key, "*")) {
-                       msg(" %s", item->title);
-                       if (item->callback)
-                               item->callback(m, item);
-               } else {
-                       msgn(ANSI_COLOR_DARKGRAY " [" ANSI_COLOR_NORMAL "%3s"
-                                       ANSI_COLOR_DARKGRAY "] " ANSI_COLOR_NORMAL,     item->key);
-               }
-
-               memset(title_buf, 0, 256);
-               if (item->title) {
-                       snprintf(title_buf, MAX_TITLE, "%s", item->title);
-
-                       if (strlen(item->title) >= MAX_TITLE) {
-                               title_buf[MAX_TITLE - 2] = '.';
-                               title_buf[MAX_TITLE - 1] = '.';
-                       }
-               }
-
-               if (item->data) {
-                       msg("%s " ANSI_COLOR_LIGHTBLUE "(%s)" ANSI_COLOR_NORMAL,
-                                       title_buf, item->data);
-               } else if (!g_strcmp0(item->key, "*")) {
-                       /* none */
-               } else {
-                       msg("%s", title_buf);
-               }
-
-               if (item->sub_menu)
-                       msg("\e[1A\e[%dC >", (int)POS_MORE);
-
-               i++;
-       }
-
-       show_pid();
-
-       _show_reserved_menu();
-
-       msg(HR_DOUBLE);
-
-       _show_prompt();
-}
-
-static void _show_item_data_input_msg(struct menu_data *item)
-{
-       msg("");
-       msg(HR_DOUBLE);
-       msg(" Input [%s] data ", item->title);
-       msg(HR_SINGLE);
-       msg(" current = [%s]", item->data);
-       msgn(" new >> ");
-}
-
-static void _move_menu(MManager *mm, struct menu_data menu[], char *key)
-{
-       struct menu_data *item;
-       int i = 0;
-
-       if (!mm->menu)
-               return;
-
-       if (!g_strcmp0(DEFAULT_MENU_PREV, key)) {
-               if (g_queue_get_length(mm->stack) > 0) {
-                       mm->menu = g_queue_pop_tail(mm->stack);
-                       g_queue_pop_tail(mm->title_stack);
-               }
-
-               _show_menu(mm, mm->menu);
-               mm->buf = key_buffer;
-
-               return;
-       } else if (!g_strcmp0(DEFAULT_MENU_MENU, key)) {
-               _show_menu(mm, mm->menu);
-               return;
-       } else if (!g_strcmp0(DEFAULT_MENU_QUIT, key)) {
-               g_main_loop_quit(mm->mainloop);
-               return;
-       } else if (!g_strcmp0(DEFAULT_MENU_NONE, key)) {
-               _show_prompt();
-               return;
-       }
-
-       while (1) {
-               int ret = RET_SUCCESS;
-               item = menu + i;
-               if (item->key == NULL)
-                       break;
-
-               if (!g_strcmp0(item->key, key)) {
-                       if (item->callback) {
-                               ret = item->callback(mm, item);
-                               _show_prompt();
-                       }
-
-                       if (RET_SUCCESS == ret) {
-                               if (item->sub_menu) {
-                                       g_queue_push_tail(mm->stack, mm->menu);
-                                       g_queue_push_tail(mm->title_stack, (gpointer *)item->title);
-
-                                       mm->menu = item->sub_menu;
-                                       _show_menu(mm, mm->menu);
-                                       mm->buf = key_buffer;
-                               }
-
-                               if (item->data) {
-                                       _show_item_data_input_msg(item);
-                                       mm->buf = item->data;
-                               }
-                       }
-
-                       return;
-               }
-
-               i++;
-       }
-
-       _show_prompt();
-}
-
-MManager *menu_manager_new(struct menu_data items[], GMainLoop *mainloop)
-{
-       MManager *mm;
-
-       mm = calloc(sizeof(struct menu_manager), 1);
-       if (!mm)
-               return NULL;
-
-       mm->stack = g_queue_new();
-       mm->title_stack = g_queue_new();
-       mm->menu = items;
-       mm->mainloop = mainloop;
-
-       return mm;
-}
-
-int menu_manager_run(MManager *mm)
-{
-       _show_menu(mm, mm->menu);
-
-       mm->buf = key_buffer;
-
-       return 0;
-}
-
-int menu_manager_set_user_data(MManager *mm, void *user_data)
-{
-       if (!mm)
-               return -1;
-
-       mm->user_data = user_data;
-
-       return 0;
-}
-
-void *menu_manager_ref_user_data(MManager *mm)
-{
-       if (!mm)
-               return NULL;
-
-       return mm->user_data;
-}
-
-gboolean on_menu_manager_keyboard(GIOChannel *src, GIOCondition con,
-               gpointer data)
-{
-       MManager *mm = data;
-       char local_buf[MENU_DATA_SIZE + 1] = { 0, };
-
-       if (fgets(local_buf, MENU_DATA_SIZE, stdin) == NULL)
-               return TRUE;
-
-       if (strlen(local_buf) > 0) {
-               if (local_buf[strlen(local_buf) - 1] == '\n')
-                       local_buf[strlen(local_buf) - 1] = '\0';
-       }
-
-       if (mm->buf == key_buffer) {
-               if (strlen(local_buf) < 1) {
-                       _show_prompt();
-                       return TRUE;
-               }
-
-               _move_menu(mm, mm->menu, local_buf);
-       } else {
-               if (mm->buf) {
-                       memset(mm->buf, 0, MENU_DATA_SIZE);
-                       memcpy(mm->buf, local_buf, MENU_DATA_SIZE);
-                       _show_input_ok();
-               }
-               mm->buf = key_buffer;
-               _move_menu(mm, mm->menu, (char *)DEFAULT_MENU_MENU);
-       }
-
-       return TRUE;
-}
-
-pid_t get_tid()
-{
-       return syscall(__NR_gettid);
-}
-
-void hide_pid()
-{
-       flag_pid_display = 0;
-}
-
-void show_pid()
-{
-       flag_pid_display = 1;
-}
-
-int is_pid_show()
-{
-       return flag_pid_display;
-}
-
-static void _hex_dump(const char *pad, int size, const void *data)
-{
-       char buf[255] = {0, };
-       char hex[4] = {0, };
-       int i;
-       unsigned char *p;
-
-       if (size <= 0) {
-               msg("%sno data", pad);
-               return;
-       }
-       p = (unsigned char *)data;
-
-       snprintf(buf, 255, "%s%04X: ", pad, 0);
-       for (i = 0; i < size; i++) {
-               snprintf(hex, 4, "%02X ", p[i]);
-               strncat(buf, hex, 255 - strlen(buf) - 1);
-
-               if ((i + 1) % 8 == 0) {
-                       if ((i + 1) % 16 == 0) {
-                               msg("%s", buf);
-                               memset(buf, 0, 255);
-                               snprintf(buf, 255, "%s%04X: ", pad, i + 1);
-                       } else {
-                               strncat(buf, TAB_SPACE, 255 - strlen(buf) - 1);
-                       }
-               }
-       }
-
-       msg("%s", buf);
-}
-
-void menu_print_dump(int data_len, void *data)
-{
-       if (!data)
-               return;
-
-       msg("");
-       msg("  \tlen=%d", data_len);
-       _hex_dump("        ", data_len, data);
-
-       msg("");
-}
diff --git a/capi/demo/menu.h b/capi/demo/menu.h
deleted file mode 100644 (file)
index 728d36c..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MENU_H__
-#define __MENU_H__
-
-__BEGIN_DECLS
-
-#define ANSI_COLOR_NORMAL              "\e[0m"
-
-#define ANSI_COLOR_BLACK               "\e[0;30m"
-#define ANSI_COLOR_RED                 "\e[0;31m"
-#define ANSI_COLOR_GREEN               "\e[0;32m"
-#define ANSI_COLOR_BROWN               "\e[0;33m"
-#define ANSI_COLOR_BLUE                        "\e[0;34m"
-#define ANSI_COLOR_MAGENTA             "\e[0;35m"
-#define ANSI_COLOR_CYAN                        "\e[0;36m"
-#define ANSI_COLOR_LIGHTGRAY   "\e[0;37m"
-
-#define ANSI_COLOR_DARKGRAY            "\e[1;30m"
-#define ANSI_COLOR_LIGHTRED            "\e[1;31m"
-#define ANSI_COLOR_LIGHTGREEN  "\e[1;32m"
-#define ANSI_COLOR_YELLOW              "\e[1;33m"
-#define ANSI_COLOR_LIGHTBLUE   "\e[1;34m"
-#define ANSI_COLOR_LIGHTMAGENTA "\e[1;35m"
-#define ANSI_COLOR_LIGHTCYAN   "\e[1;36m"
-#define ANSI_COLOR_WHITE               "\e[1;37m"
-
-
-#define msg(fmt, args...)      do { fprintf(stdout, fmt "\n", ##args); \
-               fflush(stdout); } while (0)
-#define msgn(fmt, args...)     do { fprintf(stdout, fmt, ##args); \
-               fflush(stdout); } while (0)
-
-/* Bold (red) */
-#define msgr(fmt, args...)  do { fprintf(stdout, ANSI_COLOR_RED fmt \
-               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
-
-/* Bold (green) */
-#define msgb(fmt, args...)  do { fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \
-               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
-
-/* Property message */
-#define msgp(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTMAGENTA fmt \
-               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
-
-#define msgt(n, fmt, args...) do { fprintf(stdout, "\e[%dC" fmt "\n", \
-               3 + ((n) * 2), ##args); fflush(stdout); } while (0)
-
-#define pmsg(fmt, args...) do { \
-       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
-       fprintf(stdout, fmt "\n", ##args); fflush(stdout); } while (0)
-
-#define pmsgb(fmt, args...) do { \
-       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
-       fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \
-                       ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
-
-#define pmsgt(n, fmt, args...) do { \
-       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
-       fprintf(stdout, "\e[%dC" fmt "\n", \
-                       3 + ((n) * 2), ##args); fflush(stdout); } while (0)
-
-#define MENU_DATA_SIZE 255
-
-
-
-/*
- * Horizontal Line - width: 65
- *                                     .12345678901234567890123456789012345678901234567890.
- */
-#define HR_SINGLE      "----------------------------------------" \
-                                       "-------------------------"
-#define HR_DOUBLE      "========================================" \
-                                       "========================="
-#define HR_SINGLE2     " ---------------------------------------" \
-                                       "------------------------ "
-
-#define MAX_WIDTH      strlen(HR_SINGLE)
-#define MAX_TITLE      ((MAX_WIDTH) - 10)
-#define POS_MORE       ((MAX_WIDTH) - 3)
-#define RET_SUCCESS 0
-#define RET_FAILURE -1
-
-typedef struct menu_manager MManager;
-
-struct menu_data {
-       const char *key;
-       const char *title;
-       struct menu_data *sub_menu;
-       int (*callback)(MManager *mm, struct menu_data *menu);
-       char *data;
-};
-
-MManager* menu_manager_new(struct menu_data items[], GMainLoop *mainloop);
-int menu_manager_run(MManager *mm);
-int menu_manager_set_user_data(MManager *mm, void *user_data);
-void* menu_manager_ref_user_data(MManager *mm);
-
-gboolean  on_menu_manager_keyboard(GIOChannel *src, GIOCondition con,
-               gpointer data);
-
-pid_t get_tid();
-void hide_pid();
-void show_pid();
-int is_pid_show();
-void menu_print_dump(int data_len, void *data);
-
-__END_DECLS
-
-#endif
diff --git a/capi/doc/companion_doc.h b/capi/doc/companion_doc.h
deleted file mode 100755 (executable)
index 6b460a4..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __TIZEN_NETWORK_COMPANION_DOC_H__
-#define __TIZEN_NETWORK_COMPANION_DOC_H__
-
-/**
- * @ingroup CAPI_NETWORK_FRAMEWORK
- * @defgroup CAPI_NETWORK_COMPANION_MODULE Companion Manager
- * @brief The Companion API provides functions for group management of devices.
- *
- * @section CAPI_NETWORK_COMPANION_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_MODULE_OVERVIEW Overview
- * Companion Device Management(CDM) is a term for the group managenet of smart devices, such as smartphones, wearable devices, televisions, spakers and home appliances in a local network.
- * The CDM is implemented with the use of an open souce project 'IoTivity' that has D2D management features for various vendors of smart devices.
- * The CDM functionality can provide groupe management of devices, sending data securely and configuraion settings for all types of smart devices baseed on 'OCF', including smartphones, wearable devices, TVs, home appliances, speakers, IoT things, etc.
- *
- * @section CAPI_NETWORK_COMPANION_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/network.d2d.companion\n
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_GROUP_MODULE Group Management
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_GROUP_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_GROUP_MODULE_OVERVIEW Overview
- * These functions are used to manipulate the groups.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_LOCAL_GROUP_MODULE Local Group Management
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_GROUP_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_LOCAL_GROUP_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_LOCAL_GROUP_MODULE_OVERVIEW Overview
- * These functions are used to manipulate the local groups.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_REMOTE_GROUP_MODULE Remote Group Management
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_GROUP_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_REMOTE_GROUP_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_REMOTE_GROUP_MODULE_OVERVIEW Overview
- * These functions are used to manipulate the remote groups.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_GROUP_INFORMATION_MODULE Group Information
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_GROUP_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_GROUP_INFORMATION_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_GROUP_INFORMATION_MODULE_OVERVIEW Overview
- * These functions are used to get group information using the group handle.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_DEVICE_MODULE Device Management
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_DEVICE_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_DEVICE_MODULE_OVERVIEW Overview
- * These functions are used to get information from the device handle.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-/**
- * @defgroup CAPI_NETWORK_COMPANION_DEVICE_INFORMATION_MODULE Device Information
- * @brief The Companion API provides functions for device management.
- * @ingroup CAPI_NETWORK_COMPANION_DEVICE_MODULE
- *
- * @section CAPI_NETWORK_COMPANION_DEVICE_INFORMATION_MODULE_HEADER Required Header
- *   \#include <companion.h>
- *
- * @section CAPI_NETWORK_COMPANION_DEVICE_INFORMATION_MODULE_OVERVIEW Overview
- * These functions are used to get device information using the device handle.
- *
- * It is recommended to design applications with regard to features, for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- */
-
-#endif /* __TIZEN_NETWORK_COMPANION_DOC_H__ */
diff --git a/capi/doc/mdg_doc.h b/capi/doc/mdg_doc.h
new file mode 100644 (file)
index 0000000..169ce0a
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_NETWORK_MDG_DOC_H__
+#define __TIZEN_NETWORK_MDG_DOC_H__
+
+/**
+ * @ingroup CAPI_NETWORK_FRAMEWORK
+ * @defgroup CAPI_NETWORK_MDG_MODULE Multi Device Group Manager
+ * @brief The Companion API provides functions for group management of devices.
+ *
+ * @section CAPI_NETWORK_MDG_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_MODULE_OVERVIEW Overview
+ * Multi Device Group Management(MDGM) is a term for the group managenet of smart devices, such as smartphones, wearable devices, televisions, spakers and home appliances in a local network.
+ * The MDGM is implemented with the use of an open souce project 'IoTivity' that has D2D management features for various vendors of smart devices.
+ * The MDGM functionality can provide groupe management of devices, sending data securely and configuraion settings for all types of smart devices baseed on 'OCF', including smartphones, wearable devices, TVs, home appliances, speakers, IoT things, etc.
+ *
+ * @section CAPI_NETWORK_MDG_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/network.mdg\n
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_GROUP_MODULE Group Management
+ * @brief Group Management API provides functions to manage groups.
+ * @ingroup CAPI_NETWORK_MDG_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_GROUP_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_GROUP_MODULE_OVERVIEW Overview
+ * These functions are used to manipulate the groups.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_LOCAL_GROUP_MODULE Local Group Management
+ * @brief The Local Group Management API provides functions to manage remote groups.
+ * @ingroup CAPI_NETWORK_MDG_GROUP_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_LOCAL_GROUP_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_LOCAL_GROUP_MODULE_OVERVIEW Overview
+ * These functions are used to manipulate the local groups.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_REMOTE_GROUP_MODULE Remote Group Management
+ * @brief The Remote Group Management API provides functions to manage remote groups.
+ * @ingroup CAPI_NETWORK_MDG_GROUP_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_REMOTE_GROUP_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_REMOTE_GROUP_MODULE_OVERVIEW Overview
+ * These functions are used to manipulate the remote groups.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_GROUP_INFORMATION_MODULE Group Information
+ * @brief The Group Information API provides functions to get information from group management.
+ * @ingroup CAPI_NETWORK_MDG_GROUP_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_GROUP_INFORMATION_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_GROUP_INFORMATION_MODULE_OVERVIEW Overview
+ * These functions are used to get group information using the group handle.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_DEVICE_MODULE Device Management
+ * @brief The Device Management API provides functions for device management.
+ * @ingroup CAPI_NETWORK_MDG_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_DEVICE_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_DEVICE_MODULE_OVERVIEW Overview
+ * These functions are used to get information from the device handle.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @defgroup CAPI_NETWORK_MDG_DEVICE_INFORMATION_MODULE Device Information
+ * @brief The Device Information API provides functions to get information of device management.
+ * @ingroup CAPI_NETWORK_MDG_DEVICE_MODULE
+ *
+ * @section CAPI_NETWORK_MDG_DEVICE_INFORMATION_MODULE_HEADER Required Header
+ *   \#include <mdg.h>
+ *
+ * @section CAPI_NETWORK_MDG_DEVICE_INFORMATION_MODULE_OVERVIEW Overview
+ * These functions are used to get device information using the device handle.
+ *
+ * It is recommended to design applications with regard to features, for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+#endif /* __TIZEN_NETWORK_MDG_DOC_H__ */
diff --git a/capi/include/companion.h b/capi/include/companion.h
deleted file mode 100644 (file)
index 9928a85..0000000
+++ /dev/null
@@ -1,1275 +0,0 @@
-/*
- * Network Configuration Module
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __TIZEN_NETWORK_COMPANION_H__
-#define __TIZEN_NETWORK_COMPANION_H__
-
-#include <tizen.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file companion.h
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_MODULE
- * @{
- */
-
-/**
- * @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
-
-/**
- * @brief Error codes for companion-manager.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
-       COMP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
-       COMP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
-       COMP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
-       COMP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
-       COMP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
-       COMP_ERROR_COMM_ERROR = TIZEN_ERROR_COMP | 0x01, /**< communication error */
-       COMP_ERROR_RX = TIZEN_ERROR_COMP | 0x02, /**< RX error */
-       COMP_ERROR_TX = TIZEN_ERROR_COMP | 0x03, /**< TX error */
-       COMP_ERROR_OPERATION_FAILED = TIZEN_ERROR_COMP | 0x04, /**< Operation Failed */
-       COMP_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x05, /**< Operation now in progress */
-       COMP_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */
-       COMP_ERROR_NO_DATA = TIZEN_ERROR_COMP | 0x07, /**< No Data */
-       COMP_ERROR_NOT_STARTED = TIZEN_ERROR_COMP | 0x08, /**< Not Started */
-       COMP_ERROR_UNKNOWN = -999,
-} comp_error_e;
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_DEVICE_MODULE
- * @{
- */
-
-/**
- * @brief Device handle.
- *
- * @since_tizen 5.0
- */
-typedef void *companion_device_h; /**< Device handle */
-
-/**
- * @}
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_GROUP_MODULE
- * @{
- */
-
-/**
- * @brief Group hande.
- *
- * @since_tizen 5.0
- */
-typedef void *companion_group_h; /**< Group handle */
-
-/**
- * @}
- */
-
-/**
- * @brief Initializes companion-manager.
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks You must release @a handle using companion_deinitialize().
- *
- * @param[out] handle The companion manager handle
- *
- * @return @c 0 on success, otherwise negative error value
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_ALREADY_INITIALIZED Already initialized
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #COMP_ERROR_OPERATION_FAILED Operation failed
- * @retval #COMP_ERROR_OUT_OF_MEMORY Out of memory
- */
-int companion_initialize(companion_h *handle);
-
-/**
- * @brief Deinitializes the companion-manager.
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- *
- * @return 0 on success, otherwise negative error value
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #COMP_ERROR_OPERATION_FAILED Operation failed
- */
-int companion_deinitialize(companion_h handle);
-
-/**
- * @}
- */
-
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_GROUP_MODULE
- * @{
- */
-
-/**
- * @brief Group type.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMPANION_GROUP_TYPE_ERROR = 0, /**< Error */
-       COMPANION_GROUP_TYPE_MINE = 1, /**< Local group */
-       COMPANION_GROUP_TYPE_REMOTE = 2, /**< Remote grojp */
-} companion_group_type_e;
-
-/**
- * @brief Called after companion_group_find().
- * @details This function can receive a group resource found.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a group should not be released.
- * @remarks The @a group can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] type Companion group type
- * @param[out] group Group resource found
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_group_find()
- *
- * @see companion_group_find()
- */
-typedef bool (*companion_group_found_cb)(companion_group_type_e type,
-               companion_group_h group, void *user_data);
-
-/**
- * @brief Called after companion_group_find() finished.
- * @details Called when the maximum wait time elapsed after the companion_group_find() done.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[out] result Result of operation
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_group_find()
- *
- * @see companion_group_find()
- */
-typedef void (*companion_group_find_finish_cb)(int result, void *user_data);
-
-/**
- * @brief Finds group resources in local and the network.
- * @details This function is find group resources in the network plus my local network.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- * @param[in] user_data User data poiter
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_group_get_found_groups()
- *
- */
-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);
-
-/**
- * @brief Gets a list of group resources.
- * @details This function retrieves a list of group resources found.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] groups Group resource list
- * @param[out] count Number of groups
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_group_find()
- *
- */
-int companion_group_get_found_groups(companion_h handle,
-               companion_group_h **groups, int *count);
-
-/**
- * @}
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_LOCAL_GROUP_MODULE
- * @{
- */
-
-/**
- * @brief Creates a group.
- * @details This function is to allocate new group in local companion-manager.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group_name Group name
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_find()
- * @see companion_group_get_found_groups()
- *
- */
-int companion_group_create(companion_h handle, char *group_name);
-
-/**
- * @brief Deletes the group.
- * @details This function deletes a specific group and expels all devices in that group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_request_join_group()
- * @see companion_request_leave_group ()
- * @see companion_group_merge()
- * @see companion_group_get_member_devices()
- *
- */
-int companion_group_delete(companion_h handle, companion_group_h group);
-
-/**
- * @brief Gets devices list in a group resource.
- * @details This function retrieves a devices list of group resources.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a devices should be released using companion_device_information_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
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_request_join_group()
- * @see companion_request_leave_group ()
- * @see companion_group_delete()
- * @see companion_group_merge()
- *
- */
-int companion_group_get_member_devices(companion_h handle,
-               companion_group_h group, companion_device_h **devices, int *count);
-
-/**
- * @brief Called after companion_group_invite_device().
- * @details Called when the maximum wait time elapsed or after the companion_group_invite_device()
- * finished successfully.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[out] result Result of operation
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_group_invite_device()
- *
- * @see companion_group_invite_device()
- */
-typedef void (*companion_group_invite_device_result_cb)(int result, void *user_data);
-
-/**
- * @brief Called after companion_group_eject_device().
- * @details Called when the maximum wait time elapsed or after the companion_device_eject()
- * finished successfully.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[out] result Result of operation
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_device_eject()
- *
- * @see companion_group_ejecct_device()
- */
-typedef void (*companion_group_eject_device_result_cb)(int result, void *user_data);
-
-/**
- * @brief Requests to invite a device to the group which local device owns.
- * @details This function invites a remote device to a specific group. At the time of invitation,
- * user can enter the authentication information (i.e., PIN) or use the certificate.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- * @param[in] device Device handle
- * @param[in] PIN PIN number
- * @param[in] callback Callback handler to receive the result
- * @param[in] user_data User data poiter
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_group_invite_device(companion_h handle, companion_group_h group,
-               companion_device_h device, char *PIN,
-               companion_group_invite_device_result_cb callback, void *user_data);
-
-/**
- * @brief Requests to expel the device from the group which local device owns.
- * @details This function is used to kick away a remote devices in my local group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- * @param[in] user_data User data poiter
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_group_eject_device(companion_h handle, companion_group_h group,
-               companion_device_h device, companion_group_eject_device_result_cb callback,
-               void *user_data);
-
-
-/**
- * @}
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_REMOTE_GROUP_MODULE
- * @{
- */
-
-/**
- * @brief Callback function potiner to be regsitered after sending requests.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a cmd, @arg should not be released.
- * @remarks The @a cmd, @arg can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] cmd Command
- * @param[out] device_id Device id of requester
- * @param[out] arg Argument
- * @param[out] ret Return code
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_request_result_callback()
- *
- * @see companion_request_result_callback()
- */
-typedef void (*companion_request_result_cb)(char *cmd, char *device_id,
-                                       unsigned char *arg, int len, int ret, void *user_data);
-
-/**
- * @brief Requests my device to be joined to remote group.
- * @details This function requests a remote groups to join my device in the remote groups.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group resource list
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_request_leave_group ()
- * @see companion_request_create_group()
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- *
- */
-int companion_request_join_group(companion_h handle, companion_group_h group,
-               companion_request_result_cb cb, void *user_data);
-
-/**
- * @brief Requests my device to be exit from remote group.
- * @details This function requests remote groups to exit my devices that belonged to the
- * remote group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_request_join_group()
- * @see companion_group_delete()
- * @see companion_group_merge()
- * @see companion_group_get_member_devices()
- *
- */
-int companion_request_leave_group (companion_h handle, companion_group_h group,
-               companion_request_result_cb cb, void *user_data);
-
-/**
- * @brief Requests to create a group.
- * @details We can create a group. This generated group can include device, and remote
- * devices can inquire remotely group information and device information included in group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] device Device handle
- * @param[in] group_name Group name
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_request_create_group(companion_h handle,
-       companion_device_h device, char *group_name, companion_request_result_cb cb,
-       void *user_data);
-
-/**
- * @brief Requests to invite a device to the group.
- * @details This function invites a remote device to a specific group. At the time of
- * invitation, user can enter the authentication information (i.e., PIN) or use the
- * certificate.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- * @param[in] device Device handle
- * @param[in] PIN PIN number
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_request_invite_device(companion_h handle, companion_group_h group,
-               companion_device_h device, char *PIN, companion_request_result_cb cb,
-               void *user_data);
-
-/**
- * @brief Requests to eject a device.
- * @details This function is used to kick away a remote devices in a specific group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- * @param[in] device Device handle
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_request_eject_device(companion_h handle, companion_group_h group,
-       companion_device_h device, companion_request_result_cb cb, void *user_data);
-
-/**
- * @brief Requests to delete the group.
- * @details This function deletes a specific group and expels all devices in that group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] group Group handle
- * @param[in] cb Callback handler to receive the result
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_result_callback()
- * @see companion_device_send_data()
- *
- */
-int companion_request_delete_group(companion_h handle, companion_group_h group,
-               companion_request_result_cb cb, void *user_data);
-
-/**
- * @}
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_GROUP_INFORMATION_MODULE
- * @{
- */
-
-/**
- * @brief Clones the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a dst should be released using companion_group_information_destroy().
- *
- * @param[out] dst Destination group handle
- * @param[in] src Source group handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_clone(companion_group_h dst,
-               companion_group_h src);
-
-/**
- * @brief Destroys the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @param[in] group Group handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_destroy(companion_group_h group);
-
-/**
- * @brief Gets group type of the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @param[in] group Group handle
- * @param[out] type Group type
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_get_type(companion_group_h group,
-               companion_group_type_e *type);
-
-/**
- * @brief Gets resource type of the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a resource_type should be released using free().
- *
- * @param[in] group Group handle
- * @param[out] resource_type Resource type
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_get_resource_type(
-               companion_group_h group, char **resource_type);
-
-/**
- * @brief Gets URI path of the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a uri_path should be released using free().
- *
- * @param[in] group Group handle
- * @param[out] uri_path URI path
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_get_uri_path(companion_group_h group,
-               char **uri_path);
-
-/**
- * @brief Gets name of the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a name should be released using free().
- *
- * @param[in] group Group handle
- * @param[out] name Name of the group
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_get_name(companion_group_h group,
-               char **name);
-
-/**
- * @brief Gets host address of the group handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a host_addr should be released using free().
- *
- * @param[in] group Group handle
- * @param[out] host_addr Host address of the group
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_create()
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_uri_path()
- *
- */
-int companion_group_information_get_host_addr(companion_group_h group,
-               char **host_addr);
-
-/**
- * @}
- */
-
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_DEVICE_MODULE
- * @{
- */
-
-/**
- * @brief Device type.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMPANION_DEVICE_TYPE_ERROR = 0, /**< Error */
-       COMPANION_DEVICE_TYPE_LOCAL = 1, /**< Local device */
-       COMPANION_DEVICE_TYPE_REMOTE = 2, /**< Remote device */
-} companion_device_type_e;
-
-/**
- * @brief Device Status.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMPANION_DEVICE_ADDED = 0, /**< Device Added */
-       COMPANION_DEVICE_REMOVED = 1, /**< Device Removed */
-} companion_device_status_e;
-
-/**
- * @brief Called after companion_device_find().
- * @details This function can receive a device found.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a device should not be released.
- * @remarks The @a device can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] device Device found
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_device_find()
- *
- * @see companion_device_find()
- */
-typedef bool (*companion_device_found_cb)(companion_device_h device, void *user_data);
-
-/**
- * @brief Called after companion_device_find() finished.
- * @details Called when the maximum wait time elapsed after the companion_device_find() done.
- *
- * @since_tizen 5.0
-  * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[out] result Result of operation
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_device_find()
- *
- * @see companion_device_find()
- */
-typedef void (*companion_device_find_finish_cb)(int result, void *user_data);
-
-
-/**
- * @brief Called after companion_device_send_data().
- * @details Called when the maximum wait time elapsed or after the companion_device_send_data()
- * finished successfully.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a resp_data should not be released.
- * @remarks The @a resp_data can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] result Result of operation
- * @param[out] resp_data Retrieved data
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_device_send_data()
- *
- * @see companion_device_send_data()
- */
-typedef void (*companion_device_send_data_finish_cb)(int result, char *resp_data,
-               void *user_data);
-
-/**
- * @brief Callback function pointer to be regsitered after enabling device
- * monitor
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a uuid, @arg should not be released.
- * @remarks The @a uuid, @arg can be used only in the callback. To use outside, make a copy.
- * @remarks The @a group_name, @arg should not be released.
- * @remarks The @a group_name, @arg can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] uuid Device ID
- * @param[out] group_name Group name
- * @param[out] status Device Status
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_request_result_callback()
- *
- * @see companion_device_monitor_start()
- */
-typedef void (*companion_device_monitor_result_cb)(char *uuid, char *group_name,
-                                       companion_device_status_e status, void *user_data);
-
-/**
- * @brief Finds candidate devices to include my groups in the network.
- * @details This function will search for candidate devices that can be included in local group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- * @param[in] user_data User data poiter
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_get_found_devices()
- *
- */
-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);
-
-/**
- * @brief Gets a list of candidate devices to can be included my group.
- * @details This function retrieves a list of multiple owner enabled devices found.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] devices Device list
- * @param[in] count Number of devices
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_find_mowned_device()
- *
- */
-int companion_device_get_found_devices(companion_h handle,
-               companion_device_h **devices, int *count);
-
-/**
- * @brief Finds my owned devices in the network.
- * @details This function looks up devices on your network that are registered as multiple
- * owners.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- * @param[in] user_data User data poiter
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_get_found_mowned_devices()
- *
- */
-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);
-
-/**
- * @brief Gets a list of discovered owned devices.
- * @details This function retrieves a list of my owned devices found.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @param[in] handle The companion manager handle
- * @param[in] devices Device list
- * @param[in] count Number of devices
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_find_mowned_device()
- *
- */
-int companion_device_get_found_mowned_devices(companion_h handle,
-               companion_device_h **devices, int *count);
-
-/**
- * @brief Sends data to the remote device.
- * @details We can send data to devices included in group.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- * @param[in] finish_cb Callback to be called after companion_device_send_data() complete
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_request_result_callback()
- *
- */
-int companion_device_send_data(companion_h handle, companion_device_h device,
-                          unsigned char *data, int len,
-                          companion_device_send_data_finish_cb finish_cb, void *user_data);
-
-/**
- * @}
- */
-
-/**
- * @addtogroup CAPI_NETWORK_COMPANION_DEVICE_INFORMATION_MODULE
- * @{
- */
-
-/**
- * @brief Gets my local device ID.
- * @details This function returns current UUID of local device.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a uuid should not be released.
- * @remarks The @a uuid can be used only in the callback. To use outside, make a copy.
- *
- * @param[in] handle The companion manager handle
- * @param[out] uuid Local device UUID
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_get_my_device()
- *
- */
-
-int companion_device_information_get_my_uuid(companion_h handle, char **uuid);
-
-/**
- * @brief Gets my local device handle.
- * @details This function returns the local device information handle.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a target should be released using companion_device_information_destroy().
- *
- * @param[in] handle The companion manager handle
- * @param[in] device Local device handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #COMP_ERROR_NO_DATA No data
- *
- * @see companion_device_information_get_my_uuid()
- *
- */
-int companion_device_information_get_my_device(companion_h handle,
-               companion_device_h *device);
-
-/**
- * @brief Clones the device handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a target should be released using companion_device_information_destroy().
- *
- * @param[in] target Target device handle
- * @param[in] source Source device handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_create()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_ip()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_clone(companion_device_h target,
-               companion_device_h source);
-
-/**
- * @brief Destroys the device handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @param[in] device Device handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_create()
- * @see companion_device_information_clone()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_ip()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_destroy(companion_device_h device);
-
-/**
- * @brief Gets device ID of the device handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a device_id should be released using free().
- *
- * @param[in] device Device handle
- * @param[out] device_id Device ID
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_create()
- * @see companion_device_information_clone()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_ip()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_get_device_id(companion_device_h device,
-               char **device_id);
-
-/**
- * @brief Gets IP of the device handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a ip should be released using free().
- *
- * @param[in] device Device handle
- * @param[out] ip IP address
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_create()
- * @see companion_device_information_clone()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_get_ip(companion_device_h device, char **ip);
-
-/**
- * @brief Gets device type of the device handle.
- *
- * @since_tizen 5.0
- * @privlevel public
- *
- * @remarks The @a device_type should be released using free().
- *
- * @param[in] device Device handle
- * @param[out] device_type Device type
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_create()
- * @see companion_device_information_clone()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_ip()
- *
- */
-int companion_device_information_get_device_type(companion_device_h device,
-               companion_device_type_e *device_type);
-
-int companion_device_information_get_model_name(companion_device_h device,
-               char **model_name);
-
-int companion_device_monitor_start(companion_h handle,
-                                         companion_device_monitor_result_cb cb, void *user_data);
-
-int companion_device_monitor_stop(companion_h handle);
-
-/**
- * @}
- */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_NETWORK_COMPANION_H__ */
diff --git a/capi/include/companion_internal.h b/capi/include/companion_internal.h
deleted file mode 100644 (file)
index 05b0e93..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Network Configuration Module
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __TIZEN_NETWORK_COMPANION_INTERNAL_H__
-#define __TIZEN_NETWORK_COMPANION_INTERNAL_H__
-
-#include <companion.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Creates a group handle.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a group should be released using companion_group_information_destroy().
- *
- * @param[in] group Group handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_create(companion_group_h* group);
-
-
-/**
- * @brief Creates a device handle.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a device should be released using companion_device_information_destroy().
- *
- * @param[out] device Device handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_clone()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_ip()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_create(companion_device_h* device);
-
-/**
- * @brief Combines both groups to one.
- * @details This function combines two groups into one.
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @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
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_create()
- * @see companion_request_join_group()
- * @see companion_request_leave_group ()
- * @see companion_group_delete()
- * @see companion_group_get_member_devices()
- *
- */
-int companion_group_merge(companion_h handle, companion_group_h dest_group,
-               companion_group_h src_group);
-
-
-/**
- * @brief Registers request result callback funtion.
- * @details This function registers the callback function for requested group management
- * functions and receive processing results after the request complete.
- *
- * @since_tizen 5.0
- *
- * @param[in] handle The companion manager handle
- * @param[in] callback Callback function pointer
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_device_send_data()
- *
- */
-int companion_request_result_callback(companion_h handle,
-               companion_request_result_cb callback, void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_NETWORK_COMPANION_INTERNAL_H__ */
diff --git a/capi/include/mdg.h b/capi/include/mdg.h
new file mode 100644 (file)
index 0000000..140957d
--- /dev/null
@@ -0,0 +1,1340 @@
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__
+#define __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file mdg.h
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_MODULE
+ * @{
+ */
+
+/**
+ * @brief The mdg-manager handle.
+ * @since_tizen 5.0
+ */
+typedef void *mdg_h;
+
+/**
+ * @brief Base error codes for cmdgd.
+ *
+ * @since_tizen 5.0
+ */
+#ifndef TIZEN_ERROR_COMP
+#define TIZEN_ERROR_COMP -0x02F50000 /**< Base error code */
+#endif
+
+/**
+ * @brief Error codes for cmdgd.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDG_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+       MDG_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+       MDG_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       MDG_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+       MDG_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       MDG_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+       MDG_ERROR_COMM_ERROR = TIZEN_ERROR_COMP | 0x01, /**< communication error */
+       MDG_ERROR_RX = TIZEN_ERROR_COMP | 0x02, /**< RX error */
+       MDG_ERROR_TX = TIZEN_ERROR_COMP | 0x03, /**< TX error */
+       MDG_ERROR_OPERATION_FAILED = TIZEN_ERROR_COMP | 0x04, /**< Operation Failed */
+       MDG_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x05, /**< Operation now in progress */
+       MDG_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */
+       MDG_ERROR_NO_DATA = TIZEN_ERROR_COMP | 0x07, /**< No Data */
+       MDG_ERROR_NOT_STARTED = TIZEN_ERROR_COMP | 0x08, /**< Not Started */
+       MDG_ERROR_UNKNOWN = -999,
+} mdg_error_e;
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_DEVICE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Device handle.
+ *
+ * @since_tizen 5.0
+ */
+typedef void *mdg_device_h; /**< Device handle */
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_GROUP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Group hande.
+ *
+ * @since_tizen 5.0
+ */
+typedef void *mdg_group_h; /**< Group handle */
+
+/**
+ * @}
+ */
+
+/**
+ * @brief Initializes cmdgd.
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks You must release @a handle using mdg_deinitialize().
+ *
+ * @param[out] handle The multi device group manager handle
+ *
+ * @return @c 0 on success, otherwise negative error value
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_ALREADY_INITIALIZED Already initialized
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MDG_ERROR_OPERATION_FAILED Operation failed
+ * @retval #MDG_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int mdg_initialize(mdg_h *handle);
+
+/**
+ * @brief Deinitializes the cmdgd.
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ *
+ * @return 0 on success, otherwise negative error value
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MDG_ERROR_OPERATION_FAILED Operation failed
+ */
+int mdg_deinitialize(mdg_h handle);
+
+/**
+ * @}
+ */
+
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_GROUP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Group type.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDG_GROUP_TYPE_ERROR = 0, /**< Error */
+       MDG_GROUP_TYPE_MINE = 1, /**< Local group */
+       MDG_GROUP_TYPE_REMOTE = 2, /**< Remote grojp */
+} mdg_group_type_e;
+
+/**
+ * @brief Called after mdg_group_find().
+ * @details This function can receive a group resource found.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a group should not be released.
+ * @remarks The @a group can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] type Companion group type
+ * @param[out] group Group resource found
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_group_find()
+ *
+ * @see mdg_group_find()
+ */
+typedef bool (*mdg_group_found_cb)(mdg_group_type_e type,
+               mdg_group_h group, void *user_data);
+
+/**
+ * @brief Called after mdg_group_find() finished.
+ * @details Called when the maximum wait time elapsed after the mdg_group_find() done.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[out] result Result of operation
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_group_find()
+ *
+ * @see mdg_group_find()
+ */
+typedef void (*mdg_group_find_finish_cb)(int result, void *user_data);
+
+/**
+ * @brief Finds group resources in local and the network.
+ * @details This function is find group resources in the network plus my local network.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group 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
+ * @param[in] user_data User data poiter
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_group_get_found_groups()
+ *
+ */
+int mdg_group_find(mdg_h handle, int timeout,
+               mdg_group_found_cb found_cb, mdg_group_find_finish_cb finish_cb,
+               void *user_data);
+
+/**
+ * @brief Gets a list of group resources.
+ * @details This function retrieves a list of group resources found.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] groups Group resource list
+ * @param[out] count Number of groups
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_group_find()
+ *
+ */
+int mdg_group_get_found_groups(mdg_h handle,
+               mdg_group_h **groups, int *count);
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_LOCAL_GROUP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a group.
+ * @details This function is to allocate new group in local cmdgd.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group_name Group name
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_find()
+ * @see mdg_group_get_found_groups()
+ *
+ */
+int mdg_group_create(mdg_h handle, char *group_name);
+
+/**
+ * @brief Deletes the group.
+ * @details This function deletes a specific group and expels all devices in that group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_request_join_group()
+ * @see mdg_request_leave_group ()
+ * @see mdg_group_merge()
+ * @see mdg_group_get_member_devices()
+ *
+ */
+int mdg_group_delete(mdg_h handle, mdg_group_h group);
+
+/**
+ * @brief Gets devices list in a group resource.
+ * @details This function retrieves a devices list of group resources.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a devices should be released using mdg_device_info_destroy().
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group resource list
+ * @param[out] devices Device list
+ * @param[out] count Number of devices in a group
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_request_join_group()
+ * @see mdg_request_leave_group ()
+ * @see mdg_group_delete()
+ * @see mdg_group_merge()
+ *
+ */
+int mdg_group_get_member_devices(mdg_h handle,
+               mdg_group_h group, mdg_device_h **devices, int *count);
+
+/**
+ * @brief Called after mdg_group_invite_device().
+ * @details Called when the maximum wait time elapsed or after the mdg_group_invite_device()
+ * finished successfully.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[out] result Result of operation
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_group_invite_device()
+ *
+ * @see mdg_group_invite_device()
+ */
+typedef void (*mdg_group_invite_device_result_cb)(int result, void *user_data);
+
+/**
+ * @brief Called after mdg_group_eject_device().
+ * @details Called when the maximum wait time elapsed or after the mdg_device_eject()
+ * finished successfully.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[out] result Result of operation
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_device_eject()
+ *
+ * @see mdg_group_ejecct_device()
+ */
+typedef void (*mdg_group_eject_device_result_cb)(int result, void *user_data);
+
+/**
+ * @brief Requests to invite a device to the group which local device owns.
+ * @details This function invites a remote device to a specific group. At the time of invitation,
+ * user can enter the authentication information (i.e., PIN) or use the certificate.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] device Device handle
+ * @param[in] PIN PIN number
+ * @param[in] callback Callback handler to receive the result
+ * @param[in] user_data User data poiter
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_group_invite_device(mdg_h handle, mdg_group_h group,
+               mdg_device_h device, char *PIN,
+               mdg_group_invite_device_result_cb callback, void *user_data);
+
+/**
+ * @brief Requests to expel the device from the group which local device owns.
+ * @details This function is used to kick away a remote devices in my local group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] device Device handle
+ * @param[in] callback Callback handler to receive the result
+ * @param[in] user_data User data poiter
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_group_eject_device(mdg_h handle, mdg_group_h group,
+               mdg_device_h device, mdg_group_eject_device_result_cb callback,
+               void *user_data);
+
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_REMOTE_GROUP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Callback function potiner to be regsitered after sending requests.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a cmd, @arg should not be released.
+ * @remarks The @a cmd, @arg can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] cmd Command
+ * @param[out] device_id Device id of requester
+ * @param[out] arg Argument
+ * @param[out] ret Return code
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_request_result_callback()
+ *
+ * @see mdg_request_result_callback()
+ */
+typedef void (*mdg_request_result_cb)(char *cmd, char *device_id,
+                                       unsigned char *arg, int len, int ret, void *user_data);
+
+/**
+ * @brief Requests my device to be joined to remote group.
+ * @details This function requests a remote groups to join my device in the remote groups.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group resource list
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_request_leave_group ()
+ * @see mdg_request_create_group()
+ * @see mdg_request_invite_device()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ *
+ */
+int mdg_request_join_group(mdg_h handle, mdg_group_h group,
+               mdg_request_result_cb cb, void *user_data);
+
+/**
+ * @brief Requests my device to be exit from remote group.
+ * @details This function requests remote groups to exit my devices that belonged to the
+ * remote group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_request_join_group()
+ * @see mdg_group_delete()
+ * @see mdg_group_merge()
+ * @see mdg_group_get_member_devices()
+ *
+ */
+int mdg_request_leave_group (mdg_h handle, mdg_group_h group,
+               mdg_request_result_cb cb, void *user_data);
+
+/**
+ * @brief Requests to create a group.
+ * @details We can create a group. This generated group can include device, and remote
+ * devices can inquire remotely group information and device information included in group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] device Device handle
+ * @param[in] group_name Group name
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_invite_device()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_request_create_group(mdg_h handle,
+       mdg_device_h device, char *group_name, mdg_request_result_cb cb,
+       void *user_data);
+
+/**
+ * @brief Requests to invite a device to the group.
+ * @details This function invites a remote device to a specific group. At the time of
+ * invitation, user can enter the authentication information (i.e., PIN) or use the
+ * certificate.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] device Device handle
+ * @param[in] PIN PIN number
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_request_invite_device(mdg_h handle, mdg_group_h group,
+               mdg_device_h device, char *PIN, mdg_request_result_cb cb,
+               void *user_data);
+
+/**
+ * @brief Requests to eject a device.
+ * @details This function is used to kick away a remote devices in a specific group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] device Device handle
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_request_eject_device(mdg_h handle, mdg_group_h group,
+       mdg_device_h device, mdg_request_result_cb cb, void *user_data);
+
+/**
+ * @brief Requests to delete the group.
+ * @details This function deletes a specific group and expels all devices in that group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] group Group handle
+ * @param[in] cb Callback handler to receive the result
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_invite_device()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_result_callback()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_request_delete_group(mdg_h handle, mdg_group_h group,
+               mdg_request_result_cb cb, void *user_data);
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_GROUP_INFORMATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Clones the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a dst should be released using mdg_group_info_destroy().
+ *
+ * @param[out] dst Destination group handle
+ * @param[in] src Source group handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_clone(mdg_group_h dst,
+               mdg_group_h src);
+
+/**
+ * @brief Destroys the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @param[in] group Group handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_destroy(mdg_group_h group);
+
+/**
+ * @brief Gets group type of the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @param[in] group Group handle
+ * @param[out] type Group type
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_get_type(mdg_group_h group,
+               mdg_group_type_e *type);
+
+/**
+ * @brief Gets resource type of the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a resource_type should be released using free().
+ *
+ * @param[in] group Group handle
+ * @param[out] resource_type Resource type
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_get_resource_type(
+               mdg_group_h group, char **resource_type);
+
+/**
+ * @brief Gets URI path of the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a uri_path should be released using free().
+ *
+ * @param[in] group Group handle
+ * @param[out] uri_path URI path
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_get_uri_path(mdg_group_h group,
+               char **uri_path);
+
+/**
+ * @brief Gets name of the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a name should be released using free().
+ *
+ * @param[in] group Group handle
+ * @param[out] name Name of the group
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_get_name(mdg_group_h group,
+               char **name);
+
+/**
+ * @brief Gets host address of the group handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a host_addr should be released using free().
+ *
+ * @param[in] group Group handle
+ * @param[out] host_addr Host address of the group
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_create()
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_uri_path()
+ *
+ */
+int mdg_group_info_get_host_addr(mdg_group_h group,
+               char **host_addr);
+
+/**
+ * @}
+ */
+
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_DEVICE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Device type.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDG_DEVICE_TYPE_ERROR = 0, /**< Error */
+       MDG_DEVICE_TYPE_LOCAL = 1, /**< Local device */
+       MDG_DEVICE_TYPE_REMOTE = 2, /**< Remote device */
+} mdg_device_type_e;
+
+/**
+ * @brief Device Status.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDG_DEVICE_ADDED = 0, /**< Device Added */
+       MDG_DEVICE_REMOVED = 1, /**< Device Removed */
+} mdg_device_status_e;
+
+
+/**
+ * @brief Called after mdg_device_find().
+ * @details This function can receive a device found.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a device should not be released.
+ * @remarks The @a device can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] device Device found
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_device_find()
+ *
+ * @see mdg_device_find()
+ */
+typedef bool (*mdg_device_found_cb)(mdg_device_h device, void *user_data);
+
+/**
+ * @brief Called after mdg_device_find() finished.
+ * @details Called when the maximum wait time elapsed after the mdg_device_find() done.
+ *
+ * @since_tizen 5.0
+  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[out] result Result of operation
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_device_find()
+ *
+ * @see mdg_device_find()
+ */
+typedef void (*mdg_device_find_finish_cb)(int result, void *user_data);
+
+
+/**
+ * @brief Called after mdg_device_send_data().
+ * @details Called when the maximum wait time elapsed or after the mdg_device_send_data()
+ * finished successfully.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a resp_data should not be released.
+ * @remarks The @a resp_data can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] result Result of operation
+ * @param[out] resp_data Retrieved data
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_device_send_data()
+ *
+ * @see mdg_device_send_data()
+ */
+typedef void (*mdg_device_send_data_finish_cb)(int result, char *resp_data,
+               void *user_data);
+
+/**
+ * @brief Callback function pointer to be regsitered after enabling device
+ * monitor
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a uuid, @arg should not be released.
+ * @remarks The @a uuid, @arg can be used only in the callback. To use outside, make a copy.
+ * @remarks The @a group_name, @arg should not be released.
+ * @remarks The @a group_name, @arg can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] uuid Device ID
+ * @param[out] group_name Group name
+ * @param[out] status Device Status
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with mdg_request_result_callback()
+ *
+ * @see mdg_device_monitor_start()
+ */
+typedef void (*mdg_device_monitor_result_cb)(char *uuid, char *group_name,
+                                       mdg_device_status_e status, void *user_data);
+
+
+/**
+ * @brief Finds candidate devices to include my groups in the network.
+ * @details This function will search for candidate devices that can be included in local group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group 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
+ * @param[in] user_data User data poiter
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_get_found_devices()
+ *
+ */
+int mdg_device_find(mdg_h handle, int timeout,
+               mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb,
+               void *user_data);
+
+/**
+ * @brief Gets a list of candidate devices to can be included my group.
+ * @details This function retrieves a list of multiple owner enabled devices found.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] devices Device list
+ * @param[in] count Number of devices
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_find_mowned_device()
+ *
+ */
+int mdg_device_get_found_devices(mdg_h handle,
+               mdg_device_h **devices, int *count);
+
+/**
+ * @brief Finds my owned devices in the network.
+ * @details This function looks up devices on your network that are registered as multiple
+ * owners.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group 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
+ * @param[in] user_data User data poiter
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_get_found_mowned_devices()
+ *
+ */
+int mdg_device_find_mowned_device(mdg_h handle, int timeout,
+               mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb,
+               void *user_data);
+
+/**
+ * @brief Gets a list of discovered owned devices.
+ * @details This function retrieves a list of my owned devices found.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] devices Device list
+ * @param[in] count Number of devices
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_find_mowned_device()
+ *
+ */
+int mdg_device_get_found_mowned_devices(mdg_h handle,
+               mdg_device_h **devices, int *count);
+
+/**
+ * @brief Sends data to the remote device.
+ * @details We can send data to devices included in group.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] device Device handle
+ * @param[in] data Data to send
+ * @param[in] len What length to send
+ * @param[in] finish_cb Callback to be called after mdg_device_send_data() complete
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_invite_device()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_request_result_callback()
+ *
+ */
+int mdg_device_send_data(mdg_h handle, mdg_device_h device,
+                          unsigned char *data, int len,
+                          mdg_device_send_data_finish_cb finish_cb, void *user_data);
+
+/**
+ * @brief Starts monitoring peers in the network.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] cb Callback to be called when receiving keep alive message from peers
+ * @param[in] user_data User data pointer
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_monitor_stop()
+ *
+ */
+int mdg_device_monitor_start(mdg_h handle, mdg_device_monitor_result_cb cb,
+               void *user_data);
+
+/**
+ * @brief Stops monitoring peers in the network.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_monitor_start()
+ *
+ */
+int mdg_device_monitor_stop(mdg_h handle);
+
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_NETWORK_MDG_DEVICE_INFORMATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets my local device ID.
+ * @details This function returns current UUID of local device.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a uuid should not be released.
+ * @remarks The @a uuid can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[out] uuid Local device UUID
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_get_my_device()
+ *
+ */
+
+int mdg_device_info_get_my_uuid(mdg_h handle, char **uuid);
+
+/**
+ * @brief Gets my local device handle.
+ * @details This function returns the local device information handle.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a target should be released using mdg_device_info_destroy().
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] device Local device handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MDG_ERROR_NO_DATA No data
+ *
+ * @see mdg_device_info_get_my_uuid()
+ *
+ */
+int mdg_device_info_get_my_device(mdg_h handle,
+               mdg_device_h *device);
+
+/**
+ * @brief Clones the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a target should be released using mdg_device_info_destroy().
+ *
+ * @param[in] target Target device handle
+ * @param[in] source Source device handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_device_type()
+ * @see mdg_device_info_get_model_name()
+ *
+ */
+int mdg_device_info_clone(mdg_device_h target,
+               mdg_device_h source);
+
+/**
+ * @brief Destroys the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @param[in] device Device handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_device_type()
+ * @see mdg_device_info_get_model_name()
+ *
+ */
+int mdg_device_info_destroy(mdg_device_h device);
+
+/**
+ * @brief Gets device ID of the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a device_id should be released using free().
+ *
+ * @param[in] device Device handle
+ * @param[out] device_id Device ID
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_device_type()
+ * @see mdg_device_info_get_model_name()
+ *
+ */
+int mdg_device_info_get_device_id(mdg_device_h device,
+               char **device_id);
+
+/**
+ * @brief Gets IP of the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a ip should be released using free().
+ *
+ * @param[in] device Device handle
+ * @param[out] ip IP address
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_device_type()
+ * @see mdg_device_info_get_model_name()
+ *
+ */
+int mdg_device_info_get_ip(mdg_device_h device, char **ip);
+
+/**
+ * @brief Gets device type of the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a device_type should be released using free().
+ *
+ * @param[in] device Device handle
+ * @param[out] device_type Device type
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_model_name()
+ *
+ */
+int mdg_device_info_get_device_type(mdg_device_h device,
+               mdg_device_type_e *device_type);
+
+/**
+ * @brief Gets model name of the device handle.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ *
+ * @remarks The @a model_name should be released using free().
+ *
+ * @param[in] device Device handle
+ * @param[out] model_name Model name
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_create()
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_device_type()
+ *
+ */
+int mdg_device_info_get_model_name(mdg_device_h device,
+               char **model_name);
+
+/**
+ * @}
+ */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__ */
diff --git a/capi/include/mdg_internal.h b/capi/include/mdg_internal.h
new file mode 100644 (file)
index 0000000..42266b7
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __TIZEN_NETWORK_MDG_INTERNAL_H__
+#define __TIZEN_NETWORK_MDG_INTERNAL_H__
+
+#include <mdg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Creates a group handle.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a group should be released using mdg_group_info_destroy().
+ *
+ * @param[in] group Group handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_info_clone()
+ * @see mdg_group_info_destroy()
+ * @see mdg_group_info_get_type()
+ * @see mdg_group_info_get_resource_type()
+ * @see mdg_group_info_get_uri_path()
+ * @see mdg_group_info_get_name()
+ * @see mdg_group_info_get_host_addr()
+ *
+ */
+int mdg_group_info_create(mdg_group_h* group);
+
+
+/**
+ * @brief Creates a device handle.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a device should be released using mdg_device_info_destroy().
+ *
+ * @param[out] device Device handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_device_info_clone()
+ * @see mdg_device_info_destroy()
+ * @see mdg_device_info_get_device_id()
+ * @see mdg_device_info_get_ip()
+ * @see mdg_device_info_get_device_type()
+ *
+ */
+int mdg_device_info_create(mdg_device_h* device);
+
+/**
+ * @brief Combines both groups to one.
+ * @details This function combines two groups into one.
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] dest_group Group handle to be united
+ * @param[in] src_group Group handle to be merged
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_group_create()
+ * @see mdg_request_join_group()
+ * @see mdg_request_leave_group ()
+ * @see mdg_group_delete()
+ * @see mdg_group_get_member_devices()
+ *
+ */
+int mdg_group_merge(mdg_h handle, mdg_group_h dest_group,
+               mdg_group_h src_group);
+
+
+/**
+ * @brief Registers request result callback funtion.
+ * @details This function registers the callback function for requested group management
+ * functions and receive processing results after the request complete.
+ *
+ * @since_tizen 5.0
+ *
+ * @param[in] handle The multi device group manager handle
+ * @param[in] callback Callback function pointer
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MDG_ERROR_NONE Successful
+ * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mdg_request_create_group()
+ * @see mdg_request_invite_device()
+ * @see mdg_request_eject_device()
+ * @see mdg_request_delete_group()
+ * @see mdg_device_send_data()
+ *
+ */
+int mdg_request_result_callback(mdg_h handle,
+               mdg_request_result_cb callback, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_NETWORK_MDG_INTERNAL_H__ */
diff --git a/capi/src/companion.c b/capi/src/companion.c
deleted file mode 100644 (file)
index c72089c..0000000
+++ /dev/null
@@ -1,1173 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <dlog.h>
-#include <companion.h>
-#include <companion_util.h>
-#include <companion_dbus.h>
-#include <companion_debug.h>
-#include <companion_gdbus.h>
-#include <companion_private.h>
-
-/**
- * Companion Manager CAPI
- */
-
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for dbus */
-
-#define COMPANION_LOCK \
-do { \
-       pthread_mutex_lock(&mutex); \
-} while (0);
-
-#define COMPANION_UNLOCK \
-do { \
-       pthread_mutex_unlock(&mutex); \
-} while (0);
-
-int ref_count = 0; /**< How many clients are alive */
-bool __is_initialized = false; /**< Initialize or not */
-
-EXPORT_API int companion_initialize(companion_h *handle)
-{
-       int ret = COMP_ERROR_NONE;
-       struct comp_manager_s *comp_manager = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       _BEGIN();
-
-       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) {
-               /* LCOV_EXCL_START */
-               _DBG("Already initialized");
-               return COMP_ERROR_ALREADY_INITIALIZED;
-               /* LCOV_EXCL_STOP */
-       }
-
-       COMPANION_LOCK;
-       ret = gdbus_initialize(*handle);
-       __is_initialized = true;
-       COMPANION_UNLOCK;
-       ref_count++;
-
-       _END();
-
-       return ret;
-}
-
-EXPORT_API int companion_deinitialize(companion_h handle)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       _BEGIN();
-
-       COMPANION_LOCK;
-
-       if (0 > --ref_count) {
-               /* LCOV_EXCL_START */
-               _DBG("all connections closed\n");
-               ref_count = 0;
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (__is_initialized == true && ref_count == 0) {
-               ret = gdbus_deinitialize(handle);
-               __is_initialized = false;
-       }
-
-       COMPANION_UNLOCK;
-
-       _END();
-
-       return ret;
-
-}
-
-EXPORT_API int companion_group_create(companion_h handle, char *group_name)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       /* create group to daemon using gdbus */
-       group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error);
-
-       return ret;
-}
-
-EXPORT_API void companion_group_destroy(companion_group_s *group)
-{
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_check_null_ret("group", group);
-
-       if (group->uri_path) {
-               g_free(group->uri_path);
-               group->uri_path = NULL;
-       }
-       if (group->device_id) {
-               g_free(group->device_id);
-               group->device_id = NULL;
-       }
-       if (group->group_name) {
-               g_free(group->group_name);
-               group->group_name = NULL;
-       }
-       if (group->host_addr) {
-               g_free(group->host_addr);
-               group->host_addr = NULL;
-       }
-       if (group->resource_type) {
-               g_free(group->resource_type);
-               group->resource_type = NULL;
-       }
-       g_free(group);
-       group = NULL;
-}
-
-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 = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, 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(_handle->group_proxy, timeout, &ret, NULL, &error);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_get_found_groups(companion_h handle,
-       companion_group_h **groups, int *count)
-{
-       int ret = COMP_ERROR_NONE;
-       GVariant *va = NULL;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       /* get groups from daemon using gdbus */
-       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);
-
-       /* LCOV_EXCL_START */
-       if (*count > 0) {
-               GVariantIter *iter = NULL, *iter_row = NULL;
-               GVariant *key_value;
-               const gchar *key;
-               guint i = 0;
-
-               *groups = g_new0(companion_group_h, *count);
-
-               g_variant_get(va, "aa{sv}", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-
-                       char *uri_path = NULL;
-                       char *device_id = NULL;
-                       char *group_name = NULL;
-                       char *host_addr = NULL;
-                       char *resource_type = NULL;
-
-                       companion_group_s *group = NULL;
-                       companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
-                               if (g_strcmp0(key, "URI") == 0)
-                                       uri_path = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "DeviceID") == 0)
-                                       device_id = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "GroupName") == 0)
-                                       group_name = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "HostAddress") == 0)
-                                       host_addr = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "GroupDeviceType") == 0)
-                                       resource_type = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "GroupType") == 0)
-                                       type = g_variant_get_int32(key_value);
-                       }
-                       g_variant_iter_free(iter_row);
-
-                       _INFO("DeviceID %s GroupName %s HostAddress %s GroupDeviceType %s",
-                                 device_id, group_name, host_addr, resource_type);
-
-                       group = create_group_handle(uri_path,
-                               device_id, group_name, host_addr, resource_type, type);
-
-                       (*groups)[i++] = (companion_group_h)group;
-               }
-               g_variant_iter_free(iter);
-       }
-       /* LCOV_EXCL_STOP */
-       g_variant_unref(va);
-
-       return ret;
-}
-
-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 = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, 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(_handle->group_proxy, timeout, &ret, NULL, &error);
-
-       return ret;
-}
-
-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 = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       _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(_handle->group_proxy, timeout, &ret, NULL, &error);
-
-       return ret;
-}
-
-EXPORT_API int companion_device_send_data(companion_h handle,
-       companion_device_h device, unsigned char *data, int len,
-       companion_device_send_data_finish_cb finish_cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-       unsigned char *buf = NULL;
-       GVariantBuilder *bytearray_builder = NULL;
-       int i;
-       GVariant *params = NULL;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
-
-       buf = g_try_malloc0(len + 1);
-       if (NULL == buf) {
-               /* LCOV_EXCL_START */
-               _ERR("g_malloc0 is failed");
-               return COMP_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-       memcpy(buf, data, len);
-
-       bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-       for (i = 0; i < len; i++)
-               g_variant_builder_add(bytearray_builder, "y", buf[i]);
-
-       params = g_variant_new("(iay)", len, bytearray_builder);
-       g_variant_builder_unref(bytearray_builder);
-
-       _handle->send_data_finish_cb.finish_cb = finish_cb;
-       _handle->send_data_finish_cb.user_data = user_data;
-
-       group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->ip,
-                                                         dev->sec_port, params, &ret, NULL, &error);
-
-       g_free(buf);
-       buf = NULL;
-
-       return ret;
-}
-
-/* companion_request_join_group : 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_h handle,
-       companion_device_h **devices, int *count)
-{
-       int ret = COMP_ERROR_NONE;
-       int num = 0;
-       GVariant *va = NULL;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       /* get groups from daemon using gdbus */
-       group_call_get_remote_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
-       /* *count = g_variant_n_children(va); */
-       *count = num;
-
-       _DBG("get found devices : %d", *count);
-       /* LCOV_EXCL_START */
-       if (*count > 0) {
-               GVariantIter *iter = NULL, *iter_row = NULL;
-               GVariant *key_value;
-               const gchar *key;
-               guint i = 0;
-
-               *devices = g_new0(companion_group_h, *count);
-
-               g_variant_get(va, "aa{sv}", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-                       char *deviceid = NULL;
-                       char *addr = NULL;
-                       int device_type = COMPANION_DEVICE_TYPE_ERROR;
-                       int port;
-                       int sec_port;
-                       companion_device_s *device = NULL;
-                       char *model_name = NULL;
-                       char *device_name = NULL;
-                       char *platform_ver = NULL;
-                       char *vendor_id = NULL;
-                       char *profile = NULL;
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
-                               if (g_strcmp0(key, "DeviceID") == 0)
-                                       deviceid = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "Address") == 0)
-                                       addr = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "DeviceType") == 0)
-                                       device_type = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "Port") == 0)
-                                       port = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "SecurePort") == 0)
-                                       sec_port = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "ModelName") == 0)
-                                       model_name = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "DeviceName") == 0)
-                                       device_name = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "PlatformVer") == 0)
-                                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "VendorID") == 0)
-                                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "Profile") == 0)
-                                       profile = (char *)g_variant_get_string(key_value, NULL);
-                       }
-                       g_variant_iter_free(iter_row);
-
-                       device = create_device_handle(deviceid, addr, device_type, port, sec_port,
-                               model_name, device_name, platform_ver, vendor_id, profile);
-
-                       (*devices)[i++] = (companion_device_h)device;
-               }
-               g_variant_iter_free(iter);
-       }
-       /* LCOV_EXCL_STOP */
-       g_variant_unref(va);
-
-       return ret;
-}
-
-EXPORT_API int companion_device_get_found_mowned_devices(
-       companion_h handle, companion_device_h **devices, int *count)
-{
-       int ret = COMP_ERROR_NONE;
-       int num = 0;
-       GVariant *va = NULL;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       /* get groups from daemon using gdbus */
-       group_call_get_mowned_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
-       /* *count = g_variant_n_children(va); */
-       *count = num;
-
-       _INFO("get found mowned devices : %d", *count);
-
-       /* LCOV_EXCL_START */
-       if (*count > 0) {
-               GVariantIter *iter = NULL, *iter_row = NULL;
-               GVariant *key_value;
-               const gchar *key;
-               guint i = 0;
-
-               *devices = g_new0(companion_device_h, *count);
-
-               g_variant_get(va, "aa{sv}", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-                       char *deviceid = NULL;
-                       char *addr = NULL;
-                       int device_type = COMPANION_DEVICE_TYPE_ERROR;
-                       int port;
-                       int sec_port;
-                       companion_device_s *device = NULL;
-                       char *model_name = NULL;
-                       char *device_name = NULL;
-                       char *platform_ver = NULL;
-                       char *vendor_id = NULL;
-                       char *profile = NULL;
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
-                               if (g_strcmp0(key, "DeviceID") == 0)
-                                       deviceid = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "Address") == 0)
-                                       addr = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "DeviceType") == 0)
-                                       device_type = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "Port") == 0)
-                                       port = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "SecurePort") == 0)
-                                       sec_port = g_variant_get_uint16(key_value);
-                               else if (g_strcmp0(key, "ModelName") == 0)
-                                       model_name = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "DeviceName") == 0)
-                                       device_name = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "PlatformVer") == 0)
-                                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "VendorID") == 0)
-                                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
-                               else if (g_strcmp0(key, "Profile") == 0)
-                                       profile = (char *)g_variant_get_string(key_value, NULL);
-                       }
-                       g_variant_iter_free(iter_row);
-
-                       device = create_device_handle(deviceid, addr, device_type, port, sec_port,
-                               model_name, device_name, platform_ver, vendor_id, profile);
-
-                       (*devices)[i++] = (companion_device_h)device;
-               }
-               g_variant_iter_free(iter);
-       }
-       /* LCOV_EXCL_STOP */
-       g_variant_unref(va);
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_get_my_uuid(companion_h handle, char **uuid)
-{
-       int ret = 0;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       group_call_get_my_uuid_sync(_handle->group_proxy, uuid, NULL, &error);
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_get_my_device(companion_h handle,
-       companion_device_h *device)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-       GVariant *va = NULL;
-       GVariantIter *iter = NULL;
-       const gchar *key;
-       GVariant *key_value = NULL;
-       char *deviceid = NULL;
-       char *addr = NULL;
-       int device_type = COMPANION_DEVICE_TYPE_ERROR;
-       int port = -1;
-       int sec_port = -1;
-       char *model_name = NULL;
-       char *device_name = NULL;
-       char *platform_ver = NULL;
-       char *vendor_id = NULL;
-       char *profile = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       group_call_get_my_mowned_device_sync(_handle->group_proxy, &va, NULL, &error);
-
-       g_variant_get(va, "a{sv}", &iter);
-       /* LCOV_EXCL_START */
-       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
-               if (g_strcmp0(key, "DeviceID") == 0)
-                       deviceid = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "Address") == 0)
-                       addr = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "DeviceType") == 0)
-                       device_type = g_variant_get_uint16(key_value);
-               else if (g_strcmp0(key, "Port") == 0)
-                       port = g_variant_get_uint16(key_value);
-               else if (g_strcmp0(key, "SecurePort") == 0)
-                       sec_port = g_variant_get_uint16(key_value);
-               else if (g_strcmp0(key, "ModelName") == 0)
-                       model_name = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "DeviceName") == 0)
-                       device_name = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "PlatformVer") == 0)
-                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "VendorID") == 0)
-                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "Profile") == 0)
-                       profile = (char *)g_variant_get_string(key_value, NULL);
-       }
-
-       if (deviceid == NULL || addr == NULL)
-               return COMP_ERROR_NO_DATA;
-       /* LCOV_EXCL_STOP */
-
-       *device = (companion_device_h)create_device_handle(deviceid, addr, device_type, port, sec_port,
-                               model_name, device_name, platform_ver, vendor_id, profile);
-
-       g_variant_iter_free(iter);
-
-       return ret;
-}
-
-/* group merge */
-EXPORT_API int companion_group_merge(companion_h hadnle,
-       companion_group_h dest_group, companion_group_h src_group)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(dest_group);
-       NOTUSED(src_group);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_delete(companion_h handle, companion_group_h group)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_get_member_devices(companion_h handle,
-       companion_group_h group, companion_device_h **devices, int *count)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(devices);
-       NOTUSED(count);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_invite_device(companion_h handle,
-       companion_group_h group, companion_device_h device, char *PIN,
-       companion_group_invite_device_result_cb result_cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_group_s *grp = (companion_group_s *)group;
-       companion_check_null_ret_error("grp", grp, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
-
-       _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_group_invite_device' 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(_handle->group_proxy, grp->group_name, dev->device_id, PIN,
-               &ret, NULL, &error);
-#endif
-
-       return ret;
-}
-
-EXPORT_API int companion_group_eject_device(companion_h handle,
-       companion_group_h group, companion_device_h device,
-       companion_group_eject_device_result_cb result_cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_group_s *grp = (companion_group_s *)group;
-       companion_check_null_ret_error("grp", grp, COMP_ERROR_INVALID_PARAMETER);
-
-       _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(_handle->group_proxy, grp->group_name, dev->device_id, &ret,
-               NULL, &error);
-#endif
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_create(companion_group_h* group)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_group_h _group = g_malloc0(sizeof(companion_group_s));
-       if (NULL == _group) {
-               /* LCOV_EXCL_START */
-               _ERR("Memory allocation Failed(%d)", errno);
-               return COMP_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-       *group = _group;
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_clone(companion_group_h target,
-       companion_group_h source)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_group_s * dst = (companion_group_s *)target;
-       companion_check_null_ret_error("target", target, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_group_s * src = (companion_group_s *)source;
-       companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
-
-       ret  = companion_group_information_create(&target);
-       if (COMP_ERROR_NONE != ret) {
-               /* LCOV_EXCL_START */
-               _ERR("companion_group_information_create() Failed(%d)", ret);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (src->uri_path)
-               dst->uri_path = g_strdup(src->uri_path);
-
-       if (src->device_id)
-               dst->device_id = g_strdup(src->device_id);
-
-       if (src->group_name)
-               dst->group_name = g_strdup(src->group_name);
-
-       if (src->host_addr)
-               dst->host_addr = g_strdup(src->host_addr);
-
-       if (src->resource_type)
-               dst->resource_type = g_strdup(src->resource_type);
-
-       dst->type = src->type;
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_destroy(companion_group_h data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_group_s * group = (companion_group_s *)data;
-       companion_check_null_ret_error("group", group, COMP_ERROR_INVALID_PARAMETER);
-
-       if (group->uri_path) {
-               g_free(group->uri_path);
-               group->uri_path = NULL;
-       }
-       if (group->device_id) {
-               g_free(group->device_id);
-               group->device_id = NULL;
-       }
-       if (group->group_name) {
-               g_free(group->group_name);
-               group->group_name = NULL;
-       }
-       if (group->host_addr) {
-               g_free((companion_group_s *)group->host_addr);
-               group->host_addr = NULL;
-       }
-       if (group->resource_type) {
-               g_free((companion_group_s *)group->resource_type);
-               group->resource_type = NULL;
-       }
-       g_free(group);
-       group = NULL;
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_get_type(companion_group_h group,
-       companion_group_type_e *type)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *type = ((companion_group_s *)group)->type;
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_get_resource_type(
-       companion_group_h group, char **resource_type)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *resource_type = g_strdup(((companion_group_s *)group)->resource_type);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_get_uri_path(
-       companion_group_h group, char **uri_path)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *uri_path = g_strdup(((companion_group_s *)group)->uri_path);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_get_name(
-       companion_group_h group, char **name)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *name = g_strdup(((companion_group_s *)group)->group_name);
-
-       return ret;
-}
-
-EXPORT_API int companion_group_information_get_host_addr
-       (companion_group_h group, char **host_addr)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *host_addr = g_strdup(((companion_group_s *)group)->host_addr);
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_create(companion_device_h* device)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_device_h _device = g_malloc0(sizeof(companion_device_s));
-       if (NULL == device) {
-               /* LCOV_EXCL_START */
-               _ERR("Memory allocation Failed(%d)", errno);
-               return COMP_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-       *device = _device;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_clone(companion_device_h target,
-       companion_device_h source)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_device_s * dst = (companion_device_s *)target;
-       companion_check_null_ret_error("target", target, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s * src = (companion_device_s *)source;
-       companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
-
-       ret  = companion_device_information_create(&target);
-       if (COMP_ERROR_NONE != ret) {
-               /* LCOV_EXCL_START */
-               _ERR("companion_device_information_create() Failed(%d)", ret);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (src->device_id)
-               dst->device_id = g_strdup(src->device_id);
-       if (src->ip)
-               dst->ip = g_strdup(src->ip);
-       if (src->device_type)
-               dst->device_type = src->device_type;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_destroy(companion_device_h data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       companion_device_s * device = (companion_device_s *)data;
-       companion_check_null_ret_error("data", data, COMP_ERROR_INVALID_PARAMETER);
-
-       if (device->device_id) {
-               g_free(device->device_id);
-               device->device_id = NULL;
-       }
-       if (device->ip) {
-               g_free(device->ip);
-               device->ip = NULL;
-       }
-
-       g_free(device);
-       device = NULL;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_get_device_id(
-       companion_device_h device, char **device_id)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *device_id = g_strdup(((companion_device_s *)device)->device_id);
-
-       return ret;
-
-}
-EXPORT_API int companion_device_information_get_ip(
-       companion_device_h device, char **ip)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *ip = g_strdup(((companion_device_s *)device)->ip);
-
-       return ret;
-
-}
-EXPORT_API int companion_device_information_get_device_type(
-       companion_device_h device, companion_device_type_e *device_type)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *device_type = ((companion_device_s *)device)->device_type;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_information_get_model_name(
-       companion_device_h device, char **model_name)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       *model_name = g_strdup(((companion_device_s *)device)->model_name);
-
-       return ret;
-}
-
-EXPORT_API int companion_request_create_group(companion_h handle,
-       companion_device_h device, char *group_name, companion_request_result_cb cb,
-       void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       NOTUSED(cb);
-       NOTUSED(user_data);
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("device", device, COMP_ERROR_INVALID_PARAMETER);
-       companion_check_null_ret_error("group_name", group_name,
-               COMP_ERROR_INVALID_PARAMETER);
-
-       _DBG("Device id : %s", 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_join_group(companion_h handle, companion_group_h group,
-       companion_request_result_cb callback, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(callback);
-       NOTUSED(user_data);
-
-       return ret;
-}
-
-EXPORT_API int companion_request_leave_group (companion_h handle,
-       companion_group_h group, companion_request_result_cb callback, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(callback);
-       NOTUSED(user_data);
-
-       return ret;
-}
-
-EXPORT_API int companion_request_invite_device(companion_h handle,
-       companion_group_h group, companion_device_h device, char *PIN,
-       companion_request_result_cb cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       NOTUSED(cb);
-       NOTUSED(user_data);
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_group_s *grp = (companion_group_s *)group;
-       companion_check_null_ret_error("group", group, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("device", device, COMP_ERROR_INVALID_PARAMETER);
-
-       _DBG("%s", grp->device_id);
-       _DBG("%s", grp->group_name);
-       _DBG("%s", dev->device_id);
-
-       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_device(companion_h handle,
-       companion_group_h group, companion_device_h device, companion_request_result_cb cb,
-       void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       NOTUSED(cb);
-       NOTUSED(user_data);
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_group_s *grp = (companion_group_s *)group;
-       companion_check_null_ret_error("group", group, COMP_ERROR_INVALID_PARAMETER);
-
-       companion_device_s *dev = (companion_device_s *)device;
-       companion_check_null_ret_error("device", device, COMP_ERROR_INVALID_PARAMETER);
-
-       _DBG("%s", grp->device_id);
-       _DBG("%s", grp->group_name);
-       _DBG("%s", dev->device_id);
-
-       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_h handle,
-       companion_group_h group, companion_request_result_cb cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(cb);
-       NOTUSED(user_data);
-       return ret;
-}
-
-EXPORT_API int companion_request_result_callback(companion_h handle,
-       companion_request_result_cb result_cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
-
-       _handle->request_result_cb.result_cb = result_cb;
-       _handle->request_result_cb.user_data = user_data;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_monitor_start(companion_h handle,
-                                         companion_device_monitor_result_cb cb, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle,
-                                                                  COMP_ERROR_INVALID_PARAMETER);
-
-       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 1, &ret,
-                                                        NULL, &error);
-       if (ret != COMP_ERROR_NONE) {
-               _ERR("Failed to start monitor");
-               return ret;
-       }
-
-       _handle->monitor_result_cb.cb = cb;
-       _handle->monitor_result_cb.user_data = user_data;
-
-       return ret;
-}
-
-EXPORT_API int companion_device_monitor_stop(companion_h handle)
-{
-       int ret = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       comp_manager_s *_handle = handle;
-       companion_check_null_ret_error("handle", handle,
-                                                                  COMP_ERROR_INVALID_PARAMETER);
-
-       if (_handle->monitor_result_cb.cb == NULL) {
-               _ERR("Monitor is not started");
-               return COMP_ERROR_NOT_STARTED;
-       }
-
-       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 0, &ret,
-                                                        NULL, &error);
-       if (ret != COMP_ERROR_NONE) {
-               _ERR("Failed to stop monitor");
-               return ret;
-       }
-
-       _handle->monitor_result_cb.cb = NULL;
-       _handle->monitor_result_cb.user_data = NULL;
-
-       return ret;
-}
diff --git a/capi/src/companion_dbus.c b/capi/src/companion_dbus.c
deleted file mode 100755 (executable)
index 25e152d..0000000
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <stdlib.h>
-
-#include <dlog.h>
-#include <companion.h>
-#include <companion_util.h>
-#include <companion_dbus.h>
-#include <companion_debug.h>
-#include <companion_gdbus.h>
-#include <companion_private.h>
-
-#define COMP_DBUS_SERVICE "org.tizen.companion" /**< For companion dbus */
-#define COMP_DBUS_GROUP_PATH "/org/tizen/companion/group" /**< For group dbus */
-#define COMP_DBUS_ENABLER_PATH "/org/tizen/companion/enabler" /**< dbus auto-activation */
-
-/* LCOV_EXCL_START */
-static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
-{
-       GVariantIter *iter = NULL;
-       const gchar *key;
-       GVariant *key_value = NULL;
-       companion_group_s *group = NULL;
-       char *uri_path = NULL;
-       char *device_id = NULL;
-       char *group_name = NULL;
-       char *host_addr = NULL;
-       char *resource_type = NULL;
-       companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
-
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       g_variant_get(va, "a{sv}", &iter);
-       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
-               if (g_strcmp0(key, "URI") == 0)
-                       uri_path = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "DeviceID") == 0)
-                       device_id = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "GroupName") == 0)
-                       group_name = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "HostAddress") == 0)
-                       host_addr = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "GroupDeviceType") == 0)
-                       resource_type = (char *)g_variant_get_string(key_value, NULL);
-               else if (g_strcmp0(key, "GroupType") == 0)
-                       type = g_variant_get_int32(key_value);
-       }
-
-       g_variant_iter_free(iter);
-
-       group = create_group_handle(uri_path, device_id, group_name, host_addr,
-               resource_type, type);
-       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)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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,
-       gpointer user_data)
-{
-       GVariantIter *iter = NULL;
-       GVariantIter *iter_row = NULL;
-       const gchar *key;
-       GVariant *key_value;
-       companion_device_s *device = NULL;
-
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       g_variant_get(va, "aa{sv}", &iter);
-       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-               char *device_id = NULL;
-               char *ip = NULL;
-               int device_type = COMPANION_DEVICE_TYPE_ERROR;
-               int port = -1;
-               int sec_port = -1;
-               char *model_name = NULL;
-               char *device_name = NULL;
-               char *platform_ver = NULL;
-               char *vendor_id = NULL;
-               char *profile = NULL;
-
-               while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
-                       if (g_strcmp0(key, "DeviceID") == 0)
-                               device_id = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "Address") == 0)
-                               ip = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "DeviceType") == 0)
-                               device_type = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "Port") == 0)
-                               port = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "SecurePort") == 0)
-                               sec_port = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "ModelName") == 0)
-                               model_name = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "DeviceName") == 0)
-                               device_name = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "PlatformVer") == 0)
-                               platform_ver = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "VendorID") == 0)
-                               vendor_id = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "Profile") == 0)
-                               profile = (char *)g_variant_get_string(key_value, NULL);
-               }
-               g_variant_iter_free(iter_row);
-
-               device = create_device_handle(device_id, ip, device_type, port,
-                                       sec_port, model_name, device_name, platform_ver, vendor_id, profile);
-               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)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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,
-       gpointer user_data)
-{
-       GVariantIter *iter = NULL;
-       GVariantIter *iter_row = NULL;
-       const gchar *key;
-       GVariant *key_value;
-       companion_device_s *device = NULL;
-
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       g_variant_get(va, "aa{sv}", &iter);
-       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-               char *device_id = NULL;
-               char *ip = NULL;
-               int device_type = COMPANION_DEVICE_TYPE_ERROR;
-               int port = -1;
-               int sec_port = -1;
-               char *model_name = NULL;
-               char *device_name = NULL;
-               char *platform_ver = NULL;
-               char *vendor_id = NULL;
-               char *profile = NULL;
-
-               while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
-                       if (g_strcmp0(key, "DeviceID") == 0)
-                               device_id = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "Address") == 0)
-                               ip = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "DeviceType") == 0)
-                               device_type = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "Port") == 0)
-                               port = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "SecurePort") == 0)
-                               sec_port = g_variant_get_uint16(key_value);
-                       else if (g_strcmp0(key, "ModelName") == 0)
-                               model_name = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "DeviceName") == 0)
-                               device_name = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "PlatformVer") == 0)
-                               platform_ver = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "VendorID") == 0)
-                               vendor_id = (char *)g_variant_get_string(key_value, NULL);
-                       else if (g_strcmp0(key, "Profile") == 0)
-                               profile = (char *)g_variant_get_string(key_value, NULL);
-               }
-               g_variant_iter_free(iter_row);
-
-               device = create_device_handle(device_id, ip, device_type, port,
-                                       sec_port, model_name, device_name, platform_ver, vendor_id, profile);
-               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);
-}
-
-static void _mowned_device_find_finish_cb(Group *object, gint ret,
-       gpointer user_data)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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)
-{
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       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 *device_id,
-                                       GVariant *arg, gint ret, gpointer user_data)
-{
-       int len, length = 0;
-       unsigned char *data;
-       GVariantIter *iter;
-
-       NOTUSED(object);
-
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       g_variant_get(arg, "(iay)", &len, &iter);
-
-       data = g_try_malloc0(len + 1);
-
-       while (g_variant_iter_loop(iter, "y", &data[length]))
-               length += 1;
-
-       data[length] = '\0';
-       _DBG("Received result length %d data %s", len, data);
-
-       g_variant_iter_free(iter);
-
-       if (handle->request_result_cb.result_cb)
-               handle->request_result_cb.result_cb(cmd, device_id, data, len, ret,
-                       handle->request_result_cb.user_data);
-
-       g_free(data);
-}
-
-static void __monitor_result_cb(Group *object, gchar *uuid, gchar *group_name,
-                                       gchar *status, gpointer user_data)
-{
-       companion_device_status_e device_status;
-       comp_manager_s *handle = user_data;
-       companion_check_null_ret("user_data", user_data);
-
-       _DBG("Received Monitor Result uuid %s group name %s status %s", uuid,
-                group_name, status);
-
-       if (g_strcmp0(status, "Added") == 0)
-               device_status = COMPANION_DEVICE_ADDED;
-       else if (g_strcmp0(status, "Removed") == 0)
-               device_status = COMPANION_DEVICE_REMOVED;
-       else
-               return;
-
-       if (handle->monitor_result_cb.cb)  {
-               handle->monitor_result_cb.cb(uuid, group_name, device_status,
-                                                        handle->monitor_result_cb.user_data);
-       }
-}
-/* LCOV_EXCL_STOP */
-
-
-static int _enabler_proxy_init(comp_manager_s *handle)
-{
-       GError *error = NULL;
-       const gchar *name;
-       int ret;
-
-       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 */
-       }
-
-       handle->system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (NULL == handle->system_bus) {
-               /* LCOV_EXCL_START */
-               if (error != NULL) {
-                       _ERR("Failed to connect to system bus [%s]", error->message);
-                       g_error_free(error);
-               }
-               return COMP_ERROR_IO_ERROR;
-               /* LCOV_EXCL_STOP */
-       }
-
-       name = g_dbus_connection_get_unique_name(handle->system_bus);
-       _DBG("Unique dbus name %s", name);
-
-       enabler_call_add_ref_sync(handle->enabler_proxy, name, &ret, NULL, &error);
-       if (error) {
-               /* LCOV_EXCL_START */
-               _ERR("Failed to add reference [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-               /* LCOV_EXCL_STOP */
-       }
-
-       return ret;
-}
-
-/* LCOV_EXCL_START */
-static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
-               gpointer *user_data)
-{
-       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;
-       companion_check_null_ret("user_data", user_data);
-
-       LOGD("Name owner notify [%s]", name_owner);
-
-       if (NULL == name_owner)
-               gdbus_deinitialize(handle);
-       free(name_owner);
-
-}
-/* LCOV_EXCL_STOP */
-
-static int _group_proxy_init(comp_manager_s *handle)
-{
-       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 */
-       }
-
-       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 */
-       }
-
-       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);
-       g_signal_connect(handle->group_proxy,
-               "device-monitor-result", G_CALLBACK(__monitor_result_cb), handle);
-
-       return COMP_ERROR_NONE;
-}
-
-
-static void _group_proxy_deinit(comp_manager_s *handle)
-{
-       g_object_unref(handle->group_proxy);
-       handle->group_proxy = NULL;
-}
-
-static void _enabler_proxy_deinit(comp_manager_s *handle)
-{
-       g_object_unref(handle->system_bus);
-       handle->system_bus = NULL;
-
-       g_object_unref(handle->enabler_proxy);
-       handle->enabler_proxy = NULL;
-}
-
-int gdbus_initialize(comp_manager_s *handle)
-{
-       int ret = COMP_ERROR_NONE;
-
-       _group_proxy_init(handle);
-       _enabler_proxy_init(handle);
-
-       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;
-}
-
-int gdbus_deinitialize(comp_manager_s *handle)
-{
-       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;
-}
-
diff --git a/capi/src/companion_dbus.h b/capi/src/companion_dbus.h
deleted file mode 100644 (file)
index 894768b..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __TIZEN_NETWORK_COMPANION_DBUS_INTERNAL_H__
-#define __TIZEN_NETWORK_COMPANION_DBUS_INTERNAL_H__
-
-#include <companion_private.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-int gdbus_initialize(comp_manager_s *handle);
-int gdbus_deinitialize(comp_manager_s *handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_NETWORK_COMPANION_DBUS_INTERNAL_H__ */
diff --git a/capi/src/companion_debug.h b/capi/src/companion_debug.h
deleted file mode 100644 (file)
index ec89586..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __TIZEN_NETWORK_COMPANION_DEBUG_H__
-#define __TIZEN_NETWORK_COMPANION_DEBUG_H__
-
-#include <dlog.h>
-
-#define NOTUSED(var) (var = var)
-
-#define COLOR_BLACK "\033[0;30m"
-#define COLOR_RED   "\033[0;31m"
-#define COLOR_GREEN "\033[0;32m"
-#define COLOR_BROWN "\033[0;33m"
-#define COLOR_BLUE  "\033[0;34m"
-#define COLOR_PURPLE    "\033[0;35m"
-#define COLOR_CYAN  "\033[0;36m"
-#define COLOR_GRAY  "\033[0;37m"
-#define COLOR_END   "\033[0;m"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "COMP_MANAGER_CAPI"
-
-#define _ERR(fmt, ...) \
-       do { \
-               LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
-       } while (0)
-
-#define _INFO(fmt, ...) \
-       do { \
-               LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
-       } while (0)
-
-#define _WARN(fmt, ...) \
-       do { \
-               LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
-       } while (0)
-
-#define _DBG(fmt, ...) \
-       do { \
-               LOGD(fmt, ##__VA_ARGS__); \
-       } while (0)
-
-#define _BEGIN() \
-       do { \
-               LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
-       } while (0)
-
-#define _END() \
-       do { \
-               LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
-       } while (0)
-
-#define cond_expr_ret(expr, val) \
-       do { \
-               if (expr) { \
-                       _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
-                       return (val); \
-               } \
-       } while (0)
-
-#define cond_ret(val) \
-       do { \
-               if (val) { \
-                       _ERR("[precond fail] ret : %d\n", val); \
-                       return (val); \
-               } \
-       } while (0)
-
-#define companion_check_null_ret_error(name, value, error) do { \
-       /* LCOV_EXCL_START */ \
-       if (G_UNLIKELY(NULL == (value))) { \
-                               LOGE("%s is NULL", name); \
-                               return error; \
-                       } \
-       /* LCOV_EXCL_STOP */ \
-} while (FALSE)
-
-#define companion_check_null_ret(name, value) do { \
-       /* LCOV_EXCL_START */ \
-       if (G_UNLIKELY(NULL == (value))) { \
-                               LOGE("%s is NULL", name); \
-                               return; \
-                       } \
-       /* LCOV_EXCL_STOP */ \
-} while (FALSE)
-
-
-#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
-#define TC_PRT(format, args...) PRT(format"\n", ##args)
-
-#endif /* __TIZEN_NETWORK_COMPANION_DEBUG_H__ */
diff --git a/capi/src/companion_gdbus.xml b/capi/src/companion_gdbus.xml
deleted file mode 100644 (file)
index cb4be58..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE node PUBLIC
-       "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
-       "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
-
-<node>
-       <interface name="org.tizen.companion.enabler">
-               <method name="AddRef">
-                       <arg type="s" name="name" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.companion.group">
-               <!-- Method definitions -->
-               <method name="Create">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="Find">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetFoundGroups">
-                       <arg type="i" name="result" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
-               </method>
-               <method name="Join">
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Leave">
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Delete">
-                       <arg type="i" name="group_count" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="DeviceFind">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Invite">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="s" name="uuid" direction="in"/>
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="Eject">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="s" name="uuid" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="DeviceInvite">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="s" name="uri_1" direction="in"/>
-                       <arg type="s" name="rt_1" direction="in"/>
-                       <arg type="s" name="interface_1" direction="in"/>
-                       <arg type="i" name="permission_1" direction="in"/>
-                       <arg type="s" name="uri_2" direction="in"/>
-                       <arg type="s" name="rt_2" direction="in"/>
-                       <arg type="s" name="interface_2" direction="in"/>
-                       <arg type="i" name="permission_2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="DeviceEject">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetRemoteDevice">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="PairResource">
-                       <arg type="s" name="target_1" direction="in"/>
-                       <arg type="s" name="subject_1" direction="in"/>
-                       <arg type="s" name="uri_1" direction="in"/>
-                       <arg type="s" name="rt_1" direction="in"/>
-                       <arg type="s" name="interface_1" direction="in"/>
-                       <arg type="i" name="permission_1" direction="in"/>
-                       <arg type="s" name="target_2" direction="in"/>
-                       <arg type="s" name="subject_2" direction="in"/>
-                       <arg type="s" name="uri_2" direction="in"/>
-                       <arg type="s" name="rt_2" direction="in"/>
-                       <arg type="s" name="interface_2" direction="in"/>
-                       <arg type="i" name="permission_2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="UnpairResource">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="SendData">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="addr" direction="in"/>
-                       <arg type="i" name="port" direction="in"/>
-                       <arg type="(iay)" name="data" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="FindMownedDevices">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetMownedDevice">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="GetMyMownedDevice">
-                       <arg type="a{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="GetMyUuid">
-                       <arg type="s" name="uuid" direction="out" />
-               </method>
-               <method name="RequestCreateGroup">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestInvite">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="s" name="target_uuid" direction="in" />
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestEject">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="s" name="target_uuid" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestDeleteGroup">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="StartInvitedDeviceMonitor">
-                       <arg type="i" name="start" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <!-- Signal (D-Bus) definitions -->
-               <signal name="GroupFound">
-                       <arg type="a{sv}" name="group_info" direction="out" />
-               </signal>
-               <signal name="GroupFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceFound">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </signal>
-               <signal name="DeviceFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceInviteResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceEjectResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="MownedDeviceFound">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </signal>
-               <signal name="MownedDeviceFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="JoinResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="SendDataFinish">
-                       <arg type="s" name="resp_data" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="RequestResult">
-                       <arg type="s" name="command" direction="out" />
-                       <arg type="s" name="device_id" direction="out" />
-                       <arg type="(iay)" name="arg" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceMonitorResult">
-                       <arg type="s" name="uuid" direct="out" />
-                       <arg type="s" name="group_name" direct="out" />
-                       <arg type="s" name="status" direct="out" />
-               </signal>
-       </interface>
-</node>
diff --git a/capi/src/companion_private.h b/capi/src/companion_private.h
deleted file mode 100644 (file)
index f6bbfa3..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __TIZEN_NETWORK_COMMON_COMPANION_PRIVATE_H__
-#define __TIZEN_NETWORK_COMMON_COMPANION_PRIVATE_H__
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <companion.h>
-#include <companion_gdbus.h>
-#include <companion_debug.h>
-
-#include <system_info.h>
-
-#define COMPANION_FEATURE "http://tizen.org/feature/network.d2d.companion"
-
-#define CHECK_INPUT_PARAMETER(arg) \
-       if (arg == NULL) { \
-               comp_supported("INVALID_PARAMETER"); \
-               return COMP_ERROR_INVALID_PARAMETER; \
-       }
-
-#if 0
-#define CHECK_FEATURE_SUPPORTED(feature_name) { \
-       bool comp_supported = FALSE; \
-       if (!system_info_get_platform_bool(feature_name, &comp_supported)) { \
-               if (comp_supported == FALSE) { \
-                       _ERR("companion feature is disabled"); \
-                       return COMP_ERROR_NOT_SUPPORTED; \
-               } \
-       } else { \
-               _ERR("Error - Feature getting from System Info"); \
-               return COMP_ERROR_NOT_SUPPORTED; \
-       } \
-}
-#else
-#define CHECK_FEATURE_SUPPORTED(feature_name) { \
-               _ERR("[Feature] Should be check !"); \
-       }
-#endif
-
-/**
- * @brief New group found callback structure
- * @since_tizen 5.0
- */
-typedef struct _group_found_cb_t {
-       companion_group_found_cb found_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} group_found_cb_t;
-
-/**
- * @brief New device found callback structure
- * @since_tizen 5.0
- */
-typedef struct _device_found_cb_t {
-       companion_device_found_cb found_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} device_found_cb_t;
-
-/**
- * @brief Finding groups done callback structure
- * @since_tizen 5.0
- */
-typedef struct _group_find_finish_cb_t {
-       companion_group_find_finish_cb finish_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} group_find_finish_cb_t;
-
-/**
- * @brief Fiding devices done callback structure
- * @since_tizen 5.0
- */
-typedef struct _device_find_finish_cb_t {
-       companion_device_find_finish_cb finish_cb;
-       void *user_data; /**< User data pointer */
-} device_find_finish_cb_t;
-
-/**
- * @brief New my own device found callback structure
- * @since_tizen 5.0
- */
-typedef struct _mowned_device_found_cb_t {
-       companion_device_found_cb found_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} mowned_device_found_cb_t;
-
-/**
- * @brief Finding my own device done callback structure
- * @since_tizen 5.0
- */
-typedef struct _mowned_device_find_finish_cb_t {
-       companion_device_find_finish_cb finish_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} mowned_device_find_finish_cb_t;
-
-/**
- * @brief Inviting a device done callback structure
- * @since_tizen 5.0
- */
-typedef struct _device_invite_result_cb_t {
-       companion_group_invite_device_result_cb result_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} device_invite_result_cb_t;
-
-/**
- * @brief Ejecting the device done callback structure
- * @since_tizen 5.0
- */
-typedef struct _device_eject_result_cb_t {
-       companion_group_eject_device_result_cb result_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} device_eject_result_cb_t;
-
-/**
- * @brief Sending data to the device done callback structure
- * @since_tizen 5.0
- */
-typedef struct _send_data_finish_cb_t {
-       companion_device_send_data_finish_cb finish_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} send_data_finish_cb_t;
-
-/**
- * @brief Sending internal commands to the device done callback structure
- * @since_tizen 5.0
- */
-typedef struct _request_result_cb_t {
-       companion_request_result_cb result_cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} request_result_cb_t;
-
-/**
- * @brief Sending device monitor result callback structure
- * @since_tizen 5.0
- */
-typedef struct _monitor_result_cb_t {
-       companion_device_monitor_result_cb cb; /**< User callback to be called */
-       void *user_data; /**< User data pointer */
-} monitor_result_cb_t;
-
-/**
- * @brief The companion-manager context
- * @since_tizen 5.0
- */
-typedef struct _comp_manager_s {
-       GCancellable *ca; /**< Cancelable */
-
-       Group *group_proxy; /**< To receive signal from companion-manager */
-       Enabler *enabler_proxy; /**< Enbler proxy */
-       GDBusConnection *system_bus; /**< GDBus System Bus */
-
-       group_found_cb_t group_found_cb; /**< When it called after finding a every single group */
-       group_find_finish_cb_t group_find_finish_cb; /**< When it called the group finging time is up */
-       device_found_cb_t device_found_cb; /**< When it called after finding a every single device */
-       device_find_finish_cb_t device_find_finish_cb; /**< When it called the device finging time is up */
-       mowned_device_found_cb_t mowned_device_found_cb; /**< When it called after finding a every single my own device */
-       mowned_device_find_finish_cb_t mowned_device_find_finish_cb; /**< When it called the time of finding my own devices is up */
-       device_invite_result_cb_t device_invite_result_cb; /**< When it called after invinting a device done or timeout */
-       device_eject_result_cb_t device_eject_result_cb; /**< When it called after ejecting the device done or timeout */
-       send_data_finish_cb_t send_data_finish_cb; /**< When it called after sending the device done or timeout */
-       request_result_cb_t request_result_cb; /**< When it called after sending private commands or timeout */
-       monitor_result_cb_t monitor_result_cb; /**< It is called after device status is changed */
-} comp_manager_s;
-
-/**
- * @brief The group structure
- * @since_tizen 5.0
- */
-typedef struct _companion_group_s {
-       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_s;
-
-/**
- * @brief The device structure
- * @since_tizen 5.0
- */
-typedef struct _companion_device_s {
-       char *device_id; /**< Device ID */
-       char *ip; /**< Device IP */
-       int device_type; /**< Device Type */
-       int port; /**< Port Number */
-       int sec_port; /**< Secure Port Number */
-       char *model_name;
-       char *device_name;
-       char *platform_ver;
-       char *vendor_id;
-       char *profile;
-} companion_device_s;
-
-
-#endif /* __TIZEN_NETWORK_COMMON_COMPANION_PRIVATE_H__ */
diff --git a/capi/src/companion_util.c b/capi/src/companion_util.c
deleted file mode 100644 (file)
index 82e32b4..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <glib.h>
-#include <stdlib.h>
-#include <companion.h>
-#include <companion_debug.h>
-#include <companion_private.h>
-
-companion_group_s *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_s *group = calloc(1, sizeof(companion_group_s));
-       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);
-       group->group_name = g_strdup(group_name);
-       group->host_addr = g_strdup(host_addr);
-       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 */
-}
-
-companion_device_s *create_device_handle(char *device_id, char *ip,
-       int device_type, int port, int sec_port, char *model_name, char *device_name,
-       char *platform_ver, char *vendor_id, char *profile)
-{
-       companion_device_s *device = calloc(1, sizeof(companion_device_s));
-       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 = device_type;
-       device->port = port;
-       device->sec_port = sec_port;
-       device->model_name = g_strdup(model_name);
-       device->device_name = g_strdup(device_name);
-       device->platform_ver = g_strdup(platform_ver);
-       device->vendor_id = g_strdup(vendor_id);
-       device->profile = g_strdup(profile);
-
-       if (!device->device_id || !device->ip || !device->model_name || !device->device_name ||
-               !device->platform_ver || !device->vendor_id || !device->profile) {
-               /* 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->model_name) {
-                       free(device->model_name);
-                       device->model_name = NULL;
-               }
-               if (device->device_name) {
-                       free(device->device_name);
-                       device->device_name = NULL;
-               }
-               if (device->platform_ver) {
-                       free(device->platform_ver);
-                       device->platform_ver = NULL;
-               }
-               if (device->vendor_id) {
-                       free(device->vendor_id);
-                       device->vendor_id = NULL;
-               }
-               if (device->profile) {
-                       free(device->profile);
-                       device->profile = NULL;
-               }
-               if (device->ip) {
-                       free(device->ip);
-                       device->ip = NULL;
-               }
-               free(device);
-               device = NULL;
-       }
-       return NULL;
-       /* LCOV_EXCL_STOP */
-}
diff --git a/capi/src/companion_util.h b/capi/src/companion_util.h
deleted file mode 100644 (file)
index c4803af..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __TIZEN_NETWORK_COMMON_COMPANION_UTIL_H__
-#define __TIZEN_NETWORK_COMMON_COMPANION_UTIL_H__
-
-#include <companion_private.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-companion_group_s *create_group_handle(char *uri_path, char *device_id,
-       char *group_name, char *host_addr, char *resource_type, companion_group_type_e type);
-companion_device_s *create_device_handle(char *device_id, char *ip, int device_type,
-       int port, int sec_port, char *model_name, char *device_name,
-       char *platform_ver, char *vendor_id, char *profile);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_NETWORK_COMMON_COMPANION_UTIL_H__ */
index 8a7f0e7539af7214c255d1c7321fb007f6d5cce1..8db738726f527b86eda0dccc85705222a3d1e4e4 100755 (executable)
@@ -1,4 +1,4 @@
-gdbus-codegen --interface-prefix org.tizen.companion \
-        --generate-c-code companion_gdbus \
+gdbus-codegen --interface-prefix org.tizen.mdg \
+        --generate-c-code mdg_gdbus \
         --c-generate-object-manager \
-        companion_gdbus.xml \
+        mdg_gdbus.xml \
diff --git a/capi/src/mdg.c b/capi/src/mdg.c
new file mode 100644 (file)
index 0000000..e78163a
--- /dev/null
@@ -0,0 +1,1173 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <dlog.h>
+#include <mdg.h>
+#include <mdg_util.h>
+#include <mdg_dbus.h>
+#include <mdg_debug.h>
+#include <mdg_gdbus.h>
+#include <mdg_private.h>
+
+/**
+ * Companion Manager CAPI
+ */
+
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for dbus */
+
+#define MDG_LOCK \
+do { \
+       pthread_mutex_lock(&mutex); \
+} while (0);
+
+#define MDG_UNLOCK \
+do { \
+       pthread_mutex_unlock(&mutex); \
+} while (0);
+
+int ref_count = 0; /**< How many clients are alive */
+bool __is_initialized = false; /**< Initialize or not */
+
+EXPORT_API int mdg_initialize(mdg_h *handle)
+{
+       int ret = MDG_ERROR_NONE;
+       struct mdg_manager_s *mdg_manager = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       _BEGIN();
+
+       mdg_manager = calloc(1, sizeof(mdg_manager_s));
+       if (NULL == mdg_manager) {
+               /* LCOV_EXCL_START */
+               _ERR("Failed to create handle");
+               return MDG_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+       *handle = mdg_manager;
+
+       if (__is_initialized) {
+               /* LCOV_EXCL_START */
+               _DBG("Already initialized");
+               return MDG_ERROR_ALREADY_INITIALIZED;
+               /* LCOV_EXCL_STOP */
+       }
+
+       MDG_LOCK;
+       ret = gdbus_initialize(*handle);
+       __is_initialized = true;
+       MDG_UNLOCK;
+       ref_count++;
+
+       _END();
+
+       return ret;
+}
+
+EXPORT_API int mdg_deinitialize(mdg_h handle)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       _BEGIN();
+
+       MDG_LOCK;
+
+       if (0 > --ref_count) {
+               /* LCOV_EXCL_START */
+               _DBG("all connections closed\n");
+               ref_count = 0;
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (__is_initialized == true && ref_count == 0) {
+               ret = gdbus_deinitialize(handle);
+               __is_initialized = false;
+       }
+
+       MDG_UNLOCK;
+
+       _END();
+
+       return ret;
+
+}
+
+EXPORT_API int mdg_group_create(mdg_h handle, char *group_name)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       /* create group to daemon using gdbus */
+       group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error);
+
+       return ret;
+}
+
+EXPORT_API void mdg_group_destroy(mdg_group_s *group)
+{
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_check_null_ret("group", group);
+
+       if (group->uri_path) {
+               g_free(group->uri_path);
+               group->uri_path = NULL;
+       }
+       if (group->device_id) {
+               g_free(group->device_id);
+               group->device_id = NULL;
+       }
+       if (group->group_name) {
+               g_free(group->group_name);
+               group->group_name = NULL;
+       }
+       if (group->host_addr) {
+               g_free(group->host_addr);
+               group->host_addr = NULL;
+       }
+       if (group->resource_type) {
+               g_free(group->resource_type);
+               group->resource_type = NULL;
+       }
+       g_free(group);
+       group = NULL;
+}
+
+EXPORT_API int mdg_group_find(mdg_h handle, int timeout,
+       mdg_group_found_cb found_cb, mdg_group_find_finish_cb finish_cb,
+       void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_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(_handle->group_proxy, timeout, &ret, NULL, &error);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_get_found_groups(mdg_h handle,
+       mdg_group_h **groups, int *count)
+{
+       int ret = MDG_ERROR_NONE;
+       GVariant *va = NULL;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       /* get groups from daemon using gdbus */
+       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);
+
+       /* LCOV_EXCL_START */
+       if (*count > 0) {
+               GVariantIter *iter = NULL, *iter_row = NULL;
+               GVariant *key_value;
+               const gchar *key;
+               guint i = 0;
+
+               *groups = g_new0(mdg_group_h, *count);
+
+               g_variant_get(va, "aa{sv}", &iter);
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+
+                       char *uri_path = NULL;
+                       char *device_id = NULL;
+                       char *group_name = NULL;
+                       char *host_addr = NULL;
+                       char *resource_type = NULL;
+
+                       mdg_group_s *group = NULL;
+                       mdg_group_type_e type = MDG_GROUP_TYPE_ERROR;
+
+                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                               if (g_strcmp0(key, "URI") == 0)
+                                       uri_path = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "DeviceID") == 0)
+                                       device_id = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "GroupName") == 0)
+                                       group_name = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "HostAddress") == 0)
+                                       host_addr = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "GroupDeviceType") == 0)
+                                       resource_type = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "GroupType") == 0)
+                                       type = g_variant_get_int32(key_value);
+                       }
+                       g_variant_iter_free(iter_row);
+
+                       _INFO("DeviceID %s GroupName %s HostAddress %s GroupDeviceType %s",
+                                 device_id, group_name, host_addr, resource_type);
+
+                       group = create_group_handle(uri_path,
+                               device_id, group_name, host_addr, resource_type, type);
+
+                       (*groups)[i++] = (mdg_group_h)group;
+               }
+               g_variant_iter_free(iter);
+       }
+       /* LCOV_EXCL_STOP */
+       g_variant_unref(va);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_find(mdg_h handle, int timeout,
+       mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb,
+       void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_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(_handle->group_proxy, timeout, &ret, NULL, &error);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_find_mowned_device(mdg_h handle,
+       int timeout, mdg_device_found_cb found_cb,
+       mdg_device_find_finish_cb finish_cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       _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(_handle->group_proxy, timeout, &ret, NULL, &error);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_send_data(mdg_h handle,
+       mdg_device_h device, unsigned char *data, int len,
+       mdg_device_send_data_finish_cb finish_cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       unsigned char *buf = NULL;
+       GVariantBuilder *bytearray_builder = NULL;
+       int i;
+       GVariant *params = NULL;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER);
+
+       buf = g_try_malloc0(len + 1);
+       if (NULL == buf) {
+               /* LCOV_EXCL_START */
+               _ERR("g_malloc0 is failed");
+               return MDG_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+       memcpy(buf, data, len);
+
+       bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       for (i = 0; i < len; i++)
+               g_variant_builder_add(bytearray_builder, "y", buf[i]);
+
+       params = g_variant_new("(iay)", len, bytearray_builder);
+       g_variant_builder_unref(bytearray_builder);
+
+       _handle->send_data_finish_cb.finish_cb = finish_cb;
+       _handle->send_data_finish_cb.user_data = user_data;
+
+       group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->ip,
+                                                         dev->sec_port, params, &ret, NULL, &error);
+
+       g_free(buf);
+       buf = NULL;
+
+       return ret;
+}
+
+/* mdg_request_join_group : join to remote group. if group handle is my daemon's,
+   then the api return fail error */
+EXPORT_API int mdg_device_get_found_devices(mdg_h handle,
+       mdg_device_h **devices, int *count)
+{
+       int ret = MDG_ERROR_NONE;
+       int num = 0;
+       GVariant *va = NULL;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       /* get groups from daemon using gdbus */
+       group_call_get_remote_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
+       /* *count = g_variant_n_children(va); */
+       *count = num;
+
+       _DBG("get found devices : %d", *count);
+       /* LCOV_EXCL_START */
+       if (*count > 0) {
+               GVariantIter *iter = NULL, *iter_row = NULL;
+               GVariant *key_value;
+               const gchar *key;
+               guint i = 0;
+
+               *devices = g_new0(mdg_group_h, *count);
+
+               g_variant_get(va, "aa{sv}", &iter);
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       char *deviceid = NULL;
+                       char *addr = NULL;
+                       int device_type = MDG_DEVICE_TYPE_ERROR;
+                       int port;
+                       int sec_port;
+                       mdg_device_s *device = NULL;
+                       char *model_name = NULL;
+                       char *device_name = NULL;
+                       char *platform_ver = NULL;
+                       char *vendor_id = NULL;
+                       char *profile = NULL;
+
+                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                               if (g_strcmp0(key, "DeviceID") == 0)
+                                       deviceid = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "Address") == 0)
+                                       addr = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "DeviceType") == 0)
+                                       device_type = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "Port") == 0)
+                                       port = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "SecurePort") == 0)
+                                       sec_port = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "ModelName") == 0)
+                                       model_name = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "DeviceName") == 0)
+                                       device_name = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "PlatformVer") == 0)
+                                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "VendorID") == 0)
+                                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "Profile") == 0)
+                                       profile = (char *)g_variant_get_string(key_value, NULL);
+                       }
+                       g_variant_iter_free(iter_row);
+
+                       device = create_device_handle(deviceid, addr, device_type, port, sec_port,
+                               model_name, device_name, platform_ver, vendor_id, profile);
+
+                       (*devices)[i++] = (mdg_device_h)device;
+               }
+               g_variant_iter_free(iter);
+       }
+       /* LCOV_EXCL_STOP */
+       g_variant_unref(va);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_get_found_mowned_devices(
+       mdg_h handle, mdg_device_h **devices, int *count)
+{
+       int ret = MDG_ERROR_NONE;
+       int num = 0;
+       GVariant *va = NULL;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       /* get groups from daemon using gdbus */
+       group_call_get_mowned_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
+       /* *count = g_variant_n_children(va); */
+       *count = num;
+
+       _INFO("get found mowned devices : %d", *count);
+
+       /* LCOV_EXCL_START */
+       if (*count > 0) {
+               GVariantIter *iter = NULL, *iter_row = NULL;
+               GVariant *key_value;
+               const gchar *key;
+               guint i = 0;
+
+               *devices = g_new0(mdg_device_h, *count);
+
+               g_variant_get(va, "aa{sv}", &iter);
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       char *deviceid = NULL;
+                       char *addr = NULL;
+                       int device_type = MDG_DEVICE_TYPE_ERROR;
+                       int port;
+                       int sec_port;
+                       mdg_device_s *device = NULL;
+                       char *model_name = NULL;
+                       char *device_name = NULL;
+                       char *platform_ver = NULL;
+                       char *vendor_id = NULL;
+                       char *profile = NULL;
+
+                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                               if (g_strcmp0(key, "DeviceID") == 0)
+                                       deviceid = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "Address") == 0)
+                                       addr = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "DeviceType") == 0)
+                                       device_type = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "Port") == 0)
+                                       port = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "SecurePort") == 0)
+                                       sec_port = g_variant_get_uint16(key_value);
+                               else if (g_strcmp0(key, "ModelName") == 0)
+                                       model_name = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "DeviceName") == 0)
+                                       device_name = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "PlatformVer") == 0)
+                                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "VendorID") == 0)
+                                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
+                               else if (g_strcmp0(key, "Profile") == 0)
+                                       profile = (char *)g_variant_get_string(key_value, NULL);
+                       }
+                       g_variant_iter_free(iter_row);
+
+                       device = create_device_handle(deviceid, addr, device_type, port, sec_port,
+                               model_name, device_name, platform_ver, vendor_id, profile);
+
+                       (*devices)[i++] = (mdg_device_h)device;
+               }
+               g_variant_iter_free(iter);
+       }
+       /* LCOV_EXCL_STOP */
+       g_variant_unref(va);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_get_my_uuid(mdg_h handle, char **uuid)
+{
+       int ret = 0;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       group_call_get_my_uuid_sync(_handle->group_proxy, uuid, NULL, &error);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_get_my_device(mdg_h handle,
+       mdg_device_h *device)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+       GVariant *va = NULL;
+       GVariantIter *iter = NULL;
+       const gchar *key;
+       GVariant *key_value = NULL;
+       char *deviceid = NULL;
+       char *addr = NULL;
+       int device_type = MDG_DEVICE_TYPE_ERROR;
+       int port = -1;
+       int sec_port = -1;
+       char *model_name = NULL;
+       char *device_name = NULL;
+       char *platform_ver = NULL;
+       char *vendor_id = NULL;
+       char *profile = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       group_call_get_my_mowned_device_sync(_handle->group_proxy, &va, NULL, &error);
+
+       g_variant_get(va, "a{sv}", &iter);
+       /* LCOV_EXCL_START */
+       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+               if (g_strcmp0(key, "DeviceID") == 0)
+                       deviceid = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "Address") == 0)
+                       addr = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "DeviceType") == 0)
+                       device_type = g_variant_get_uint16(key_value);
+               else if (g_strcmp0(key, "Port") == 0)
+                       port = g_variant_get_uint16(key_value);
+               else if (g_strcmp0(key, "SecurePort") == 0)
+                       sec_port = g_variant_get_uint16(key_value);
+               else if (g_strcmp0(key, "ModelName") == 0)
+                       model_name = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "DeviceName") == 0)
+                       device_name = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "PlatformVer") == 0)
+                       platform_ver = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "VendorID") == 0)
+                       vendor_id = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "Profile") == 0)
+                       profile = (char *)g_variant_get_string(key_value, NULL);
+       }
+
+       if (deviceid == NULL || addr == NULL)
+               return MDG_ERROR_NO_DATA;
+       /* LCOV_EXCL_STOP */
+
+       *device = (mdg_device_h)create_device_handle(deviceid, addr, device_type, port, sec_port,
+                               model_name, device_name, platform_ver, vendor_id, profile);
+
+       g_variant_iter_free(iter);
+
+       return ret;
+}
+
+/* group merge */
+EXPORT_API int mdg_group_merge(mdg_h hadnle,
+       mdg_group_h dest_group, mdg_group_h src_group)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(dest_group);
+       NOTUSED(src_group);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_delete(mdg_h handle, mdg_group_h group)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_get_member_devices(mdg_h handle,
+       mdg_group_h group, mdg_device_h **devices, int *count)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(devices);
+       NOTUSED(count);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_invite_device(mdg_h handle,
+       mdg_group_h group, mdg_device_h device, char *PIN,
+       mdg_group_invite_device_result_cb result_cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_group_s *grp = (mdg_group_s *)group;
+       mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER);
+
+       _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 'mdg_group_invite_device' 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(_handle->group_proxy, grp->group_name, dev->device_id, PIN,
+               &ret, NULL, &error);
+#endif
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_eject_device(mdg_h handle,
+       mdg_group_h group, mdg_device_h device,
+       mdg_group_eject_device_result_cb result_cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_group_s *grp = (mdg_group_s *)group;
+       mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER);
+
+       _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 'mdg_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(_handle->group_proxy, grp->group_name, dev->device_id, &ret,
+               NULL, &error);
+#endif
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_create(mdg_group_h* group)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_group_h _group = g_malloc0(sizeof(mdg_group_s));
+       if (NULL == _group) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation Failed(%d)", errno);
+               return MDG_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+       *group = _group;
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_clone(mdg_group_h target,
+       mdg_group_h source)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_group_s * dst = (mdg_group_s *)target;
+       mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_group_s * src = (mdg_group_s *)source;
+       mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER);
+
+       ret  = mdg_group_info_create(&target);
+       if (MDG_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
+               _ERR("mdg_group_info_create() Failed(%d)", ret);
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (src->uri_path)
+               dst->uri_path = g_strdup(src->uri_path);
+
+       if (src->device_id)
+               dst->device_id = g_strdup(src->device_id);
+
+       if (src->group_name)
+               dst->group_name = g_strdup(src->group_name);
+
+       if (src->host_addr)
+               dst->host_addr = g_strdup(src->host_addr);
+
+       if (src->resource_type)
+               dst->resource_type = g_strdup(src->resource_type);
+
+       dst->type = src->type;
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_destroy(mdg_group_h data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_group_s * group = (mdg_group_s *)data;
+       mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER);
+
+       if (group->uri_path) {
+               g_free(group->uri_path);
+               group->uri_path = NULL;
+       }
+       if (group->device_id) {
+               g_free(group->device_id);
+               group->device_id = NULL;
+       }
+       if (group->group_name) {
+               g_free(group->group_name);
+               group->group_name = NULL;
+       }
+       if (group->host_addr) {
+               g_free((mdg_group_s *)group->host_addr);
+               group->host_addr = NULL;
+       }
+       if (group->resource_type) {
+               g_free((mdg_group_s *)group->resource_type);
+               group->resource_type = NULL;
+       }
+       g_free(group);
+       group = NULL;
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_get_type(mdg_group_h group,
+       mdg_group_type_e *type)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *type = ((mdg_group_s *)group)->type;
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_get_resource_type(
+       mdg_group_h group, char **resource_type)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *resource_type = g_strdup(((mdg_group_s *)group)->resource_type);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_get_uri_path(
+       mdg_group_h group, char **uri_path)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *uri_path = g_strdup(((mdg_group_s *)group)->uri_path);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_get_name(
+       mdg_group_h group, char **name)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *name = g_strdup(((mdg_group_s *)group)->group_name);
+
+       return ret;
+}
+
+EXPORT_API int mdg_group_info_get_host_addr
+       (mdg_group_h group, char **host_addr)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *host_addr = g_strdup(((mdg_group_s *)group)->host_addr);
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_create(mdg_device_h* device)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_device_h _device = g_malloc0(sizeof(mdg_device_s));
+       if (NULL == device) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation Failed(%d)", errno);
+               return MDG_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+       *device = _device;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_clone(mdg_device_h target,
+       mdg_device_h source)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_device_s * dst = (mdg_device_s *)target;
+       mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s * src = (mdg_device_s *)source;
+       mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER);
+
+       ret  = mdg_device_info_create(&target);
+       if (MDG_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
+               _ERR("mdg_device_info_create() Failed(%d)", ret);
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (src->device_id)
+               dst->device_id = g_strdup(src->device_id);
+       if (src->ip)
+               dst->ip = g_strdup(src->ip);
+       if (src->device_type)
+               dst->device_type = src->device_type;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_destroy(mdg_device_h data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_device_s * device = (mdg_device_s *)data;
+       mdg_check_null_ret_error("data", data, MDG_ERROR_INVALID_PARAMETER);
+
+       if (device->device_id) {
+               g_free(device->device_id);
+               device->device_id = NULL;
+       }
+       if (device->ip) {
+               g_free(device->ip);
+               device->ip = NULL;
+       }
+
+       g_free(device);
+       device = NULL;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_get_device_id(
+       mdg_device_h device, char **device_id)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *device_id = g_strdup(((mdg_device_s *)device)->device_id);
+
+       return ret;
+
+}
+EXPORT_API int mdg_device_info_get_ip(
+       mdg_device_h device, char **ip)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *ip = g_strdup(((mdg_device_s *)device)->ip);
+
+       return ret;
+
+}
+EXPORT_API int mdg_device_info_get_device_type(
+       mdg_device_h device, mdg_device_type_e *device_type)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *device_type = ((mdg_device_s *)device)->device_type;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_info_get_model_name(
+       mdg_device_h device, char **model_name)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       *model_name = g_strdup(((mdg_device_s *)device)->model_name);
+
+       return ret;
+}
+
+EXPORT_API int mdg_request_create_group(mdg_h handle,
+       mdg_device_h device, char *group_name, mdg_request_result_cb cb,
+       void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       NOTUSED(cb);
+       NOTUSED(user_data);
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER);
+       mdg_check_null_ret_error("group_name", group_name,
+               MDG_ERROR_INVALID_PARAMETER);
+
+       _DBG("Device id : %s", 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 mdg_request_join_group(mdg_h handle, mdg_group_h group,
+       mdg_request_result_cb callback, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(callback);
+       NOTUSED(user_data);
+
+       return ret;
+}
+
+EXPORT_API int mdg_request_leave_group (mdg_h handle,
+       mdg_group_h group, mdg_request_result_cb callback, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(callback);
+       NOTUSED(user_data);
+
+       return ret;
+}
+
+EXPORT_API int mdg_request_invite_device(mdg_h handle,
+       mdg_group_h group, mdg_device_h device, char *PIN,
+       mdg_request_result_cb cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       NOTUSED(cb);
+       NOTUSED(user_data);
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_group_s *grp = (mdg_group_s *)group;
+       mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER);
+
+       _DBG("%s", grp->device_id);
+       _DBG("%s", grp->group_name);
+       _DBG("%s", dev->device_id);
+
+       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 mdg_request_eject_device(mdg_h handle,
+       mdg_group_h group, mdg_device_h device, mdg_request_result_cb cb,
+       void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       NOTUSED(cb);
+       NOTUSED(user_data);
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_group_s *grp = (mdg_group_s *)group;
+       mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER);
+
+       mdg_device_s *dev = (mdg_device_s *)device;
+       mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER);
+
+       _DBG("%s", grp->device_id);
+       _DBG("%s", grp->group_name);
+       _DBG("%s", dev->device_id);
+
+       group_call_request_eject(_handle->group_proxy, grp->device_id, grp->group_name,
+               dev->device_id, NULL, NULL, NULL);
+
+       return ret;
+}
+
+EXPORT_API int mdg_request_delete_group(mdg_h handle,
+       mdg_group_h group, mdg_request_result_cb cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(cb);
+       NOTUSED(user_data);
+       return ret;
+}
+
+EXPORT_API int mdg_request_result_callback(mdg_h handle,
+       mdg_request_result_cb result_cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+
+       _handle->request_result_cb.result_cb = result_cb;
+       _handle->request_result_cb.user_data = user_data;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_monitor_start(mdg_h handle,
+                                         mdg_device_monitor_result_cb cb, void *user_data)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle,
+                                                                  MDG_ERROR_INVALID_PARAMETER);
+
+       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 1, &ret,
+                                                        NULL, &error);
+       if (ret != MDG_ERROR_NONE) {
+               _ERR("Failed to start monitor");
+               return ret;
+       }
+
+       _handle->monitor_result_cb.cb = cb;
+       _handle->monitor_result_cb.user_data = user_data;
+
+       return ret;
+}
+
+EXPORT_API int mdg_device_monitor_stop(mdg_h handle)
+{
+       int ret = MDG_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+       mdg_manager_s *_handle = handle;
+       mdg_check_null_ret_error("handle", handle,
+                                                                  MDG_ERROR_INVALID_PARAMETER);
+
+       if (_handle->monitor_result_cb.cb == NULL) {
+               _ERR("Monitor is not started");
+               return MDG_ERROR_NOT_STARTED;
+       }
+
+       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 0, &ret,
+                                                        NULL, &error);
+       if (ret != MDG_ERROR_NONE) {
+               _ERR("Failed to stop monitor");
+               return ret;
+       }
+
+       _handle->monitor_result_cb.cb = NULL;
+       _handle->monitor_result_cb.user_data = NULL;
+
+       return ret;
+}
diff --git a/capi/src/mdg_dbus.c b/capi/src/mdg_dbus.c
new file mode 100644 (file)
index 0000000..f6c9ab7
--- /dev/null
@@ -0,0 +1,497 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+
+#include <dlog.h>
+#include <mdg.h>
+#include <mdg_util.h>
+#include <mdg_dbus.h>
+#include <mdg_debug.h>
+#include <mdg_gdbus.h>
+#include <mdg_private.h>
+
+#define COMP_DBUS_SERVICE "org.tizen.mdg" /**< For multi device group manager dbus */
+#define COMP_DBUS_GROUP_PATH "/org/tizen/mdg/group" /**< For group dbus */
+#define COMP_DBUS_ENABLER_PATH "/org/tizen/mdg/enabler" /**< dbus auto-activation */
+
+/* LCOV_EXCL_START */
+static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
+{
+       GVariantIter *iter = NULL;
+       const gchar *key;
+       GVariant *key_value = NULL;
+       mdg_group_s *group = NULL;
+       char *uri_path = NULL;
+       char *device_id = NULL;
+       char *group_name = NULL;
+       char *host_addr = NULL;
+       char *resource_type = NULL;
+       mdg_group_type_e type = MDG_GROUP_TYPE_ERROR;
+
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       g_variant_get(va, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+               if (g_strcmp0(key, "URI") == 0)
+                       uri_path = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "DeviceID") == 0)
+                       device_id = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "GroupName") == 0)
+                       group_name = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "HostAddress") == 0)
+                       host_addr = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "GroupDeviceType") == 0)
+                       resource_type = (char *)g_variant_get_string(key_value, NULL);
+               else if (g_strcmp0(key, "GroupType") == 0)
+                       type = g_variant_get_int32(key_value);
+       }
+
+       g_variant_iter_free(iter);
+
+       group = create_group_handle(uri_path, device_id, group_name, host_addr,
+               resource_type, type);
+       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)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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,
+       gpointer user_data)
+{
+       GVariantIter *iter = NULL;
+       GVariantIter *iter_row = NULL;
+       const gchar *key;
+       GVariant *key_value;
+       mdg_device_s *device = NULL;
+
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       g_variant_get(va, "aa{sv}", &iter);
+       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+               char *device_id = NULL;
+               char *ip = NULL;
+               int device_type = MDG_DEVICE_TYPE_ERROR;
+               int port = -1;
+               int sec_port = -1;
+               char *model_name = NULL;
+               char *device_name = NULL;
+               char *platform_ver = NULL;
+               char *vendor_id = NULL;
+               char *profile = NULL;
+
+               while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                       if (g_strcmp0(key, "DeviceID") == 0)
+                               device_id = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "Address") == 0)
+                               ip = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "DeviceType") == 0)
+                               device_type = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "Port") == 0)
+                               port = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "SecurePort") == 0)
+                               sec_port = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "ModelName") == 0)
+                               model_name = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "DeviceName") == 0)
+                               device_name = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "PlatformVer") == 0)
+                               platform_ver = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "VendorID") == 0)
+                               vendor_id = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "Profile") == 0)
+                               profile = (char *)g_variant_get_string(key_value, NULL);
+               }
+               g_variant_iter_free(iter_row);
+
+               device = create_device_handle(device_id, ip, device_type, port,
+                                       sec_port, model_name, device_name, platform_ver, vendor_id, profile);
+               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)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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,
+       gpointer user_data)
+{
+       GVariantIter *iter = NULL;
+       GVariantIter *iter_row = NULL;
+       const gchar *key;
+       GVariant *key_value;
+       mdg_device_s *device = NULL;
+
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       g_variant_get(va, "aa{sv}", &iter);
+       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+               char *device_id = NULL;
+               char *ip = NULL;
+               int device_type = MDG_DEVICE_TYPE_ERROR;
+               int port = -1;
+               int sec_port = -1;
+               char *model_name = NULL;
+               char *device_name = NULL;
+               char *platform_ver = NULL;
+               char *vendor_id = NULL;
+               char *profile = NULL;
+
+               while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                       if (g_strcmp0(key, "DeviceID") == 0)
+                               device_id = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "Address") == 0)
+                               ip = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "DeviceType") == 0)
+                               device_type = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "Port") == 0)
+                               port = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "SecurePort") == 0)
+                               sec_port = g_variant_get_uint16(key_value);
+                       else if (g_strcmp0(key, "ModelName") == 0)
+                               model_name = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "DeviceName") == 0)
+                               device_name = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "PlatformVer") == 0)
+                               platform_ver = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "VendorID") == 0)
+                               vendor_id = (char *)g_variant_get_string(key_value, NULL);
+                       else if (g_strcmp0(key, "Profile") == 0)
+                               profile = (char *)g_variant_get_string(key_value, NULL);
+               }
+               g_variant_iter_free(iter_row);
+
+               device = create_device_handle(device_id, ip, device_type, port,
+                                       sec_port, model_name, device_name, platform_ver, vendor_id, profile);
+               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);
+}
+
+static void _mowned_device_find_finish_cb(Group *object, gint ret,
+       gpointer user_data)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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)
+{
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       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 *device_id,
+                                       GVariant *arg, gint ret, gpointer user_data)
+{
+       int len, length = 0;
+       unsigned char *data;
+       GVariantIter *iter;
+
+       NOTUSED(object);
+
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       g_variant_get(arg, "(iay)", &len, &iter);
+
+       data = g_try_malloc0(len + 1);
+
+       while (g_variant_iter_loop(iter, "y", &data[length]))
+               length += 1;
+
+       data[length] = '\0';
+       _DBG("Received result length %d data %s", len, data);
+
+       g_variant_iter_free(iter);
+
+       if (handle->request_result_cb.result_cb)
+               handle->request_result_cb.result_cb(cmd, device_id, data, len, ret,
+                       handle->request_result_cb.user_data);
+
+       g_free(data);
+}
+
+static void __monitor_result_cb(Group *object, gchar *uuid, gchar *group_name,
+                                       gchar *status, gpointer user_data)
+{
+       mdg_device_status_e device_status;
+       mdg_manager_s *handle = user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       _DBG("Received Monitor Result uuid %s group name %s status %s", uuid,
+                group_name, status);
+
+       if (g_strcmp0(status, "Added") == 0)
+               device_status = MDG_DEVICE_ADDED;
+       else if (g_strcmp0(status, "Removed") == 0)
+               device_status = MDG_DEVICE_REMOVED;
+       else
+               return;
+
+       if (handle->monitor_result_cb.cb)  {
+               handle->monitor_result_cb.cb(uuid, group_name, device_status,
+                                                        handle->monitor_result_cb.user_data);
+       }
+}
+/* LCOV_EXCL_STOP */
+
+
+static int _enabler_proxy_init(mdg_manager_s *handle)
+{
+       GError *error = NULL;
+       const gchar *name;
+       int ret;
+
+       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 MDG_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       handle->system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (NULL == handle->system_bus) {
+               /* LCOV_EXCL_START */
+               if (error != NULL) {
+                       _ERR("Failed to connect to system bus [%s]", error->message);
+                       g_error_free(error);
+               }
+               return MDG_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       name = g_dbus_connection_get_unique_name(handle->system_bus);
+       _DBG("Unique dbus name %s", name);
+
+       enabler_call_add_ref_sync(handle->enabler_proxy, name, &ret, NULL, &error);
+       if (error) {
+               /* LCOV_EXCL_START */
+               _ERR("Failed to add reference [%s]", error->message);
+               g_error_free(error);
+               return MDG_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       return ret;
+}
+
+/* LCOV_EXCL_START */
+static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
+               gpointer *user_data)
+{
+       GDBusProxy *proxy = G_DBUS_PROXY(object);
+       gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
+       mdg_manager_s *handle = (mdg_manager_s *)user_data;
+       mdg_check_null_ret("user_data", user_data);
+
+       LOGD("Name owner notify [%s]", name_owner);
+
+       if (NULL == name_owner)
+               gdbus_deinitialize(handle);
+       free(name_owner);
+
+}
+/* LCOV_EXCL_STOP */
+
+static int _group_proxy_init(mdg_manager_s *handle)
+{
+       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 MDG_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       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 MDG_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       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);
+       g_signal_connect(handle->group_proxy,
+               "device-monitor-result", G_CALLBACK(__monitor_result_cb), handle);
+
+       return MDG_ERROR_NONE;
+}
+
+
+static void _group_proxy_deinit(mdg_manager_s *handle)
+{
+       g_object_unref(handle->group_proxy);
+       handle->group_proxy = NULL;
+}
+
+static void _enabler_proxy_deinit(mdg_manager_s *handle)
+{
+       g_object_unref(handle->system_bus);
+       handle->system_bus = NULL;
+
+       g_object_unref(handle->enabler_proxy);
+       handle->enabler_proxy = NULL;
+}
+
+int gdbus_initialize(mdg_manager_s *handle)
+{
+       int ret = MDG_ERROR_NONE;
+
+       _group_proxy_init(handle);
+       _enabler_proxy_init(handle);
+
+       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;
+}
+
+int gdbus_deinitialize(mdg_manager_s *handle)
+{
+       int ret = MDG_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;
+}
+
diff --git a/capi/src/mdg_dbus.h b/capi/src/mdg_dbus.h
new file mode 100644 (file)
index 0000000..838b2fd
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_NETWORK_MDG_DBUS_INTERNAL_H__
+#define __TIZEN_NETWORK_MDG_DBUS_INTERNAL_H__
+
+#include <mdg_private.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int gdbus_initialize(mdg_manager_s *handle);
+int gdbus_deinitialize(mdg_manager_s *handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_NETWORK_MDG_DBUS_INTERNAL_H__ */
diff --git a/capi/src/mdg_debug.h b/capi/src/mdg_debug.h
new file mode 100644 (file)
index 0000000..01b1bd4
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_NETWORK_MDG_DEBUG_H__
+#define __TIZEN_NETWORK_MDG_DEBUG_H__
+
+#include <dlog.h>
+
+#define NOTUSED(var) (var = var)
+
+#define COLOR_BLACK "\033[0;30m"
+#define COLOR_RED   "\033[0;31m"
+#define COLOR_GREEN "\033[0;32m"
+#define COLOR_BROWN "\033[0;33m"
+#define COLOR_BLUE  "\033[0;34m"
+#define COLOR_PURPLE    "\033[0;35m"
+#define COLOR_CYAN  "\033[0;36m"
+#define COLOR_GRAY  "\033[0;37m"
+#define COLOR_END   "\033[0;m"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "MDG_CAPI"
+
+#define _ERR(fmt, ...) \
+       do { \
+               LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+
+#define _INFO(fmt, ...) \
+       do { \
+               LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+
+#define _WARN(fmt, ...) \
+       do { \
+               LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+
+#define _DBG(fmt, ...) \
+       do { \
+               LOGD(fmt, ##__VA_ARGS__); \
+       } while (0)
+
+#define _BEGIN() \
+       do { \
+               LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
+       } while (0)
+
+#define _END() \
+       do { \
+               LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
+       } while (0)
+
+#define cond_expr_ret(expr, val) \
+       do { \
+               if (expr) { \
+                       _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
+                       return (val); \
+               } \
+       } while (0)
+
+#define cond_ret(val) \
+       do { \
+               if (val) { \
+                       _ERR("[precond fail] ret : %d\n", val); \
+                       return (val); \
+               } \
+       } while (0)
+
+#define mdg_check_null_ret_error(name, value, error) do { \
+       /* LCOV_EXCL_START */ \
+       if (G_UNLIKELY(NULL == (value))) { \
+                               LOGE("%s is NULL", name); \
+                               return error; \
+                       } \
+       /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+#define mdg_check_null_ret(name, value) do { \
+       /* LCOV_EXCL_START */ \
+       if (G_UNLIKELY(NULL == (value))) { \
+                               LOGE("%s is NULL", name); \
+                               return; \
+                       } \
+       /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+
+#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
+#define TC_PRT(format, args...) PRT(format"\n", ##args)
+
+#endif /* __TIZEN_NETWORK_MDG_DEBUG_H__ */
diff --git a/capi/src/mdg_gdbus.xml b/capi/src/mdg_gdbus.xml
new file mode 100644 (file)
index 0000000..5aa4c1e
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE node PUBLIC
+       "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
+       "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
+
+<node>
+       <interface name="org.tizen.mdg.enabler">
+               <method name="AddRef">
+                       <arg type="s" name="name" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.mdg.group">
+               <!-- Method definitions -->
+               <method name="Create">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="Find">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetFoundGroups">
+                       <arg type="i" name="result" direction="out" />
+                       <arg type="aa{sv}" name="groups" direction="out" />
+               </method>
+               <method name="Join">
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Leave">
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Delete">
+                       <arg type="i" name="group_count" direction="out" />
+                       <arg type="aa{sv}" name="groups" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="DeviceFind">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Invite">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="s" name="uuid" direction="in"/>
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="Eject">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="s" name="uuid" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="DeviceInvite">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="s" name="uri_1" direction="in"/>
+                       <arg type="s" name="rt_1" direction="in"/>
+                       <arg type="s" name="interface_1" direction="in"/>
+                       <arg type="i" name="permission_1" direction="in"/>
+                       <arg type="s" name="uri_2" direction="in"/>
+                       <arg type="s" name="rt_2" direction="in"/>
+                       <arg type="s" name="interface_2" direction="in"/>
+                       <arg type="i" name="permission_2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="DeviceEject">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetRemoteDevice">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="PairResource">
+                       <arg type="s" name="target_1" direction="in"/>
+                       <arg type="s" name="subject_1" direction="in"/>
+                       <arg type="s" name="uri_1" direction="in"/>
+                       <arg type="s" name="rt_1" direction="in"/>
+                       <arg type="s" name="interface_1" direction="in"/>
+                       <arg type="i" name="permission_1" direction="in"/>
+                       <arg type="s" name="target_2" direction="in"/>
+                       <arg type="s" name="subject_2" direction="in"/>
+                       <arg type="s" name="uri_2" direction="in"/>
+                       <arg type="s" name="rt_2" direction="in"/>
+                       <arg type="s" name="interface_2" direction="in"/>
+                       <arg type="i" name="permission_2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="UnpairResource">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="SendData">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="addr" direction="in"/>
+                       <arg type="i" name="port" direction="in"/>
+                       <arg type="(iay)" name="data" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="FindMownedDevices">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetMownedDevice">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyMownedDevice">
+                       <arg type="a{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyUuid">
+                       <arg type="s" name="uuid" direction="out" />
+               </method>
+               <method name="RequestCreateGroup">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestInvite">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="s" name="target_uuid" direction="in" />
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestEject">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="s" name="target_uuid" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestDeleteGroup">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="StartInvitedDeviceMonitor">
+                       <arg type="i" name="start" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <!-- Signal (D-Bus) definitions -->
+               <signal name="GroupFound">
+                       <arg type="a{sv}" name="group_info" direction="out" />
+               </signal>
+               <signal name="GroupFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
+               <signal name="DeviceFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceInviteResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceEjectResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="MownedDeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
+               <signal name="MownedDeviceFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="JoinResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="SendDataFinish">
+                       <arg type="s" name="resp_data" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="RequestResult">
+                       <arg type="s" name="command" direction="out" />
+                       <arg type="s" name="device_id" direction="out" />
+                       <arg type="(iay)" name="arg" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceMonitorResult">
+                       <arg type="s" name="uuid" direct="out" />
+                       <arg type="s" name="group_name" direct="out" />
+                       <arg type="s" name="status" direct="out" />
+               </signal>
+       </interface>
+</node>
diff --git a/capi/src/mdg_private.h b/capi/src/mdg_private.h
new file mode 100644 (file)
index 0000000..1d22168
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__
+#define __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <mdg.h>
+#include <mdg_gdbus.h>
+#include <mdg_debug.h>
+
+#include <system_info.h>
+
+#define MDG_FEATURE "http://tizen.org/feature/network.mdg"
+
+#define CHECK_INPUT_PARAMETER(arg) \
+       if (arg == NULL) { \
+               mdg_supported("INVALID_PARAMETER"); \
+               return MDG_ERROR_INVALID_PARAMETER; \
+       }
+
+#if 0
+#define CHECK_FEATURE_SUPPORTED(feature_name) { \
+       bool mdg_supported = FALSE; \
+       if (!system_info_get_platform_bool(feature_name, &mdg_supported)) { \
+               if (mdg_supported == FALSE) { \
+                       _ERR("Multi Device Group Manager feature is disabled"); \
+                       return MDG_ERROR_NOT_SUPPORTED; \
+               } \
+       } else { \
+               _ERR("Error - Feature getting from System Info"); \
+               return MDG_ERROR_NOT_SUPPORTED; \
+       } \
+}
+#else
+#define CHECK_FEATURE_SUPPORTED(feature_name) { \
+               _ERR("[Feature] Should be check !"); \
+       }
+#endif
+
+/**
+ * @brief New group found callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _group_found_cb_t {
+       mdg_group_found_cb found_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} group_found_cb_t;
+
+/**
+ * @brief New device found callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _device_found_cb_t {
+       mdg_device_found_cb found_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} device_found_cb_t;
+
+/**
+ * @brief Finding groups done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _group_find_finish_cb_t {
+       mdg_group_find_finish_cb finish_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} group_find_finish_cb_t;
+
+/**
+ * @brief Fiding devices done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _device_find_finish_cb_t {
+       mdg_device_find_finish_cb finish_cb;
+       void *user_data; /**< User data pointer */
+} device_find_finish_cb_t;
+
+/**
+ * @brief New my own device found callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _mowned_device_found_cb_t {
+       mdg_device_found_cb found_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} mowned_device_found_cb_t;
+
+/**
+ * @brief Finding my own device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _mowned_device_find_finish_cb_t {
+       mdg_device_find_finish_cb finish_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} mowned_device_find_finish_cb_t;
+
+/**
+ * @brief Inviting a device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _device_invite_result_cb_t {
+       mdg_group_invite_device_result_cb result_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} device_invite_result_cb_t;
+
+/**
+ * @brief Ejecting the device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _device_eject_result_cb_t {
+       mdg_group_eject_device_result_cb result_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} device_eject_result_cb_t;
+
+/**
+ * @brief Sending data to the device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _send_data_finish_cb_t {
+       mdg_device_send_data_finish_cb finish_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} send_data_finish_cb_t;
+
+/**
+ * @brief Sending internal commands to the device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _request_result_cb_t {
+       mdg_request_result_cb result_cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} request_result_cb_t;
+
+/**
+ * @brief Sending device monitor result callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _monitor_result_cb_t {
+       mdg_device_monitor_result_cb cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} monitor_result_cb_t;
+
+/**
+ * @brief The cmdgd context
+ * @since_tizen 5.0
+ */
+typedef struct _mdg_manager_s {
+       GCancellable *ca; /**< Cancelable */
+
+       Group *group_proxy; /**< To receive signal from cmdgd */
+       Enabler *enabler_proxy; /**< Enbler proxy */
+       GDBusConnection *system_bus; /**< GDBus System Bus */
+
+       group_found_cb_t group_found_cb; /**< When it called after finding a every single group */
+       group_find_finish_cb_t group_find_finish_cb; /**< When it called the group finging time is up */
+       device_found_cb_t device_found_cb; /**< When it called after finding a every single device */
+       device_find_finish_cb_t device_find_finish_cb; /**< When it called the device finging time is up */
+       mowned_device_found_cb_t mowned_device_found_cb; /**< When it called after finding a every single my own device */
+       mowned_device_find_finish_cb_t mowned_device_find_finish_cb; /**< When it called the time of finding my own devices is up */
+       device_invite_result_cb_t device_invite_result_cb; /**< When it called after invinting a device done or timeout */
+       device_eject_result_cb_t device_eject_result_cb; /**< When it called after ejecting the device done or timeout */
+       send_data_finish_cb_t send_data_finish_cb; /**< When it called after sending the device done or timeout */
+       request_result_cb_t request_result_cb; /**< When it called after sending private commands or timeout */
+       monitor_result_cb_t monitor_result_cb; /**< It is called after device status is changed */
+} mdg_manager_s;
+
+/**
+ * @brief The group structure
+ * @since_tizen 5.0
+ */
+typedef struct _mdg_group_s {
+       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 */
+       mdg_group_type_e type; /**< Mine or Remote */
+} mdg_group_s;
+
+/**
+ * @brief The device structure
+ * @since_tizen 5.0
+ */
+typedef struct _mdg_device_s {
+       char *device_id; /**< Device ID */
+       char *ip; /**< Device IP */
+       int device_type; /**< Device Type */
+       int port; /**< Port Number */
+       int sec_port; /**< Secure Port Number */
+       char *model_name;
+       char *device_name;
+       char *platform_ver;
+       char *vendor_id;
+       char *profile;
+} mdg_device_s;
+
+
+#endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */
diff --git a/capi/src/mdg_util.c b/capi/src/mdg_util.c
new file mode 100644 (file)
index 0000000..bc91fb5
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <glib.h>
+#include <stdlib.h>
+#include <mdg.h>
+#include <mdg_debug.h>
+#include <mdg_private.h>
+
+mdg_group_s *create_group_handle(char *uri_path, char *device_id,
+       char *group_name, char *host_addr, char *resource_type, mdg_group_type_e type)
+{
+       mdg_group_s *group = calloc(1, sizeof(mdg_group_s));
+       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);
+       group->group_name = g_strdup(group_name);
+       group->host_addr = g_strdup(host_addr);
+       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 */
+}
+
+mdg_device_s *create_device_handle(char *device_id, char *ip,
+       int device_type, int port, int sec_port, char *model_name, char *device_name,
+       char *platform_ver, char *vendor_id, char *profile)
+{
+       mdg_device_s *device = calloc(1, sizeof(mdg_device_s));
+       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 = device_type;
+       device->port = port;
+       device->sec_port = sec_port;
+       device->model_name = g_strdup(model_name);
+       device->device_name = g_strdup(device_name);
+       device->platform_ver = g_strdup(platform_ver);
+       device->vendor_id = g_strdup(vendor_id);
+       device->profile = g_strdup(profile);
+
+       if (!device->device_id || !device->ip || !device->model_name || !device->device_name ||
+               !device->platform_ver || !device->vendor_id || !device->profile) {
+               /* 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->model_name) {
+                       free(device->model_name);
+                       device->model_name = NULL;
+               }
+               if (device->device_name) {
+                       free(device->device_name);
+                       device->device_name = NULL;
+               }
+               if (device->platform_ver) {
+                       free(device->platform_ver);
+                       device->platform_ver = NULL;
+               }
+               if (device->vendor_id) {
+                       free(device->vendor_id);
+                       device->vendor_id = NULL;
+               }
+               if (device->profile) {
+                       free(device->profile);
+                       device->profile = NULL;
+               }
+               if (device->ip) {
+                       free(device->ip);
+                       device->ip = NULL;
+               }
+               free(device);
+               device = NULL;
+       }
+       return NULL;
+       /* LCOV_EXCL_STOP */
+}
diff --git a/capi/src/mdg_util.h b/capi/src/mdg_util.h
new file mode 100644 (file)
index 0000000..39d5d6e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_NETWORK_COMMON_MDG_UTIL_H__
+#define __TIZEN_NETWORK_COMMON_MDG_UTIL_H__
+
+#include <mdg_private.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+mdg_group_s *create_group_handle(char *uri_path, char *device_id,
+       char *group_name, char *host_addr, char *resource_type, mdg_group_type_e type);
+mdg_device_s *create_device_handle(char *device_id, char *ip, int device_type,
+       int port, int sec_port, char *model_name, char *device_name,
+       char *platform_ver, char *vendor_id, char *profile);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_NETWORK_COMMON_MDG_UTIL_H__ */
diff --git a/capi/test/CMakeLists.txt b/capi/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a9cad37
--- /dev/null
@@ -0,0 +1,14 @@
+SET(MDG_TEST "mdg-test")
+
+SET(MDG_TEST_SOURCES
+       main.c
+       menu.c
+       mdg-manager.c
+)
+
+ADD_EXECUTABLE(${MDG_TEST} ${MDG_TEST_SOURCES})
+
+TARGET_LINK_LIBRARIES(${MDG_TEST}
+        ${mdg_test_pkgs_LIBRARIES} capi-network-mdg)
+
+INSTALL(TARGETS ${MDG_TEST} DESTINATION bin/)
diff --git a/capi/test/common.h b/capi/test/common.h
new file mode 100644 (file)
index 0000000..01eade4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __COMMON_H__
+#define __COMMON_H__
+
+#include <mdg.h>
+
+__BEGIN_DECLS
+
+const char* mdg_error_to_string(mdg_error_e err);
+const char *mdg_group_type_to_string(mdg_group_type_e e);
+
+__END_DECLS
+
+#endif /** __COMMON_H__ */
diff --git a/capi/test/main.c b/capi/test/main.c
new file mode 100644 (file)
index 0000000..d6d97a1
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <mdg_internal.h>
+#include "menu.h"
+#include "common.h"
+
+extern struct menu_data menu_mdg_manager[];
+
+extern GList *found_group_list;
+extern GList *found_device_list;
+extern mdg_h handle;
+
+#define CASE_TO_STR(x) case x: return #x;
+
+void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
+                                                       int len, int ret, void *user_data);
+
+const char* mdg_error_to_string(mdg_error_e err)
+{
+       switch (err) {
+       /* CHECK: List all enum values here */
+       CASE_TO_STR(MDG_ERROR_NONE)
+       CASE_TO_STR(MDG_ERROR_IO_ERROR)
+       CASE_TO_STR(MDG_ERROR_INVALID_PARAMETER)
+       CASE_TO_STR(MDG_ERROR_OUT_OF_MEMORY)
+       CASE_TO_STR(MDG_ERROR_PERMISSION_DENIED)
+       CASE_TO_STR(MDG_ERROR_NOT_SUPPORTED)
+       CASE_TO_STR(MDG_ERROR_COMM_ERROR)
+       CASE_TO_STR(MDG_ERROR_RX)
+       CASE_TO_STR(MDG_ERROR_TX)
+       CASE_TO_STR(MDG_ERROR_OPERATION_FAILED)
+       CASE_TO_STR(MDG_ERROR_ALREADY_IN_PROGRESS)
+       CASE_TO_STR(MDG_ERROR_ALREADY_INITIALIZED)
+       CASE_TO_STR(MDG_ERROR_NO_DATA)
+       CASE_TO_STR(MDG_ERROR_NOT_STARTED)
+       CASE_TO_STR(MDG_ERROR_UNKNOWN)
+       default :
+               return "MDG_ERROR_GENERAL";
+       }
+}
+
+const char *mdg_group_type_to_string(mdg_group_type_e e)
+{
+       switch (e) {
+       CASE_TO_STR(MDG_GROUP_TYPE_MINE)
+       CASE_TO_STR(MDG_GROUP_TYPE_REMOTE)
+       default :
+               return "Unknown station type";
+       }
+}
+
+
+static int __init_func(MManager *mm, struct menu_data *menu)
+{
+       int ret = -1;
+
+       ret = mdg_initialize(&handle);
+       if (ret != 0) {
+               msg("Failed to initialize mdgd: [%s(0x%X)]",
+                               mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       ret = mdg_request_result_callback(handle, receive_request_result,
+                                       NULL);
+       if (ret != 0) {
+               msg("Failed to request result callback: [%s(0x%X)]",
+                               mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static struct menu_data menu_main[] = {
+       { "1", "Comp-Manager", menu_mdg_manager, NULL, NULL },
+       { NULL, NULL, },
+};
+
+static gboolean __create_init_menu(struct menu_data init_menu[1])
+{
+       init_menu[0].key = "1";
+       init_menu[0].title = "Init";
+       init_menu[0].sub_menu = menu_main;
+       init_menu[0].callback = __init_func;
+       init_menu[0].data = NULL;
+
+       return TRUE;
+}
+
+void _free_device(gpointer data)
+{
+       mdg_device_info_destroy(data);
+}
+
+int main(int arg, char **argv)
+{
+       GMainLoop *mainloop = NULL;
+       GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
+       MManager *manager;
+       struct menu_data init_menu[1+1] = { {NULL, NULL, } };
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+       g_type_init();
+#endif
+       mainloop = g_main_loop_new(NULL, FALSE);
+
+       msg("");
+       msg("* Companion-Manager Test application ");
+       msg("* Build On: %s  %s", __DATE__, __TIME__);
+
+       if (__create_init_menu(init_menu) == FALSE)
+               goto OUT;
+
+       manager = menu_manager_new(init_menu, mainloop);
+       if (!manager)
+               goto OUT;
+
+       menu_manager_run(manager);
+
+       g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
+                               on_menu_manager_keyboard, manager);
+       g_main_loop_run(mainloop);
+
+OUT:
+       if (found_group_list)
+               g_list_free_full(found_group_list, _free_device);
+       if (found_device_list)
+               g_list_free_full(found_device_list, _free_device);
+
+       mdg_deinitialize(handle);
+
+       g_main_loop_unref(mainloop);
+       msg("******* Bye bye *******");
+
+       return 0;
+}
diff --git a/capi/test/mdg-manager.c b/capi/test/mdg-manager.c
new file mode 100644 (file)
index 0000000..4e4e0c4
--- /dev/null
@@ -0,0 +1,1370 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "menu.h"
+#include "common.h"
+
+mdg_h handle = NULL;
+
+GList *found_group_list;
+GList *found_device_list;
+GList *my_devices_list;
+
+static char groupid[MENU_DATA_SIZE + 1] = "mygroup";
+static char request_groupid[MENU_DATA_SIZE + 1] = "subgroup";
+static char timeout[MENU_DATA_SIZE + 1] = "2";
+static char group_idx[MENU_DATA_SIZE + 1] = "1";
+static char group_idx_a[MENU_DATA_SIZE + 1] = "1";
+static char group_idx_b[MENU_DATA_SIZE + 1] = "2";
+static char device_idx[MENU_DATA_SIZE + 1] = "1";
+static char pin[MENU_DATA_SIZE + 1] = "12341234";
+static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
+static char monitor[MENU_DATA_SIZE + 1] = "1";
+
+static int run_group_find(MManager *mm, struct menu_data *menu);
+static int run_devices_find(MManager *mm, struct menu_data *menu);
+
+static const char* __device_type_to_string(mdg_device_type_e type)
+{
+       switch (type) {
+       /* CHECK: List all enum values here */
+       case MDG_DEVICE_TYPE_LOCAL:
+               return "Local";
+       case MDG_DEVICE_TYPE_REMOTE:
+               return "Remote";
+       default :
+               return "Unknown";
+       }
+}
+
+void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
+                                                       int len, int ret, void *user_data)
+{
+       msg("_request_result_cb is called command %s Requester id %s", cmd,
+                               device_id);
+
+       if (cmd == NULL) {
+               msgp("cmd is null [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return;
+       }
+
+       if (strncmp("COMP_REQ_CREATE_GROUP", cmd, strlen(cmd)) == 0) {
+               msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret),
+                        ret);
+               if (ret == MDG_ERROR_NONE && arg != NULL) {
+                       msgb("Created Group name is %s", arg);
+                       run_group_find(NULL, NULL);
+                       run_devices_find(NULL, NULL);
+               }
+       } else if (strncmp("COMP_REQ_INVITE_DEVICE", cmd, strlen(cmd)) == 0) {
+               msgp("[CMD] Request Invite [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               if (ret == MDG_ERROR_NONE && arg != NULL)
+                       msgb("Invited Device ID is %s", arg);
+       } else if (strncmp("COMP_REQ_EJECT_DEVICE", cmd, strlen(cmd)) == 0) {
+               msgp("[CMD] Request Eject [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               if (ret == MDG_ERROR_NONE && arg != NULL)
+                       msgb("Ejected Device ID is %s", arg);
+       } else if (strncmp("COMP_REQ_DELETE_GROUP", cmd, strlen(cmd)) == 0) {
+               msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret),
+                        ret);
+               if (ret == MDG_ERROR_NONE && arg != NULL)
+                       msgb("Deleted Group name is %s", arg);
+       } else if (strncmp("COMP_REQ_SEND_DATA", cmd, strlen(cmd)) == 0) {
+               msgp("Received data [%d] %s", strlen((char *)arg), arg);
+       } else {
+               msgp("[Recv][%d] %s", strlen((char *) arg), arg);
+       }
+}
+
+int run_get_my_id(MManager *mm, struct menu_data *menu)
+{
+       msg("Get Device ID of my device");
+
+       int ret;
+       char *uuid;
+       ret = mdg_device_info_get_my_uuid(handle, &uuid);
+
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get My Device ID: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - mdg_device_my_deviceid() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+       msgb("[ID] : [%s]", uuid);
+
+       return RET_SUCCESS;
+}
+
+void _device_eject_result_cb(int result, void *user_data)
+{
+       msgb("\rEject Device Complete [%s]", mdg_error_to_string(result));
+}
+
+static int run_device_eject(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       mdg_group_h group = NULL;
+       mdg_device_h device = NULL;
+
+       msg("Eject Device");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       if (strlen(device_idx)) {
+               idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (NULL == found_device_list) {
+               msgr("Find device first");
+               return RET_FAILURE;
+       }
+
+       device = g_list_nth_data(found_device_list, idx - 1);
+       if (NULL == device) {
+               msgr("Failed to g_hash_table_find");
+               return RET_FAILURE;
+       }
+
+       ret = mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+void _device_invite_result_cb(int result, void *user_data)
+{
+       msgb("\rInvite Device Finished [%s]", mdg_error_to_string(result));
+}
+
+static int run_device_invite(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       mdg_group_h group = NULL;
+       mdg_device_h device = NULL;
+
+       msg("Invite Device");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       if (strlen(device_idx)) {
+               idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (NULL == found_device_list) {
+               msgr("Find device first");
+               return RET_FAILURE;
+       }
+
+       device = g_list_nth_data(found_device_list, idx - 1);
+       if (NULL == device) {
+               msgr("Failed to g_hash_table_find");
+               return RET_FAILURE;
+       }
+
+       ret = mdg_group_invite_device(handle, group, device, pin, _device_invite_result_cb, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to device invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_invite_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static void _destroy_mdg_device_info(gpointer data)
+{
+       mdg_device_info_destroy((mdg_device_h)data);
+}
+
+static int run_devices_show(MManager *mm, struct menu_data *menu)
+{
+       char *deviceid = NULL;
+       char *ip = NULL;
+       mdg_device_type_e devicetype;
+       mdg_device_h device;
+       int ret;
+       int count;
+       mdg_device_h *devices = NULL;
+       int i;
+       GList *iter = NULL;
+
+       ret = mdg_device_get_found_devices(handle, &devices, &count);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get Found Devices: [%s(0x%X)]",
+                        mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       } else {
+               if (found_device_list) {
+                       g_list_free_full(found_device_list, _destroy_mdg_device_info);
+                       found_device_list = NULL;
+               }
+
+               for (i = 0; i < count; i++)
+                       found_device_list = g_list_append(found_device_list, devices[i]);
+       }
+
+       /* Get a first item */
+       i = 0;
+       iter = g_list_first(found_device_list);
+       while (NULL != iter) {
+               device = iter->data;
+               if (!device) {
+                       msgr("device list is null");
+                       break;
+               }
+               mdg_device_info_get_device_id(device, &deviceid);
+               mdg_device_info_get_ip(device, &ip);
+               mdg_device_info_get_device_type(device, &devicetype);
+               msgp("[%d] deviceid: %s, IP: %s type: %s", i+1, deviceid, ip,
+                        __device_type_to_string(devicetype));
+
+               if (deviceid) {
+                       free(deviceid);
+                       deviceid = NULL;
+               }
+               if (ip) {
+                       free(ip);
+                       ip  = NULL;
+               }
+               /* Next item */
+               iter = g_list_next(iter);
+               i++;
+       }
+
+       return RET_SUCCESS;
+}
+
+#if 0
+static int run_group_get_members(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       int count;
+       mdg_group_h group = NULL;
+       mdg_device_h **devices = NULL;
+
+       msg("Get Group Members");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_group_get_member_devices(group, devices, &count);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_get_member_devices() ret: [0x%X] [%s]", ret,
+               mdg_error_to_string(ret));
+
+       for (int i = 0; i < count; i++) {
+
+               char *device_id = NULL;
+               char *ip = NULL;
+               mdg_device_type_e device_type;
+
+               mdg_device_info_get_device_id(devices[i], &device_id);
+               mdg_device_info_get_ip(devices[i], &ip);
+               mdg_device_info_get_device_type(devices[i], &device_type);
+
+               msgp("device_id : %s, name : %s, type : %s", device_id, ip,
+                       __device_type_to_string(device_type));
+
+               if (device_id)
+                       free(device_id);
+               if (ip)
+                       free(ip);
+       }
+
+       return RET_SUCCESS;
+}
+#endif
+
+static int run_group_merge(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int a, b;
+       mdg_group_h group_a;
+       mdg_group_h group_b;
+
+       msg("Merge Group");
+
+       if (strlen(group_idx_a)) {
+               a = (unsigned short)strtol(group_idx_a, NULL, 10);
+               if (0 >= a) {
+                       msgp("Invalid index. set to 1");
+                       a = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group_a = g_list_nth_data(found_group_list, a - 1);
+               if (NULL == group_a) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       if (strlen(group_idx_b)) {
+               b = (unsigned short)strtol(group_idx_b, NULL, 10);
+               if (0 >= b) {
+                       msgp("Invalid index. set to 2");
+                       b = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group_b = g_list_nth_data(found_group_list, b - 1);
+               if (NULL == group_b) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+
+       ret = mdg_group_merge(handle, group_a, group_b);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Merge Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_merge() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_group_delete(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       mdg_group_h group;
+
+       msg("Delete Group");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_group_delete(handle, group);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_delete() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+int run_device_show_found(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int count;
+       mdg_device_h *devices = NULL;
+
+       ret = mdg_device_get_found_devices(handle, &devices, &count);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get Found Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_device_get_found_devices() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       for (int i = 0; i < count; i++) {
+               char *device_id = NULL;
+               char *ip = NULL;
+               mdg_device_type_e device_type;
+
+               mdg_device_info_get_device_id(devices[i], &device_id);
+               mdg_device_info_get_ip(devices[i], &ip);
+               mdg_device_info_get_device_type(devices[i], &device_type);
+
+               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
+                       __device_type_to_string(device_type));
+
+               if (device_id)
+                       free(device_id);
+               if (ip)
+                       free(ip);
+       }
+
+       return RET_SUCCESS;
+}
+
+void _device_finish_cb(int result, void *user_data)
+{
+       msgb("\rFind Device Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
+}
+
+bool _device_found_cb(mdg_device_h device, void *user_data)
+{
+       char *ip = NULL;
+       char *device_id = NULL;
+       char *model_name = NULL;
+       mdg_device_type_e device_type;
+       GList *iter = NULL;
+       gboolean is_exist = FALSE;
+
+       mdg_device_info_get_device_id(device, &device_id);
+       mdg_device_info_get_ip(device, &ip);
+       mdg_device_info_get_device_type(device, &device_type);
+       mdg_device_info_get_model_name(device, &model_name);
+
+       iter = found_device_list;
+       while (iter != NULL) {
+               mdg_device_h temp = (mdg_device_h)iter->data;
+               char *temp_device_id;
+
+               mdg_device_info_get_device_id(temp, &temp_device_id);
+
+               if (g_strcmp0(device_id, temp_device_id) == 0) {
+                       is_exist = TRUE;
+                       free(temp_device_id);
+                       mdg_device_info_destroy(device);
+                       break;
+               }
+
+               free(temp_device_id);
+               iter = g_list_next(iter);
+       }
+
+       if (is_exist == FALSE) {
+               found_device_list = g_list_append(found_device_list, device);
+               msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, ip,
+                       __device_type_to_string(device_type), model_name);
+       }
+
+       if (device_id)
+               free(device_id);
+       if (ip)
+               free(ip);
+
+       return TRUE;
+}
+
+static int run_devices_find(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int duration;
+       msg("Find Devices");
+
+       if (strlen(timeout))
+               duration = (unsigned short)strtol(timeout, NULL, 10);
+
+       ret = mdg_device_find(handle, duration, _device_found_cb, _device_finish_cb, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Find Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_device_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       if (found_device_list) {
+               g_list_free_full(found_device_list, _destroy_mdg_device_info);
+               found_device_list = NULL;
+       }
+
+       return RET_SUCCESS;
+}
+
+int run_device_show_my_device(MManager *mm, struct menu_data *menu)
+{
+       int ret = 0;
+       mdg_device_h device = NULL;
+
+       msg("Get My Device");
+
+       ret = mdg_device_info_get_my_device(handle, &device);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get My Device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_device_info_get_my_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       if (ret == 0) {
+               char *device_id = NULL;
+               char *ip = NULL;
+               mdg_device_type_e device_type;
+
+               mdg_device_info_get_device_id(device, &device_id);
+               mdg_device_info_get_ip(device, &ip);
+               mdg_device_info_get_device_type(device, &device_type);
+
+               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
+                       __device_type_to_string(device_type));
+
+               if (device_id)
+                       free(device_id);
+               if (ip)
+                       free(ip);
+
+               mdg_device_info_destroy(device);
+               device = NULL;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_group_leave(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       mdg_group_h group;
+
+       msg("Leave Group");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_leave_group (handle, group, receive_request_result, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Leave Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_request_leave_group () ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_group_show(MManager *mm, struct menu_data *menu)
+{
+       char *rt;
+       char *uri;
+       mdg_group_type_e type;
+       mdg_group_h group;
+
+       int i;
+       GList *iter = NULL;
+
+       /* Get a first item */
+       i = 0;
+       iter = g_list_first(found_group_list);
+       while (NULL != iter) {
+               group = iter->data;
+               if (!group) {
+                       msgr("groups is null");
+                       break;
+               }
+               mdg_group_info_get_type(group, &type);
+               mdg_group_info_get_uri_path(group, &uri);
+               mdg_group_info_get_resource_type(group, &rt);
+               msgp("[%d] type: %s, URI: %s RT: %s", i+1, mdg_group_type_to_string(type), uri, rt);
+               if (uri) {
+                       free(uri);
+                       uri = NULL;
+               }
+               if (rt) {
+                       free(rt);
+                       rt = NULL;
+               }
+               /* Next item */
+               iter = g_list_next(iter);
+               i++;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_group_join(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx;
+       mdg_group_h group;
+
+       msg("Join Group");
+
+       if (strlen(group_idx)) {
+               idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_join_group(handle, group, receive_request_result, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Join Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_request_join_group() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static void _destroy_mdg_group_info(gpointer data)
+{
+       mdg_group_info_destroy((mdg_group_h)data);
+}
+
+static int run_group_show_found(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int count;
+       mdg_group_h *groups;
+
+       msg("Show Found Group(s)");
+
+       ret = mdg_group_get_found_groups(handle, &groups, &count);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get Found Groups: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_get_found_groups() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       if (found_group_list) {
+               g_list_free_full(found_group_list, _destroy_mdg_group_info);
+               found_group_list = NULL;
+       }
+
+       for (int i = 0; i < count; i++) {
+               mdg_group_type_e type;
+               char *uri_path;
+               char *group_name;
+
+               mdg_group_info_get_type(groups[i], &type);
+               mdg_group_info_get_uri_path(groups[i], &uri_path);
+               mdg_group_info_get_name(groups[i], &group_name);
+
+               if (type == MDG_GROUP_TYPE_MINE)
+                       msgb("%d. type : MINE, name : %s, uri : %s", i+1, group_name, uri_path);
+               else
+                       msgb("%d. type : REMOTE, name : %s, uri : %s", i+1, group_name, uri_path);
+
+               found_group_list = g_list_append(found_group_list, groups[i]);
+
+               g_free(uri_path);
+               g_free(group_name);
+       }
+
+       return RET_SUCCESS;
+}
+
+bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data)
+{
+       char *group_name;
+
+       mdg_group_info_get_name(group, &group_name);
+
+       if (type == MDG_GROUP_TYPE_MINE)
+               msgp("\rfound group type : MINE, name : %s", group_name);
+       else
+               msgp("\rfound group type : REMOTE, name : %s", group_name);
+
+       found_group_list = g_list_append(found_group_list, group);
+
+       return TRUE;
+}
+
+void _group_finish_cb(int result, void *user_data)
+{
+       msgb("\rFind Group Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
+}
+
+static int run_group_find(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int duration;
+       msg("Find Group");
+
+       if (strlen(timeout))
+               duration = (unsigned short)strtol(timeout, NULL, 10);
+
+       ret = mdg_group_find(handle, duration, _group_found_cb, _group_finish_cb, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Find Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       if (found_group_list) {
+               g_list_free_full(found_group_list, _destroy_mdg_group_info);
+               found_group_list = NULL;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_group_create(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       msg("Create Group");
+
+       ret = mdg_group_create(handle, groupid);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Create Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_group_create() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+       msgb("Create Group Successfully");
+
+       return RET_SUCCESS;
+}
+
+void _send_data_finish_cb(int result, char *resp_data, void *user_data)
+{
+       msgb("\rFind Send Data Finished = %d", result);
+       if (resp_data != NULL && strlen(resp_data) > 0)
+               msgp("Response from %s", resp_data);
+}
+
+static int __send_data(int idx)
+{
+       int ret = 0;
+       char *deviceid = NULL;
+       char *address = NULL;
+       mdg_device_h device = NULL;
+
+       if (found_device_list) {
+               device = g_list_nth_data(found_device_list, idx - 1);
+               if (NULL == device) {
+                       msgr("Find my device first");
+                       return RET_FAILURE;
+               }
+       }
+
+       mdg_device_info_get_device_id(device, &deviceid);
+       mdg_device_info_get_ip(device, &address);
+       msgp("Sent to [ID] %s [IP] %s", deviceid, address);
+       if (deviceid) {
+               free(deviceid);
+               deviceid = NULL;
+       }
+       if (address) {
+               free(address);
+               address = NULL;
+       }
+
+       ret = mdg_device_send_data(handle, device, (unsigned char *) message,
+                                                strlen(message), _send_data_finish_cb, NULL);
+       if (MDG_ERROR_NONE != ret)
+               msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
+
+       return ret;
+}
+
+static int run_send_data(MManager *mm, struct menu_data *menu)
+{
+       int idx = 0;
+       int count = g_list_length(found_device_list);
+
+       if (0 >= count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       if (strlen(device_idx)) {
+               idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= idx) {
+                       msgp("Invalid index. set to 1");
+                       idx = 1;
+               }
+       }
+       return __send_data(idx);
+}
+
+static int run_send_data_all(MManager *mm, struct menu_data *menu)
+{
+       int count = 0;
+
+       count = g_list_length(found_device_list);
+
+       if (0 >= count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       for (int i = 1; i <= count; i++)
+               __send_data(i);
+
+       return RET_SUCCESS;
+}
+
+void _mowned_device_finish_cb(int result, void *user_data)
+{
+       msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
+               mdg_error_to_string(result));
+}
+
+bool _mowned_device_found_cb(mdg_device_h device, void *user_data)
+{
+       char *ip = NULL;
+       char *device_id = NULL;
+       mdg_device_type_e device_type;
+
+       mdg_device_info_get_device_id(device, &device_id);
+       mdg_device_info_get_ip(device, &ip);
+       mdg_device_info_get_device_type(device, &device_type);
+
+       msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
+               __device_type_to_string(device_type));
+
+       if (device_id)
+               free(device_id);
+       if (ip)
+               free(ip);
+
+       my_devices_list = g_list_append(my_devices_list, device);
+
+       return TRUE;
+}
+
+static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int duration;
+       msg("Find My Owned Devices");
+
+       if (strlen(timeout))
+               duration = (unsigned short)strtol(timeout, NULL, 10);
+
+       ret = mdg_device_find_mowned_device(handle, duration, _mowned_device_found_cb,
+               _mowned_device_finish_cb, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Find My Owned Devices: [%s(0x%X)]",
+                       mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_device_find_mowned_device() ret: [0x%X] [%s]",
+               ret, mdg_error_to_string(ret));
+
+       if (my_devices_list) {
+               g_list_free_full(my_devices_list, _destroy_mdg_device_info);
+               my_devices_list = NULL;
+       }
+
+       return RET_SUCCESS;
+}
+
+int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int count;
+       mdg_device_h *devices = NULL;
+
+       ret = mdg_device_get_found_mowned_devices(handle, &devices, &count);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Get Found Mowned Devices: [%s(0x%X)]",
+                       mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - mdg_device_get_found_mowned_devices() ret: [0x%X] [%s]", ret,
+               mdg_error_to_string(ret));
+
+       for (int i = 0; i < count; i++) {
+               char *device_id = NULL;
+               char *ip = NULL;
+               mdg_device_type_e device_type;
+
+               mdg_device_info_get_device_id(devices[i], &device_id);
+               mdg_device_info_get_ip(devices[i], &ip);
+               mdg_device_info_get_device_type(devices[i], &device_type);
+
+               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
+                       __device_type_to_string(device_type));
+
+               if (device_id)
+                       free(device_id);
+               if (ip)
+                       free(ip);
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_request_create_group(MManager *mm, struct menu_data *menu)
+{
+       int ret = 0;
+       int dev_count = 0;
+       mdg_device_h device = NULL;
+
+       msg("Request create group");
+
+       dev_count = g_list_length(found_device_list);
+
+       if (0 >= dev_count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       int dev_idx;
+       if (device_idx != NULL && strlen(device_idx)) {
+               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= dev_idx) {
+                       msgp("Invalid index. set to 1");
+                       dev_idx = 1;
+               }
+       }
+
+       if (found_device_list) {
+               device = g_list_nth_data(found_device_list, dev_idx - 1);
+               if (NULL == device) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_create_group(handle, device, request_groupid,
+               receive_request_result, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Request Create Group: [%s(0x%X)]",
+                       mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - mdg_request_create_group() ret: [0x%X] [%s]",
+               ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_request_invite(MManager *mm, struct menu_data *menu)
+{
+       int ret = 0;
+       int grp_count = 0;
+       int dev_count = 0;
+       mdg_device_h device = NULL;
+       mdg_group_h group = NULL;
+
+       dev_count = g_list_length(found_device_list);
+       grp_count = g_list_length(found_group_list);
+
+       if (0 >= dev_count || 0 >= grp_count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       int grp_idx;
+       if (group_idx != NULL && strlen(group_idx)) {
+               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= grp_idx) {
+                       msgp("Invalid index. set to 1");
+                       grp_idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, grp_idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       int dev_idx;
+       if (device_idx != NULL && strlen(device_idx)) {
+               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= dev_idx) {
+                       msgp("Invalid index. set to 1");
+                       dev_idx = 1;
+               }
+       }
+
+       if (found_device_list) {
+               device = g_list_nth_data(found_device_list, dev_idx - 1);
+               if (NULL == device) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_invite_device(handle, group, device, pin,
+               receive_request_result, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Request Invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - mdg_request_invite_device() ret: [0x%X] [%s]",
+               ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_request_eject(MManager *mm, struct menu_data *menu)
+{
+       int ret = 0;
+       int grp_count = 0;
+       int dev_count = 0;
+       mdg_device_h device = NULL;
+       mdg_group_h group = NULL;
+
+       dev_count = g_list_length(found_device_list);
+       grp_count = g_list_length(found_group_list);
+
+       if (0 >= dev_count || 0 >= grp_count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       int grp_idx;
+       if (group_idx != NULL && strlen(group_idx)) {
+               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= grp_idx) {
+                       msgp("Invalid index. set to 1");
+                       grp_idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, grp_idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       int dev_idx;
+       if (device_idx != NULL && strlen(device_idx)) {
+               dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= dev_idx) {
+                       msgp("Invalid index. set to 1");
+                       dev_idx = 1;
+               }
+       }
+
+       if (found_device_list) {
+               device = g_list_nth_data(found_device_list, dev_idx - 1);
+               if (NULL == device) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_eject_device(handle, group, device, receive_request_result,
+               NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_request_delete_group(MManager *mm, struct menu_data *menu)
+{
+       int ret = 0;
+       int grp_count = 0;
+       mdg_group_h group = NULL;
+
+       grp_count = g_list_length(found_group_list);
+
+       if (0 >= grp_count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       int grp_idx;
+       if (group_idx != NULL && strlen(group_idx)) {
+               grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
+               if (0 >= grp_idx) {
+                       msgp("Invalid index. set to 1");
+                       grp_idx = 1;
+               }
+       }
+
+       if (found_group_list) {
+               group = g_list_nth_data(found_group_list, grp_idx - 1);
+               if (NULL == group) {
+                       msgr("Failed to g_hash_table_find");
+                       return RET_FAILURE;
+               }
+       }
+
+       ret = mdg_request_delete_group(handle, group, receive_request_result, NULL);
+       if (MDG_ERROR_NONE != ret) {
+               msgr("Failed to Request Delete Group: [%s(0x%X)]",
+                       mdg_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - mdg_request_delete_group() ret: [0x%X] [%s]",
+               ret, mdg_error_to_string(ret));
+
+       return RET_SUCCESS;
+}
+
+static void device_monitor_result(char *uuid, char *group_name,
+                                                 mdg_device_status_e status, void *user_data)
+{
+       msgp("device monitor result uuid %s group_name %s status %s", uuid,
+                group_name, status == MDG_DEVICE_ADDED ? "ADDED" : "REMOVED");
+}
+
+static int run_start_device_monitor(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+
+       if (g_strcmp0(monitor, "1") == 0) {
+               msg(" - Start device monitor");
+               ret = mdg_device_monitor_start(handle, device_monitor_result,
+                                                                                        NULL);
+               if (MDG_ERROR_NONE != ret) {
+                       msgr("Failed to Start Monitor: [%s(0x%X)]",
+                                mdg_error_to_string(ret), ret);
+                       return RET_FAILURE;
+               }
+       } else {
+               msg(" - Stop device monitor");
+               ret = mdg_device_monitor_stop(handle);
+               if (MDG_ERROR_NONE != ret) {
+                       msgr("Failed to Stop Monitor: [%s(0x%X)]",
+                                mdg_error_to_string(ret), ret);
+                       return RET_FAILURE;
+               }
+       }
+       return RET_SUCCESS;
+}
+
+
+static struct menu_data menu_group_create[] = {
+       { "0", "Group Name", NULL, NULL, groupid },
+       { "1", "Run", NULL, run_group_create, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_find[] = {
+       { "0", "Timeout", NULL, NULL, timeout },
+       { "1", "Run", NULL, run_group_find, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_join[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Index", NULL, NULL, group_idx },
+       { "2", "Run", NULL, run_group_join, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_leave[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Index", NULL, NULL, group_idx },
+       { "2", "Run", NULL, run_group_leave, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_delete[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Index", NULL, NULL, group_idx },
+       { "2", "Run", NULL, run_group_delete, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_merge[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "A Index", NULL, NULL, group_idx_a },
+       { "2", "B Index", NULL, NULL, group_idx_b },
+       { "3", "Run", NULL, run_group_merge, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_devices_find[] = {
+       { "0", "Timeout", NULL, NULL, timeout },
+       { "1", "Run", NULL, run_devices_find, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_invite_device[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
+       { "2", "Group Index", NULL, NULL, group_idx },
+       { "3", "Device Index", NULL, NULL, device_idx },
+       { "4", "PIN", NULL, NULL, pin },
+       { "5", "Run", NULL, run_device_invite, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_group_eject_device[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
+       { "2", "Group Index", NULL, NULL, group_idx },
+       { "3", "Device Index", NULL, NULL, device_idx },
+       { "4", "Run", NULL, run_device_eject, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_send_data[] = {
+       { "0", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL },
+       { "1", "Message", NULL, NULL, message },
+       { "2", "Device Index", NULL, NULL, device_idx },
+       { "3", "Send (Unicast)", NULL, run_send_data, NULL },
+       { "4", "Send (Broadcast)", NULL, run_send_data_all, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_devices_find_mownd_device[] = {
+       { "0", "Timeout", NULL, NULL, timeout },
+       { "1", "Run", NULL, run_devices_find_mowned_device, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_request_create_group[] = {
+       { "0", "Show Found Device(s)", NULL, run_devices_show, NULL },
+       { "1", "Device Index", NULL, NULL, device_idx },
+       { "2", "Request Group Name", NULL, NULL, request_groupid },
+       { "3", "Run", NULL, run_request_create_group, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_request_invite[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
+       { "2", "Group Index", NULL, NULL, group_idx },
+       { "3", "Device Index", NULL, NULL, device_idx },
+       { "4", "PIN", NULL, NULL, pin },
+       { "5", "Run", NULL, run_request_invite, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_request_eject[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
+       { "2", "Group Index", NULL, NULL, group_idx },
+       { "3", "Device Index", NULL, NULL, device_idx },
+       { "4", "Run", NULL, run_request_eject, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_request_delete_group[] = {
+       { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+       { "1", "Group Index", NULL, NULL, group_idx },
+       { "2", "Run", NULL, run_request_delete_group, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_monitor[] = {
+       { "1", "Input 1 to Start and 2 to Stop Monitor", NULL, NULL,  monitor },
+       { "2", "Start/Stop Device Monitor", NULL, run_start_device_monitor, NULL },
+       { NULL, NULL, },
+};
+
+struct menu_data menu_mdg_manager[] = {
+       { "0", "Show My Device ID", NULL, run_get_my_id, NULL },
+       { "1", "Show My Device", NULL, run_device_show_my_device, NULL },
+       { "2", "Create Group", menu_group_create, NULL, NULL },
+       { "3", "Find Group(s)", menu_group_find, NULL, NULL },
+       { "4", "Show Found Group(s)", NULL, run_group_show_found , NULL },
+       { "5", "Join Group (Not yet developed)", menu_group_join, NULL, NULL },
+       { "6", "Leave Group (Not yet developed)", menu_group_leave, NULL, NULL },
+       { "7", "Delete Group (Not yet developed)", menu_group_delete, NULL, NULL },
+       { "8", "Find Device(s)", menu_devices_find, NULL, NULL },
+       { "9", "Show Found Device(s)", NULL, run_device_show_found, NULL },
+       { "10", "Invite Device", menu_group_invite_device, NULL, NULL },
+       { "11", "Eject Device", menu_group_eject_device, NULL, NULL },
+       { "12", "Find My Owned Device(s)", menu_devices_find_mownd_device, NULL, NULL },
+       { "13", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL},
+       { "14", "Send Message", menu_send_data, NULL, NULL },
+       { "15", "Request Create Group", menu_request_create_group, NULL, NULL },
+       { "16", "Request Invite", menu_request_invite, NULL, NULL },
+       { "17", "Request Eject", menu_request_eject, NULL, NULL },
+       { "18", "Request Delete Group (Not yet developed)", menu_request_delete_group,
+               NULL, NULL },
+       { "19", "Start/Stop Device Monitor", menu_monitor, NULL, NULL },
+       { NULL, NULL, },
+};
diff --git a/capi/test/mdg-test.c b/capi/test/mdg-test.c
new file mode 100644 (file)
index 0000000..639317c
--- /dev/null
@@ -0,0 +1,489 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <sys/time.h>
+
+#include <mdg.h>
+
+#define BUFFER_LEN 100
+#define TEST_CASE_MAX 10
+
+#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
+#define TC_PRT(format, args...) PRT(format"\n", ##args)
+
+#define BEGIN() TC_PRT("BEGIN");
+#define END() TC_PRT("END");
+
+GMainLoop *main_loop = NULL;
+
+typedef struct {
+       const char *tc_name;
+       int tc_code;
+       int (*tc_func)(void);
+} tc_table_t;
+
+GList *found_group_list;
+GList *found_device_list;
+
+mdg_h handle = NULL;
+
+#define CASE_TO_STR(x) case x: return #x;
+static const char* __device_type_to_string(mdg_device_type_e type)
+{
+       switch (type) {
+       /* CHECK: List all enum values here */
+       CASE_TO_STR(MDG_DEVICE_TYPE_LOCAL)
+       CASE_TO_STR(MDG_DEVICE_TYPE_REMOTE)
+       default :
+               return "MDG_DEVICE_TYPE_ERROR";
+       }
+}
+
+static bool test_get_user_int(const char *msg, int *num)
+{
+       if (msg == NULL || num == NULL)
+               return false;
+
+       int rv;
+       char buf[32] = { 0, };
+       printf("%s\n", msg);
+       rv = read(0, buf, 32);
+
+       if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
+               return false;
+
+       *num = atoi(buf);
+       return true;
+}
+
+static bool test_get_user_string(const char *msg, char *buf, int buf_size)
+{
+       if (msg == NULL || buf == NULL || buf_size < 2)
+               return false;
+
+       int rv;
+       printf("%s\n", msg);
+       memset(buf, 0, buf_size);
+       rv = read(0, buf, buf_size - 1);
+
+       if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
+               buf[0] = '\0';
+               return false;
+       }
+
+       if (rv >= 0)
+               buf[rv] = '\0';
+
+       return true;
+}
+
+int mdg_initialize_test(void)
+{
+       int ret = 0;
+
+       BEGIN();
+
+       ret = mdg_initialize(&handle);
+
+       if (ret == 0)
+               TC_PRT("Initialize successful");
+       else
+               TC_PRT("Initialize failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+int mdg_group_create_test(void)
+{
+       int ret = 0;
+       char input_str[50] = {0, };
+       mdg_h handle = NULL;
+
+       BEGIN();
+
+       if (test_get_user_string("Input group name(ex - GROUP123)"
+                                                " - (Enter for skip) :", input_str, 50)) {
+               g_strstrip(input_str);
+       } else {
+               TC_PRT("Invalid Input !!![%s]", input_str);
+               END();
+               return -1;
+       }
+
+       ret = mdg_group_create(handle, input_str);
+
+       if (ret == 0)
+               TC_PRT("Group create successful");
+       else
+               TC_PRT("Group create failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data)
+{
+       char *uri_path;
+
+       mdg_group_info_get_uri_path(group, &uri_path);
+
+       TC_PRT("found group type : %d, uri : %s", type, uri_path);
+
+       found_group_list = g_list_append(found_group_list, group);
+}
+
+void _group_finish_cb(int result, void *user_data)
+{
+       TC_PRT("find operation finished");
+}
+
+int mdg_group_find_test(void)
+{
+       int ret = 0;
+       int input_int = 0;
+
+       BEGIN();
+       found_group_list = NULL;
+
+       if (!test_get_user_int("==> Input timeout value (sec)"
+                                                " - (Enter for skip) :", &input_int)) {
+               input_int = 5;
+               TC_PRT("default timeout value [%d]", input_int);
+       }
+
+       mdg_group_find(handle, input_int, _group_found_cb, _group_finish_cb, NULL);
+
+       if (ret == 0)
+               TC_PRT("group find successful");
+       else
+               TC_PRT("group find failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+int mdg_group_get_found_groups_test(void)
+{
+       int ret = 0;
+       int count;
+       mdg_group_h *groups;
+
+       BEGIN();
+
+       found_group_list = NULL;
+
+       ret = mdg_group_get_found_groups(handle, &groups, &count);
+
+       if (ret == 0)
+               TC_PRT("group find successful");
+       else
+               TC_PRT("group find failed, ret [%d]", ret);
+
+       TC_PRT("Found group count : %d", count);
+
+       for (int i = 0; i < count; i++) {
+               mdg_group_type_e type;
+               char *uri_path;
+               mdg_group_info_get_type(groups[i], &type);
+               mdg_group_info_get_uri_path(groups[i], &uri_path);
+               TC_PRT("%d. type : %d, uri path : %s", i+1, type, uri_path);
+               found_group_list = g_list_append(found_group_list, groups[i]);
+       }
+
+       END();
+       return ret;
+}
+
+bool _device_found_cb(mdg_device_h device, void *user_data)
+{
+       char *device_id;
+       char *ip;
+       mdg_device_type_e device_type;
+
+       mdg_device_info_get_device_id(device, &device_id);
+       mdg_device_info_get_ip(device, &ip);
+       mdg_device_info_get_device_type(device, &device_type);
+
+       TC_PRT("found device device_id : %s, ip : %s, device_type : %s", device_id, ip,
+               __device_type_to_string(device_type));
+
+       found_device_list = g_list_append(found_device_list, device);
+}
+
+int mdg_device_find_test(void)
+{
+       int ret = 0;
+       int input_int = 0;
+
+       BEGIN();
+       found_device_list = NULL;
+
+       if (!test_get_user_int("==> Input timeout value (sec)"
+                                                " - (Enter for skip) :", &input_int)) {
+               input_int = 5;
+               TC_PRT("default timeout value [%d]", input_int);
+       }
+
+       mdg_device_find(handle, input_int, _device_found_cb, _group_finish_cb, NULL);
+
+       if (ret == 0)
+               TC_PRT("device find successful");
+       else
+               TC_PRT("device find failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+int mdg_device_get_found_devices_test(void)
+{
+       int ret = 0;
+       int count = 0;
+       mdg_device_h *devices;
+
+       BEGIN();
+
+       found_device_list = NULL;
+
+       ret = mdg_device_get_found_devices(hadnle, &devices, &count);
+
+       if (ret == 0)
+               TC_PRT("device find successful");
+       else
+               TC_PRT("device find failed, ret [%d]", ret);
+
+       TC_PRT("Found device count : ", count);
+
+       for (int i = 0; i < count; i++) {
+               char *uuid;
+               char *ip;
+               mdg_device_type_e device_type;
+
+               mdg_device_info_get_device_id(devices[i], &uuid);
+               mdg_device_info_get_ip(devices[i], &ip);
+               mdg_device_info_get_device_type(devices[i], &device_type);
+
+               TC_PRT("%d. uuid : %s, ip : %s, device_type : %s", i+1, uuid, ip,
+                       __device_type_to_string(device_type));
+               found_device_list = g_list_append(found_device_list, devices[i]);
+       }
+
+       END();
+       return ret;
+}
+
+void _device_invite_result_cb(int result, void *user_data)
+{
+       TC_PRT("Invite complete !!!! ret : %d", result);
+}
+
+int mdg_device_invite_test(void)
+{
+       int ret = 0;
+       BEGIN();
+
+       /* using stored group list and device list */
+       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
+               TC_PRT("Invite Test Start");
+               mdg_group_h group = (mdg_group_h)(found_group_list[0].data);
+               mdg_device_h device = (mdg_device_h)(found_device_list[0].data);
+
+               mdg_group_invite_device(handle, group, device, "12341234", _device_invite_result_cb, NULL);
+
+       } else {
+               TC_PRT("not exist found group or device list");
+       }
+
+       END();
+       return ret;
+}
+
+void _device_eject_result_cb(int result, void *user_data)
+{
+       TC_PRT("eject complete !!!! ret : %d", result);
+}
+
+int mdg_device_eject_test(void)
+{
+       int ret = 0;
+       BEGIN();
+
+       /* using stored group list and device list */
+       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
+               TC_PRT("Invite Test Start");
+               mdg_group_h group = (mdg_group_h)(found_group_list[0].data);
+               mdg_device_h device = (mdg_device_h)(found_device_list[0].data);
+
+               /* using stored group list and device list */
+               mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
+       } else {
+               TC_PRT("not exist found group or device list");
+       }
+
+
+       END();
+       return ret;
+}
+
+//send_data_callback : if the remote device not invited, then callback is called include result failed.
+//send_data_callback : if the remote device invited, then callback result successful.
+
+int mdg_send_data_to_remote_device_test(void)
+{
+       int ret = 0;
+       BEGIN();
+
+       if (g_list_length(found_device_list) > 0) {
+               mdg_device_h device = (mdg_device_h)(found_device_list[0].data);
+               ret = mdg_device_send_data(handle, device, "123", NULL, NULL);
+       } else {
+               TC_PRT("not exist found device list");
+       }
+
+       END();
+       return ret;
+}
+
+int mdg_deinitialize_test(void)
+{
+       int ret = 0;
+
+       BEGIN();
+
+       ret = mdg_deinitialize(handle);
+
+       if (ret == 0)
+               TC_PRT("Initialize successful");
+       else
+               TC_PRT("Initialize failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+tc_table_t tc_table[] = {
+       /* manager api */
+       {"mdg_initialize_test",  1,     mdg_initialize_test},
+       {"mdg_group_create_test",  2,   mdg_group_create_test},
+       {"mdg_group_find_test",  3,     mdg_group_find_test},
+       {"mdg_group_get_found_groups_test",  4, mdg_group_get_found_groups_test},
+       {"mdg_device_find_test",  5,    mdg_device_find_test},
+       {"mdg_device_get_found_devices_test",  6,       mdg_device_get_found_devices_test},
+       {"mdg_device_invite_test",  7,  mdg_device_invite_test},
+       {"mdg_device_eject_test",  8,   mdg_device_eject_test},
+       {"mdg_send_data_to_remote_device_test",  9,     mdg_send_data_to_remote_device_test},
+       {"mdg_deinitialize_test",  TEST_CASE_MAX,       mdg_deinitialize_test},
+
+       /*-----------*/
+       {"Finish",                                                                      0x0000, NULL},
+       {NULL,                                                                          0x00ff, NULL},
+};
+
+static void tc_usage_print(void)
+{
+       int i = 0;
+
+       while (tc_table[i].tc_name) {
+               if (tc_table[i].tc_code != 0x00ff)
+                       printf("Key [%2d] : usage %s\n", tc_table[i].tc_code, tc_table[i].tc_name);
+               else
+                       printf("Key [%2d] : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
+
+               i++;
+       }
+}
+
+static int test_input_callback(void *data)
+{
+       long test_id = (long)data;
+       int ret = 0;
+
+       if ((test_id >= 1) && (test_id <= TEST_CASE_MAX)) {
+               TC_PRT("test_input_callback test_id : %ld", test_id);
+
+               if (tc_table[test_id-1].tc_func != NULL) {
+                       ret = tc_table[test_id-1].tc_func();
+
+                       if (ret != 0)
+                               TC_PRT(">>>>> Test Error Returned !!! : %d", ret);
+               }
+       }
+
+       return 0;
+}
+
+static int test_terminate(void)
+{
+       int ret = 0;
+
+       TC_PRT("Finished");
+
+       mdg_deinitialize_test();
+       g_main_loop_quit(main_loop);
+
+       return ret;
+}
+
+static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+       char buf[BUFFER_LEN] = {0,};
+       long test_id;
+       int rv = 0;
+
+       memset(buf, 0, sizeof(buf));
+
+       rv = read(0, buf, 100);
+
+       if (rv < 0 || buf[0] == '0') {
+               test_terminate();
+               exit(1);
+       }
+
+       if (*buf == '\n' || *buf == '\r')
+               tc_usage_print();
+
+       test_id = atoi(buf);
+
+       test_input_callback((void *)test_id);
+
+       return TRUE;
+}
+
+
+int main(int argc, char ** argv)
+{
+       GIOChannel *key_io;
+
+       main_loop = g_main_loop_new(NULL, FALSE);
+       key_io = g_io_channel_unix_new(0);
+
+       printf("Test Thread created...\n");
+
+       g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL);
+       g_main_loop_run(main_loop);
+
+       g_io_channel_unref(key_io);
+       g_main_loop_unref(main_loop);
+
+       return 0;
+}
diff --git a/capi/test/menu.c b/capi/test/menu.c
new file mode 100644 (file)
index 0000000..c217f6b
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <glib.h>
+#include <asm/unistd.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "menu.h"
+
+#define DEFAULT_MENU_MENU      "m"
+#define DEFAULT_MENU_PREV      "p"
+#define DEFAULT_MENU_QUIT      "q"
+#define DEFAULT_MENU_NONE      "-"
+#define TAB_SPACE     "  "
+
+struct menu_manager {
+       GQueue *stack;
+       GQueue *title_stack;
+
+       struct menu_data *menu;
+
+       char *buf;
+
+       void *user_data;
+       GMainLoop *mainloop;
+};
+
+
+char key_buffer[MENU_DATA_SIZE];
+int flag_pid_display = 1;
+
+extern unsigned short dest_addr16;
+extern struct menu_data menu_sel_device[];
+
+static void _show_prompt(void)
+{
+       msgn("(%5d) >> ", get_tid());
+}
+
+static void _show_reserved_menu(void)
+{
+       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
+       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
+       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
+                       " ] " ANSI_COLOR_NORMAL "Previous menu " , DEFAULT_MENU_PREV);
+       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
+                       " ] " ANSI_COLOR_NORMAL "Show Menu " , DEFAULT_MENU_MENU);
+       msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY
+                       " ] " ANSI_COLOR_NORMAL "Quit " , DEFAULT_MENU_QUIT);
+}
+
+static void _show_input_ok(void)
+{
+       msg("OK.");
+}
+
+static void _show_menu(MManager *m, struct menu_data menu[])
+{
+       int i = 0;
+       int len = 0;
+       struct menu_data *item;
+       char title_buf[256] = { 0, };
+
+       if (!menu)
+               return;
+
+       msg("");
+       msg(HR_DOUBLE);
+
+       len = g_queue_get_length(m->title_stack);
+       msgn(ANSI_COLOR_YELLOW " Main");
+       if (len > 0) {
+               for (i = 0; i < len; i++) {
+                       msgn(ANSI_COLOR_NORMAL " >> " ANSI_COLOR_YELLOW "%s",
+                                       (char *)g_queue_peek_nth(m->title_stack, i));
+               }
+       }
+       msg(ANSI_COLOR_NORMAL);
+       msg(HR_SINGLE);
+
+       hide_pid();
+       i = 0;
+
+       while (1) {
+               item = menu + i;
+               if (item->key == NULL)
+                       break;
+
+               if (!g_strcmp0(item->key, "-")) {
+                       msgn("       ");
+               } else if (!g_strcmp0(item->key, "_")) {
+                       msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL);
+
+                       if (item->callback)
+                               item->callback(m, item);
+
+                       i++;
+
+                       continue;
+               } else if (!g_strcmp0(item->key, "*")) {
+                       msg(" %s", item->title);
+                       if (item->callback)
+                               item->callback(m, item);
+               } else {
+                       msgn(ANSI_COLOR_DARKGRAY " [" ANSI_COLOR_NORMAL "%3s"
+                                       ANSI_COLOR_DARKGRAY "] " ANSI_COLOR_NORMAL,     item->key);
+               }
+
+               memset(title_buf, 0, 256);
+               if (item->title) {
+                       snprintf(title_buf, MAX_TITLE, "%s", item->title);
+
+                       if (strlen(item->title) >= MAX_TITLE) {
+                               title_buf[MAX_TITLE - 2] = '.';
+                               title_buf[MAX_TITLE - 1] = '.';
+                       }
+               }
+
+               if (item->data) {
+                       msg("%s " ANSI_COLOR_LIGHTBLUE "(%s)" ANSI_COLOR_NORMAL,
+                                       title_buf, item->data);
+               } else if (!g_strcmp0(item->key, "*")) {
+                       /* none */
+               } else {
+                       msg("%s", title_buf);
+               }
+
+               if (item->sub_menu)
+                       msg("\e[1A\e[%dC >", (int)POS_MORE);
+
+               i++;
+       }
+
+       show_pid();
+
+       _show_reserved_menu();
+
+       msg(HR_DOUBLE);
+
+       _show_prompt();
+}
+
+static void _show_item_data_input_msg(struct menu_data *item)
+{
+       msg("");
+       msg(HR_DOUBLE);
+       msg(" Input [%s] data ", item->title);
+       msg(HR_SINGLE);
+       msg(" current = [%s]", item->data);
+       msgn(" new >> ");
+}
+
+static void _move_menu(MManager *mm, struct menu_data menu[], char *key)
+{
+       struct menu_data *item;
+       int i = 0;
+
+       if (!mm->menu)
+               return;
+
+       if (!g_strcmp0(DEFAULT_MENU_PREV, key)) {
+               if (g_queue_get_length(mm->stack) > 0) {
+                       mm->menu = g_queue_pop_tail(mm->stack);
+                       g_queue_pop_tail(mm->title_stack);
+               }
+
+               _show_menu(mm, mm->menu);
+               mm->buf = key_buffer;
+
+               return;
+       } else if (!g_strcmp0(DEFAULT_MENU_MENU, key)) {
+               _show_menu(mm, mm->menu);
+               return;
+       } else if (!g_strcmp0(DEFAULT_MENU_QUIT, key)) {
+               g_main_loop_quit(mm->mainloop);
+               return;
+       } else if (!g_strcmp0(DEFAULT_MENU_NONE, key)) {
+               _show_prompt();
+               return;
+       }
+
+       while (1) {
+               int ret = RET_SUCCESS;
+               item = menu + i;
+               if (item->key == NULL)
+                       break;
+
+               if (!g_strcmp0(item->key, key)) {
+                       if (item->callback) {
+                               ret = item->callback(mm, item);
+                               _show_prompt();
+                       }
+
+                       if (RET_SUCCESS == ret) {
+                               if (item->sub_menu) {
+                                       g_queue_push_tail(mm->stack, mm->menu);
+                                       g_queue_push_tail(mm->title_stack, (gpointer *)item->title);
+
+                                       mm->menu = item->sub_menu;
+                                       _show_menu(mm, mm->menu);
+                                       mm->buf = key_buffer;
+                               }
+
+                               if (item->data) {
+                                       _show_item_data_input_msg(item);
+                                       mm->buf = item->data;
+                               }
+                       }
+
+                       return;
+               }
+
+               i++;
+       }
+
+       _show_prompt();
+}
+
+MManager *menu_manager_new(struct menu_data items[], GMainLoop *mainloop)
+{
+       MManager *mm;
+
+       mm = calloc(sizeof(struct menu_manager), 1);
+       if (!mm)
+               return NULL;
+
+       mm->stack = g_queue_new();
+       mm->title_stack = g_queue_new();
+       mm->menu = items;
+       mm->mainloop = mainloop;
+
+       return mm;
+}
+
+int menu_manager_run(MManager *mm)
+{
+       _show_menu(mm, mm->menu);
+
+       mm->buf = key_buffer;
+
+       return 0;
+}
+
+int menu_manager_set_user_data(MManager *mm, void *user_data)
+{
+       if (!mm)
+               return -1;
+
+       mm->user_data = user_data;
+
+       return 0;
+}
+
+void *menu_manager_ref_user_data(MManager *mm)
+{
+       if (!mm)
+               return NULL;
+
+       return mm->user_data;
+}
+
+gboolean on_menu_manager_keyboard(GIOChannel *src, GIOCondition con,
+               gpointer data)
+{
+       MManager *mm = data;
+       char local_buf[MENU_DATA_SIZE + 1] = { 0, };
+
+       if (fgets(local_buf, MENU_DATA_SIZE, stdin) == NULL)
+               return TRUE;
+
+       if (strlen(local_buf) > 0) {
+               if (local_buf[strlen(local_buf) - 1] == '\n')
+                       local_buf[strlen(local_buf) - 1] = '\0';
+       }
+
+       if (mm->buf == key_buffer) {
+               if (strlen(local_buf) < 1) {
+                       _show_prompt();
+                       return TRUE;
+               }
+
+               _move_menu(mm, mm->menu, local_buf);
+       } else {
+               if (mm->buf) {
+                       memset(mm->buf, 0, MENU_DATA_SIZE);
+                       memcpy(mm->buf, local_buf, MENU_DATA_SIZE);
+                       _show_input_ok();
+               }
+               mm->buf = key_buffer;
+               _move_menu(mm, mm->menu, (char *)DEFAULT_MENU_MENU);
+       }
+
+       return TRUE;
+}
+
+pid_t get_tid()
+{
+       return syscall(__NR_gettid);
+}
+
+void hide_pid()
+{
+       flag_pid_display = 0;
+}
+
+void show_pid()
+{
+       flag_pid_display = 1;
+}
+
+int is_pid_show()
+{
+       return flag_pid_display;
+}
+
+static void _hex_dump(const char *pad, int size, const void *data)
+{
+       char buf[255] = {0, };
+       char hex[4] = {0, };
+       int i;
+       unsigned char *p;
+
+       if (size <= 0) {
+               msg("%sno data", pad);
+               return;
+       }
+       p = (unsigned char *)data;
+
+       snprintf(buf, 255, "%s%04X: ", pad, 0);
+       for (i = 0; i < size; i++) {
+               snprintf(hex, 4, "%02X ", p[i]);
+               strncat(buf, hex, 255 - strlen(buf) - 1);
+
+               if ((i + 1) % 8 == 0) {
+                       if ((i + 1) % 16 == 0) {
+                               msg("%s", buf);
+                               memset(buf, 0, 255);
+                               snprintf(buf, 255, "%s%04X: ", pad, i + 1);
+                       } else {
+                               strncat(buf, TAB_SPACE, 255 - strlen(buf) - 1);
+                       }
+               }
+       }
+
+       msg("%s", buf);
+}
+
+void menu_print_dump(int data_len, void *data)
+{
+       if (!data)
+               return;
+
+       msg("");
+       msg("  \tlen=%d", data_len);
+       _hex_dump("        ", data_len, data);
+
+       msg("");
+}
diff --git a/capi/test/menu.h b/capi/test/menu.h
new file mode 100644 (file)
index 0000000..728d36c
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MENU_H__
+#define __MENU_H__
+
+__BEGIN_DECLS
+
+#define ANSI_COLOR_NORMAL              "\e[0m"
+
+#define ANSI_COLOR_BLACK               "\e[0;30m"
+#define ANSI_COLOR_RED                 "\e[0;31m"
+#define ANSI_COLOR_GREEN               "\e[0;32m"
+#define ANSI_COLOR_BROWN               "\e[0;33m"
+#define ANSI_COLOR_BLUE                        "\e[0;34m"
+#define ANSI_COLOR_MAGENTA             "\e[0;35m"
+#define ANSI_COLOR_CYAN                        "\e[0;36m"
+#define ANSI_COLOR_LIGHTGRAY   "\e[0;37m"
+
+#define ANSI_COLOR_DARKGRAY            "\e[1;30m"
+#define ANSI_COLOR_LIGHTRED            "\e[1;31m"
+#define ANSI_COLOR_LIGHTGREEN  "\e[1;32m"
+#define ANSI_COLOR_YELLOW              "\e[1;33m"
+#define ANSI_COLOR_LIGHTBLUE   "\e[1;34m"
+#define ANSI_COLOR_LIGHTMAGENTA "\e[1;35m"
+#define ANSI_COLOR_LIGHTCYAN   "\e[1;36m"
+#define ANSI_COLOR_WHITE               "\e[1;37m"
+
+
+#define msg(fmt, args...)      do { fprintf(stdout, fmt "\n", ##args); \
+               fflush(stdout); } while (0)
+#define msgn(fmt, args...)     do { fprintf(stdout, fmt, ##args); \
+               fflush(stdout); } while (0)
+
+/* Bold (red) */
+#define msgr(fmt, args...)  do { fprintf(stdout, ANSI_COLOR_RED fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+/* Bold (green) */
+#define msgb(fmt, args...)  do { fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+/* Property message */
+#define msgp(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTMAGENTA fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+#define msgt(n, fmt, args...) do { fprintf(stdout, "\e[%dC" fmt "\n", \
+               3 + ((n) * 2), ##args); fflush(stdout); } while (0)
+
+#define pmsg(fmt, args...) do { \
+       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
+       fprintf(stdout, fmt "\n", ##args); fflush(stdout); } while (0)
+
+#define pmsgb(fmt, args...) do { \
+       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
+       fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \
+                       ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+#define pmsgt(n, fmt, args...) do { \
+       if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \
+       fprintf(stdout, "\e[%dC" fmt "\n", \
+                       3 + ((n) * 2), ##args); fflush(stdout); } while (0)
+
+#define MENU_DATA_SIZE 255
+
+
+
+/*
+ * Horizontal Line - width: 65
+ *                                     .12345678901234567890123456789012345678901234567890.
+ */
+#define HR_SINGLE      "----------------------------------------" \
+                                       "-------------------------"
+#define HR_DOUBLE      "========================================" \
+                                       "========================="
+#define HR_SINGLE2     " ---------------------------------------" \
+                                       "------------------------ "
+
+#define MAX_WIDTH      strlen(HR_SINGLE)
+#define MAX_TITLE      ((MAX_WIDTH) - 10)
+#define POS_MORE       ((MAX_WIDTH) - 3)
+#define RET_SUCCESS 0
+#define RET_FAILURE -1
+
+typedef struct menu_manager MManager;
+
+struct menu_data {
+       const char *key;
+       const char *title;
+       struct menu_data *sub_menu;
+       int (*callback)(MManager *mm, struct menu_data *menu);
+       char *data;
+};
+
+MManager* menu_manager_new(struct menu_data items[], GMainLoop *mainloop);
+int menu_manager_run(MManager *mm);
+int menu_manager_set_user_data(MManager *mm, void *user_data);
+void* menu_manager_ref_user_data(MManager *mm);
+
+gboolean  on_menu_manager_keyboard(GIOChannel *src, GIOCondition con,
+               gpointer data);
+
+pid_t get_tid();
+void hide_pid();
+void show_pid();
+int is_pid_show();
+void menu_print_dump(int data_len, void *data);
+
+__END_DECLS
+
+#endif
index 50e8981fc063c390006f1c7618ad81b75c479fe3..8f241779baf1e1a4dd9275346f17f308cdfbabc9 100644 (file)
@@ -1,12 +1,12 @@
-SET(COMP_UNIT_TEST "companion_unit_test")
+SET(MDG_UNIT_TEST "mdg_unit_test")
 
-SET(COMP_UNIT_TEST_SOURCES
-       companion_unit_test.cpp
+SET(MDG_UNIT_TEST_SOURCES
+       mdg_unit_test.cpp
 )
 
-ADD_EXECUTABLE(${COMP_UNIT_TEST} ${COMP_UNIT_TEST_SOURCES})
+ADD_EXECUTABLE(${MDG_UNIT_TEST} ${MDG_UNIT_TEST_SOURCES})
 
-TARGET_LINK_LIBRARIES(${COMP_UNIT_TEST}
-       ${daemon_pkgs_LIBRARIES} capi-network-companion)
+TARGET_LINK_LIBRARIES(${MDG_UNIT_TEST}
+       ${daemon_pkgs_LIBRARIES} capi-network-mdg)
 
-INSTALL(TARGETS ${COMP_UNIT_TEST} DESTINATION bin/)
+INSTALL(TARGETS ${MDG_UNIT_TEST} DESTINATION bin/)
diff --git a/capi/unittest/companion_unit_test.cpp b/capi/unittest/companion_unit_test.cpp
deleted file mode 100644 (file)
index 2a5414a..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-#include <unistd.h>
-#include <glib.h>
-#include <dlog.h>
-#include <companion.h>
-#include <iostream>
-
-using namespace std;
-
-using ::testing::EmptyTestEventListener;
-using ::testing::InitGoogleTest;
-using ::testing::Test;
-using ::testing::TestCase;
-using ::testing::TestEventListeners;
-using ::testing::TestInfo;
-using ::testing::TestPartResult;
-using ::testing::UnitTest;
-
-companion_h handle = NULL;
-
-TEST(companion, companion_initialize_p) {
-
-}
-
-TEST(companion, companion_initialize_n) {
-
-}
-
-TEST(companion, companion_deinitialize_p) {
-
-}
-
-TEST(companion, companion_deinitialize_n) {
-
-}
-
-TEST(companion, companion_group_create_p) {
-       cout << "TEST START" << endl;
-
-       int ret;
-
-       companion_initialize(&handle);
-       ret = companion_group_create(handle, (char *)"group1");
-
-       cout << "TEST END :" <<  ret << endl;
-}
-
-GMainLoop *main_loop = NULL;
-
-bool _companion_group_found_cb(companion_group_type_e type, companion_group_h group_handle, void *user_data)
-{
-       char *uri_path;
-       companion_group_information_get_uri_path(group_handle, &uri_path);
-
-       cout << "group type : " << type << ", uri : " << uri_path << endl;
-
-       return true;
-}
-
-void _companion_finish_cb(int result, void *user_data)
-{
-       cout << "find finish : " << result << endl;
-       g_main_loop_quit(main_loop);
-
-       companion_group_h *groups;
-       int count;
-
-       companion_group_get_found_groups(handle, &groups, &count);
-       cout << "Found groups device count : " << count << endl;
-
-       for (int i = 0; i < count; i++) {
-               companion_group_type_e type;
-               char *uri_path;
-               companion_group_information_get_type(groups[i], &type);
-               companion_group_information_get_uri_path(groups[i], &uri_path);
-               cout << i+1 << ". device group type : " << type << ", uri_path : " << uri_path << endl;
-       }
-}
-
-TEST(companion, companion_group_find_p) {
-       cout << "TEST START" << endl;
-       companion_initialize(&handle);
-       main_loop = g_main_loop_new(NULL, FALSE);
-       companion_group_find(handle, 5, _companion_group_found_cb, _companion_finish_cb, main_loop);
-       g_main_loop_run(main_loop);
-       cout << "TEST END" << endl;
-}
-
-int main(int argc, char **argv) {
-       InitGoogleTest(&argc, argv);
-       return RUN_ALL_TESTS();
-}
diff --git a/capi/unittest/mdg_unit_test.cpp b/capi/unittest/mdg_unit_test.cpp
new file mode 100644 (file)
index 0000000..a9786b2
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <glib.h>
+#include <dlog.h>
+#include <mdg.h>
+#include <iostream>
+
+using namespace std;
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+mdg_h handle = NULL;
+
+TEST(mdg, mdg_initialize_p) {
+
+}
+
+TEST(mdg, mdg_initialize_n) {
+
+}
+
+TEST(mdg, mdg_deinitialize_p) {
+
+}
+
+TEST(mdg, mdg_deinitialize_n) {
+
+}
+
+TEST(mdg, mdg_group_create_p) {
+       cout << "TEST START" << endl;
+
+       int ret;
+
+       mdg_initialize(&handle);
+       ret = mdg_group_create(handle, (char *)"group1");
+
+       cout << "TEST END :" <<  ret << endl;
+}
+
+GMainLoop *main_loop = NULL;
+
+bool _mdg_group_found_cb(mdg_group_type_e type, mdg_group_h group_handle, void *user_data)
+{
+       char *uri_path;
+       mdg_group_info_get_uri_path(group_handle, &uri_path);
+
+       cout << "group type : " << type << ", uri : " << uri_path << endl;
+
+       return true;
+}
+
+void _mdg_finish_cb(int result, void *user_data)
+{
+       cout << "find finish : " << result << endl;
+       g_main_loop_quit(main_loop);
+
+       mdg_group_h *groups;
+       int count;
+
+       mdg_group_get_found_groups(handle, &groups, &count);
+       cout << "Found groups device count : " << count << endl;
+
+       for (int i = 0; i < count; i++) {
+               mdg_group_type_e type;
+               char *uri_path;
+               mdg_group_info_get_type(groups[i], &type);
+               mdg_group_info_get_uri_path(groups[i], &uri_path);
+               cout << i+1 << ". device group type : " << type << ", uri_path : " << uri_path << endl;
+       }
+}
+
+TEST(mdg, mdg_group_find_p) {
+       cout << "TEST START" << endl;
+       mdg_initialize(&handle);
+       main_loop = g_main_loop_new(NULL, FALSE);
+       mdg_group_find(handle, 5, _mdg_group_found_cb, _mdg_finish_cb, main_loop);
+       g_main_loop_run(main_loop);
+       cout << "TEST END" << endl;
+}
+
+int main(int argc, char **argv) {
+       InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/packaging/capi-network-companion.manifest b/packaging/capi-network-companion.manifest
deleted file mode 100644 (file)
index a76fdba..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
-       <request>
-               <domain name="_" />
-       </request>
-</manifest>
diff --git a/packaging/capi-network-mdg.manifest b/packaging/capi-network-mdg.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/compmanager.service b/packaging/compmanager.service
deleted file mode 100644 (file)
index e8500f6..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=Companion Manager
-After=feedbckd.service
-
-[Service]
-Type=dbus
-User=network_fw
-Group=network_fw
-BusName=org.tizen.companion
-SmackProcessLabel=System
-ExecStart=/usr/bin/companion-manager
-
-[Install]
-WantedBy=multi-user.target
old mode 100755 (executable)
new mode 100644 (file)
index e63f343..3c8c0cd
@@ -7,11 +7,11 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source3:    %{name}.manifest
 Source4:    %{name}-devel.manifest
-Source6:    compmanager.service
-Source7:    net.compmanager.service
+Source6:    mdgd.service
+Source7:    net.mdgd.service
 Source8:    ma.service
 Source9:    net.ma.service
-Source10:    capi-network-companion.manifest
+Source10:    capi-network-mdg.manifest
 
 BuildRequires: cmake
 BuildRequires: pkgconfig(iotivity)
@@ -100,9 +100,9 @@ rm -rf %{buildroot}/BUILD/%{name}*
 
 mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services/
 
-cp %{SOURCE7} %{buildroot}%{_datadir}/dbus-1/system-services/net.compmanager.service
+cp %{SOURCE7} %{buildroot}%{_datadir}/dbus-1/system-services/net.mdgd.service
 mkdir -p %{buildroot}%{_unitdir}
-cp %{SOURCE6} %{buildroot}%{_unitdir}/compmanager.service
+cp %{SOURCE6} %{buildroot}%{_unitdir}/mdgd.service
 
 cp %{SOURCE9} %{buildroot}%{_datadir}/dbus-1/system-services/net.ma.service
 mkdir -p %{buildroot}%{_unitdir}
@@ -117,24 +117,24 @@ rm -rf %{NETWORK_FW_DATADIR}/*.db-journal
 %license LICENSE
 %defattr(-,root,root,-)
 %{_bindir}/mot-agent
-%{_bindir}/companion-manager
+%{_bindir}/mdgd
 %attr(644,root,root) %{_datadir}/dbus-1/system-services/*
-%attr(644,root,root) %{_unitdir}/compmanager.service
+%attr(644,root,root) %{_unitdir}/mdgd.service
 %attr(644,root,root) %{_unitdir}/ma.service
 %attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_ma.dat
-%attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_comp_manager.dat
+%attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_mdg_manager.dat
 
 %files devel
 %manifest %{name}-devel.manifest
 
 %files capi
-%manifest capi-network-companion.manifest
+%manifest capi-network-mdg.manifest
 %defattr(-,root,root,-)
-%{_libdir}/libcapi-network-companion.so*
+%{_libdir}/libcapi-network-mdg.so*
 
 %files capi-devel
 %{_includedir}/*.h
 %{_libdir}/pkgconfig/*.pc
-%{_libdir}/libcapi-network-companion.so
-%attr(777,root,root) %{_bindir}/companion_unit_test
-%attr(777,root,root) %{_bindir}/companion_demo
+%{_libdir}/libcapi-network-mdg.so
+%attr(777,root,root) %{_bindir}/mdg_unit_test
+%attr(777,root,root) %{_bindir}/mdg-test
diff --git a/packaging/mdgd.service b/packaging/mdgd.service
new file mode 100644 (file)
index 0000000..09a5120
--- /dev/null
@@ -0,0 +1,14 @@
+[Unit]
+Description=Multi Device Group Manager
+After=feedbckd.service
+
+[Service]
+Type=dbus
+User=network_fw
+Group=network_fw
+BusName=org.tizen.mdg
+SmackProcessLabel=System
+ExecStart=/usr/bin/mdgd
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/net.compmanager.service b/packaging/net.compmanager.service
deleted file mode 100644 (file)
index 656e3b8..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-[D-BUS Service]
-Name=org.tizen.companion
-
-Exec=/bin/false
-User=network_fw
-Group=network_fw
-SystemdService=compmanager.service
diff --git a/packaging/net.mdgd.service b/packaging/net.mdgd.service
new file mode 100644 (file)
index 0000000..59fa3ab
--- /dev/null
@@ -0,0 +1,7 @@
+[D-BUS Service]
+Name=org.tizen.mdg
+
+Exec=/bin/false
+User=network_fw
+Group=network_fw
+SystemdService=mdgd.service
diff --git a/src/companion-manager/CMakeLists.txt b/src/companion-manager/CMakeLists.txt
deleted file mode 100644 (file)
index 9eaee14..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-MESSAGE("===================================================================")
-MESSAGE("Building...companion-manager")
-MESSAGE("===================================================================")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
-EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
-                " \\
-                --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/src/companion_gdbus \\
-                --interface-prefix org.tizen.companion. \\
-                ${CMAKE_CURRENT_SOURCE_DIR}/src/companion_gdbus.xml \\
-                ")
-
-MESSAGE(" - Set source folder")
-FILE(GLOB COMP_MANAGER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
-
-SET(COMP_MANAGER "companion-manager")
-ADD_EXECUTABLE(${COMP_MANAGER} ${COMP_MANAGER_SRCS})
-TARGET_LINK_LIBRARIES(${COMP_MANAGER} ${daemon_pkgs_LIBRARIES} pthread)
-INSTALL(TARGETS ${COMP_MANAGER} DESTINATION bin)
-INSTALL(FILES oic_svr_db_comp_manager.dat DESTINATION ${NETWORK_FW_DATADIR})
diff --git a/src/companion-manager/include/comp_context.h b/src/companion-manager/include/comp_context.h
deleted file mode 100644 (file)
index db9e234..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_CONTEXT_H__
-#define __COMP_CONTEXT_H__
-
-#include <glib.h>
-#include <comp_log.h>
-#include <unistd.h>
-#include <gio/gio.h>
-#include <companion_gdbus.h>
-#include <sys/types.h>
-#include <sqlite3.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef struct {
-       GMainLoop *main_loop;
-       //GDBusConnection *connection;
-       int ref_count;
-
-       // resource list
-       GList *resource_list[COMP_RESOURCE_TYPE_MAX];
-
-       char *device_uuid;
-       bool mot_me; /**< Indicator whether mot local comp-manager */
-       GList *grp_list;
-       GList *pairwise_list;
-
-       bool monitor_started;
-
-       //sqlite3 db
-       sqlite3 *db;
-} comp_context_t;
-
-typedef struct {
-       char *conn_name;
-       int conn_id;
-       GDBusConnection *connection;
-} comp_conn_destroy_data;
-
-int comp_context_create();
-int comp_context_destroy();
-void comp_context_mutex_lock();
-void comp_context_mutex_unlock();
-
-comp_context_t *comp_context_get_context();
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __COMP_CONTEXT_H__ */
diff --git a/src/companion-manager/include/comp_db.h b/src/companion-manager/include/comp_db.h
deleted file mode 100755 (executable)
index 1156237..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_DB_H__
-#define __COMP_DB_H__
-
-#define COMP_DB_FILE "/opt/usr/dbspace/.comp.db"
-#define COMP_DB_TABLE "comp_group_information"
-
-int comp_db_init();
-int comp_db_deinit();
-int comp_db_insert(char *group_name, char *device_id);
-int comp_db_delete_group(char *group_name);
-int comp_db_delete_device(char *group_name, char *device_id);
-
-#endif
diff --git a/src/companion-manager/include/comp_enum.h b/src/companion-manager/include/comp_enum.h
deleted file mode 100644 (file)
index 4ca0046..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_ENUM_H__
-#define __COMP_ENUM_H__
-
-#include <tizen.h>
-
-#define NOTUSED(var) (var = var) /**< It is used to avoid generating build warning */
-
-#define TIZEN_ERROR_COMP 0 /**< Same one */
-
-/**
- * @brief Error codes for companion-manager.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
-       COMP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
-       COMP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
-       COMP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
-       COMP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
-       COMP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
-       COMP_ERROR_COMM_ERROR = TIZEN_ERROR_COMP | 0x01, /**< communication error */
-       COMP_ERROR_RX = TIZEN_ERROR_COMP | 0x02, /**< RX error */
-       COMP_ERROR_TX = TIZEN_ERROR_COMP | 0x03, /**< TX error */
-       COMP_ERROR_PLUGIN_FAIL = TIZEN_ERROR_COMP | 0x04, /**< Plugin failed */
-       COMP_ERROR_OPERATION_FAILED = TIZEN_ERROR_COMP | 0x05, /**< Operation Failed */
-       COMP_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */
-       COMP_ERROR_UNKNOWN = -999,
-} comp_error_e;
-
-/**
- * @brief Resource type.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMP_RESOURCE_TYPE_GROUP = 0, /**< Group resource type  */
-       COMP_RESOURCE_TYPE_DEVICE, /**< Device resource type  */
-       COMP_RESOURCE_TYPE_OPERATION, /**< Operation resource type */
-       COMP_RESOURCE_TYPE_DATA, /**< Data resource type */
-       COMP_RESOURCE_TYPE_MAX
-} comp_resource_type_e;
-
-/**
- * @brief Group type.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMP_GROUP_GROUP_ERROR = 0, /**< Group type error */
-       COMP_GROUP_GROUP_LOCAL = 1, /**< Local group type */
-       COMP_GROUP_GROUP_REMOTE = 2, /**< Remote group type */
-} comp_group_type_e;
-
-typedef enum {
-       COMP_GROUP_DEVICE_ERROR = 0, /**< Group type error */
-       COMP_GROUP_DEVICE_LOCAL = 1, /**< Local group type */
-       COMP_GROUP_DEVICE_REMOTE = 2, /**< Remote group type */
-} comp_device_type_e;
-
-/**
- * @brief The command type for request.
- *
- * @since_tizen 5.0
- */
-typedef enum {
-       COMP_REQ_UNKNOWN_COMMAND = -1, /**< Unknown Command */
-       COMP_REQ_SEND_DATA = 0, /**< Send data */
-       COMP_REQ_CREATE_GROUP, /**< Create Group */
-       COMP_REQ_INVITE_DEVICE, /**< Invite Device */
-       COMP_REQ_EJECT_DEVICE, /**< Exile Device */
-       COMP_REQ_DELETE_GROUP, /**< Delete Group */
-       COMP_REQ_KEEP_ALIVE, /**< Keep Alive Message */
-       COMP_REQ_SEND_DATA_ALL, /**< Send data in subnet */
-} comp_request_type_e;
-
-#endif /* __COMP_ENUM_H__ */
diff --git a/src/companion-manager/include/comp_gdbus.h b/src/companion-manager/include/comp_gdbus.h
deleted file mode 100644 (file)
index 4da1940..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_GDBUS_H__
-#define __COMP_GDBUS_H__
-
-#include <comp_gdbus_group.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define COMP_DBUS_SERVICE "org.tizen.companion" /**< For companion dbus */
-#define COMP_DBUS_GROUP_PATH "/org/tizen/companion/group" /**< For group commands */
-#define COMP_DBUS_ENABLER_PATH "/org/tizen/companion/enabler" /**< For d-bus activation */
-
-int comp_gdbus_init();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __COMP_GDBUS_H__ */
diff --git a/src/companion-manager/include/comp_gdbus_group.h b/src/companion-manager/include/comp_gdbus_group.h
deleted file mode 100644 (file)
index 32a43d4..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_GDBUS_GROUP_H__
-#define __COMP_GDBUS_GROUP_H__
-
-#include <comp_group.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-Group *group_dbus_get_object();
-
-gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
-       gpointer user_data);
-
-gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gint timeout,
-       gpointer user_data);
-
-gboolean group_get_found_groups(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data);
-
-gboolean group_join(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data);
-
-gboolean group_leave(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data);
-
-gboolean group_delete(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data);
-
-gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation,
-       gint timeout, gpointer user_data);
-
-gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gchar *pin, gchar *uri_1, gchar *rt_1,
-       gchar *interface_1, int permission_1, gchar *uri_2, gchar *rt_2,
-       gchar *interface_2, int permission_2, gpointer user_data);
-
-gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data);
-
-gboolean group_invite(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
-       gchar *uuid, gchar *pin, gpointer user_data);
-
-gboolean group_eject(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
-       gchar *uuid, gpointer user_data);
-
-gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data);
-
-gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation,
-       gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1,
-       gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2,
-       gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2,
-       gpointer user_data);
-
-gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data);
-
-gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev, gchar *addr, int port, GVariant *params,
-       gpointer user_data);
-
-gboolean group_find_mowned_devices(Group *group,
-       GDBusMethodInvocation *invocation, int timeout, gpointer user_data);
-
-gboolean group_get_mowned_device(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data);
-
-gboolean group_get_my_mowned_device(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data);
-
-gboolean group_get_my_uuid(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data);
-
-gboolean group_request_create_group(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gpointer user_data);
-
-gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data);
-
-gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data);
-
-gboolean group_request_delete_group(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gpointer user_data);
-
-gboolean group_start_invited_device_monitor(Group *group,
-                                       GDBusMethodInvocation *invocation, int start,
-                                       gpointer user_data);
-
-void notify_group_found(GVariant *group_data);
-void notify_group_find_finish(int ret);
-void notify_device_found(int device_count, GVariant *device_data);
-void notify_device_find_finish(int ret);
-void notify_group_device_invite_result(int ret);
-void notify_group_device_eject_result(int ret);
-void notify_mowned_device_found(int device_count, GVariant *device_data);
-void notify_mowned_device_find_finish(int ret);
-void notify_group_join(int result);
-void notify_send_data_finish(const char *resp_data, int ret);
-void notify_request_result(const char *cmd, const char *requester_id,
-                                                  unsigned char *arg, int len, int ret);
-void notify_device_monitor_result(const char *uuid, const char *group_name,
-                                                                 const char *status);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __COMP_GDBUS_GROUP_H__ */
diff --git a/src/companion-manager/include/comp_group.h b/src/companion-manager/include/comp_group.h
deleted file mode 100755 (executable)
index ca16f84..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_GROUP_H__
-#define __COMP_GROUP_H__
-
-#include <comp_iot.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef struct {
-       char *uri_path; /**< URI path */
-       char *device_id; /**< Device ID */
-       char *host_addr; /**< Host address */
-       char *group_name; /**< Group name */
-       char *resource_type; /**< Resource type */
-       comp_group_type_e type; /**< Group yype */
-} comp_group_t;
-
-typedef struct {
-       char *device_id; /**< Device Id */
-       int adapter; /**< Adapter type */
-       int flags; /**< Flags */
-       int port; /**< Remtoe device is listening this port */
-       char *addr; /**< IP Address of remote device */
-       int ifindex; /**< Network interfce index of Remote device */
-       char *route_data; /**< Route data */
-       char *remote_id; /**< Remote Id */
-       int conn_type; /**< Connection type */
-       int secure_port; /**< Secured port once TLS handhaking complete */
-       int tcp_port; /**< TCP port when using CoAP over TCP */
-       char *sec_ver; /**< OCF Security specification version */
-       int dev_status; /**< Device status */
-       char *model_name; /**< Device ID */
-       char *device_name; /**< Host address */
-       char *platform_ver; /**< Group name */
-       char *vendor_id; /**< Resource type */
-       char *profile; /**< Group yype */
-       bool mowned;
-       comp_device_type_e type;
-} comp_mot_device_t;
-
-typedef struct {
-       char *group_name;
-       char *uuid_dev1; /**< Source device Id */
-       char *uuid_dev2; /**< Target device Id */
-       char *pin; /**< Random or pre-configured PIN */
-       char *uri_1; /**< URI at source resource */
-       char *rt_1; /**< Resource type at source resource */
-       char *interface_1; /**< Interface at source resource */
-       int permission_1; /**< CRUDN for target device */
-       char *uri_2; /**< URI at target resource */
-       char *rt_2; /**< Resource type at target resource */
-       char *interface_2; /**< Interface at target resource */
-       int permission_2; /**< CRUDN for source device */
-} comp_group_invite_info_t;
-
-typedef struct {
-       char *group_name; /**< Group Name */
-       char *uuid; /**< Device ID */
-       char *host; /**< Device Host Address */
-       int count; /**< Count of successful post method */
-} comp_invited_device_t;
-
-/* Called when daemon is start. */
-int comp_group_initialize();
-
-/* create group and destroy */
-int comp_group_create(const char* name);
-int comp_group_destroy(comp_group_t *handle);
-
-/* Find Remote groups */
-int comp_group_find(int timeout);
-GVariant *comp_group_get_found_groups();
-int comp_group_add_new(char *uri_path, char *device_id, char *device_name,
-                                char *host_addr, char *resource_type, comp_group_type_e type);
-
-/* Join the remote devices in my daemon */
-int comp_group_get_groups(comp_group_t ***handles, int *count); //Get all of group in my daemon
-int comp_group_get_remote_devices(/* callback */); //Get all of device in network (Async)
-
-int comp_group_add_new_mot_device(comp_mot_device_t *device);
-void comp_group_notify_mot_enable_device_done();
-int comp_group_find_mot_enabled_devices(int timeout);
-
-char *comp_group_invite_get_uuid();
-char *comp_group_invite_get_pin();
-
-/* Join to device in group (async) */
-int comp_group_invite(const char *group_name, const char *uuid,
-                                         const char *pin);
-comp_group_invite_info_t *comp_group_get_invite_info();
-void comp_group_free_invite_info();
-void comp_group_notify_group_invite(int result);
-
-/* eject from group (async) */
-int comp_group_eject(const gchar *group_name, gchar *uuid_dev1, const char *uuid_dev2);
-void comp_group_notify_group_dismiss(int result);
-
-int comp_group_pair_resource(char* target1, char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
-       char *uri2, char *rt2, char *interface2, int permission2);
-
-int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2);
-int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port,
-                                                unsigned char *data, int len);
-void comp_group_notify_keepalive_response(comp_command_t *cmd);
-
-GVariant *comp_group_get_remote_mot_enabled_devices();
-int comp_group_get_mot_device_count();
-
-int comp_group_add_new_mowned_device(comp_mot_device_t *device);
-void comp_group_notify_mowned_device_find_done();
-int comp_group_find_mowned_devices();
-GVariant *comp_group_get_mowned_devices();
-int comp_group_get_mowned_device_count();
-GVariant *comp_group_get_my_mowned_devices();
-void comp_group_change_mowned_device(comp_mot_device_t *device);
-
-/* Join to remote device group */
-int comp_group_join();
-int comp_group_leave_from(/* callback */); //leave from certain remote group (Async)
-
-/* Called when daemon is end. */
-int comp_group_deinitialize();
-
-/* Getter for a group */
-int comp_group_get_group_name(comp_group_t *handle, char **name);
-int comp_group_get_group_type(comp_group_t *handle, int *type);
-int comp_group_get_group_device_type(comp_group_t *handle);
-int comp_group_get_group_device_id(comp_group_t *handle);
-
-/* notify */
-int comp_group_event_handler(/*callback*/); // event hadnler
-int comp_group_add_device_in_group(const char *group_name, const char *uuid);
-int comp_group_remove_device_in_group(char *group_name, char *uuid);
-
-/* Group management */
-int comp_group_request_create_group(char *uuid, char *group_name);
-int comp_group_request_invite(char *uuid, char *group_name, char *target_uuid, char *PIN);
-int comp_group_request_eject(char *uuid, char *group_name, char *target_uuid);
-int comp_group_request_delete_group(char *uuid, char *group_name);
-
-int comp_group_start_invited_device_monitor(int start);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __COMP_GROUP_H__ */
diff --git a/src/companion-manager/include/comp_iot.h b/src/companion-manager/include/comp_iot.h
deleted file mode 100644 (file)
index 97472ec..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_IOT_H__
-#define __COMP_IOT_H__
-
-#include <comp_resource.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define SVR_PATH "/tmp/.svr.dat" /**< For Temp */
-
-typedef struct _iot_discovery_t {
-       gchar *uuid; /**< Device Id */
-       gchar *data; /**< Data to send */
-       gchar *host; /**< Target host IP address + Port */
-} iot_discovery_t;
-
-typedef struct _comp_command_t {
-       int tid; /**< Timer ID */
-       int resource_type; /**< OCF resource type */
-       comp_request_type_e command; /**< Comments set for group management */
-       gchar *uuid; /**< Device UUID */
-       gchar *host; /**< Host address + Port */
-       gchar *arg1; /**< Arguement #1 */
-       gchar *arg2; /**< Arguement #2 */
-       gchar *arg3; /**< Arguement #3 */
-       gchar *arg4; /**< Arguement #4 */
-#ifdef SUPPORT_BASE64_ENCODING
-       unsigned char *data;
-       int data_len;
-#endif
-       void *user_data;
-} comp_command_t;
-
-int comp_iot_initialize();
-int comp_iot_add_resource(comp_resource_type_e resource_type, const char *uri);
-int comp_iot_delete_resource(comp_resource_type_e resource_type);
-int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, void *user_data);
-int comp_iot_send_data(comp_resource_type_e resource_type, int timeout,
-                                          comp_command_t *cmd);
-int comp_iot_deinitialize();
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __COMP_IOT_H__ */
diff --git a/src/companion-manager/include/comp_log.h b/src/companion-manager/include/comp_log.h
deleted file mode 100644 (file)
index 079b89d..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_LOG_H__
-#define __COMP_LOG_H__
-
-#include <dlog.h>
-#include <comp_enum.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define COLOR_RED               "\033[0;31m"
-#define COLOR_GREEN             "\033[0;32m"
-#define COLOR_BROWN             "\033[0;33m"
-#define COLOR_BLUE              "\033[0;34m"
-#define COLOR_PURPLE            "\033[0;35m"
-#define COLOR_CYAN              "\033[0;36m"
-#define COLOR_LIGHTBLUE         "\033[0;37m"
-#define COLOR_END               "\033[0;m"
-
-#define LOG_TAG "COMP_MANAGER"
-
-#define LOG_DEBUG(fmt, ...) \
-       do { \
-               LOGD(COLOR_BROWN" " fmt COLOR_END, ##__VA_ARGS__); \
-       } while (0)
-#define LOG_ERR(fmt, ...) \
-       do { \
-               LOGE(COLOR_RED" " fmt COLOR_END, ##__VA_ARGS__); \
-       } while (0)
-#define LOG_BEGIN() \
-       do { \
-               LOGD(COLOR_BLUE "BEGIN" COLOR_END); \
-       } while (0)
-#define LOG_END() \
-       do { \
-               LOGD(COLOR_BLUE "END" COLOR_END); \
-       } while (0)
-
-#define NOTUSED(var) (var = var)
-
-#define comp_check_null_ret_error(name, value, error) do { \
-       /* LCOV_EXCL_START */ \
-       if (G_UNLIKELY(NULL == (value))) { \
-                               LOGE("%s is NULL", name); \
-                               return error; \
-                       } \
-       /* LCOV_EXCL_STOP */ \
-} while (FALSE)
-
-#define comp_check_null_ret(name, value) do { \
-       /* LCOV_EXCL_START */ \
-       if (G_UNLIKELY(NULL == (value))) { \
-                               LOGE("%s is NULL", name); \
-                               return; \
-                       } \
-       /* LCOV_EXCL_STOP */ \
-} while (FALSE)
-
-const char *comp_log_get_error_string(int result);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __COMP_LOG_H__ */
diff --git a/src/companion-manager/include/comp_manager.h b/src/companion-manager/include/comp_manager.h
deleted file mode 100644 (file)
index c7f0d11..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_MANAGER_H__
-#define __COMP_MANAGER_H__
-
-#include <comp_log.h>
-#include <comp_group.h>
-#include <comp_resource.h>
-#include <comp_gdbus.h>
-#include <comp_db.h>
-
-#endif /* __COMP_MANAGER_H__ */
diff --git a/src/companion-manager/include/comp_mot_agent.h b/src/companion-manager/include/comp_mot_agent.h
deleted file mode 100644 (file)
index c4537a2..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
- #ifndef __COMP_MOT_AGENT_H__
- #define __COMP_MOT_AGENT_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int agent_dbus_start();
-int agent_dbus_stop();
-
-int agent_enable();
-int agent_disable();
-int agent_get_ownerid(char* deviceid);
-int agent_find_mot_enable_devices(int timeout);
-int agent_find_mowned_devices();
-int agent_mot(char* uuid_str, char *pin);
-int agent_resources_pairwise(char* target1, char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
-       char *uri2, char *rt2, char *interface2, int permission2);
-int agent_unlink_resources(char* uuid_str1, char *uuid_str2);
-int agent_remove_subowner(char* uuid_str);
-int agent_remove_subowned(char* uuid_str);
-int agent_pair(const char *pin, char* target1, const char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, const char* target2,
-       char *subject2, char *uri2, char *rt2, char *interface2, int permission2);
-int agent_unpair(char* uuid_str1, const char *uuid_str2);
-
-#ifdef __cplusplus
-}
-#endif
-
- #endif /* __COMP_MOT_AGENT_H__ */
diff --git a/src/companion-manager/include/comp_resource.h b/src/companion-manager/include/comp_resource.h
deleted file mode 100644 (file)
index f5d7885..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_RESOURCE_H__
-#define __COMP_RESOURCE_H__
-
-#include <comp_context.h>
-#include <octypes.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef struct {
-       comp_resource_type_e resource_type;
-       char *type;
-       char *uri_prefix;
-       unsigned char policies;
-} comp_rd_t;
-
-typedef struct {
-       char *uri;
-} comp_re_t;
-
-int comp_resource_append(comp_resource_type_e resource_type, const char *uri);
-char *comp_resource_get_type(comp_resource_type_e resource_type);
-char *comp_resource_get_uri_prefix(comp_resource_type_e resource_type);
-unsigned char comp_resource_get_policies(comp_resource_type_e resource_type);
-void comp_resource_print_list();
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __COMP_RESOURCE_H__ */
diff --git a/src/companion-manager/include/comp_util.h b/src/companion-manager/include/comp_util.h
deleted file mode 100644 (file)
index 0c5edd2..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __COMP_UTIL_H__
-#define __COMP_UTIL_H__
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define LOCAL_IP 1 /**< Local IP */
-#define REMOTE_IP 2 /**< Remote IP */
-
-void comp_remove_ip_info(void);
-int comp_make_ip_info(void);
-int comp_is_local_ip(char *ipdata);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __COMP_UTIL_H__ */
diff --git a/src/companion-manager/oic_svr_db_comp_manager.dat b/src/companion-manager/oic_svr_db_comp_manager.dat
deleted file mode 100644 (file)
index bdc3480..0000000
Binary files a/src/companion-manager/oic_svr_db_comp_manager.dat and /dev/null differ
diff --git a/src/companion-manager/oic_svr_db_comp_manager.json b/src/companion-manager/oic_svr_db_comp_manager.json
deleted file mode 100644 (file)
index 943566f..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-{\r
-    "cred":{\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "*",\r
-                "credtype": 16,\r
-                "privatedata": {\r
-                    "encoding": "oic.sec.encoding.raw",\r
-                    "data": "12341234"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
-    },\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/cred",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.cred"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 6\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/comp/group",\r
-                            "rel": "",\r
-                            "rt": ["core.comp.group"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/comp/device",\r
-                            "rel": "",\r
-                            "rt": ["core.comp.device"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }, {\r
-                            "href": "/comp/operation",\r
-                            "rel": "",\r
-                            "rt": ["core.comp.operation"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 31\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/pconf",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pconf"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/dpairing",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.dpairing"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "00000000-0000-0000-0000-000000000000"\r
-    },\r
-    "pstat": {\r
-        "isop": false,\r
-        "cm": 2,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4,\r
-        "deviceuuid": "00000000-0000-0000-0000-000000000000",\r
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
-    },\r
-    "doxm": {\r
-        "oxms": [0, 65280],\r
-        "oxmsel": 65280,\r
-        "sct": 17,\r
-        "owned": false,\r
-        "x.org.iotivity.mom": 1,\r
-        "deviceuuid": "00000000-0000-0000-0000-000000000000",\r
-        "devowneruuid": "00000000-0000-0000-0000-000000000000",\r
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
-    }\r
-}\r
diff --git a/src/companion-manager/src/comp_context.c b/src/companion-manager/src/comp_context.c
deleted file mode 100644 (file)
index 7aeb82f..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_context.h>
-
-static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
-static comp_context_t *_comp_ctx;
-
-int comp_context_create()
-{
-       _comp_ctx = g_new0(comp_context_t, 1);
-       if (!_comp_ctx) {
-               LOG_DEBUG("create comp_context is failed");
-               return COMP_ERROR_UNKNOWN;
-       }
-       _comp_ctx->mot_me = FALSE;
-
-       return COMP_ERROR_NONE;
-}
-
-void comp_context_mutex_lock()
-{
-       LOG_DEBUG("context mutex lock");
-       pthread_mutex_lock(&context_lock);
-}
-
-void comp_context_mutex_unlock()
-{
-       LOG_DEBUG("context mutex unlock");
-       pthread_mutex_unlock(&context_lock);
-}
-
-int comp_context_destroy()
-{
-       return COMP_ERROR_NONE;
-}
-
-comp_context_t *comp_context_get_context()
-{
-       return _comp_ctx;
-}
-
diff --git a/src/companion-manager/src/comp_db.c b/src/companion-manager/src/comp_db.c
deleted file mode 100644 (file)
index 3849dbb..0000000
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_db.h>
-#include <comp_context.h>
-#include <comp_group.h>
-
-static bool __is_table_existing(const char *table)
-{
-       bool result;
-       char *sql;
-       int ret;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       sql = sqlite3_mprintf("SELECT count(*) FROM sqlite_master WHERE type='table' AND name ='%s';", table);
-       if (sql != NULL) {
-               sqlite3_stmt *stmt = NULL;
-
-               ret = sqlite3_prepare_v2(comp_ctx->db, sql, strlen(sql), &stmt, NULL);
-               if (ret == SQLITE_OK) {
-                       ret = sqlite3_step(stmt);
-                       if (ret == SQLITE_ROW) {
-                               int count;
-
-                               count = sqlite3_column_int(stmt, 0);
-                               if (count > 0)
-                                       result = true;
-                               else
-                                       result = false;
-                       } else {
-                               LOG_ERR("sqlite3_step failed, [%d:%s]", ret, sqlite3_errmsg(comp_ctx->db));
-
-                               result = false;
-                       }
-
-                       sqlite3_finalize(stmt);
-               } else {
-                       LOG_ERR("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(comp_ctx->db));
-
-                       result = false;
-               }
-
-               sqlite3_free(sql);
-       } else {
-               LOG_ERR("sqlite3_mprintf failed");
-
-               result = false;
-       }
-
-       return result;
-}
-
-static int __create_table()
-{
-       int ret = 0;
-       int sql_ret;
-       char *sql = NULL;
-       char *error = NULL;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == NULL) {
-               LOG_ERR("comp_ctx->db is NULL");
-               return -1;
-       }
-
-       sql = sqlite3_mprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, group_name TEXT, device_id TEXT);",
-               COMP_DB_TABLE);
-
-       if (sql != NULL) {
-               sql_ret = sqlite3_exec(comp_ctx->db, sql, NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
-                       ret = -1;
-                       sqlite3_free(error);
-               }
-               sqlite3_free(sql);
-       } else {
-               LOG_ERR("sql is NULL");
-               ret = -1;
-       }
-
-       return ret;
-}
-
-static void __prepare_table()
-{
-       if (__is_table_existing(COMP_DB_TABLE) == false)
-               __create_table();
-}
-
-static int __check_integrity()
-{
-       sqlite3_stmt *stmt = NULL;
-       int result = 0;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == 0) {
-               LOG_ERR("failed to check handle");
-               return -1;
-       }
-
-       int ret = sqlite3_prepare_v2(comp_ctx->db, "PRAGMA integrity_check", -1, &stmt, NULL);
-       if (ret != SQLITE_OK && ret != SQLITE_BUSY) {
-               LOG_ERR("failed to check integrity: %s", sqlite3_errmsg(comp_ctx->db));
-               return -1;
-       } else {
-               ret = sqlite3_step(stmt);
-               if (ret == SQLITE_ROW) {
-                       const char *ret_val = (const char *)sqlite3_column_text(stmt, 0);
-                       LOG_ERR("ret_val: %s", ret_val);
-                       if (ret_val && strcmp(ret_val, "ok") == 0) {
-                               result = 0;
-                       } else {
-                               LOG_ERR("failed to check integrity");
-                               result = -1;
-                       }
-               } else {
-                       result = 0;
-               }
-       }
-
-       sqlite3_finalize(stmt);
-
-       return result;
-}
-
-int comp_db_init()
-{
-       int ret = 0;
-       int sql_ret;
-       char *error = NULL;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == NULL) {
-               sql_ret = sqlite3_open_v2(COMP_DB_FILE, &(comp_ctx->db),
-                       SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_open_v2 failed, (%d)", sql_ret);
-                       goto ERR;
-               }
-
-               if (__check_integrity() < 0) {
-                       LOG_ERR("Failed to check integrity");
-                       unlink(COMP_DB_FILE);
-                       comp_ctx->db = NULL;
-                       sql_ret = sqlite3_open_v2(COMP_DB_FILE, &comp_ctx->db, SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
-                       if (sql_ret != SQLITE_OK) {
-                               LOG_ERR("sqlite3_open_v2 failed, (%d)", sql_ret);
-                               goto ERR;
-                       }
-               }
-
-               /* Enable persist journal mode */
-               sql_ret = sqlite3_exec(comp_ctx->db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("Fail to change journal mode: (%d) %s", sql_ret, error);
-                       sqlite3_free(error);
-
-                       goto ERR;
-               }
-
-               __prepare_table();
-       }
-
-       if (comp_ctx->db != NULL) {
-               //iot activity per each column
-               LOG_ERR("comp db init");
-               //comp_group_create(group_name);
-       }
-
-       return ret;
-
-ERR:
-       if (comp_ctx->db != NULL) {
-               sql_ret = sqlite3_close(comp_ctx->db);
-               if (sql_ret == SQLITE_OK)
-                       comp_ctx->db = NULL;
-               else
-                       LOG_ERR("sqlite3_close failed, [%d]", sql_ret);
-       }
-
-       return ret;
-}
-int comp_db_deinit()
-{
-       int ret = 0;
-       int sql_ret;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db != NULL) {
-               sql_ret = sqlite3_close(comp_ctx->db);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_close failed, %d", sql_ret);
-                       return -1;
-               }
-               comp_ctx->db = NULL;
-       }
-
-       return ret;
-}
-
-int comp_db_insert(char *group_name, char *device_id)
-{
-       int ret = 0;
-       int sql_ret;
-       char *sql = NULL;
-       char *error = NULL;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == NULL) {
-               LOG_ERR("mtp_ctx->db is NULL");
-               return -1;
-       }
-
-       sql = sqlite3_mprintf("INSERT INTO %s (group_name, device_id) values(%Q, %Q);",
-               COMP_DB_TABLE,
-               group_name,
-               device_id);
-
-       if (sql != NULL) {
-               sql_ret = sqlite3_exec(comp_ctx->db, sql, NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
-                       ret = -1;
-                       sqlite3_free(error);
-               }
-               sqlite3_free(sql);
-       } else {
-               LOG_ERR("sql is NULL");
-               ret = -1;
-       }
-
-       return ret;
-}
-
-int comp_db_delete_group(char *group_name)
-{
-       int ret = 0;
-       int sql_ret;
-       char *sql = NULL;
-       char *error = NULL;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == NULL) {
-               LOG_ERR("comp_ctx->db is NULL");
-               return -1;
-       }
-
-       if (group_name == NULL) {
-               LOG_ERR("group_name is NULL");
-               return -1;
-       }
-
-       sql = sqlite3_mprintf("DELETE FROM %s WHERE group_name=%Q",
-               COMP_DB_TABLE,
-               group_name);
-
-       if (sql != NULL) {
-               sql_ret = sqlite3_exec(comp_ctx->db, sql, NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
-                       ret = -1;
-                       sqlite3_free(error);
-               }
-               sqlite3_free(sql);
-       } else {
-               LOG_ERR("sql is NULL");
-               ret = -1;
-       }
-
-       return ret;
-}
-
-int comp_db_delete_device(char *group_name, char *device_id)
-{
-       int ret = 0;
-       int sql_ret;
-       char *sql = NULL;
-       char *error = NULL;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (comp_ctx->db == NULL) {
-               LOG_ERR("comp_ctx->db is NULL");
-               return -1;
-       }
-
-       if (group_name == NULL) {
-               LOG_ERR("group_name is NULL");
-               return -1;
-       }
-
-       if (device_id == NULL) {
-               LOG_ERR("device_id is NULL");
-               return -1;
-       }
-
-       sql = sqlite3_mprintf("DELETE FROM %s WHERE group_name=%Q and device_id=%Q",
-               COMP_DB_TABLE,
-               group_name,
-               device_id);
-
-       if (sql != NULL) {
-               sql_ret = sqlite3_exec(comp_ctx->db, sql, NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
-                       ret = -1;
-                       sqlite3_free(error);
-               }
-               sqlite3_free(sql);
-       } else {
-               LOG_ERR("sql is NULL");
-               ret = -1;
-       }
-
-       return ret;
-
-}
-
-int comp_db_print()
-{
-       return 0;
-}
-
diff --git a/src/companion-manager/src/comp_gdbus.c b/src/companion-manager/src/comp_gdbus.c
deleted file mode 100644 (file)
index d923c80..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_gdbus.h>
-#include <sys/types.h>
-
-#define DBUS_SERVICE_DBUS              "org.freedesktop.DBus"
-#define DBUS_INTERFACE_DBUS            "org.freedesktop.DBus"
-
-static Group *group_skeleton;
-static Enabler *enabler_skeleton;
-
-Group *group_dbus_get_object()
-{
-       return group_skeleton;
-}
-
-static bool __group_init(GDBusConnection *connection)
-{
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       GDBusObjectManagerServer *group;
-
-       // Add interface to default object path
-       group_skeleton = group_skeleton_new();
-
-       // Register for method callbacks as signal callbacks
-       g_signal_connect(group_skeleton,
-               "handle-create",
-               G_CALLBACK(group_create),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-find",
-               G_CALLBACK(group_find),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-get-found-groups",
-               G_CALLBACK(group_get_found_groups),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-join",
-               G_CALLBACK(group_join),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-leave",
-               G_CALLBACK(group_leave),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-delete",
-               G_CALLBACK(group_delete),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-device-find",
-               G_CALLBACK(group_device_find),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-invite",
-               G_CALLBACK(group_invite),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-eject",
-               G_CALLBACK(group_eject),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-device-invite",
-               G_CALLBACK(group_device_invite),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-device-eject",
-               G_CALLBACK(group_device_eject),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-get-remote-device",
-               G_CALLBACK(group_get_remote_device),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-pair-resource",
-               G_CALLBACK(group_pair_resource),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-unpair-resource",
-               G_CALLBACK(group_unpair_resource),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-send-data",
-               G_CALLBACK(group_send_data),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-find-mowned-devices",
-               G_CALLBACK(group_find_mowned_devices),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-get-mowned-device",
-               G_CALLBACK(group_get_mowned_device),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-get-my-mowned-device",
-               G_CALLBACK(group_get_my_mowned_device),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-get-my-uuid",
-               G_CALLBACK(group_get_my_uuid),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-request-create-group",
-               G_CALLBACK(group_request_create_group),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-request-invite",
-               G_CALLBACK(group_request_invite),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-request-eject",
-               G_CALLBACK(group_request_eject),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-request-delete-group",
-               G_CALLBACK(group_request_delete_group),
-               NULL);
-
-       g_signal_connect(group_skeleton,
-               "handle-start-invited-device-monitor",
-               G_CALLBACK(group_start_invited_device_monitor),
-               NULL);
-
-       group = g_dbus_object_manager_server_new(COMP_DBUS_GROUP_PATH);
-
-       // Set connection to 'manager'
-       g_dbus_object_manager_server_set_connection(group, connection);
-
-       // Export 'group' interface on companion-manager DBUS
-       ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(group_skeleton),
-                               connection, COMP_DBUS_GROUP_PATH, &error);
-
-       if (ret == FALSE) {
-               LOG_DEBUG("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return ret;
-}
-
-static void _app_conn_destroyed_cb(GDBusConnection *conn, const gchar *Name,
-                          const gchar *path, const gchar *interface, const gchar *sig,
-                          GVariant *param, gpointer user_data)
-{
-       gchar *name = NULL;
-       gchar *old = NULL;
-       gchar *new = NULL;
-       comp_conn_destroy_data *data = user_data;
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       if (param == NULL)
-               return;
-
-       g_variant_get(param, "(sss)", &name, &old, &new);
-
-       if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
-               LOG_DEBUG("App %s Destroyed: name %s id %d", data->conn_name, name,
-                       data->conn_id);
-
-               comp_ctx->ref_count -= 1;
-
-               g_dbus_connection_signal_unsubscribe(data->connection, data->conn_id);
-       }
-
-       g_free(name);
-       g_free(old);
-       g_free(new);
-       g_free(data->conn_name);
-       g_free(data);
-
-       if (comp_ctx->ref_count == 0) {
-               LOG_DEBUG("No app remaining quit comapnion-manager");
-               g_main_loop_quit(comp_ctx->main_loop);
-       }
-
-       return;
-}
-
-static gboolean _register_comp_conn_destroy_signal(Enabler *enabler,
-                                                                  gchar *name)
-{
-       comp_conn_destroy_data *data;
-       GDBusConnection *connection = NULL;
-
-       connection = g_dbus_interface_skeleton_get_connection(
-                                         (GDBusInterfaceSkeleton *)enabler_skeleton);
-       if (NULL == connection) {
-               LOG_ERR("Failed to get GDbus connection");
-               return FALSE;
-       }
-
-       data = g_try_malloc0(sizeof(comp_conn_destroy_data));
-       if (NULL == data) {
-               LOG_ERR("Failed to Allocate memory");
-               return FALSE;
-       }
-
-       data->conn_name = g_strdup(name);
-       data->connection = connection;
-
-       data->conn_id = g_dbus_connection_signal_subscribe(connection,
-                                                       DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
-                                                       "NameOwnerChanged", NULL, name,
-                                                       G_DBUS_SIGNAL_FLAGS_NONE, _app_conn_destroyed_cb,
-                                                       data, NULL);
-
-       return TRUE;
-}
-
-gboolean enabler_add_ref(Enabler *enabler, GDBusMethodInvocation *invocation,
-       gchar *name, gpointer user_data)
-{
-       LOG_DEBUG("Add Reference for %s", name);
-
-       if (TRUE == _register_comp_conn_destroy_signal(enabler, name)) {
-               comp_context_t *comp_ctx = comp_context_get_context();
-               comp_ctx->ref_count += 1;
-
-               enabler_complete_add_ref(enabler, invocation, 0);
-       } else {
-               LOG_ERR("Failed to register connection destroy signal");
-               enabler_complete_add_ref(enabler, invocation,
-                                        COMP_ERROR_OPERATION_FAILED);
-       }
-
-       return TRUE;
-}
-
-static bool __enabler_init(GDBusConnection *connection)
-{
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       GDBusObjectManagerServer *enabler;
-
-       // Add interface to default object path
-       enabler_skeleton = enabler_skeleton_new();
-
-       // Register for method callbacks as signal callbacks
-       g_signal_connect(enabler_skeleton,
-               "handle-add-ref",
-               G_CALLBACK(enabler_add_ref),
-               NULL);
-
-       enabler = g_dbus_object_manager_server_new(COMP_DBUS_ENABLER_PATH);
-
-       // Set connection to 'enabler'
-       g_dbus_object_manager_server_set_connection(enabler, connection);
-
-       // Export 'enabler' interface on companion DBUS
-       ret = g_dbus_interface_skeleton_export(
-                               G_DBUS_INTERFACE_SKELETON(enabler_skeleton), connection,
-                               COMP_DBUS_ENABLER_PATH, &error);
-
-       if (ret == FALSE) {
-               LOG_DEBUG("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return ret;
-}
-
-
-static void on_bus_acquired(GDBusConnection *connection, const gchar *path,
-       gpointer user_data)
-{
-       if (__group_init(connection) == false)
-               LOG_DEBUG("Can not signal connect");
-
-       if (__enabler_init(connection) == false)
-               LOG_ERR("Can't signal connect");
-}
-
-static void on_name_acquired(GDBusConnection *connection, const gchar *name,
-       gpointer user_data)
-{
-       LOG_DEBUG("on_name_acquired : %s", name);
-}
-
-static void on_name_lost(GDBusConnection *connnection, const gchar *name,
-       gpointer user_data)
-{
-       LOG_DEBUG("on_name_lost : %s", name);
-}
-
-int comp_gdbus_init()
-{
-       g_bus_own_name(G_BUS_TYPE_SYSTEM, COMP_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE,
-               on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
-
-       return 0;
-}
diff --git a/src/companion-manager/src/comp_gdbus_group.c b/src/companion-manager/src/comp_gdbus_group.c
deleted file mode 100644 (file)
index c2ecd53..0000000
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_gdbus_group.h>
-
-/* GDBUS Group Layer */
-/* In this gdbus group layer, Please call the "fn_group" service layer function.*/
-
-gboolean group_create(Group *group, GDBusMethodInvocation *invocation,
-       gchar *group_name, gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("group create called using dbus successful");
-
-       result = comp_group_create(group_name);
-
-       group_complete_create(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gint timeout,
-       gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("group find called using dbus successful");
-
-       comp_group_find(timeout);
-
-       group_complete_find(group, invocation, result);
-       return TRUE;
-}
-
-gboolean group_get_found_groups(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data)
-{
-       gint result = 0;
-       GVariant *group_data;
-
-       LOG_DEBUG("get found groups called using dbus successful");
-
-       group_data = comp_group_get_found_groups();
-
-       group_complete_get_found_groups(group, invocation, result, group_data);
-       return TRUE;
-}
-
-gboolean group_join(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("join called using dbus successful");
-
-       result = comp_group_join();
-
-       group_complete_join(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_leave(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data)
-{
-       //group_complete_leave(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_delete(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data)
-{
-       //group_complete_delete(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation,
-       gint timeout, gpointer user_data)
-{
-       int result = 0;
-
-       result = comp_group_find_mot_enabled_devices(timeout);
-
-       group_complete_device_find(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gchar *pin, gchar *uri_1, gchar *rt_1,
-       gchar *interface_1, int permission_1, gchar *uri_2, gchar *rt_2,
-       gchar *interface_2, int permission_2, gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("group device invite called using dbus successful");
-/*
-       result = comp_group_invite(uuid_dev1, uuid_dev2, pin, uri_1, rt_1,
-                                       interface_1, permission_1, uri_2, rt_2, interface_2,
-                                       permission_2);
-*/
-       group_complete_device_invite(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("group device eject called using dbus successful");
-
-       result = comp_group_eject(NULL, uuid_dev1, uuid_dev2);
-
-       group_complete_device_eject(group, invocation, result);
-
-       return TRUE;
-}
-
-gboolean group_invite(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
-       gchar *uuid, gchar *pin, gpointer user_data)
-{
-       gint result = 0;
-
-       LOG_DEBUG("group invite called using dbus successful");
-
-       result = comp_group_invite(group_name, uuid, pin);
-
-       /* Now, for the sake of convenience, we change 'group_complete_invite' to 'group_complete_device_invite'. */
-#if 0
-       group_complete_invite(group, invocation, result);
-#else
-       group_complete_device_invite(group, invocation, result);
-#endif
-
-       return TRUE;
-}
-
-gboolean group_eject(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
-       gchar *uuid, gpointer user_data)
-{
-       gint result = 0;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       if (!comp_ctx) {
-               LOG_ERR("ctx is null");
-               return FALSE;
-       }
-
-       result = comp_group_eject(group_name, comp_ctx->device_uuid, uuid);
-
-       /* Now, for the sake of convenience, we change 'group_complete_eject' to 'group_complete_device_eject'. */
-#if 0
-       group_complete_invite(group, invocation, result);
-#else
-       group_complete_device_eject(group, invocation, result);
-#endif
-
-       return TRUE;
-}
-
-gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation,
-       gpointer user_data)
-{
-       int dev_count = 0;
-       GVariant *device_data;
-
-       LOG_DEBUG("get remote device called using dbus successful");
-
-       dev_count = comp_group_get_mot_device_count();
-       device_data = comp_group_get_remote_mot_enabled_devices();
-
-       group_complete_get_remote_device(group, invocation, dev_count, device_data);
-
-       return TRUE;
-}
-
-gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation,
-       gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1,
-       gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2,
-       gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2,
-       gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("pair resource called using dbus successful");
-
-       ret = comp_group_pair_resource(target_1, subject_1, uri_1, rt_1,
-                                          interface_1, permission_1, target_2, subject_2, uri_2,
-                                          rt_2, interface_2, permission_2);
-
-       group_complete_pair_resource(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("unpair resource called using dbus successful");
-
-       ret = comp_group_unpair_resource(uuid_dev1, uuid_dev2);
-
-       group_complete_unpair_resource(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid_dev, gchar *addr, int port, GVariant *params,
-       gpointer user_data)
-{
-       int ret = 0;
-       int length = 0;
-       int len;
-       unsigned char *data;
-       GVariantIter *iter;
-
-       LOG_DEBUG("send data called using dbus successful");
-
-       g_variant_get(params, "(iay)", &len, &iter);
-
-       data = g_try_malloc0(len + 1);
-       if (NULL == data) {
-               group_complete_send_data(group, invocation, -1);
-               LOG_ERR("Failed to allocate memory");
-               return TRUE;
-       }
-
-       while (g_variant_iter_loop(iter, "y", &data[length]))
-               length += 1;
-
-       g_variant_iter_free(iter);
-
-       ret = comp_group_send_data(uuid_dev, addr, port, data, len);
-
-       group_complete_send_data(group, invocation, 0);
-
-       g_free(data);
-
-       return ret;
-}
-
-gboolean group_find_mowned_devices(Group *group,
-       GDBusMethodInvocation *invocation, gint timeout, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("find mot owned devices called using dbus successful");
-
-       ret = comp_group_find_mowned_devices(timeout);
-
-       group_complete_find_mowned_devices(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_get_mowned_device(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data)
-{
-       int dev_count = 0;
-       GVariant *device_data;
-
-       LOG_DEBUG("get mowned device called using dbus successful");
-
-       dev_count = comp_group_get_mowned_device_count();
-       device_data = comp_group_get_mowned_devices();
-
-       group_complete_get_mowned_device(group, invocation, dev_count, device_data);
-
-       return TRUE;
-}
-
-gboolean group_get_my_mowned_device(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data)
-{
-       GVariant *device_data;
-
-       LOG_DEBUG("get mowned device called using dbus successful");
-
-       device_data = comp_group_get_my_mowned_devices();
-       LOG_DEBUG("get mowned device called end ");
-
-       group_complete_get_my_mowned_device(group, invocation, device_data);
-
-       return TRUE;
-}
-
-gboolean group_get_my_uuid(Group *group,
-       GDBusMethodInvocation *invocation, gpointer user_data)
-{
-       LOG_DEBUG("get my uuid called using dbus successful");
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       group_complete_get_my_uuid(group, invocation, comp_ctx->device_uuid);
-
-       return TRUE;
-}
-
-gboolean group_request_create_group(Group *group, GDBusMethodInvocation
-       *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("Request Create Group called using dbus successful");
-
-       ret = comp_group_request_create_group(uuid, group_name);
-
-       group_complete_request_create_group(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("Request Invite called using dbus successful");
-
-       ret = comp_group_request_invite(uuid, group_name, target_uuid, PIN);
-
-       group_complete_request_invite(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("Request Eject called using dbus successful");
-
-       ret = comp_group_request_eject(uuid, group_name, target_uuid);
-
-       group_complete_request_eject(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_request_delete_group(Group *group,
-       GDBusMethodInvocation *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("Request Delete Group called using dbus successful");
-
-       ret = comp_group_request_delete_group(uuid, group_name);
-
-       group_complete_request_delete_group(group, invocation, ret);
-
-       return TRUE;
-}
-
-gboolean group_start_invited_device_monitor(Group *group,
-                                       GDBusMethodInvocation *invocation, int start,
-                                       gpointer user_data)
-{
-       int ret = 0;
-
-       LOG_DEBUG("Start Myowned device monitor");
-
-       ret = comp_group_start_invited_device_monitor(start);
-
-       group_complete_start_invited_device_monitor(group, invocation, ret);
-
-       return TRUE;
-}
-
-void notify_group_found(GVariant *group_data)
-{
-       group_emit_group_found(group_dbus_get_object(), group_data);
-}
-
-void notify_group_find_finish(int ret)
-{
-       group_emit_group_find_finish(group_dbus_get_object(), ret);
-}
-
-void notify_device_found(int device_count, GVariant *device_data)
-{
-       group_emit_device_found(group_dbus_get_object(), device_count, device_data);
-}
-
-void notify_device_find_finish(int ret)
-{
-       group_emit_device_find_finish(group_dbus_get_object(), ret);
-}
-
-void notify_group_device_invite_result(int ret)
-{
-       group_emit_device_invite_result(group_dbus_get_object(), ret);
-}
-
-void notify_group_device_eject_result(int ret)
-{
-       group_emit_device_eject_result(group_dbus_get_object(), ret);
-}
-
-void notify_mowned_device_found(int device_count, GVariant *device_data)
-{
-       group_emit_mowned_device_found(group_dbus_get_object(), device_count, device_data);
-}
-
-void notify_mowned_device_find_finish(int ret)
-{
-       group_emit_mowned_device_find_finish(group_dbus_get_object(), ret);
-}
-void notify_group_join(int result)
-{
-       group_emit_join_result(group_dbus_get_object(), result);
-}
-
-void notify_send_data_finish(const char *resp_data, int ret)
-{
-       group_emit_send_data_finish(group_dbus_get_object(), resp_data, ret);
-}
-
-void notify_request_result(const char *cmd, const char *requester_id,
-                                                  unsigned char *arg, int len, int ret)
-{
-       GVariantBuilder *bytearray_builder = NULL;
-       GVariant *params = NULL;
-       int i;
-
-       bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
-       for (i = 0; i < len; i++)
-               g_variant_builder_add(bytearray_builder, "y", arg[i]);
-
-       params = g_variant_new("(iay)", len, bytearray_builder);
-       g_variant_builder_unref(bytearray_builder);
-
-       group_emit_request_result(group_dbus_get_object(), cmd, requester_id,
-                                                         params, ret);
-}
-
-void notify_device_monitor_result(const char *uuid, const char *group_name,
-                                                                 const char *status)
-{
-       group_emit_device_monitor_result(group_dbus_get_object(), uuid, group_name,
-                                                                         status);
-}
-
diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c
deleted file mode 100755 (executable)
index 9f20313..0000000
+++ /dev/null
@@ -1,1354 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_enum.h>
-#include <comp_group.h>
-#include <comp_mot_agent.h>
-#include <comp_gdbus_group.h>
-#include <comp_db.h>
-#include <comp_util.h>
-
-GList *found_group_list;
-GList *mot_enb_dev_list = NULL;
-GList *mowned_dev_list = NULL;
-GList *invited_dev_list = NULL;
-comp_group_invite_info_t *group_invite_info = NULL;
-comp_mot_device_t *my_device = NULL;
-
-#define KEEPALIVE_MESSAGE_TIMEOUT 900
-#define CHECK_DEVICE_STATUS_TIMEOUT 3000
-
-/* Called when daemon is start. */
-int comp_group_initialize()
-{
-       //Initialize memory of context
-       //1. group creation
-       //db select
-       //2. device creation
-       //db select by group
-
-       return COMP_ERROR_NONE;
-}
-
-typedef struct {
-       char *name; /**< Group name */
-       GList *device_list; /**< Remote device UUIDs. (char* type) */
-} comp_grp_t;
-
-void __print_foreach_device(gpointer data, gpointer user_data)
-{
-       char *uuid = (char *)data;
-       LOG_DEBUG("        - %s", uuid);
-}
-
-void __print_foreach_grp(gpointer data, gpointer user_data)
-{
-       comp_grp_t *grp = (comp_grp_t *)data;
-       LOG_DEBUG("Group name : %s", grp->name);
-       LOG_DEBUG("    <Device>");
-       g_list_foreach(grp->device_list, __print_foreach_device, NULL);
-       LOG_DEBUG("");
-}
-
-void __print_groups_information()
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret("comp_ctx", comp_ctx);
-
-       LOG_DEBUG("-------------------------------------------");
-       g_list_foreach(comp_ctx->grp_list, __print_foreach_grp, NULL);
-       LOG_DEBUG("-------------------------------------------");
-}
-
-/* create group and destroy */
-int comp_group_create(const char* name)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
-       GList *list = comp_ctx->grp_list;
-
-       GList *l;
-       for (l = list; l != NULL; l = l->next) {
-               comp_grp_t *grp = (comp_grp_t *)l->data;
-
-               if (strcmp(grp->name, name) == 0) {
-                       LOG_ERR("already exists name in structure");
-                       return COMP_ERROR_UNKNOWN;
-               }
-       }
-
-       ret = comp_iot_add_resource(COMP_RESOURCE_TYPE_GROUP, name);
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("Add resource is failed : %s", comp_log_get_error_string(ret));
-       }
-
-       comp_grp_t *grp = g_new0(comp_grp_t, 1);
-       grp->name = strdup(name);
-
-       comp_ctx->grp_list = g_list_append(comp_ctx->grp_list, grp);
-
-       comp_group_add_device_in_group(name, comp_ctx->device_uuid);
-       comp_resource_print_list();
-       __print_groups_information();
-
-       LOG_END();
-
-       return COMP_ERROR_NONE;
-}
-
-int comp_group_destroy(comp_group_t *handle)
-{
-       int ret = COMP_ERROR_NONE;
-       NOTUSED(handle);
-       return ret;
-}
-
-static void _free_device_func(gpointer data)
-{
-       comp_check_null_ret("data", data);
-       g_free(data);
-       data = NULL;
-}
-
-static void _free_group_func(gpointer data)
-{
-       comp_group_t *group = (comp_group_t *)data;
-       comp_check_null_ret("group", group);
-
-       if (group->uri_path != NULL) {
-               g_free(group->uri_path);
-               group->uri_path = NULL;
-       }
-       if (group->device_id != NULL) {
-               g_free(group->device_id);
-               group->device_id = NULL;
-       }
-       if (group->group_name != NULL) {
-               g_free(group->group_name);
-               group->group_name = NULL;
-       }
-       if (group->host_addr != NULL) {
-               g_free(group->host_addr);
-               group->host_addr = NULL;
-       }
-       if (group->resource_type != NULL) {
-               g_free(group->resource_type);
-               group->resource_type = NULL;
-       }
-       g_free(group);
-       group = NULL;
-}
-
-static void _mot_enb_dev_list_free_func(gpointer data)
-{
-       comp_mot_device_t *device = (comp_mot_device_t *)data;
-       comp_check_null_ret("device", device);
-
-       if (device->device_id != NULL) {
-               g_free(device->device_id);
-               device->device_id = NULL;
-       }
-       if (device->addr != NULL) {
-               g_free(device->addr);
-               device->addr = NULL;
-       }
-       if (device->route_data != NULL) {
-               g_free(device->route_data);
-               device->route_data = NULL;
-       }
-       if (device->remote_id != NULL) {
-               g_free(device->remote_id);
-               device->remote_id = NULL;
-       }
-       if (device->sec_ver != NULL) {
-               g_free(device->sec_ver);
-               device->sec_ver = NULL;
-       }
-       g_free(device);
-       device = NULL;
-}
-
-int comp_group_find(int timeout)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       /* list freeing */
-       g_list_free_full(found_group_list, _free_group_func);
-       found_group_list = NULL;
-
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       comp_check_null_ret_error("cmd", cmd, COMP_ERROR_INVALID_PARAMETER);
-       ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_GROUP, timeout, cmd);
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("Failed to discover resource : %s", comp_log_get_error_string(ret));
-
-       LOG_END();
-
-       return ret;
-}
-
-GVariant *comp_group_get_found_groups()
-{
-       GVariantBuilder *builder;
-       GVariant *group_data;
-       GList *iter = NULL;
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
-
-       iter = found_group_list;
-       while (iter != NULL) {
-               comp_group_t *group = (comp_group_t *)iter->data;
-
-               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
-               g_variant_builder_add(builder, "{sv}", "URI",
-                                                         g_variant_new_string(group->uri_path));
-               g_variant_builder_add(builder, "{sv}", "DeviceID",
-                                                         g_variant_new_string(group->device_id));
-               g_variant_builder_add(builder, "{sv}", "GroupName",
-                                                         g_variant_new_string(group->group_name));
-               g_variant_builder_add(builder, "{sv}", "HostAddress",
-                                                         g_variant_new_string(group->host_addr));
-               g_variant_builder_add(builder, "{sv}", "GroupDeviceType",
-                                                         g_variant_new_string(group->resource_type));
-               /*When we get found groups, we can get my groups also. */
-               g_variant_builder_add(builder, "{sv}", "GroupType",
-                                                         g_variant_new_int32(group->type));
-               g_variant_builder_close(builder);
-
-               iter = g_list_next(iter);
-       }
-
-       group_data = g_variant_builder_end(builder);
-       g_variant_builder_unref(builder);
-
-       return group_data;
-}
-
-int comp_group_add_new(char *uri_path, char *device_id, char *device_name,
-                                        char *host_addr, char *resource_type, comp_group_type_e type)
-{
-       comp_group_t *group;
-       GVariantBuilder *builder;
-       GVariant *group_data;
-
-       LOG_BEGIN();
-
-       group = g_try_malloc0(sizeof(comp_group_t));
-       group->uri_path = g_strdup(uri_path);
-       group->device_id = g_strdup(device_id);
-       group->group_name = g_strdup(device_name);
-       group->host_addr = g_strdup(host_addr);
-       group->resource_type =  g_strdup(resource_type);
-       group->type = type;
-
-       found_group_list = g_list_append(found_group_list, group);
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
-       g_variant_builder_add(builder, "{sv}", "URI",
-                                                 g_variant_new_string(group->uri_path));
-       g_variant_builder_add(builder, "{sv}", "DeviceID",
-                                                 g_variant_new_string(group->device_id));
-       g_variant_builder_add(builder, "{sv}", "GroupName",
-                                                 g_variant_new_string(group->group_name));
-       g_variant_builder_add(builder, "{sv}", "HostAddress",
-                                                 g_variant_new_string(group->host_addr));
-       g_variant_builder_add(builder, "{sv}", "GroupDeviceType",
-                                                 g_variant_new_string(group->resource_type));
-       g_variant_builder_add(builder, "{sv}", "GroupType",
-                                                 g_variant_new_int32(group->type));
-
-       group_data = g_variant_builder_end(builder);
-
-       notify_group_found(group_data);
-
-       g_variant_builder_unref(builder);
-
-       LOG_END();
-
-       return COMP_ERROR_NONE;
-}
-
-/* Join the remote devices in my daemon */
-
-// Find MOT enabled devices
-int comp_group_add_new_mot_device(comp_mot_device_t *device)
-{
-       GList *iter = NULL;
-       gboolean is_exist = FALSE;
-
-       LOG_BEGIN();
-
-       iter = mot_enb_dev_list;
-       while (iter != NULL) {
-               comp_mot_device_t *temp = (comp_mot_device_t *)iter->data;
-
-               if (g_strcmp0(temp->device_id, device->device_id) == 0) {
-                       LOG_DEBUG("Device %s already exists in mot enable device list",
-                                         device->device_id);
-                       is_exist = TRUE;
-                       break;
-               }
-
-               iter = g_list_next(iter);
-       }
-
-       if (is_exist == FALSE) {
-               LOG_DEBUG("Add device with uuid %s to mot enabled device list",
-                                 device->device_id);
-               mot_enb_dev_list = g_list_append(mot_enb_dev_list, device);
-       }
-
-       LOG_END();
-
-       return is_exist;
-}
-
-
-GVariant *comp_group_get_remote_mot_enabled_devices()
-{
-       GVariantBuilder *builder;
-       GVariant *group_data;
-       GList *iter = NULL;
-
-       comp_remove_ip_info();
-       comp_make_ip_info();
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
-
-       iter = mot_enb_dev_list;
-       while (iter != NULL) {
-               comp_mot_device_t *device = (comp_mot_device_t *)iter->data;
-
-               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
-               g_variant_builder_add(builder, "{sv}", "DeviceID",
-                                                         g_variant_new_string(device->device_id));
-               g_variant_builder_add(builder, "{sv}", "Adapter",
-                                                         g_variant_new_int32(device->adapter));
-               g_variant_builder_add(builder, "{sv}", "Flags",
-                                                         g_variant_new_int32(device->flags));
-               g_variant_builder_add(builder, "{sv}", "Port",
-                                                         g_variant_new_uint16(device->port));
-               g_variant_builder_add(builder, "{sv}", "Address",
-                                                         g_variant_new_string(device->addr));
-               g_variant_builder_add(builder, "{sv}", "DeviceType",
-                                                         g_variant_new_uint16(comp_is_local_ip(device->addr)));
-               g_variant_builder_add(builder, "{sv}", "Ifindex",
-                                                         g_variant_new_int32(device->ifindex));
-               g_variant_builder_add(builder, "{sv}", "RouteData",
-                                                         g_variant_new_string(device->route_data));
-               g_variant_builder_add(builder, "{sv}", "ConnType",
-                                                         g_variant_new_int32(device->conn_type));
-               g_variant_builder_add(builder, "{sv}", "SecurePort",
-                                                         g_variant_new_uint16(device->secure_port));
-               g_variant_builder_add(builder, "{sv}", "TcpPort",
-                                                         g_variant_new_uint16(device->tcp_port));
-               g_variant_builder_add(builder, "{sv}", "SecVer",
-                                                         g_variant_new_string(device->sec_ver));
-               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
-                                                         g_variant_new_int32(device->dev_status));
-               LOG_DEBUG("%s", device->model_name);
-               g_variant_builder_add(builder, "{sv}", "ModelName",
-                                                         g_variant_new_string(device->model_name));
-               g_variant_builder_add(builder, "{sv}", "DeviceName",
-                                                         g_variant_new_string(device->device_name));
-               g_variant_builder_add(builder, "{sv}", "PlatformVer",
-                                                         g_variant_new_string(device->platform_ver));
-               g_variant_builder_add(builder, "{sv}", "VendorID",
-                                                         g_variant_new_string(device->vendor_id));
-               g_variant_builder_add(builder, "{sv}", "Profile",
-                                                         g_variant_new_string(device->profile));
-
-               g_variant_builder_close(builder);
-
-               iter = g_list_next(iter);
-       }
-
-       group_data = g_variant_builder_end(builder);
-       g_variant_builder_unref(builder);
-
-       return group_data;
-}
-
-int comp_group_get_mot_device_count()
-{
-       if (mot_enb_dev_list)
-               return g_list_length(mot_enb_dev_list);
-
-       return 0;
-}
-
-void comp_group_notify_mot_enable_device_done()
-{
-       GVariant *device_data;
-       int count = comp_group_get_mot_device_count();
-
-       LOG_BEGIN();
-
-       device_data = comp_group_get_remote_mot_enabled_devices();
-
-       notify_device_found(count, device_data);
-
-       LOG_END();
-}
-
-int comp_group_find_mot_enabled_devices(int timeout)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       /* list freeing */
-       g_list_free_full(mot_enb_dev_list, _mot_enb_dev_list_free_func);
-       mot_enb_dev_list = NULL;
-
-       ret = agent_find_mot_enable_devices(timeout);
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("Failed to find mot enable devices : %s",
-                                comp_log_get_error_string(ret));
-       }
-
-       LOG_END();
-
-       return ret;
-}
-
-void comp_group_notify_keepalive_response(comp_command_t *cmd)
-{
-       GList *iter = NULL;
-       gboolean is_exist = FALSE;
-       comp_invited_device_t *temp;
-
-       LOG_DEBUG("Response received from uuid %s", cmd->uuid);
-
-       iter = invited_dev_list;
-       while (iter != NULL) {
-               temp = (comp_invited_device_t *)iter->data;
-
-               if ((g_strcmp0(temp->group_name, cmd->arg1) == 0) &&
-                       (g_strcmp0(temp->uuid, cmd->uuid) == 0)) {
-                       LOG_DEBUG("Device %s count %d found in invited device list",
-                                         cmd->uuid, temp->count);
-                       is_exist = TRUE;
-                       break;
-               }
-
-               iter = g_list_next(iter);
-       }
-
-       if (is_exist == TRUE)
-               temp->count += 1;
-}
-
-int comp_group_request_keepalive(char *uuid, char *group_name, char *host)
-{
-       int ret = COMP_ERROR_NONE;
-
-       LOG_DEBUG("[Request KeepAlive] to %s", uuid);
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       cmd->command = COMP_REQ_KEEP_ALIVE;
-       cmd->uuid = g_strdup(uuid);
-       cmd->arg1 = g_strdup(group_name);
-       cmd->host = g_strdup(host);
-
-       ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 2, cmd);
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("Failed to send data : %s",
-                               comp_log_get_error_string(ret));
-               return ret;
-       }
-
-       return 0;
-}
-
-comp_group_invite_info_t *comp_group_get_invite_info()
-{
-       return group_invite_info;
-}
-
-void comp_group_free_invite_info()
-{
-       LOG_DEBUG("Remove Group Invite Information %p", group_invite_info);
-
-       if (group_invite_info) {
-               g_free(group_invite_info->group_name);
-               g_free(group_invite_info->uuid_dev1);
-               g_free(group_invite_info->uuid_dev2);
-               g_free(group_invite_info->pin);
-               g_free(group_invite_info->uri_1);
-               g_free(group_invite_info->rt_1);
-               g_free(group_invite_info->interface_1);
-               g_free(group_invite_info->uri_2);
-               g_free(group_invite_info->rt_2);
-               g_free(group_invite_info->interface_2);
-               g_free(group_invite_info);
-
-               group_invite_info = NULL;
-       }
-}
-
-static comp_mot_device_t *_check_device_in_mot_enb_dev_list(char *uuid)
-{
-       comp_mot_device_t *device;
-       GList *iter;
-
-       iter = mot_enb_dev_list;
-
-       while (iter != NULL) {
-               device = (comp_mot_device_t *)iter->data;
-
-               if (g_strcmp0(device->device_id, uuid) == 0) {
-                       LOG_DEBUG("Device %s is available in mot enable device list", uuid);
-                       return device;
-               }
-       }
-
-       return NULL;
-}
-
-static char *_addr2host(char *addr, int port)
-{
-       char ip[50];
-       char *percent;
-
-       g_strlcpy(ip, addr, strlen(addr) + 1);
-
-       /* Remove % from address */
-       percent = strchr(ip, '%');
-       if (percent)
-               percent[0] = '\0';
-
-       /* IPv6 Address should be encoded for RFC6874  */
-       if (strchr(ip, ':')) /* IPv6 Adress */
-               return g_strdup_printf("coaps://[%s%s%s]:%d", ip, "%25",
-                                                                       percent + 1, port);
-       else /* IPv4 Address */
-               return g_strdup_printf("coaps://%s:%d", ip, port);
-}
-
-void comp_group_notify_group_invite(int ret)
-{
-       /*
-        * ret = 0 OC_STACK_OK
-        * ret = 49 OC_STACK_DUPLICATE_UUID
-        */
-       if ((ret == 0 || ret == 49) && group_invite_info) {
-               comp_invited_device_t *device;
-               GList *iter = NULL;
-               gboolean is_exist = FALSE;
-
-               device = g_try_malloc0(sizeof(comp_invited_device_t));
-               device->group_name = g_strdup(group_invite_info->group_name);
-               device->uuid = g_strdup(group_invite_info->uuid_dev2);
-
-               iter = invited_dev_list;
-               while (iter != NULL) {
-                       comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
-
-                       if ((g_strcmp0(temp->group_name, device->group_name) == 0) &&
-                               (g_strcmp0(temp->uuid, device->uuid) == 0)) {
-                               LOG_DEBUG("Device %s already exists in invited device list",
-                                                 temp->uuid);
-                               is_exist = TRUE;
-                               break;
-                       }
-
-                       iter = g_list_next(iter);
-               }
-
-               if (is_exist == FALSE) {
-                       comp_mot_device_t *temp;
-                       temp = _check_device_in_mot_enb_dev_list(device->uuid);
-                       if (temp)
-                               device->host = _addr2host(temp->addr, temp->secure_port);
-
-                       device->count = 0;
-                       LOG_DEBUG("Add device %s group %s host %s to invited device list",
-                                         device->uuid, device->group_name, device->host);
-                       invited_dev_list = g_list_prepend(invited_dev_list, device);
-
-                       comp_group_request_keepalive(device->uuid, device->group_name,
-                                                                                device->host);
-
-                       comp_context_t *comp_ctx = comp_context_get_context();
-                       comp_check_null_ret("comp_ctx", comp_ctx);
-
-                       if (comp_ctx->monitor_started == true) {
-                               notify_device_monitor_result(device->uuid, device->group_name,
-                                                                                        "Added");
-
-                               comp_group_start_invited_device_monitor(1);
-                       }
-
-               } else {
-                       g_free(device->uuid);
-                       g_free(device->group_name);
-                       g_free(device);
-               }
-       }
-
-       comp_group_free_invite_info();
-
-       notify_group_device_invite_result(ret);
-}
-
-
-#define FULL_PERMISSION 31
-
-int _is_pairwise_uuid(char *uuid)
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
-
-       GList *iter = NULL;
-
-       iter = comp_ctx->pairwise_list;
-       while (iter != NULL) {
-               char *pairwise_uuid = (char *)iter->data;
-
-               if (strcmp(pairwise_uuid, uuid) == 0)
-                       return 0;
-
-               iter = g_list_next(iter);
-       }
-
-       return -1;
-}
-
-int comp_group_add_device_in_group(const char *group_name, const char *uuid)
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
-
-       GList *iter = NULL;
-
-       iter = comp_ctx->grp_list;
-       while (iter != NULL) {
-               comp_grp_t *group = (comp_grp_t *)iter->data;
-
-               if (strcmp(group_name, group->name) == 0) {
-                       GList *device_iter = group->device_list;
-                       while (device_iter != NULL) {
-                               char *device_uuid = (char *)device_iter->data;
-                               if (strcmp(device_uuid, uuid) == 0)
-                                       return -1;
-
-                               device_iter = g_list_next(device_iter);
-                       }
-
-                       group->device_list = g_list_append(group->device_list, strdup(uuid));
-                       comp_db_insert(group_name, uuid);
-
-                       __print_groups_information();
-                       return 0;
-               }
-
-               iter = g_list_next(iter);
-       }
-
-       return -1;
-}
-
-//Join to device in group (async)
-int comp_group_invite(const char *group_name, const char *uuid, const char *pin)
-{
-       int ret = COMP_ERROR_NONE;
-
-       LOG_BEGIN();
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
-
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-       /*
-        * 1. Perform MOT
-        * 2. Discover Mowned devices
-        * 3. Pairwise
-        */
-       LOG_DEBUG("group name : %s, uuid : %s", group_name, uuid);
-
-       if (_is_pairwise_uuid(uuid) < 0) {
-
-               ret = agent_mot(uuid, pin);
-               if (ret == COMP_ERROR_NONE) {
-                       group_invite_info = g_try_malloc0(sizeof(comp_group_invite_info_t));
-                       group_invite_info->uuid_dev1 = g_strdup(comp_ctx->device_uuid);
-                       group_invite_info->uuid_dev2 = g_strdup(uuid);
-                       group_invite_info->pin = g_strdup(pin);
-                       group_invite_info->uri_1 = g_strdup("/comp/data/1");
-                       group_invite_info->rt_1 = g_strdup("core.comp.data");
-                       group_invite_info->interface_1 = g_strdup("oic.if.baseline");
-                       group_invite_info->permission_1 = FULL_PERMISSION;
-                       group_invite_info->uri_2 = g_strdup("/comp/data/1");
-                       group_invite_info->rt_2 = g_strdup("core.comp.data");
-                       group_invite_info->interface_2 = g_strdup("oic.if.baseline");
-                       group_invite_info->permission_2 = FULL_PERMISSION;
-               }
-       }
-
-#else
-       group_invite_info = g_try_malloc0(sizeof(comp_group_invite_info_t));
-       group_invite_info->uuid_dev2 = g_strdup(uuid);
-       group_invite_info->group_name = g_strdup(group_name);
-
-       ret = agent_pair(pin, comp_ctx->device_uuid, uuid, "/comp/data/1",
-                                        "core.comp.data", "oic.if.baseline", FULL_PERMISSION, uuid,
-                                        comp_ctx->device_uuid, "/comp/data/1", "core.comp.data",
-                                        "oic.if.baseline", FULL_PERMISSION);
-#endif
-
-       if (comp_group_add_device_in_group(group_name, uuid) < 0)
-               return COMP_ERROR_NONE;
-
-       LOG_END();
-
-       return ret;
-}
-
-void comp_group_notify_group_dismiss(int result)
-{
-       LOG_DEBUG("Notify group eject %d", result);
-
-       notify_group_device_eject_result(result);
-}
-
-int comp_group_remove_device_in_group(char *group_name, char *uuid)
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
-
-       GList *iter = NULL;
-
-       /* Find the device at every group in list */
-       iter = comp_ctx->grp_list;
-       while (iter != NULL) {
-               comp_grp_t *group = (comp_grp_t *)iter->data;
-               if (strcmp(group_name, group->name) == 0) {
-                       GList *device_iter = group->device_list;
-
-                       device_iter = g_list_remove_all(device_iter, uuid);
-               }
-
-               iter = g_list_next(iter);
-       }
-       comp_db_delete_device(group_name, uuid);
-       __print_groups_information();
-
-       return 0;
-}
-
-//dismiss from group (async)
-int comp_group_eject(const gchar *group_name, gchar *uuid_dev1, const gchar *uuid_dev2)
-{
-       int ret;
-
-       LOG_BEGIN();
- #ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-       ret = agent_remove_mo_at_device(uuid);
-       /*
-        * 1. Unpair device
-        * 2. Remove MOT at device #2
-        * 3. Remove cred at local (device #1)
-        * */
-#else
-       ret = agent_unpair(uuid_dev1, uuid_dev2);
-#endif
-       comp_group_remove_device_in_group(group_name, uuid_dev2);
-
-       LOG_END();
-
-       return ret;
-}
-
-int comp_group_pair_resource(char* target1, char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
-       char *uri2, char *rt2, char *interface2, int permission2)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       ret = agent_resources_pairwise(target1, subject1, uri1, rt1, interface1, permission1,
-                                                target2, subject2, uri2, rt2, interface2, permission2);
-
-       LOG_END();
-
-       return ret;
-}
-
-int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       ret = agent_unlink_resources(uuid_dev1, uuid_dev2);
-
-       LOG_END();
-
-       return ret;
-}
-
-int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port,
-                                                unsigned char *data, int len)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       comp_command_t *cmd = g_try_malloc0(sizeof(comp_command_t));
-       if (NULL == cmd) {
-               ret = COMP_ERROR_OUT_OF_MEMORY;
-               LOG_ERR("Failed to alloc memory");
-               return ret;
-       }
-
-       cmd->command = COMP_REQ_SEND_DATA;
-       cmd->uuid = g_strdup(uuid_dev);
-
-       cmd->host = _addr2host(addr, port);
-
-#ifdef SUPPORT_BASE64_ENCODING
-       cmd->data = g_try_malloc0(len + 1);
-       if (NULL == cmd->data) {
-               ret = COMP_ERROR_OUT_OF_MEMORY;
-               LOG_ERR("Send Data Fail to uuid = %s host %s error=%s",
-                       cmd->uuid, cmd->host, comp_log_get_error_string(ret));
-               return ret;
-       }
-
-       memcpy(cmd->data, data, len);
-       cmd->data_len = len;
-#else
-       cmd->arg1 = g_try_malloc0(len + 1);
-       if (NULL == cmd->arg1) {
-               ret = COMP_ERROR_OUT_OF_MEMORY;
-               LOG_ERR("Send Data Fail to uuid = %s host %s error=%s",
-                       cmd->uuid, cmd->host, comp_log_get_error_string(ret));
-               return ret;
-       }
-
-       memcpy(cmd->arg1, data, len);
-       cmd->arg1[len] = '\0';
-#endif
-
-       LOG_DEBUG("UUID %s host %s", cmd->uuid, cmd->host);
-
-       ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 3, cmd);
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("Failed to send data : %s",
-                               comp_log_get_error_string(ret));
-       }
-
-       LOG_END();
-
-       return ret;
-}
-
-int  comp_group_add_new_mowned_device(comp_mot_device_t *device)
-{
-       GList *iter = NULL;
-       gboolean is_exist = FALSE;
-
-       LOG_BEGIN();
-
-       iter = mowned_dev_list;
-       while (iter != NULL) {
-               comp_mot_device_t *temp = (comp_mot_device_t *)iter->data;
-
-               if (g_strcmp0(temp->device_id, device->device_id) == 0) {
-                       LOG_DEBUG("Device %s already exists in mowned device list",
-                                         device->device_id);
-                       is_exist = TRUE;
-                       break;
-               }
-
-               iter = g_list_next(iter);
-       }
-
-       if (is_exist == FALSE) {
-               LOG_DEBUG("Add device with uuid %s to mowned device list",
-                                 device->device_id);
-               mowned_dev_list = g_list_append(mowned_dev_list, device);
-       }
-
-       LOG_END();
-
-       return is_exist;
-}
-
-GVariant *comp_group_get_mowned_devices()
-{
-       GVariantBuilder *builder;
-       GVariant *group_data;
-       GList *iter = NULL;
-
-       comp_remove_ip_info();
-       comp_make_ip_info();
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
-
-       iter = mowned_dev_list;
-       while (iter != NULL) {
-               comp_mot_device_t *device = (comp_mot_device_t *)iter->data;
-
-               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
-               g_variant_builder_add(builder, "{sv}", "DeviceID",
-                                                         g_variant_new_string(device->device_id));
-               g_variant_builder_add(builder, "{sv}", "Adapter",
-                                                         g_variant_new_int32(device->adapter));
-               g_variant_builder_add(builder, "{sv}", "Flags",
-                                                         g_variant_new_int32(device->flags));
-               g_variant_builder_add(builder, "{sv}", "Port",
-                                                         g_variant_new_uint16(device->port));
-               g_variant_builder_add(builder, "{sv}", "Address",
-                                                         g_variant_new_string(device->addr));
-               g_variant_builder_add(builder, "{sv}", "DeviceType",
-                                                         g_variant_new_uint16(comp_is_local_ip(device->addr)));
-               g_variant_builder_add(builder, "{sv}", "Ifindex",
-                                                         g_variant_new_int32(device->ifindex));
-               g_variant_builder_add(builder, "{sv}", "RouteData",
-                                                         g_variant_new_string(device->route_data));
-               g_variant_builder_add(builder, "{sv}", "ConnType",
-                                                         g_variant_new_int32(device->conn_type));
-               g_variant_builder_add(builder, "{sv}", "SecurePort",
-                                                         g_variant_new_uint16(device->secure_port));
-               g_variant_builder_add(builder, "{sv}", "TcpPort",
-                                                         g_variant_new_uint16(device->tcp_port));
-               g_variant_builder_add(builder, "{sv}", "SecVer",
-                                                         g_variant_new_string(device->sec_ver));
-               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
-                                                         g_variant_new_int32(device->dev_status));
-               g_variant_builder_add(builder, "{sv}", "ModelName",
-                                                         g_variant_new_string(device->model_name));
-               g_variant_builder_add(builder, "{sv}", "DeviceName",
-                                                         g_variant_new_string(device->device_name));
-               g_variant_builder_add(builder, "{sv}", "PlatformVer",
-                                                         g_variant_new_string(device->platform_ver));
-               g_variant_builder_add(builder, "{sv}", "VendorID",
-                                                         g_variant_new_string(device->vendor_id));
-               g_variant_builder_add(builder, "{sv}", "Profile",
-                                                         g_variant_new_string(device->profile));
-
-               g_variant_builder_close(builder);
-
-               iter = g_list_next(iter);
-       }
-
-       group_data = g_variant_builder_end(builder);
-       g_variant_builder_unref(builder);
-
-       return group_data;
-}
-
-void comp_group_change_mowned_device(comp_mot_device_t *device)
-{
-       LOG_BEGIN();
-
-       my_device = device;
-
-       LOG_END();
-}
-
-GVariant *comp_group_get_my_mowned_devices()
-{
-       GVariantBuilder *builder;
-       GVariant *group_data;
-
-       comp_remove_ip_info();
-       comp_make_ip_info();
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
-       if (my_device != NULL) {
-               g_variant_builder_add(builder, "{sv}", "DeviceID",
-                                                         g_variant_new_string(my_device->device_id));
-               g_variant_builder_add(builder, "{sv}", "Adapter",
-                                                         g_variant_new_int32(my_device->adapter));
-               g_variant_builder_add(builder, "{sv}", "Flags",
-                                                         g_variant_new_int32(my_device->flags));
-               g_variant_builder_add(builder, "{sv}", "Port",
-                                                         g_variant_new_uint16(my_device->port));
-               g_variant_builder_add(builder, "{sv}", "Address",
-                                                         g_variant_new_string(my_device->addr));
-               g_variant_builder_add(builder, "{sv}", "DeviceType",
-                                                         g_variant_new_uint16(comp_is_local_ip(my_device->addr)));
-               g_variant_builder_add(builder, "{sv}", "Ifindex",
-                                                         g_variant_new_int32(my_device->ifindex));
-               g_variant_builder_add(builder, "{sv}", "RouteData",
-                                                         g_variant_new_string(my_device->route_data));
-               g_variant_builder_add(builder, "{sv}", "ConnType",
-                                                         g_variant_new_int32(my_device->conn_type));
-               g_variant_builder_add(builder, "{sv}", "SecurePort",
-                                                         g_variant_new_uint16(my_device->secure_port));
-               g_variant_builder_add(builder, "{sv}", "TcpPort",
-                                                         g_variant_new_uint16(my_device->tcp_port));
-               g_variant_builder_add(builder, "{sv}", "SecVer",
-                                                         g_variant_new_string(my_device->sec_ver));
-               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
-                                                         g_variant_new_int32(my_device->dev_status));
-               g_variant_builder_add(builder, "{sv}", "ModelName",
-                                                         g_variant_new_string(my_device->model_name));
-               g_variant_builder_add(builder, "{sv}", "DeviceName",
-                                                         g_variant_new_string(my_device->device_name));
-               g_variant_builder_add(builder, "{sv}", "PlatformVer",
-                                                         g_variant_new_string(my_device->platform_ver));
-               g_variant_builder_add(builder, "{sv}", "VendorID",
-                                                         g_variant_new_string(my_device->vendor_id));
-               g_variant_builder_add(builder, "{sv}", "Profile",
-                                                         g_variant_new_string(my_device->profile));
-       }
-
-       group_data = g_variant_builder_end(builder);
-       g_variant_builder_unref(builder);
-
-       return group_data;
-}
-
-int comp_group_get_mowned_device_count()
-{
-       if (mowned_dev_list)
-               return g_list_length(mowned_dev_list);
-
-       return 0;
-}
-
-void comp_group_notify_mowned_device_find_done()
-{
-       GVariant *device_data;
-       int count = g_list_length(mowned_dev_list);
-
-       LOG_BEGIN();
-
-       device_data = comp_group_get_mowned_devices();
-
-       notify_mowned_device_found(count, device_data);
-
-       LOG_END();
-}
-
-int comp_group_find_mowned_devices(int timeout)
-{
-       int ret;
-
-       LOG_BEGIN();
-
-       /* list freeing */
-       g_list_free_full(mowned_dev_list, _mot_enb_dev_list_free_func);
-       mowned_dev_list = NULL;
-
-       ret = agent_find_mowned_devices(timeout);
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("Failed to find mowned devices : %s",
-                                comp_log_get_error_string(ret));
-       }
-
-       LOG_END();
-
-       return ret;
-}
-
-/* Join to remote device group */
-
-int comp_group_join()
-{
-       int ret = COMP_ERROR_NONE;
-
-       LOG_BEGIN();
-
-
-       LOG_END();
-
-       return ret;
-}
-
-int comp_group_leave_from(/* callback */) //leave from certain remote group (Async)
-{
-       int ret = COMP_ERROR_NONE;
-       return ret;
-}
-
-/* Called when daemon is end. */
-int comp_group_deinitialize()
-{
-       int ret = COMP_ERROR_NONE;
-       return ret;
-}
-
-int comp_group_get_group_name(comp_group_t *handle, char **name)
-{
-       int ret = COMP_ERROR_NONE;
-       NOTUSED(handle);
-       NOTUSED(name);
-       return ret;
-}
-
-int comp_group_get_group_type(comp_group_t *handle, int *type)
-{
-       int ret = COMP_ERROR_NONE;
-       NOTUSED(handle);
-       NOTUSED(type);
-       return ret;
-}
-
-int comp_group_get_group_device_type(comp_group_t *handle)
-{
-       int ret = COMP_ERROR_NONE;
-       NOTUSED(handle);
-       return ret;
-}
-
-int comp_group_get_group_device_id(comp_group_t *handle)
-{
-       int ret = COMP_ERROR_NONE;
-       NOTUSED(handle);
-       return ret;
-}
-
-int comp_group_request_create_group(char *uuid, char *group_name)
-{
-       int ret = COMP_ERROR_NONE;
-       comp_mot_device_t *device;
-
-       LOG_ERR("[Request Create Group] %s", group_name);
-       LOG_ERR("[Request Create Group] to %s", uuid);
-
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       cmd->command = COMP_REQ_CREATE_GROUP;
-       cmd->uuid = g_strdup(uuid);
-       cmd->arg1 = g_strdup(group_name);
-
-       device = _check_device_in_mot_enb_dev_list(uuid);
-       if (device) {
-               cmd->host = _addr2host(device->addr, device->secure_port);
-               ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to send data : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       } else {
-               ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to discover resource : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       }
-
-       return ret;
-}
-
-int comp_group_request_invite(char *uuid, char *group_name, char *target_uuid, char *PIN)
-{
-       int ret = COMP_ERROR_NONE;
-       comp_mot_device_t *device;
-
-       LOG_ERR("[Request Invite] %s, %s, %s", group_name, target_uuid, PIN);
-       LOG_ERR("[Request Invite] to %s", uuid);
-
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       cmd->command = COMP_REQ_INVITE_DEVICE;
-       cmd->uuid = g_strdup(uuid);
-       cmd->arg1 = g_strdup(group_name);
-       cmd->arg2 = g_strdup(target_uuid);
-       cmd->arg3 = g_strdup(PIN);
-
-       device = _check_device_in_mot_enb_dev_list(uuid);
-       if (device) {
-               cmd->host = _addr2host(device->addr, device->secure_port);
-               ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to send data : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       } else {
-               ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to discover resource : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       }
-
-       return ret;
-}
-
-
-int comp_group_request_eject(char *uuid, char *group_name, char *target_uuid)
-{
-       int ret = COMP_ERROR_NONE;
-       comp_mot_device_t *device;
-
-       LOG_ERR("[Request Eject] %s, %s", group_name, target_uuid);
-       LOG_ERR("[Request Eject] to %s", uuid);
-
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       cmd->command = COMP_REQ_EJECT_DEVICE;
-       cmd->uuid = g_strdup(uuid);
-       cmd->arg1 = g_strdup(group_name);
-       cmd->arg2 = g_strdup(target_uuid);
-
-       device = _check_device_in_mot_enb_dev_list(uuid);
-       if (device) {
-               cmd->host = _addr2host(device->addr, device->secure_port);
-               ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to send data : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       } else {
-               ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to discover resource : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       }
-
-       return ret;
-
-}
-
-
-int comp_group_request_delete_group(char *uuid, char *group_name)
-{
-       int ret = COMP_ERROR_NONE;
-       comp_mot_device_t *device;
-
-       LOG_ERR("[Request Delete Group] %s", group_name);
-       LOG_ERR("[Request Delete Group] to %s", uuid);
-
-       comp_command_t *cmd = g_new0(comp_command_t, 1);
-       cmd->command = COMP_REQ_DELETE_GROUP;
-       cmd->uuid = g_strdup(uuid);
-       cmd->arg1 = g_strdup(group_name);
-
-       device = _check_device_in_mot_enb_dev_list(uuid);
-       if (device) {
-               cmd->host = _addr2host(device->addr, device->secure_port);
-               ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to send data : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       } else {
-               ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 5, cmd);
-               if (ret != COMP_ERROR_NONE) {
-                       LOG_ERR("Failed to discover resource : %s",
-                                       comp_log_get_error_string(ret));
-               }
-       }
-
-       return ret;
-}
-
-static gboolean __send_keepalive_messages(gpointer user_data)
-{
-       GList *iter = NULL;
-
-       iter = invited_dev_list;
-       while (iter != NULL) {
-               comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
-
-               comp_group_request_keepalive(temp->uuid, temp->group_name, temp->host);
-
-               iter = g_list_next(iter);
-       }
-
-       return TRUE;
-}
-
-static gboolean __check_invited_device_status(gpointer user_data)
-{
-       int *t_id = (int *)user_data;
-       GList *iter = NULL;
-
-       g_source_remove(*t_id);
-       *t_id = 0;
-
-       iter = invited_dev_list;
-       while (iter != NULL) {
-               comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
-
-               iter = g_list_next(iter);
-
-               LOG_DEBUG("uuid %s count %d", temp->uuid, temp->count);
-
-               if (temp->count == 0) {
-                       LOG_DEBUG("Remove device with uuid %s", temp->uuid);
-                       invited_dev_list = g_list_remove(invited_dev_list, temp);
-
-                       notify_device_monitor_result(temp->uuid, temp->group_name,
-                                                                                "Removed");
-
-                       g_free(temp->host);
-                       g_free(temp->uuid);
-                       g_free(temp->group_name);
-                       g_free(temp);
-               } else {
-                       temp->count = 0;
-               }
-       }
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, FALSE);
-
-       if (comp_ctx->monitor_started == false) {
-               g_free(t_id);
-               return FALSE;
-       }
-
-       if (g_list_length(invited_dev_list) == 0) {
-               g_free(t_id);
-               return FALSE;
-       }
-
-       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
-                                                 NULL);
-
-       return TRUE;
-}
-
-int comp_group_start_invited_device_monitor(int start)
-{
-       int *t_id;
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx,
-                                                         COMP_ERROR_INVALID_PARAMETER);
-
-       if (start) { /* Start Monitor */
-               comp_ctx->monitor_started = true;
-               LOG_DEBUG("Start invited device monitor");
-       } else { /* Stop Monitor */
-               comp_ctx->monitor_started = false;
-               LOG_DEBUG("Stop invited device monitor");
-               return COMP_ERROR_NONE;
-       }
-
-       t_id = g_try_malloc0(sizeof(int));
-
-       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
-                                                 NULL);
-
-       g_timeout_add(CHECK_DEVICE_STATUS_TIMEOUT, __check_invited_device_status,
-                                                 t_id);
-
-       return COMP_ERROR_NONE;
-}
diff --git a/src/companion-manager/src/comp_iot.cpp b/src/companion-manager/src/comp_iot.cpp
deleted file mode 100755 (executable)
index 32fcbad..0000000
+++ /dev/null
@@ -1,1195 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <tzplatform_config.h>
-
-#include <utlist.h>
-#include <base64.h>
-#include <sys/utsname.h>
-
-#include <octypes.h>
-#include <pmtypes.h>
-#include <pmutility.h>
-#include <securevirtualresourcetypes.h>
-
-#include <iotivity_config.h>
-#include <platform_features.h>
-#include <ocprovisioningmanager.h>
-#include <doxmresource.h>
-#include <system_info.h>
-#include <vconf.h>
-#include <system_settings.h>
-
-#include <comp_iot.h>
-#include <comp_group.h>
-#include <comp_gdbus_group.h>
-#include <comp_mot_agent.h>
-
-#include "OCProvisioningManager.hpp"
-#include "OCPlatform.h"
-#include "OCApi.h"
-
-using namespace OC;
-using namespace std;
-
-#define MAX_FILE_PATH_LEN 1024
-#define SVR_DB_FILE_NAME "oic_svr_db_comp_manager.dat"
-#define SYSTEM_INFO_PLATFORM_VERSION "http://tizen.org/feature/platform.version"
-#define SYSTEM_INFO_MANUF_NAME "http://tizen.org/system/manufacturer"
-#define SYSTEM_INFO_MODEL_NAME "http://tizen.org/system/model_name"
-#define SYSTEM_INFO_BUILD_STRING "http://tizen.org/system/build.string"
-#define SYSTEM_INFO_TIZEN_ID "http://tizen.org/system/tizenid"
-#define SYSTEM_INFO_PROFILE "http://tizen.org/feature/profile"
-
-int last_get_result;
-OCPersistentStorage ps;
-
-static int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
-{
-       if (NULL == uuid || NULL == strUuid || NULL != *strUuid) {
-               LOG_ERR("ConvertUuidToStr : Invalid param");
-               return OC_STACK_INVALID_PARAM;
-       }
-
-       size_t uuidIdx = 0;
-       size_t urnIdx = 0;
-       const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
-       char* convertedUrn = (char*)calloc(urnBufSize, sizeof(char));
-       if (NULL == convertedUrn) {
-               LOG_ERR("Memory Allocation Failed");
-               goto exit;
-       }
-
-       for (uuidIdx = 0, urnIdx = 0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize;
-               uuidIdx++, urnIdx += 2) {
-               // canonical format for UUID has '8-4-4-4-12'
-               if (uuidIdx == 4 || uuidIdx == 6 || uuidIdx == 8 || uuidIdx == 10) {
-                       snprintf(convertedUrn + urnIdx, 2, "%c", '-');
-                       urnIdx++;
-               }
-               snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
-       }
-       convertedUrn[urnBufSize - 1] = '\0';
-
-       *strUuid = convertedUrn;
-       return OC_STACK_OK;
-
-exit:
-       return OC_STACK_NO_MEMORY;
-}
-
-#define CASE_TO_STR(x) case x: return #x;
-
-static const char *command2string(comp_request_type_e command)
-{
-       switch (command) {
-       CASE_TO_STR(COMP_REQ_SEND_DATA)
-       CASE_TO_STR(COMP_REQ_CREATE_GROUP)
-       CASE_TO_STR(COMP_REQ_INVITE_DEVICE)
-       CASE_TO_STR(COMP_REQ_EJECT_DEVICE)
-       CASE_TO_STR(COMP_REQ_DELETE_GROUP)
-       default:
-               return "Unknown Command";
-       }
-}
-
-static comp_request_type_e string2command(char *command)
-{
-       if (g_strcmp0(command, "5") == 0)
-               return COMP_REQ_SEND_DATA;
-       else if (g_strcmp0(command, "1") == 0)
-               return COMP_REQ_CREATE_GROUP;
-       else if (g_strcmp0(command, "2") == 0)
-               return COMP_REQ_INVITE_DEVICE;
-       else if (g_strcmp0(command, "3") == 0)
-               return COMP_REQ_EJECT_DEVICE;
-       else if (g_strcmp0(command, "4") == 0)
-               return COMP_REQ_DELETE_GROUP;
-       else
-               return COMP_REQ_UNKNOWN_COMMAND;
-}
-
-static FILE* client_open(const char* /*path*/, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                       "/opt/usr/data", SVR_DB_FILE_NAME);
-
-       LOG_DEBUG("Open file %s", data_dir);
-
-    return fopen(data_dir, mode);
-}
-
-int __comp_iot_get_platform_info(OCPlatformInfo *platform_info)
-{
-       int ret;
-       char *tizen_id = NULL;
-       char *device_name = NULL;
-       char platform_id[1024];
-
-       device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-       if (device_name == NULL)
-               LOG_ERR("vconf_get_str() Fail");
-
-       ret = system_info_get_platform_string(SYSTEM_INFO_TIZEN_ID, &tizen_id);
-       if (SYSTEM_INFO_ERROR_NONE != ret)
-               LOG_ERR("system_info_get_platform_string() Fail(%d)", ret);
-
-       snprintf(platform_id, sizeof(platform_id), "%s(%s)",
-                        device_name ? device_name : "", tizen_id ? tizen_id : "");
-
-       free(device_name);
-       free(tizen_id);
-       LOG_DEBUG("platform_id: %s", platform_id);
-
-       /* Mandatory (oic.wk.p) */
-       platform_info->platformID = strdup(platform_id);
-
-       /* Mandatory (oic.wk.p) */
-       ret = system_info_get_platform_string(SYSTEM_INFO_MANUF_NAME,
-                       &platform_info->manufacturerName);
-       if (SYSTEM_INFO_ERROR_NONE != ret) {
-               LOG_ERR("system_info_get_platform_string(manufacturer) Fail(%d)", ret);
-               free(platform_info->platformID);
-               return -1;
-       }
-
-       ret = system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME,
-                       &platform_info->modelNumber);
-       if (SYSTEM_INFO_ERROR_NONE != ret)
-               LOG_ERR("system_info_get_platform_string(model_name) Fail(%d)", ret);
-
-       ret = system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION,
-                       &platform_info->platformVersion);
-       if (SYSTEM_INFO_ERROR_NONE != ret)
-               LOG_ERR("system_info_get_platform_string(platform_version) Fail(%d)", ret);
-
-       ret = system_info_get_platform_string(SYSTEM_INFO_BUILD_STRING,
-                       &platform_info->firmwareVersion);
-       if (SYSTEM_INFO_ERROR_NONE != ret)
-               LOG_ERR("system_info_get_platform_string(build_string) Fail(%d)", ret);
-
-       platform_info->manufacturerUrl = g_strdup("NONE");
-       platform_info->dateOfManufacture = g_strdup("NONE");
-
-       struct utsname uts;
-
-       if (!uname(&uts))
-               platform_info->operatingSystemVersion = g_strdup(uts.sysname);
-       else
-               platform_info->operatingSystemVersion = g_strdup("NONE");
-
-       platform_info->hardwareVersion = g_strdup("0-0");
-       platform_info->supportUrl = g_strdup("NONE");
-       platform_info->systemTime = g_strdup("NONE");
-
-       return 0;
-}
-
-static void _clean_platform_info(OCPlatformInfo *platform_info)
-{
-       comp_check_null_ret("platform_info", platform_info);
-
-       if (platform_info->platformID) {
-               free(platform_info->platformID);
-               platform_info->platformID = NULL;
-       }
-       if (platform_info->manufacturerName) {
-               free(platform_info->manufacturerName);
-               platform_info->manufacturerName = NULL;
-       }
-       if (platform_info->modelNumber) {
-               free(platform_info->modelNumber);
-               platform_info->modelNumber = NULL;
-       }
-       if (platform_info->platformVersion) {
-               free(platform_info->platformVersion);
-               platform_info->platformVersion = NULL;
-       }
-       if (platform_info->firmwareVersion) {
-               free(platform_info->firmwareVersion);
-               platform_info->firmwareVersion = NULL;
-       }
-       if (platform_info->manufacturerUrl) {
-               free(platform_info->manufacturerUrl);
-               platform_info->manufacturerUrl = NULL;
-       }
-       if (platform_info->dateOfManufacture) {
-               free(platform_info->dateOfManufacture);
-               platform_info->dateOfManufacture = NULL;
-       }
-       if (platform_info->operatingSystemVersion) {
-               free(platform_info->operatingSystemVersion);
-               platform_info->operatingSystemVersion = NULL;
-       }
-       if (platform_info->hardwareVersion) {
-               free(platform_info->hardwareVersion);
-               platform_info->hardwareVersion = NULL;
-       }
-       if (platform_info->supportUrl) {
-               free(platform_info->supportUrl);
-               platform_info->supportUrl = NULL;
-       }
-       if (platform_info->systemTime) {
-               free(platform_info->systemTime);
-               platform_info->systemTime = NULL;
-       }
-}
-
-int comp_iot_initialize()
-{
-       char *device_id = NULL;
-       int ret;
-       OCPlatformInfo platform_info = {0};
-
-       ps.open = client_open;
-       ps.read = fread;
-       ps.write = fwrite;
-       ps.close = fclose;
-       ps.unlink = unlink;
-
-       PlatformConfig cfg {
-               OC::ServiceType::InProc,
-                       OC::ModeType::Both,
-                       (OCTransportAdapter)(OCTransportAdapter::OC_ADAPTER_IP),
-                       OC::QualityOfService::LowQos,
-                       &ps
-       };
-
-       OCPlatform::Configure(cfg);
-
-       ret = __comp_iot_get_platform_info(&platform_info);
-       if (ret != 0) {
-               _clean_platform_info(&platform_info);
-               LOG_ERR("Failed to get platform info %d", ret);
-               return COMP_ERROR_NONE;
-       }
-
-       ret = OCPlatform::registerPlatformInfo(platform_info);
-       if (ret != OC_STACK_OK)
-       {
-               _clean_platform_info(&platform_info);
-               LOG_ERR("Platform Registration failed");
-               return COMP_ERROR_NONE;
-    }
-       _clean_platform_info(&platform_info);
-
-       OCDeviceInfo device_info = {0};
-       device_info.deviceName = g_strdup("UNKNOWN");
-
-       ret = OCPlatform::registerDeviceInfo(device_info);
-
-       if (ret != OC_STACK_OK)
-       {
-               LOG_ERR("Device Registration failed");
-               return COMP_ERROR_NONE;
-    }
-
-       g_free(device_info.deviceName);
-
-       OicUuid_t uuid;
-
-       ret = GetDoxmDeviceID(&uuid);
-       if      (OC_STACK_OK != ret)
-               LOG_DEBUG("GetDoxmDevOwnerId failed = [%d][%s]", ret, get_error_message(ret));
-
-       ret = ConvertUuidToStr(&uuid, &device_id);
-       if (OC_STACK_OK != ret)
-               LOG_DEBUG("ConvertUuidToStr failed = [%d][%s]", ret, get_error_message(ret));
-
-       LOG_DEBUG("device_id : %s", device_id);
-
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
-
-       comp_ctx->device_uuid = g_strdup(device_id);
-
-       /* Do Self-Ownership Transfer */
-       ret = OCSecure::configSelfOwnership();
-       if (OC_STACK_OK != ret ) {
-               LOG_ERR( "OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret));
-       }
-
-       /*
-               "Device" resource
-               For get peer description.
-               ex) /comp/device
-       */
-       comp_iot_add_resource(COMP_RESOURCE_TYPE_DEVICE, "");
-
-       /*
-               "operation" resource
-               The operation resource is a control command channel between daemon and daemon.
-               resource type is core.comp.operation
-               Within this function we create a default operation resource. (uri is /comp/operation/1)
-               If we need more control channels, increase the number.
-               ex) /comp/operation/2, /comp/operation/3
-       */
-       comp_iot_add_resource(COMP_RESOURCE_TYPE_OPERATION, "1");
-
-       /*
-               "DATA" resource
-               To show the send data to remote daemon.
-               It can be used when the remote device is mot enable and pairwise.
-               ex) /comp/data/1
-       */
-       comp_iot_add_resource(COMP_RESOURCE_TYPE_DATA, "1");
-
-       return COMP_ERROR_NONE;
-}
-
-static void _print_oc_representation(OCRepresentation rep)
-{
-       /* attribute.type() is an enum class AttributeType defined in
-        * AttributeValue.h header file of IoTivity */
-       for (auto& attribute : rep) {
-               LOG_DEBUG("%s of type %d with value %s", attribute.attrname().c_str(),
-                                 attribute.type(),
-                                 attribute.getValueToString().c_str());
-       }
-}
-
-OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> request)
-{
-       LOG_DEBUG("_request_handler is called");
-
-       if (request) {
-               std::string requestType = request->getRequestType();
-               int requestFlag = request->getRequestHandlerFlag();
-
-               LOG_DEBUG("request type %s flag %x", requestType.c_str(), requestFlag);
-
-               if (requestType == "GET") {
-                       //Send Peer Description
-                       LOG_DEBUG("requestFlag : GET");
-                       auto pResponse = std::make_shared<OC::OCResourceResponse>();
-                       OCRepresentation rep;
-
-                       /* Set Peer Description */
-
-                       char *device_name = NULL;
-                       char *model_name = NULL;
-                       char *platform_ver = NULL;
-                       char *profile = NULL;
-                       char *vendor_id = NULL;
-
-                       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
-                       system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
-                       system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
-                       system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
-                       /* How to get the vendor id? */
-
-                       LOG_DEBUG("device name : %s", device_name);
-                       LOG_DEBUG("model name : %s", model_name);
-                       LOG_DEBUG("platform ver name : %s", platform_ver);
-                       LOG_DEBUG("profile : %s", profile);
-
-                       rep.setValue("model_name", std::string(model_name));
-                       rep.setValue("platform_ver", std::string(platform_ver));
-                       rep.setValue("profile", std::string(profile));
-                       rep.setValue("device_name", std::string(device_name));
-                       rep.setValue("vendor_id", std::string("6FFF"));
-
-                       pResponse->setRequestHandle(request->getRequestHandle());
-                       pResponse->setResourceHandle(request->getResourceHandle());
-                       pResponse->setErrorCode(200);
-                       pResponse->setResponseResult(OC_EH_OK);
-                       pResponse->setResourceRepresentation(rep, DEFAULT_INTERFACE);
-                       OCPlatform::sendResponse(pResponse);
-               } else if (requestType == "POST") {
-                       if (requestFlag & RequestHandlerFlag::RequestFlag) {
-                               LOG_DEBUG("requestFlag : Request");
-                               auto pResponse = std::make_shared<OC::OCResourceResponse>();
-                               unsigned char *arg = NULL;
-                               int arg_len = 0;
-                               int result;
-                               int cmd;
-                               std::string requester_id, group_name, uuid, data;
-#ifdef SUPPORT_BASE64_ENCODING
-                               int payload_len;
-                               size_t outSize;
-                               uint8_t *out;
-                               uint32_t len = 0;
-#endif
-                               comp_context_t *comp_ctx;
-
-                               try {
-                                       OCRepresentation rep = request->getResourceRepresentation();
-
-                                       _print_oc_representation(rep);
-
-                                       ObservationInfo observationInfo = request->getObservationInfo();
-                                       LOG_DEBUG("Received request from %s:%d",
-                                                 observationInfo.address.c_str(), observationInfo.port);
-
-                                       if (!rep.getValue("CMD", cmd))
-                                               LOG_ERR("CMD not found in representation");
-                                       else
-                                               LOG_DEBUG("Command received %d", cmd);
-
-                                       if (!rep.getValue("device_id", requester_id))
-                                               LOG_ERR("device_id not found in representation");
-                                       else
-                                               LOG_DEBUG("device_id received %s", requester_id.c_str());
-
-                                       switch(cmd) {
-                                       case COMP_REQ_SEND_DATA:
-                                               LOG_DEBUG("Receive Data");
-#ifdef SUPPORT_BASE64_ENCODING
-                                               if (!rep.getValue("data", data))
-                                                       LOG_ERR("data not found");
-
-                                               /*
-                                                * BASE64 encoding/decoding system use '=' as padding byte
-                                                * But, query parameter does not allow use '=' character.Basically,
-                                                * So, in order to use BASE64 as query parameters, we need additioinal length param
-                                                * such as 'len=xx'
-                                                */
-                                               payload_len = strlen(data.c_str()); /* This data may be cliped the last padding 1~2 bytes ('='/'==') */
-
-                                               LOG_DEBUG("data = %s payload_len = %d", data.c_str(),
-                                                                 payload_len);
-
-                                               outSize = B64DECODE_OUT_SAFESIZE(payload_len + 1);
-                                               out = (uint8_t *)g_try_malloc0(outSize);
-                                               if (NULL == out) {
-                                                       LOG_ERR("Can't allocate memory for base64 str");
-                                                       return OC_EH_OK;
-                                               }
-
-                                               if (B64_OK != b64Decode(data.c_str(), payload_len, out,
-                                                                                          outSize, &len)) {
-                                                       LOG_ERR("Base64 decoding failed.");
-                                                       g_free(out);
-                                                       return OC_EH_OK;
-                                               }
-
-                                               arg = (unsigned char *) g_try_malloc0(len);
-                                               memcpy(arg, out, len);
-                                               arg_len = len;
-
-                                               g_free(out);
-
-                                               LOG_DEBUG("Successfully decoded from base64");
-#else
-                                               if (!rep.getValue("data", data))
-                                                       LOG_ERR("data not found");
-
-                                               LOG_DEBUG("Receive Data = %s", data.c_str());
-                                               arg = (unsigned char *) g_strdup(data.c_str());
-                                               arg_len = strlen(data.c_str());
-#endif
-                                               break;
-                                       case COMP_REQ_CREATE_GROUP:
-                                               LOG_DEBUG("Request create group");
-
-                                               if (rep.getValue("name", group_name)) {
-                                                       LOG_DEBUG("group_name : %s", group_name.c_str());
-                                                       result = comp_group_create(group_name.c_str());
-                                                       arg = (unsigned char *) g_strdup(group_name.c_str());
-                                                       arg_len = strlen(group_name.c_str());
-                                               }
-                                               break;
-                                       case COMP_REQ_INVITE_DEVICE:
-                                               LOG_DEBUG("Request invite device");
-
-                                               if (!rep.getValue("name", group_name))
-                                                       LOG_ERR("Group name not found");
-                                               if (!rep.getValue("id", uuid))
-                                                       LOG_ERR("UUID not found");
-
-                                               LOG_DEBUG("group name : %s, UUID : %s", group_name.c_str(),
-                                                                 uuid.c_str());
-
-                                               result = comp_group_invite(group_name.c_str(),
-                                                                          uuid.c_str(), "12341234");
-                                               arg = (unsigned char *) g_strdup(uuid.c_str());
-                                               arg_len = strlen(uuid.c_str());
-                                               break;
-                                       case COMP_REQ_EJECT_DEVICE:
-                                               LOG_DEBUG("Request eject device");
-
-                                               comp_ctx = comp_context_get_context();
-
-                                               if (!rep.getValue("name", group_name))
-                                                       LOG_ERR("Group name not found");
-                                               if (!rep.getValue("id", uuid))
-                                                       LOG_ERR("UUID not found");
-
-                                               LOG_DEBUG("group name : %s Self UUID : %s Target UUID : %s",
-                                                                 group_name.c_str(),comp_ctx->device_uuid,
-                                                                 uuid.c_str());
-
-                                               result = comp_group_eject(group_name.c_str(), comp_ctx->device_uuid,
-                                                                          uuid.c_str());
-                                               arg = (unsigned char *) g_strdup(uuid.c_str());
-                                               arg_len = strlen(uuid.c_str());
-                                               break;
-                                       case COMP_REQ_DELETE_GROUP:
-                                               LOG_DEBUG("Request delete group");
-                                               arg = (unsigned char *) g_strdup("DELETED");
-                                               arg_len = strlen("DELETED");
-                                               break;
-                                       case COMP_REQ_KEEP_ALIVE:
-                                               LOG_DEBUG("Keep Alive message");
-
-                                               if (rep.getValue("group_name", group_name)) {
-                                                       LOG_DEBUG("group_name : %s", group_name.c_str());
-                                               }
-                                               break;
-                                       default:
-                                               LOG_ERR("Unknown request command %d", cmd);
-                                               break;
-                                       }
-
-                                       if (cmd != COMP_REQ_KEEP_ALIVE) {
-                                               const char *cmd_str;
-                                               cmd_str = command2string((comp_request_type_e) cmd);
-                                               notify_request_result(cmd_str, requester_id.c_str(), arg,
-                                                                                         arg_len, result);
-                                       }
-
-                                       g_free(arg);
-
-                                       pResponse->setRequestHandle(request->getRequestHandle());
-                                       pResponse->setResourceHandle(request->getResourceHandle());
-                                       pResponse->setErrorCode(200);
-                                       pResponse->setResponseResult(OC_EH_OK);
-                                       OCPlatform::sendResponse(pResponse);
-                               } catch (std::exception& e) {
-                                       LOG_ERR("Exceptioin occured %s", e.what());
-                               }
-                       }
-               } else {
-                       LOG_ERR("Invalid Request Type");
-                       return OC_EH_OK;
-               }
-       }
-
-       return OC_EH_OK;
-}
-
-int comp_iot_add_resource(comp_resource_type_e resource_type, const char *uri)
-{
-       OCResourceHandle resourceHandle;
-       std::string uri_path;
-
-       uri_path =  std::string(comp_resource_get_uri_prefix(resource_type)) +
-                               std::string(uri);
-
-       LOG_DEBUG("[ADD] resource uri is %s", uri_path.c_str());
-
-       OCStackResult result = OCPlatform::registerResource(resourceHandle,
-                                                       uri_path,
-                                                       std::string(comp_resource_get_type(resource_type)),
-                                                       std::string(DEFAULT_INTERFACE), &_request_handler,
-                                                       comp_resource_get_policies(resource_type));
-       if (result != OC_STACK_OK) {
-               LOG_ERR("Failed to create resource");
-               return COMP_ERROR_NONE;
-       }
-
-       LOG_DEBUG("Successfully created resource");
-
-       //Append to resource list
-       comp_resource_append(resource_type, uri_path.c_str());
-
-       return COMP_ERROR_NONE;
-}
-
-int found_group_count = 0;
-
-static void _clear_user_data(void *user_data)
-{
-       comp_command_t *cmd = (comp_command_t *)user_data;
-
-       if (NULL == cmd)
-               return;
-
-       if (cmd->tid) {
-               g_source_remove(cmd->tid);
-       }
-
-       if (cmd->uuid) {
-               g_free(cmd->uuid);
-               cmd->uuid = NULL;
-       }
-       if (cmd->host) {
-               g_free(cmd->host);
-               cmd->host = NULL;
-       }
-       if (cmd->arg1) {
-               g_free(cmd->arg1);
-               cmd->arg1 = NULL;
-       }
-       if (cmd->arg2) {
-               g_free(cmd->arg2);
-               cmd->arg2 = NULL;
-       }
-       if (cmd->arg3) {
-               g_free(cmd->arg3);
-               cmd->arg3 = NULL;
-       }
-       if (cmd->arg4) {
-               g_free(cmd->arg4);
-               cmd->arg4 = NULL;
-       }
-
-#ifdef SUPPORT_BASE64_ENCODING
-       if (cmd->data) {
-               g_free(cmd->data);
-               cmd->data = NULL;
-       }
-#endif
-
-       g_free(cmd);
-       cmd = NULL;
-}
-
-static void _on_post(const HeaderOptions& /*headerOptions*/,
-                                        const OCRepresentation& rep, const int eCode,
-                                        void *user_data)
-{
-       int ret;
-       comp_command_t *cmd = (comp_command_t *)user_data;
-
-       try {
-               if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED ||
-                       eCode == OC_STACK_RESOURCE_CHANGED) {
-                       last_get_result = 0;
-                       LOG_DEBUG("Post request is successful");
-
-                       if (cmd->command == COMP_REQ_KEEP_ALIVE) {
-                               comp_group_notify_keepalive_response(cmd);
-                               return;
-                       }
-               } else {
-                       last_get_result = eCode;
-                       LOG_ERR("_on_post Response error %d", eCode);
-               }
-       } catch(std::exception& e) {
-               LOG_ERR("Exception %s in on post", e.what());
-       }
-
-       notify_send_data_finish("RESP_DATA", last_get_result);
-
-       //_clear_user_data(cmd);
-}
-
-static void _on_get(const HeaderOptions& /*headerOptions*/,
-                               const OCRepresentation& rep, const int eCode,
-                               void *user_data)
-{
-       int ret;
-       LOG_DEBUG("On get function.");
-
-       try {
-               if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED ||
-                       eCode == OC_STACK_RESOURCE_CHANGED) {
-                       gchar *key;
-                       GVariant *val;
-                       gsize len = 0;
-                       comp_mot_device_t *device = (comp_mot_device_t *)user_data;
-                       comp_check_null_ret("device", device);
-
-                       std::string modelName;
-                       std::string platformVer;
-                       std::string Profile;
-                       std::string deviceName;
-                       std::string vendorID;
-
-                       rep.getValue("model_name", modelName);
-                       rep.getValue("platform_ver", platformVer);
-                       rep.getValue("profile", Profile);
-                       rep.getValue("device_name", deviceName);
-                       rep.getValue("vendor_id", vendorID);
-
-                       comp_check_null_ret("modelName", modelName.c_str());
-                       comp_check_null_ret("platformVer", platformVer.c_str());
-                       comp_check_null_ret("Profile", Profile.c_str());
-                       comp_check_null_ret("deviceName", deviceName.c_str());
-                       comp_check_null_ret("vendorID", vendorID.c_str());
-
-                       device->model_name = g_strdup(modelName.c_str());
-                       device->platform_ver= g_strdup(platformVer.c_str());
-                       device->profile = g_strdup(Profile.c_str());
-                       device->device_name = g_strdup(deviceName.c_str());
-                       device->vendor_id = g_strdup(vendorID.c_str());
-
-                       if (device->mowned == false)
-                               comp_group_add_new_mot_device(device);
-                       else
-                               comp_group_add_new_mowned_device(device);
-               } else {
-                       LOG_ERR("_on_get Response error %d", eCode);
-               }
-       } catch(std::exception& e) {
-               LOG_ERR("Exception %s in on get", e.what());
-       }
-}
-
-static int _perform_mot_me(gpointer data)
-{
-       int ret;
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, FALSE);
-
-       ret = agent_mot(comp_ctx->device_uuid, "12341234");
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("agent_mot(%s) Failed", comp_ctx->device_uuid);
-
-       return FALSE;
-}
-
-static bool _found_resource(std::shared_ptr<OCResource> resource,
-                                                       void *user_data)
-{
-       int ret;
-       char *resource_uri_path;
-       char *resource_device_id = NULL;
-       char *resource_host;
-       char *resource_type = NULL;
-       comp_group_type_e group_type;
-       std::string resourceURI;
-       std::string hostAddress;
-
-       LOG_DEBUG("Found Resource");
-       try {
-               if (resource) {
-                       resource_host = g_strdup(resource->host().c_str());
-
-                       resource_uri_path = g_strdup(resource->uri().c_str());
-                       resource_device_id = g_strdup(resource->sid().c_str());
-
-                       LOG_DEBUG("Resource URI : %s", resource_uri_path);
-                       LOG_DEBUG("Host Address : %s", resource_host);
-
-                       LOG_DEBUG("Resource Device ID : %s", resource_device_id);
-
-                       for(auto &resourceTypes : resource->getResourceTypes()) {
-                               resource_type = g_strdup(resourceTypes.c_str());
-                               LOG_DEBUG("Resource Type : %s", resource_type);
-                       }
-
-                       if (g_strcmp0(resource_type, "core.comp.group") == 0) {
-                               comp_context_t *comp_ctx = comp_context_get_context();
-                               if (g_strcmp0(resource_device_id, comp_ctx->device_uuid) == 0)
-                                       group_type = COMP_GROUP_GROUP_LOCAL;
-                               else
-                                       group_type = COMP_GROUP_GROUP_REMOTE;
-
-                               char *temp = g_strdup(resource_uri_path);
-                               char *ptr = strtok(temp, "/");
-                               ptr = strtok(NULL, "/");
-                               ptr = strtok(NULL, "/");
-
-                               LOG_DEBUG("group name is %s", ptr);
-                               comp_group_add_new(resource_uri_path, resource_device_id, ptr,
-                                                                  resource_host, resource_type, group_type);
-                               found_group_count++;
-
-                               g_free(temp);
-
-                       } else if (g_strcmp0(resource_type, "core.comp.device") == 0) {
-                               comp_command_t *cmd = (comp_command_t *)user_data;
-                               GVariant *parameters = (GVariant *)cmd->user_data;
-                               GVariant *device_info;
-                               bool mowned;
-                               GVariantIter *iter = NULL;
-                               gchar *key;
-                               comp_mot_device_t *device = NULL;
-
-                               if (NULL == parameters) {
-                                       LOG_ERR("No Multiple Owned devices found");
-                                       return TRUE;
-                               }
-
-                               if (strcmp(cmd->arg1, "disc_mot_enb_devs_done") == 0)
-                                       mowned = false;
-                               else
-                                       mowned = true;
-
-                               g_variant_get(parameters, "(aa{sv})", &iter);
-                               while ((device_info = g_variant_iter_next_value(iter))) {
-                                       GVariant *val = g_variant_lookup_value(device_info, "deviceId", G_VARIANT_TYPE_STRING);
-                                       gsize len = 0;
-                                       const char *device_id = g_variant_get_string(val, &len);
-                                       if (g_strcmp0(resource_device_id, device_id) == 0) {
-                                               device = (comp_mot_device_t *)g_try_malloc0(sizeof(comp_mot_device_t));
-
-                                               LOG_DEBUG("deviceId = %s", device_id);
-                                               device->device_id = g_strdup(device_id);
-
-                                               val = g_variant_lookup_value(device_info, "adapter", G_VARIANT_TYPE_INT32);
-                                               int adapter = g_variant_get_int32(val);
-                                               device->adapter = adapter;
-
-                                               val = g_variant_lookup_value(device_info, "flags", G_VARIANT_TYPE_INT32);
-                                               int flags = g_variant_get_int32(val);
-                                               LOG_DEBUG("flags = %d", flags);
-                                               device->flags = flags;
-
-                                               val = g_variant_lookup_value(device_info, "port", G_VARIANT_TYPE_UINT16);
-                                               int port = g_variant_get_uint16(val);
-                                               LOG_DEBUG("port = %d", port);
-                                               device->port = port;
-
-                                               val = g_variant_lookup_value(device_info, "addr", G_VARIANT_TYPE_STRING);
-                                               const char *addr = g_variant_get_string(val, &len);
-                                               LOG_DEBUG("addr = %s", addr);
-                                               device->addr = g_strdup(addr);
-
-                                               val = g_variant_lookup_value(device_info, "ifindex", G_VARIANT_TYPE_INT32);
-                                               int ifindex = g_variant_get_int32(val);
-                                               LOG_DEBUG("ifindex = %d", ifindex);
-                                               device->ifindex = ifindex;
-
-                                               val = g_variant_lookup_value(device_info, "routeData", G_VARIANT_TYPE_STRING);
-                                               const char *routeData = g_variant_get_string(val, &len);
-                                               LOG_DEBUG("routeData = %s", routeData);
-                                               device->route_data = g_strdup(routeData);
-
-                                               val = g_variant_lookup_value(device_info, "remoteId", G_VARIANT_TYPE_STRING);
-                                               const char *remoteId = g_variant_get_string(val, &len);
-                                               LOG_DEBUG("remoteId = %s", remoteId);
-                                               device->remote_id = g_strdup(remoteId);
-
-                                               val = g_variant_lookup_value(device_info, "connType", G_VARIANT_TYPE_UINT32);
-                                               int connType = g_variant_get_uint32(val);
-                                               LOG_DEBUG("connType = %d", connType);
-                                               device->conn_type = connType;
-
-                                               val = g_variant_lookup_value(device_info, "securePort", G_VARIANT_TYPE_UINT16);
-                                               int securePort = g_variant_get_uint16(val);
-                                               LOG_DEBUG("securePort = %d", securePort);
-                                               device->secure_port = securePort;
-#ifdef WITH_TCP
-                                               val = g_variant_lookup_value(device_info, "tcpPort", G_VARIANT_TYPE_UINT16);
-                                               int tcpPort = g_variant_get_uint16(val);
-                                               LOG_DEBUG("tcpPort = %d", tcpPort);
-                                               device->tcp_port = tcpPort;
-#endif
-                                               val = g_variant_lookup_value(device_info, "secVer", G_VARIANT_TYPE_STRING);
-                                               const char *secVer = g_variant_get_string(val, &len);
-                                               LOG_DEBUG("secVer = %s", secVer);
-                                               device->sec_ver = g_strdup(secVer);
-
-                                               val = g_variant_lookup_value(device_info, "devStatus", G_VARIANT_TYPE_UINT32);
-                                               int devStatus = g_variant_get_uint32(val);
-                                               LOG_DEBUG("devStatus = %d", devStatus);
-                                               device->dev_status = devStatus;
-
-                                               device->mowned = mowned;
-                                       }
-                               }
-
-                               comp_check_null_ret_error("device", device, TRUE);
-
-                               if (strcmp(cmd->uuid, resource_device_id) != 0) {
-                                       LOG_DEBUG("Get peer description from another device");
-                                       /* Get Peer Description using "Get" operation */
-                                       device->type = COMP_GROUP_DEVICE_REMOTE;
-                                       resource->get(QueryParamsMap(), std::bind(&_on_get, std::placeholders::_1,
-                                               std::placeholders::_2, std::placeholders::_3, device));
-                               } else {
-                                       LOG_DEBUG("It's me. Get peer description myself");
-                                       device->type = COMP_GROUP_DEVICE_LOCAL;
-
-                                       comp_context_t *comp_ctx = comp_context_get_context();
-                                       if (comp_ctx && (FALSE == comp_ctx->mot_me)) {
-                                               g_timeout_add(10, _perform_mot_me, NULL);
-                                               comp_ctx->mot_me = TRUE;
-                                       }
-
-                                       char *device_name = NULL;
-                                       char *model_name = NULL;
-                                       char *platform_ver = NULL;
-                                       char *profile = NULL;
-                                       char *vendor_id = NULL;
-
-                                       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
-                                       system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
-                                       system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
-                                       system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
-                                       /* How to get the vendor id? */
-
-                                       device->model_name = g_strdup(device_name);
-                                       device->platform_ver= g_strdup(model_name);
-                                       device->profile = g_strdup(platform_ver);
-                                       device->device_name = g_strdup(profile);
-                                       device->vendor_id = g_strdup("6FFF");
-
-                                       comp_group_change_mowned_device(device);
-                               }
-                       } else if (g_strcmp0(resource_type, "core.comp.data") == 0) {
-                               comp_command_t *cmd = (comp_command_t *)user_data;
-
-                               LOG_DEBUG("Resource Type %s", resource_type);
-                               LOG_DEBUG("Command Device ID: %s", cmd ? cmd->uuid : "NULL");
-
-                               if (cmd != NULL && strcmp(cmd->uuid, resource_device_id) == 0) {
-                                       OCRepresentation rep;
-
-                                       LOG_DEBUG("Request to Remote Device");
-
-                                       LOG_DEBUG("CMD = %s", command2string(cmd->command));
-
-                                       rep.setValue("CMD", cmd->command);
-
-                                       comp_context_t *comp_ctx = comp_context_get_context();
-                                       rep.setValue("device_id", std::string(comp_ctx->device_uuid));
-
-                                       if (cmd->command == COMP_REQ_CREATE_GROUP) { //request create group
-                                               rep.setValue("name", std::string(cmd->arg1));
-                                       } else if (cmd->command == COMP_REQ_INVITE_DEVICE) { //request invite
-                                               rep.setValue("name", std::string(cmd->arg1));
-                                               rep.setValue("id", std::string(cmd->arg2));
-                                               rep.setValue("PIN", std::string(cmd->arg3));
-                                       } else if (cmd->command == COMP_REQ_EJECT_DEVICE) { //request eject
-                                               rep.setValue("name", std::string(cmd->arg1));
-                                               rep.setValue("id", std::string(cmd->arg2));
-                                       } else if (cmd->command == COMP_REQ_DELETE_GROUP) { //request delete group
-                                               rep.setValue("name", std::string(cmd->arg1));
-                                       } else { /* Send Data */
-#ifdef SUPPORT_BASE64_ENCODING
-                                               uint32_t outSize = 0;
-                                               size_t b64BufSize = B64ENCODE_OUT_SAFESIZE(
-                                                                          (cmd->data_len + 1));
-                                               char *b64Buf = (char *) g_malloc0(b64BufSize);
-                                               if (NULL == b64Buf) {
-                                                       _clear_user_data(cmd);
-                                                       return TRUE;
-                                               }
-                                               b64Encode(cmd->data, cmd->data_len,
-                                                                 b64Buf, b64BufSize, &outSize);
-                                               b64Buf[b64BufSize] = '\0';
-                                               rep.setValue("data", std::string(b64Buf));
-                                               LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s",
-                                                                 b64BufSize, outSize, b64Buf);
-                                               g_free(b64Buf);
-#else
-                                               rep.setValue("data", std::string(cmd->arg1));
-#endif
-                                       }
-                                       resource->post(rep, QueryParamsMap(),
-                                                  std::bind (&_on_post, std::placeholders::_1,
-                                                  std::placeholders::_2, std::placeholders::_3, cmd));
-                               }
-                       }
-
-                       g_free(resource_uri_path);
-                       g_free(resource_host);
-                       g_free(resource_type);
-                       g_free(resource_device_id);
-               }
-               else {
-                       LOG_ERR("Resource is invalid");
-               }
-       }
-       catch(std::exception& e)
-       {
-               LOG_ERR("Exception in foundResource: %s", e.what());
-       }
-
-       return TRUE;
-}
-
-static gboolean _timeout_cb(gpointer data)
-{
-       int ret = -1;
-       comp_command_t *cmd = (comp_command_t *)data;
-
-       if (cmd->resource_type == COMP_RESOURCE_TYPE_GROUP) {
-               if (found_group_count > 0)
-                       ret = 0;
-
-               notify_group_find_finish(ret);
-
-       } else if (cmd->resource_type == COMP_RESOURCE_TYPE_DATA) {
-               if (cmd->command != COMP_REQ_KEEP_ALIVE)
-                       notify_send_data_finish("RESP_DATA", last_get_result);
-       } else if (cmd->resource_type == COMP_RESOURCE_TYPE_DEVICE) {
-               if (strcmp(cmd->arg1, "disc_mot_enb_devs_done") == 0) {
-                       LOG_DEBUG("Device Find Done. notified");
-                       comp_group_notify_mot_enable_device_done();
-
-                       if (comp_group_get_mot_device_count() > 0)
-                               ret = 0;
-
-                       notify_device_find_finish(ret);
-               } else {
-                       LOG_DEBUG("MOT Device Find Done. notified");
-                       comp_group_notify_mowned_device_find_done();
-
-                       if (comp_group_get_mowned_device_count() > 0)
-                               ret = 0;
-
-                       notify_mowned_device_find_finish(ret);
-               }
-       }
-
-       _clear_user_data(data);
-
-       return false;
-}
-
-int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
-       void *user_data)
-{
-       int ret;
-       std::ostringstream requestURI;
-       comp_command_t *cmd = (comp_command_t *) user_data;
-       comp_check_null_ret_error("cmd", cmd, COMP_ERROR_INVALID_PARAMETER);
-
-       found_group_count = 0;
-
-       try {
-               requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" <<
-                       comp_resource_get_type(resource_type);
-
-               auto found_cb = std::bind (&_found_resource, std::placeholders::_1,
-                                                                  cmd);
-               if (cmd) {
-                       LOG_DEBUG("Querying for Resource host address  %s",
-                                         cmd->host ? cmd->host : "NULL");
-
-                       if (cmd->host)
-                               ret = OCPlatform::findResource(cmd->host, requestURI.str(),
-                                                                                          CT_ADAPTER_IP,
-                                                                                          found_cb);
-                       else
-                               ret = OCPlatform::findResource("", requestURI.str(),
-                                                                                          CT_ADAPTER_IP,
-                                                                                          found_cb);
-               }
-       } catch (OCException &e) {
-               LOG_ERR("Failed to find resource %s", e.what());
-               ret = e.code();
-       }
-
-       cmd->resource_type = resource_type;
-       cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
-
-       LOG_DEBUG("find resource : %s", get_error_message(ret));
-
-       return ret;
-}
-
-int comp_iot_send_data(comp_resource_type_e resource_type, int timeout,
-                                          comp_command_t *cmd)
-{
-       int ret;
-       OCResource::Ptr resource;
-       std::string requestURI;
-       std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
-       std::vector<std::string> resource_types;
-       resource_types = {comp_resource_get_type(resource_type)};
-
-       try {
-               requestURI = std::string(comp_resource_get_uri_prefix(resource_type)) +
-                                                       "1";
-
-               LOG_DEBUG("Request URI %s", requestURI.c_str());
-
-               resource = OCPlatform::constructResourceObject(std::string(cmd->host),
-                                                          requestURI, CT_ADAPTER_IP, false,
-                                                          resource_types, ifaces);
-               if (!resource) {
-                       LOG_ERR("Failed to construct resource");
-                       return -1;
-               }
-
-               OCRepresentation rep;
-               rep.setValue("CMD", cmd->command);
-
-               comp_context_t *comp_ctx = comp_context_get_context();
-               rep.setValue("device_id", std::string(comp_ctx->device_uuid));
-
-#ifdef SUPPORT_BASE64_ENCODING
-               uint32_t outSize = 0;
-               size_t b64BufSize;
-               char *b64Buf;
-#endif
-               switch (cmd->command) {
-               case COMP_REQ_SEND_DATA:
-#ifdef SUPPORT_BASE64_ENCODING
-                       b64BufSize = B64ENCODE_OUT_SAFESIZE((cmd->data_len + 1));
-                       b64Buf = (char *) g_try_malloc0(b64BufSize + 1);
-                       if (NULL == b64Buf) {
-                               _clear_user_data(cmd);
-                               return TRUE;
-                       }
-                       b64Encode(cmd->data, cmd->data_len,
-                                         b64Buf, b64BufSize, &outSize);
-                       rep.setValue("data", std::string(b64Buf));
-                       LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s",
-                                         b64BufSize, outSize, b64Buf);
-                       g_free(b64Buf);
-#else
-                       rep.setValue("data", std::string(cmd->arg1));
-#endif
-                       break;
-               case COMP_REQ_CREATE_GROUP:
-               case COMP_REQ_DELETE_GROUP:
-                       rep.setValue("name", std::string(cmd->arg1));
-                       break;
-               case COMP_REQ_INVITE_DEVICE:
-                       rep.setValue("name", std::string(cmd->arg1));
-                       rep.setValue("id", std::string(cmd->arg2));
-                       rep.setValue("PIN", std::string(cmd->arg3));
-                       break;
-               case COMP_REQ_EJECT_DEVICE:
-                       rep.setValue("name", std::string(cmd->arg1));
-                       rep.setValue("id", std::string(cmd->arg2));
-                       break;
-               case COMP_REQ_KEEP_ALIVE:
-                       rep.setValue("group_name", std::string(cmd->arg1));
-                       break;
-               default:
-                       LOG_ERR("Invalid command %d", cmd->command);
-                       return -1;
-               }
-
-               ret = resource->post(rep, QueryParamsMap(),
-                                                  std::bind (&_on_post, std::placeholders::_1,
-                                                  std::placeholders::_2, std::placeholders::_3, cmd));
-
-       } catch (OCException &e) {
-               LOG_ERR("Failed to send data %s", e.what());
-               ret = e.code();
-       }
-
-       cmd->resource_type = resource_type;
-       cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
-
-       LOG_DEBUG("Send Data : %s", get_error_message(ret));
-
-       return ret;
-}
-
-int comp_iot_delete_resource(comp_resource_type_e resource_type)
-{
-       //delete resource from resource list using resource_type and index
-       //delete DB
-       return COMP_ERROR_NONE;
-}
-
-int comp_iot_deinitialize()
-{
-       return COMP_ERROR_NONE;
-}
diff --git a/src/companion-manager/src/comp_log.c b/src/companion-manager/src/comp_log.c
deleted file mode 100644 (file)
index 0e3238d..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_log.h>
-
-const char *comp_log_get_error_string(int result)
-{
-       switch (result) {
-       case COMP_ERROR_NONE:
-               return "COMP_ERROR_NONE";
-       case COMP_ERROR_IO_ERROR:
-               return "COMP_ERROR_IO_ERROR";
-       case COMP_ERROR_INVALID_PARAMETER:
-               return "COMP_ERROR_INVALID_PARAMETER";
-       case COMP_ERROR_OUT_OF_MEMORY:
-               return "COMP_ERROR_OUT_OF_MEMORY";
-       case COMP_ERROR_PERMISSION_DENIED:
-               return "COMP_ERROR_PERMISSION_DENIED";
-       case COMP_ERROR_NOT_SUPPORTED:
-               return "COMP_ERROR_NOT_SUPPORTED";
-       case COMP_ERROR_COMM_ERROR:
-               return "COMP_ERROR_COMM_ERROR";
-       case COMP_ERROR_RX:
-               return "COMP_ERROR_RX";
-       case COMP_ERROR_TX:
-               return "COMP_ERROR_RX";
-       case COMP_ERROR_PLUGIN_FAIL:
-               return "COMP_ERROR_PLUGIN_FAIL";
-       case COMP_ERROR_OPERATION_FAILED:
-               return "COMP_ERROR_OPERATION_FAILED";
-       default:
-               return "UNKNOWN";
-       }
-}
diff --git a/src/companion-manager/src/comp_manager.c b/src/companion-manager/src/comp_manager.c
deleted file mode 100644 (file)
index c094a09..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_manager.h>
-#include <comp_mot_agent.h>
-
-int main(int argc, char *argv[])
-{
-       int ret;
-
-       LOG_DEBUG("COMP Manager start");
-
-       //1. create & get context
-       ret = comp_context_create();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("COMP context create failed : %s", comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-
-       //2. iotivity iniatlize
-       ret = comp_iot_initialize();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("COMP iot initialize failed : %s", comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-
-       //3. Initializing Data
-       ret = comp_db_init();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("COMP db initialize failed : %s", comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-
-       //4. dbus interface initialize
-       ret = comp_gdbus_init();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("COMP gdbus initialize failed : %s", comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-
-       //5. Make TX interface
-
-       //example code
-       //6. group mgr initialize
-       ret = comp_group_initialize();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("COMP group initialize failed : %s", comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-
-       //7. operation mgr initialize
-       ret = agent_dbus_start();
-       if (ret != COMP_ERROR_NONE) {
-               LOG_ERR("MOT agent interface initialize failed : %s",
-                       comp_log_get_error_string(ret));
-               goto EXIT;
-       }
-       agent_enable();
-
-       //8. g main loop run
-       comp_context_t *comp_ctx = comp_context_get_context();
-       comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
-
-       comp_ctx->main_loop = g_main_loop_new(NULL, FALSE);
-       g_main_loop_run(comp_ctx->main_loop);
-
-EXIT:
-       //9. deinitialize phase
-       agent_disable();
-       ret = agent_dbus_stop();
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("MOT agent interface deinitialize failed : %s",
-                       comp_log_get_error_string(ret));
-
-       ret = comp_group_deinitialize();
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("COMP group deinitialize failed : %s", comp_log_get_error_string(ret));
-
-       ret = comp_db_deinit();
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("COMP db deinitialize failed : %s", comp_log_get_error_string(ret));
-
-       ret = comp_iot_deinitialize();
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("COMP iot deinitialize failed : %s", comp_log_get_error_string(ret));
-
-       ret = comp_context_destroy();
-       if (ret != COMP_ERROR_NONE)
-               LOG_ERR("COMP context destroy failed : %s", comp_log_get_error_string(ret));
-
-       LOG_DEBUG("COMP Manager exit");
-
-       return 0;
-}
diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c
deleted file mode 100644 (file)
index 94cdfc7..0000000
+++ /dev/null
@@ -1,839 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <error.h>
-
-#include <glib.h>
-#include <gio/gio.h>
-
-#include <comp_log.h>
-#include <comp_enum.h>
-#include <comp_group.h>
-#include <comp_gdbus_group.h>
-
-#define AGENT_SERVER_NAME "net.ma"
-#define AGENT_OBJECT_PATH "/net/ma"
-#define AGENT_SERVICE_INTERFACE "net.ma"
-
-#define AGENT_ENABLER_NAME "net.ma.enabler"
-#define AGENT_ENABLER_OBJ_PATH "/net/ma/enabler"
-#define AGENT_ENABLER_INTERFACE "net.ma.enabler"
-
-#define AGENT_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */
-
-struct agent_s {
-       GDBusProxy *gproxy_agent_service; /**< Proxy for MOT agent */
-       gpointer dbus_connection; /**< Dbus connection for MOT agent */
-       GCancellable *ca; /**< Cancellable for MOT agent */
-       GList *dbus_sub_ids; /**< DBus ID for MOT agent */
-};
-struct agent_s agent; /**< MOT agent context */
-
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-static bool mot_dev2 = false;
-static char *device_uuid1 = NULL;
-static char *device_uuid2 = NULL;
-#endif
-
-int agent_get_ownerid(char* deviceid)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "get_ownerid",
-                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(si)", deviceid, &result);
-               LOGD("get_ownerid status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_find_mot_enable_devices(int timeout)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_UNKNOWN;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mot_enb_devs",
-                               g_variant_new("(i)", timeout), G_DBUS_CALL_FLAGS_NONE,  -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("disc_mot_enb_devs status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_find_mowned_devices(int timeout)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_UNKNOWN;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mowned_devs",
-                               g_variant_new("(i)", timeout), G_DBUS_CALL_FLAGS_NONE,  -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("disc_mowned_devs status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_mot(char* uuid_str, char *pin)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "mot",
-                       g_variant_new("(ss)", uuid_str, pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("mot status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_resources_pairwise(char* target1, char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, char* target2, char *subject2, char *uri2,
-       char *rt2, char *interface2, int permission2)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "pairwise",
-                       g_variant_new("(sssssisssssi)",
-                               target1, subject1, uri1, rt1, interface1, permission1,
-                               target2, subject2, uri2, rt2, interface2, permission2),
-                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("pairwise status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_unlink_resources(char* uuid_str1, char *uuid_str2)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unlink",
-                       g_variant_new("(ss)", uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("remove_subowner status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-       if (result == COMP_ERROR_NONE) {
-               device_uuid1 = g_strdup(uuid_str1);
-               device_uuid2 = g_strdup(uuid_str2);
-       }
-#endif
-       return result;
-}
-
-int agent_remove_subowner(char* uuid_str)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_subowner",
-                       g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("remove_subowner status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_remove_subowned(char* uuid_str)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_device",
-                       g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("remove_cred_cocal status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_pair(const char *pin, char* target1, const char *subject1, char *uri1,
-       char *rt1, char *interface1, int permission1, const char* target2,
-       char *subject2, char *uri2, char *rt2, char *interface2, int permission2)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "pair",
-                       g_variant_new("(ssssssisssssi)", pin,
-                               target1, subject1, uri1, rt1, interface1, permission1,
-                               target2, subject2, uri2, rt2, interface2, permission2),
-                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("pair status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_unpair(char* uuid_str1, const char *uuid_str2)
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unpair",
-                       g_variant_new("(ss)", uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOGD("remove_subowner status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_enable()
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_connection_call_sync(agent.dbus_connection,
-                       AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
-                       "enable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOG_DEBUG("MOT Agent Enabled status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return result;
-}
-
-int agent_disable()
-{
-       GVariant *variant = NULL;
-       int result = COMP_ERROR_NONE;
-       GError *error = NULL;
-
-       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
-               LOG_ERR("I/O error");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       variant = g_dbus_connection_call_sync(agent.dbus_connection,
-                       AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
-                       "disable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-       if (variant) {
-               g_variant_get(variant, "(i)", &result);
-               LOG_DEBUG("MOT Agent Disabled status 0x%x", result);
-       } else if (error) {
-               LOGE("Failed DBus call [%s]", error->message);
-               g_error_free(error);
-               return COMP_ERROR_IO_ERROR;
-       }
-       return result;
-}
-
-static int _close_gdbus_call()
-{
-       /* CHECK: is connection ref count required? */
-       g_object_unref(agent.dbus_connection);
-       agent.dbus_connection = NULL;
-
-       return COMP_ERROR_NONE;
-}
-
-static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
-               gpointer *userdata)
-{
-       GDBusProxy *proxy = G_DBUS_PROXY(object);
-       gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
-
-       NOTUSED(userdata);
-
-       LOG_DEBUG("Name owner notify [%s]", name_owner);
-
-       if (NULL == name_owner)
-               _close_gdbus_call();
-
-       g_free(name_owner);
-}
-
-static int _create_gdbus_call()
-{
-       int id;
-       GError *error = NULL;
-
-       if (agent.dbus_connection != NULL)
-               return COMP_ERROR_ALREADY_IN_PROGRESS;
-
-       agent.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (NULL == agent.dbus_connection) {
-               if (error != NULL) {
-                       LOG_ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
-                       g_error_free(error);
-               }
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       id = g_signal_connect(agent.dbus_connection, "notify::g-name-owner",
-                       G_CALLBACK(_dbus_name_owner_notify), &agent);
-       if (0 == id) {
-               LOGE("g_signal_connect() Fail");
-               g_object_unref(agent.dbus_connection);
-               agent.dbus_connection = NULL;
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       return COMP_ERROR_NONE;
-}
-
-static GDBusProxy *_get_proxy_service()
-{
-       GDBusProxy *proxy = NULL;
-
-       if (NULL == agent.gproxy_agent_service) {
-               proxy = g_dbus_proxy_new_sync(agent.dbus_connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
-                       AGENT_SERVER_NAME, AGENT_OBJECT_PATH, AGENT_SERVICE_INTERFACE,
-                       NULL, NULL);
-       } else
-               proxy = agent.gproxy_agent_service;
-
-       return proxy;
-}
-
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-static gboolean __perform_agent_pairwise(gpointer data)
-{
-       int ret;
-
-       mot_dev2 = false;
-
-       comp_group_invite_info_t *group_invite_info;
-
-       group_invite_info = comp_group_get_invite_info();
-
-       if (!group_invite_info) {
-               LOG_ERR("group_invite_info is null");
-               return FALSE;
-       }
-
-       ret = agent_pairwise(group_invite_info->uuid_dev1, group_invite_info->uuid_dev2,
-                                                group_invite_info->uri_1, group_invite_info->rt_1,
-                                                group_invite_info->interface_1,
-                                                group_invite_info->permission_1,
-                                                group_invite_info->uuid_dev2, group_invite_info->uuid_dev1,
-                                                group_invite_info->uri_2, group_invite_info->rt_2,
-                                                group_invite_info->interface_2,
-                                                group_invite_info->permission_2);
-       if (ret != COMP_ERROR_NONE)
-               comp_group_notify_group_invite(ret);
-
-       return FALSE;
-}
-
-static gboolean __perform_remove_mot_dev2(gpointer data)
-{
-       int ret;
-
-       ret = agent_remove_subowner(device_uuid2);
-       if (ret != COMP_ERROR_NONE) {
-               comp_group_notify_group_dismiss(ret);
-               g_free(device_uuid1);
-               device_uuid1 = NULL;
-               g_free(device_uuid2);
-               device_uuid1 = NULL;
-       }
-
-       return FALSE;
-}
-
-static gboolean __perform_remove_cred_at_local(gpointer data)
-{
-       int ret;
-
-       ret = agent_remove_subowned(device_uuid2);
-       if (ret != COMP_ERROR_NONE) {
-               comp_group_notify_group_dismiss(ret);
-               g_free(device_uuid1);
-               device_uuid1 = NULL;
-               g_free(device_uuid2);
-               device_uuid1 = NULL;
-       }
-       return FALSE;
-}
-#endif
-
-static void _free_device_info(comp_mot_device_t *device)
-{
-       if (!device)
-               return;
-
-       if (device->device_id != NULL) {
-               g_free(device->device_id);
-               device->device_id = NULL;
-       }
-       if (device->addr != NULL) {
-               g_free(device->addr);
-               device->addr = NULL;
-       }
-       if (device->route_data != NULL) {
-               g_free(device->route_data);
-               device->route_data = NULL;
-       }
-       if (device->remote_id != NULL) {
-               g_free(device->remote_id);
-               device->remote_id = NULL;
-       }
-       if (device->sec_ver != NULL) {
-               g_free(device->sec_ver);
-               device->sec_ver = NULL;
-       }
-       g_free(device);
-       device = NULL;
-}
-
-static void _agent_signal_handler(GDBusConnection *connection,
-               const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
-               const gchar *signal_name, GVariant *parameters, gpointer userdata)
-{
-       int result = COMP_ERROR_NONE;
-       struct agent_s *h = userdata;
-
-       if (NULL == h) {
-               LOG_ERR("user_data is null");
-               return;
-       }
-
-       LOG_DEBUG("signal received = %s", signal_name);
-
-       if (0 == g_strcmp0(signal_name, "subowner_enabled")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-       } else if (0 == g_strcmp0(signal_name, "disc_mot_enb_devs_done") ||
-               0 == g_strcmp0(signal_name, "disc_mowned_devs_done")) {
-               comp_context_t *comp_ctx = comp_context_get_context();
-               comp_check_null_ret("comp_ctx", comp_ctx);
-
-               if (NULL == parameters) {
-                       LOG_ERR("No MOT enabled devices found");
-                       return;
-               }
-
-               comp_command_t *cmd = g_new0(comp_command_t, 1);
-               cmd->uuid = g_strdup(comp_ctx->device_uuid);
-               cmd->user_data = (void *)g_variant_ref(parameters);
-               cmd->arg1 = g_strdup(signal_name);
-
-               comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DEVICE, 2, cmd);
-               LOG_DEBUG("Peer description discovery Start");
-       } else if (0 == g_strcmp0(signal_name, "acl_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-       } else if (0 == g_strcmp0(signal_name, "cred_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-       } else if (0 == g_strcmp0(signal_name, "mot_done")) {
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-               comp_mot_device_t *device;
-               comp_context_t *comp_ctx = comp_context_get_context();
-               comp_check_null_ret("comp_ctx", comp_ctx);
-
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-
-               if (result != 0 && result != 49 &&
-                       (comp_group_get_invite_info() != NULL))
-                       comp_group_notify_group_invite(result);
-
-               if (comp_ctx && (TRUE == comp_ctx->mot_me))
-                       g_timeout_add(10, __perform_agent_pairwise, NULL);
-#endif
-       } else if (0 == g_strcmp0(signal_name, "remove_mo_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-               g_timeout_add(10, __perform_remove_cred_at_local, NULL);
-#endif
-       } else if (0 == g_strcmp0(signal_name, "remove_cred_local_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-               comp_group_notify_group_dismiss(result);
-               g_free(device_uuid1);
-               device_uuid1 = NULL;
-               g_free(device_uuid2);
-               device_uuid1 = NULL;
-#endif
-       } else if (0 == g_strcmp0(signal_name, "pairwise_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-
-               if (comp_group_get_invite_info() != NULL)
-                       comp_group_notify_group_invite(result);
-       } else if (0 == g_strcmp0(signal_name, "unlink_done")) {
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
-               if (result != 0) {
-                       comp_group_notify_group_dismiss(result);
-                       g_free(device_uuid1);
-                       device_uuid1 = NULL;
-                       g_free(device_uuid2);
-                       device_uuid1 = NULL;
-               }
-
-               g_timeout_add(10, __perform_remove_mot_dev2, NULL);
-#endif
-       } else if (0 == g_strcmp0(signal_name, "pair_done")) {
-
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-
-               comp_group_notify_group_invite(result);
-       } else if (0 == g_strcmp0(signal_name, "unpair_done")) {
-
-               g_variant_get(parameters, "(i)", &result);
-               LOG_DEBUG("Result : %d", result);
-
-               comp_group_notify_group_dismiss(result);
-       }
-}
-static int _subscribe_event()
-{
-       unsigned int id;
-       struct agent_s *h = &agent;
-
-       /* subowner_enabled */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "subowner_enabled", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(subowner_enabled) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (subowner_enabled) signal %d", id);
-
-       /* disc_mot_enb_devs_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "disc_mot_enb_devs_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(disc_mot_enb_devs_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (disc_mot_enb_devs_done) signal %d", id);
-
-       /* disc_mowned_devs_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "disc_mowned_devs_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(disc_mowned_devs_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (disc_mowned_devs_done) signal %d", id);
-
-       /* mot_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "mot_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(mot_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (mot_done) signal %d", id);
-
-       /* acl_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "acl_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(acl_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (acl_done) signal %d", id);
-
-       /*cred_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "cred_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(cred_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (cred_done) signal %d", id);
-
-       /*pairwise_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "pairwise_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(pairwise_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (pairwise_done) signal %d", id);
-
-       /*unlink_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "unlink_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(unlink_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (unlink_done) signal %d", id);
-
-       /* remove_mo_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "remove_mo_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(remove_mo_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (remove_mo_done) signal %d", id);
-
-       /* remove_cred_local_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "remove_cred_local_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(remove_cred_local_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (remove_cred_local_done) signal %d", id);
-
-       /*pair_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "pair_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(pair_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (pair_done) signal %d", id);
-
-       /*unpair_done */
-       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
-                       "unpair_done", AGENT_OBJECT_PATH, NULL,
-                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
-       if (0 == id) {
-               LOG_ERR("g_dbus_connection_signal_subscribe(unpair_done) Fail(%d)", errno);
-               return -1;
-       }
-       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-       LOG_DEBUG("subscribed for (unpair_done) signal %d", id);
-
-       return 0;
-}
-
-static void _on_unsubscribe_ids(gpointer data, gpointer userdata)
-{
-       unsigned int id = GPOINTER_TO_UINT(data);
-       struct agent_s *h = (struct agent_s*)userdata;
-       if (NULL == h) {
-               LOG_ERR("Invaild parameter");
-               return;
-       }
-       LOG_DEBUG("[Signal unsubscribe] : %d", id);
-       g_dbus_connection_signal_unsubscribe(h->dbus_connection, id);
-}
-static void _unsubscribe_event()
-{
-       g_list_foreach(agent.dbus_sub_ids, _on_unsubscribe_ids, &agent);
-       g_list_free(agent.dbus_sub_ids);
-       agent.dbus_sub_ids = NULL;
-}
-
-int agent_dbus_start()
-{
-       int ret = COMP_ERROR_NONE;
-
-       ret = _create_gdbus_call();
-       if (COMP_ERROR_NONE != ret)
-               return ret;
-
-       agent.ca = g_cancellable_new();
-
-       /* Create all proxies here */
-       agent.gproxy_agent_service = _get_proxy_service();
-       if (NULL == agent.gproxy_agent_service) {
-               LOG_ERR("Couldn't get _get_proxy_service");
-               return COMP_ERROR_IO_ERROR;
-       }
-
-       g_dbus_proxy_set_default_timeout(
-               G_DBUS_PROXY(agent.gproxy_agent_service), AGENT_DBUS_PROXY_TIMEOUT);
-
-       /* Subscribe events */
-       _subscribe_event();
-
-       return COMP_ERROR_NONE;
-}
-
-int agent_dbus_stop()
-{
-       int ret = COMP_ERROR_NONE;
-
-       _unsubscribe_event();
-
-       /* Unref all proxies here */
-       if (agent.gproxy_agent_service) {
-               g_object_unref(agent.gproxy_agent_service);
-               agent.gproxy_agent_service = NULL;
-       }
-
-       g_cancellable_cancel(agent.ca);
-       g_object_unref(agent.ca);
-       agent.ca = NULL;
-
-       ret = _close_gdbus_call();
-       return ret;
-}
-
diff --git a/src/companion-manager/src/comp_resource.c b/src/companion-manager/src/comp_resource.c
deleted file mode 100644 (file)
index 76338dd..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <comp_resource.h>
-
-/* resource_type, type, uri, policies */
-static comp_rd_t comp_rds[] = {
-       {COMP_RESOURCE_TYPE_GROUP, "core.comp.group", "/comp/group/",
-               OC_DISCOVERABLE | OC_OBSERVABLE},
-       {COMP_RESOURCE_TYPE_DEVICE, "core.comp.device", "/comp/device",
-               OC_DISCOVERABLE | OC_OBSERVABLE},
-       {COMP_RESOURCE_TYPE_OPERATION, "core.comp.operation", "/comp/operation/",
-               OC_DISCOVERABLE | OC_OBSERVABLE},
-       {COMP_RESOURCE_TYPE_DATA, "core.comp.data", "/comp/data/",
-               OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE},
-};
-
-int comp_resource_append(comp_resource_type_e resource_type, const char *uri)
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-       GList *list = comp_ctx->resource_list[resource_type];
-
-       //append resource handle / name to list
-       comp_re_t *element = g_new0(comp_re_t, 1);
-       element->uri = g_strdup(uri);
-       list = g_list_append(list, element);
-
-       comp_ctx->resource_list[resource_type] = list;
-
-       return 0;
-}
-
-char *comp_resource_get_type(comp_resource_type_e resource_type)
-{
-       return comp_rds[resource_type].type;
-}
-
-char *comp_resource_get_uri_prefix(comp_resource_type_e resource_type)
-{
-       return comp_rds[resource_type].uri_prefix;
-}
-
-unsigned char comp_resource_get_policies(comp_resource_type_e resource_type)
-{
-       return comp_rds[resource_type].policies;
-}
-
-void __print_foreach_resource(gpointer data, gpointer user_data)
-{
-       comp_re_t *re = (comp_re_t *)data;
-       LOG_DEBUG("    ** uri : %s", re->uri);
-}
-
-void comp_resource_print_list()
-{
-       comp_context_t *comp_ctx = comp_context_get_context();
-
-       LOG_DEBUG("-------------------Print resource list-----------------------");
-
-       for (int i = 0; i < COMP_RESOURCE_TYPE_MAX; i++) {
-               LOG_DEBUG("Resource type %d list length : %d",
-                       i, g_list_length(comp_ctx->resource_list[i]));
-               g_list_foreach(comp_ctx->resource_list[i], __print_foreach_resource, NULL);
-       }
-
-       LOG_DEBUG("-------------------Print resource list end-------------------");
-}
-
diff --git a/src/companion-manager/src/comp_util.c b/src/companion-manager/src/comp_util.c
deleted file mode 100644 (file)
index 35c32a3..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
-#include <arpa/inet.h>
-#include <dirent.h>
-#include <glib.h>
-
-#include <comp_log.h>
-#include <comp_util.h>
-
-#define IPV6_ADDR_GLOBAL 0x0000U
-#define IPV6_ADDR_LOOPBACK 0x0010U
-#define IPV6_ADDR_LINKLOCAL 0x0020U
-#define IPV6_ADDR_SITELOCAL 0x0040U
-#define IPV6_ADDR_COMPATv4 0x0080U
-
-typedef struct _ipv4_info_s {
-       char *ifname; /**< Network interface name */
-       char *mac; /**< MAC address */
-       bool active; /**< interface active or not */
-       int mtu; /**< MTU size */
-       char *ip; /**< IPv4 address */
-       char *broadcast; /**< Broadcast address */
-       char *mask; /**< Net-mask */
-} ipv4_info_s;
-
-typedef struct _ipv6_info_s {
-       char *ifname; /**< Network interface name */
-       char *ip; /**< IPv6 address */
-       int prefix; /**< Prefix length  */
-       char *scope; /**< Scope */
-} ipv6_info_s;
-
-typedef struct _ip_info_s {
-       GList *ipv4_list; /**< IPv4 address list */
-       GList *ipv6_list; /**< IPv6 address list */
-} ip_info_s;
-
-ip_info_s g_ip_info; /**< Local IP address list */
-
-static void __free_ipv4_info(gpointer data)
-{
-       ipv4_info_s *ipv4info = (ipv4_info_s *)data;
-       if (NULL == data)
-               return;
-
-       if (ipv4info->ifname) {
-               free(ipv4info->ifname);
-               ipv4info->ifname = NULL;
-       }
-       if (ipv4info->mac) {
-               free(ipv4info->mac);
-               ipv4info->mac = NULL;
-       }
-       if (ipv4info->ip) {
-               free(ipv4info->ip);
-               ipv4info->ip = NULL;
-       }
-       if (ipv4info->broadcast) {
-               free(ipv4info->broadcast);
-               ipv4info->broadcast = NULL;
-       }
-       if (ipv4info->mask) {
-               free(ipv4info->mask);
-               ipv4info->mask = NULL;
-       }
-       free(ipv4info);
-       ipv4info = NULL;
-}
-
-static void __free_ipv6_info(gpointer data)
-{
-       ipv6_info_s *ipv6info = (ipv6_info_s *)data;
-       if (NULL == data)
-               return;
-
-       if (ipv6info->ifname) {
-               free(ipv6info->ifname);
-               ipv6info->ifname = NULL;
-       }
-       if (ipv6info->ip) {
-               free(ipv6info->ip);
-               ipv6info->ip = NULL;
-       }
-       if (ipv6info->scope) {
-               free(ipv6info->scope);
-               ipv6info->scope= NULL;
-       }
-       free(ipv6info);
-       ipv6info = NULL;
-}
-
-void comp_remove_ip_info(void)
-{
-       if (g_ip_info.ipv4_list) {
-               g_list_free_full(g_ip_info.ipv4_list, __free_ipv4_info);
-               g_ip_info.ipv4_list = NULL;
-       }
-       if (g_ip_info.ipv6_list) {
-               g_list_free_full(g_ip_info.ipv6_list, __free_ipv6_info);
-               g_ip_info.ipv6_list = NULL;
-       }
-}
-
-static void _parse_inet6(const char *ifname) {
-    FILE *f;
-    int scope, prefix;
-    unsigned char ipv6[16];
-    char dname[IFNAMSIZ];
-    char address[INET6_ADDRSTRLEN];
-    char *scopestr;
-
-    f = fopen("/proc/net/if_inet6", "r");
-    if (f == NULL) {
-               LOGE("Failed to access /proc/net/if_inet6");
-        return;
-    }
-
-    while (19 == fscanf(f," %2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" \
-               "%2hhx%2hhx%2hhx%2hhx%2hhx %*x %x %x %*x %s",
-               &ipv6[0], &ipv6[1], &ipv6[2], &ipv6[3], &ipv6[4], &ipv6[5], &ipv6[6], &ipv6[7],
-               &ipv6[8], &ipv6[9], &ipv6[10], &ipv6[11], &ipv6[12], &ipv6[13], &ipv6[14],
-               &ipv6[15], &prefix, &scope, dname)) {
-
-        if (strcmp(ifname, dname) != 0)
-            continue;
-
-        if (inet_ntop(AF_INET6, ipv6, address, sizeof(address)) == NULL)
-            continue;
-
-               ipv6_info_s *_ipv6 = calloc(1, sizeof(ipv6_info_s));
-               if (NULL == _ipv6) {
-                       LOGE("Memory allocation failed");
-                        goto FINISH_READING_IPV6;
-               }
-               _ipv6->ifname = g_strdup(ifname);
-
-        switch (scope) {
-        case IPV6_ADDR_GLOBAL:
-            scopestr = "Global";
-            break;
-        case IPV6_ADDR_LINKLOCAL:
-            scopestr = "Link";
-            break;
-        case IPV6_ADDR_SITELOCAL:
-            scopestr = "Site";
-            break;
-        case IPV6_ADDR_COMPATv4:
-            scopestr = "Compat";
-            break;
-        case IPV6_ADDR_LOOPBACK:
-            scopestr = "Host";
-            break;
-        default:
-            scopestr = "Unknown";
-        }
-               _ipv6->ip = g_strdup(address); /* ex) fe80::212:34ff:fe5a:ec0e */
-               _ipv6->prefix = prefix; /* ex) 64 */
-               _ipv6->scope = g_strdup(scopestr); /* Link */
-
-               g_ip_info.ipv6_list = g_list_append(g_ip_info.ipv6_list, _ipv6);
-    }
-FINISH_READING_IPV6:
-    fclose(f);
-}
-
-static void _parse_ioctl(const char *ifname)
-{
-    int sock;
-    struct ifreq ifr;
-    struct sockaddr_in *ipaddr;
-    char address[INET_ADDRSTRLEN];
-    size_t ifnamelen;
-
-    /* copy ifname to ifr object */
-    ifnamelen = strlen(ifname);
-    if (ifnamelen >= sizeof(ifr.ifr_name)) {
-        return ;
-    }
-    memcpy(ifr.ifr_name, ifname, ifnamelen);
-    ifr.ifr_name[ifnamelen] = '\0';
-
-    /* open socket */
-    sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
-    if (sock < 0) {
-               LOGE("socket creation faild");
-        return;
-    }
-
-       ipv4_info_s *_ipv4 = calloc(1, sizeof(ipv4_info_s));
-       if (NULL == _ipv4) {
-               LOGE("Memory allocation failed");
-                goto FINISH_READING_IPV4;
-       }
-       _ipv4->ifname = g_strdup(ifname); /* ex) wlan0 */
-
-    /* process mac */
-    if (ioctl(sock, SIOCGIFHWADDR, &ifr) != -1) {
-               char buf[64] = {0,};
-               snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
-                       ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
-                       ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
-                       ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
-               _ipv4->mac = g_strdup(buf); /* ex) 00:12:34:5a:ec:0e */
-    }
-
-    /* process mtu */
-    if (ioctl(sock, SIOCGIFMTU, &ifr) != -1) {
-               _ipv4->mtu = ifr.ifr_mtu; /* ex) 1492 */
-    }
-
-    /* die if cannot get address */
-    if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) {
-               _ipv4->active = false;
-        goto FINISH_READING_IPV4;
-    }
-
-    /* process ip */
-    ipaddr = (struct sockaddr_in *)&ifr.ifr_addr;
-    if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
-               _ipv4->ip = g_strdup(address); /* ex) 192.168.86.111 */
-    }
-
-    /* try to get broadcast */
-    if (ioctl(sock, SIOCGIFBRDADDR, &ifr) != -1) {
-        ipaddr = (struct sockaddr_in *)&ifr.ifr_broadaddr;
-        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
-                       _ipv4->broadcast = g_strdup(address); /* ex) 192.168.86.255 */
-        }
-    }
-
-    /* try to get mask */
-    if (ioctl(sock, SIOCGIFNETMASK, &ifr) != -1) {
-        ipaddr = (struct sockaddr_in *)&ifr.ifr_netmask;
-        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
-                       _ipv4->mask = g_strdup(address); /* ex) 255.255.255.0 */
-        }
-    }
-FINISH_READING_IPV4:
-    close(sock);
-       g_ip_info.ipv4_list = g_list_append(g_ip_info.ipv4_list, _ipv4);
-}
-
-
-int comp_make_ip_info(void)
-{
-    DIR *d;
-    struct dirent *de;
-
-    d = opendir("/sys/class/net/");
-    if (d == NULL) {
-               LOGE("Failed to access /sys/class/net/");
-        return -1;
-    }
-
-    while (NULL != (de = readdir(d))) {
-        if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
-            continue;
-
-        _parse_ioctl(de->d_name);
-        _parse_inet6(de->d_name);
-    }
-    closedir(d);
-
-    return 0;
-}
-
-int comp_is_local_ip(char *ipdata)
-{
-       char *ip = NULL;
-       char *ifname = NULL;
-       char *save_str = NULL;
-       char *addr = NULL;
-       GList *iter = NULL;
-       ipv6_info_s *ipv6info = NULL;
-       ipv4_info_s *ipv4info = NULL;
-
-       addr = g_strdup(ipdata);
-
-       ip = strtok_r(addr, "%", &save_str);
-       ifname = strtok_r(NULL, "%", &save_str);
-
-       iter = g_list_first(g_ip_info.ipv6_list);
-       while (NULL != iter) {
-               ipv6info = iter->data;
-               if (ipv6info && ipv6info->ip && !strncmp(ipv6info->ip, ip,
-                                                                                                INET6_ADDRSTRLEN)) {
-                       g_free(addr);
-                       return LOCAL_IP;
-               }
-               iter = g_list_next(iter);
-       }
-
-       iter = g_list_first(g_ip_info.ipv4_list);
-       while (NULL != iter) {
-               ipv4info = iter->data;
-               if (ipv4info && ipv4info->ip && !strncmp(ipv4info->ip, ip,
-                                                                                                INET_ADDRSTRLEN)) {
-                       g_free(addr);
-                       return LOCAL_IP;
-               }
-               iter = g_list_next(iter);
-       }
-
-       g_free(addr);
-       return REMOTE_IP;
-}
-
diff --git a/src/companion-manager/src/companion_gdbus.xml b/src/companion-manager/src/companion_gdbus.xml
deleted file mode 100644 (file)
index cb4be58..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE node PUBLIC
-       "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
-       "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
-
-<node>
-       <interface name="org.tizen.companion.enabler">
-               <method name="AddRef">
-                       <arg type="s" name="name" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.companion.group">
-               <!-- Method definitions -->
-               <method name="Create">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="Find">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetFoundGroups">
-                       <arg type="i" name="result" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
-               </method>
-               <method name="Join">
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Leave">
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Delete">
-                       <arg type="i" name="group_count" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="DeviceFind">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="Invite">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="s" name="uuid" direction="in"/>
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="Eject">
-                       <arg type="s" name="group_name" direction="in"/>
-                       <arg type="s" name="uuid" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="DeviceInvite">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="s" name="uri_1" direction="in"/>
-                       <arg type="s" name="rt_1" direction="in"/>
-                       <arg type="s" name="interface_1" direction="in"/>
-                       <arg type="i" name="permission_1" direction="in"/>
-                       <arg type="s" name="uri_2" direction="in"/>
-                       <arg type="s" name="rt_2" direction="in"/>
-                       <arg type="s" name="interface_2" direction="in"/>
-                       <arg type="i" name="permission_2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="DeviceEject">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetRemoteDevice">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="PairResource">
-                       <arg type="s" name="target_1" direction="in"/>
-                       <arg type="s" name="subject_1" direction="in"/>
-                       <arg type="s" name="uri_1" direction="in"/>
-                       <arg type="s" name="rt_1" direction="in"/>
-                       <arg type="s" name="interface_1" direction="in"/>
-                       <arg type="i" name="permission_1" direction="in"/>
-                       <arg type="s" name="target_2" direction="in"/>
-                       <arg type="s" name="subject_2" direction="in"/>
-                       <arg type="s" name="uri_2" direction="in"/>
-                       <arg type="s" name="rt_2" direction="in"/>
-                       <arg type="s" name="interface_2" direction="in"/>
-                       <arg type="i" name="permission_2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="UnpairResource">
-                       <arg type="s" name="uuid_dev1" direction="in"/>
-                       <arg type="s" name="uuid_dev2" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="SendData">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="addr" direction="in"/>
-                       <arg type="i" name="port" direction="in"/>
-                       <arg type="(iay)" name="data" direction="in"/>
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="FindMownedDevices">
-                       <arg type="i" name="timeout" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="GetMownedDevice">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="GetMyMownedDevice">
-                       <arg type="a{sv}" name="device_info" direction="out" />
-               </method>
-               <method name="GetMyUuid">
-                       <arg type="s" name="uuid" direction="out" />
-               </method>
-               <method name="RequestCreateGroup">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestInvite">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="s" name="target_uuid" direction="in" />
-                       <arg type="s" name="pin" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestEject">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="s" name="target_uuid" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="RequestDeleteGroup">
-                       <arg type="s" name="uuid" direction="in" />
-                       <arg type="s" name="group_name" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <method name="StartInvitedDeviceMonitor">
-                       <arg type="i" name="start" direction="in" />
-                       <arg type="i" name="result" direction="out" />
-               </method>
-               <!-- Signal (D-Bus) definitions -->
-               <signal name="GroupFound">
-                       <arg type="a{sv}" name="group_info" direction="out" />
-               </signal>
-               <signal name="GroupFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceFound">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </signal>
-               <signal name="DeviceFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceInviteResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceEjectResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="MownedDeviceFound">
-                       <arg type="i" name="device_count" direction="out" />
-                       <arg type="aa{sv}" name="device_info" direction="out" />
-               </signal>
-               <signal name="MownedDeviceFindFinish">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="JoinResult">
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="SendDataFinish">
-                       <arg type="s" name="resp_data" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="RequestResult">
-                       <arg type="s" name="command" direction="out" />
-                       <arg type="s" name="device_id" direction="out" />
-                       <arg type="(iay)" name="arg" direction="out" />
-                       <arg type="i" name="result" direction="out" />
-               </signal>
-               <signal name="DeviceMonitorResult">
-                       <arg type="s" name="uuid" direct="out" />
-                       <arg type="s" name="group_name" direct="out" />
-                       <arg type="s" name="status" direct="out" />
-               </signal>
-       </interface>
-</node>
diff --git a/src/companion-manager/src/gen.sh b/src/companion-manager/src/gen.sh
deleted file mode 100755 (executable)
index 8a7f0e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-gdbus-codegen --interface-prefix org.tizen.companion \
-        --generate-c-code companion_gdbus \
-        --c-generate-object-manager \
-        companion_gdbus.xml \
diff --git a/src/include/d2d-log.h b/src/include/d2d-log.h
deleted file mode 100644 (file)
index acf6448..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __D2D_LOG_H__
-#define __D2D_LOG_H__
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#ifdef USE_DLOG
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "D2D_COMMON"
-
-#define D2D_LOGV(format, args...) LOGV(format, ##args)
-#define D2D_LOGD(format, args...) LOGD(format, ##args)
-#define D2D_LOGI(format, args...) LOGI(format, ##args)
-#define D2D_LOGW(format, args...) LOGW(format, ##args)
-#define D2D_LOGE(format, args...) LOGE(format, ##args)
-#define D2D_LOGF(format, args...) LOGF(format, ##args)
-
-#define __D2D_LOG_FUNC_ENTER__ LOGD("Enter")
-#define __D2D_LOG_FUNC_EXIT__ LOGD("Quit")
-
-#define D2D_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args)
-#define D2D_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args)
-
-#else /* USE_DLOG */
-
-#define D2D_LOGV(format, args...)
-#define D2D_LOGD(format, args...)
-#define D2D_LOGI(format, args...)
-#define D2D_LOGW(format, args...)
-#define D2D_LOGE(format, args...)
-#define D2D_LOGF(format, args...)
-
-#define __D2D_LOG_FUNC_ENTER__
-#define __D2D_LOG_FUNC_EXIT__
-
-#define D2D_SECLOGI(format, args...)
-#define D2D_SECLOGD(format, args...)
-
-#endif /* USE_DLOG */
-
-#endif /* __D2D_LOG_H__ */
diff --git a/src/mdg-manager/CMakeLists.txt b/src/mdg-manager/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ef76120
--- /dev/null
@@ -0,0 +1,22 @@
+MESSAGE("===================================================================")
+MESSAGE("Building...mdg-manager")
+MESSAGE("===================================================================")
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+                " \\
+                --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/src/mdg_gdbus \\
+                --interface-prefix org.tizen.mdg. \\
+                ${CMAKE_CURRENT_SOURCE_DIR}/src/mdg_gdbus.xml \\
+                ")
+
+MESSAGE(" - Set source folder")
+FILE(GLOB MDG_MANAGER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
+
+SET(MDG_MANAGER "mdgd")
+ADD_EXECUTABLE(${MDG_MANAGER} ${MDG_MANAGER_SRCS})
+TARGET_LINK_LIBRARIES(${MDG_MANAGER} ${daemon_pkgs_LIBRARIES} pthread)
+INSTALL(TARGETS ${MDG_MANAGER} DESTINATION bin)
+INSTALL(FILES oic_svr_db_mdg_manager.dat DESTINATION ${NETWORK_FW_DATADIR})
diff --git a/src/mdg-manager/include/mdgd_context.h b/src/mdg-manager/include/mdgd_context.h
new file mode 100644 (file)
index 0000000..59f4cdf
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_CONTEXT_H__
+#define __MDGD_CONTEXT_H__
+
+#include <glib.h>
+#include <mdgd_log.h>
+#include <unistd.h>
+#include <gio/gio.h>
+#include <mdg_gdbus.h>
+#include <sys/types.h>
+#include <sqlite3.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct {
+       GMainLoop *main_loop;
+       //GDBusConnection *connection;
+       int ref_count;
+
+       // resource list
+       GList *resource_list[MDGD_RESOURCE_TYPE_MAX];
+
+       char *device_uuid;
+       bool mot_me; /**< Indicator whether mot local comp-manager */
+       GList *grp_list;
+       GList *pairwise_list;
+
+       bool monitor_started;
+
+       //sqlite3 db
+       sqlite3 *db;
+} mdgd_context_t;
+
+typedef struct {
+       char *conn_name;
+       int conn_id;
+       GDBusConnection *connection;
+} mdgd_conn_destroy_data;
+
+int mdgd_context_create();
+int mdgd_context_destroy();
+void mdgd_context_mutex_lock();
+void mdgd_context_mutex_unlock();
+
+mdgd_context_t *mdgd_context_get_context();
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __MDGD_CONTEXT_H__ */
diff --git a/src/mdg-manager/include/mdgd_db.h b/src/mdg-manager/include/mdgd_db.h
new file mode 100644 (file)
index 0000000..1fbeea1
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_DB_H__
+#define __MDGD_DB_H__
+
+#define MDGD_DB_FILE "/opt/usr/dbspace/.comp.db"
+#define MDGD_DB_TABLE "mdgd_group_information"
+
+int mdgd_db_init();
+int mdgd_db_deinit();
+int mdgd_db_insert(char *group_name, char *device_id);
+int mdgd_db_delete_group(char *group_name);
+int mdgd_db_delete_device(char *group_name, char *device_id);
+
+#endif
diff --git a/src/mdg-manager/include/mdgd_enum.h b/src/mdg-manager/include/mdgd_enum.h
new file mode 100644 (file)
index 0000000..b8c3b94
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_ENUM_H__
+#define __MDGD_ENUM_H__
+
+#include <tizen.h>
+
+#define NOTUSED(var) (var = var) /**< It is used to avoid generating build warning */
+
+#define TIZEN_ERROR_COMP 0 /**< Same one */
+
+/**
+ * @brief Error codes for cmdgd.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDGD_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+       MDGD_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+       MDGD_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       MDGD_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+       MDGD_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       MDGD_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+       MDGD_ERROR_COMM_ERROR = TIZEN_ERROR_COMP | 0x01, /**< communication error */
+       MDGD_ERROR_RX = TIZEN_ERROR_COMP | 0x02, /**< RX error */
+       MDGD_ERROR_TX = TIZEN_ERROR_COMP | 0x03, /**< TX error */
+       MDGD_ERROR_PLUGIN_FAIL = TIZEN_ERROR_COMP | 0x04, /**< Plugin failed */
+       MDGD_ERROR_OPERATION_FAILED = TIZEN_ERROR_COMP | 0x05, /**< Operation Failed */
+       MDGD_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */
+       MDGD_ERROR_UNKNOWN = -999,
+} mdgd_error_e;
+
+/**
+ * @brief Resource type.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDGD_RESOURCE_TYPE_GROUP = 0, /**< Group resource type  */
+       MDGD_RESOURCE_TYPE_DEVICE, /**< Device resource type  */
+       MDGD_RESOURCE_TYPE_OPERATION, /**< Operation resource type */
+       MDGD_RESOURCE_TYPE_DATA, /**< Data resource type */
+       MDGD_RESOURCE_TYPE_MAX
+} mdgd_resource_type_e;
+
+/**
+ * @brief Group type.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDGD_GROUP_GROUP_ERROR = 0, /**< Group type error */
+       MDGD_GROUP_GROUP_LOCAL = 1, /**< Local group type */
+       MDGD_GROUP_GROUP_REMOTE = 2, /**< Remote group type */
+} mdgd_group_type_e;
+
+typedef enum {
+       MDGD_GROUP_DEVICE_ERROR = 0, /**< Group type error */
+       MDGD_GROUP_DEVICE_LOCAL = 1, /**< Local group type */
+       MDGD_GROUP_DEVICE_REMOTE = 2, /**< Remote group type */
+} mdgd_device_type_e;
+
+/**
+ * @brief The command type for request.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MDGD_REQ_UNKNOWN_COMMAND = -1, /**< Unknown Command */
+       MDGD_REQ_SEND_DATA = 0, /**< Send data */
+       MDGD_REQ_CREATE_GROUP, /**< Create Group */
+       MDGD_REQ_INVITE_DEVICE, /**< Invite Device */
+       MDGD_REQ_EJECT_DEVICE, /**< Exile Device */
+       MDGD_REQ_DELETE_GROUP, /**< Delete Group */
+       MDGD_REQ_KEEP_ALIVE, /**< Keep Alive Message */
+       MDGD_REQ_SEND_DATA_ALL, /**< Send data in subnet */
+} mdgd_request_type_e;
+
+#endif /* __MDGD_ENUM_H__ */
diff --git a/src/mdg-manager/include/mdgd_gdbus.h b/src/mdg-manager/include/mdgd_gdbus.h
new file mode 100644 (file)
index 0000000..4299f15
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_GDBUS_H__
+#define __MDGD_GDBUS_H__
+
+#include <mdgd_gdbus_group.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define MDGD_DBUS_SERVICE "org.tizen.mdg" /**< For multi device group manager dbus */
+#define MDGD_DBUS_GROUP_PATH "/org/tizen/mdg/group" /**< For group commands */
+#define  MDGD_DBUS_ENABLER_PATH "/org/tizen/mdg/enabler" /**< For d-bus activation */
+
+int mdgd_gdbus_init();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MDGD_GDBUS_H__ */
diff --git a/src/mdg-manager/include/mdgd_gdbus_group.h b/src/mdg-manager/include/mdgd_gdbus_group.h
new file mode 100644 (file)
index 0000000..8574815
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_GDBUS_GROUP_H__
+#define __MDGD_GDBUS_GROUP_H__
+
+#include <mdgd_group.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+Group *group_dbus_get_object();
+
+gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
+       gpointer user_data);
+
+gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gint timeout,
+       gpointer user_data);
+
+gboolean group_get_found_groups(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data);
+
+gboolean group_join(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data);
+
+gboolean group_leave(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data);
+
+gboolean group_delete(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data);
+
+gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation,
+       gint timeout, gpointer user_data);
+
+gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gchar *pin, gchar *uri_1, gchar *rt_1,
+       gchar *interface_1, int permission_1, gchar *uri_2, gchar *rt_2,
+       gchar *interface_2, int permission_2, gpointer user_data);
+
+gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data);
+
+gboolean group_invite(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
+       gchar *uuid, gchar *pin, gpointer user_data);
+
+gboolean group_eject(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
+       gchar *uuid, gpointer user_data);
+
+gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data);
+
+gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation,
+       gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1,
+       gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2,
+       gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2,
+       gpointer user_data);
+
+gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data);
+
+gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev, gchar *addr, int port, GVariant *params,
+       gpointer user_data);
+
+gboolean group_find_mowned_devices(Group *group,
+       GDBusMethodInvocation *invocation, int timeout, gpointer user_data);
+
+gboolean group_get_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
+gboolean group_get_my_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
+gboolean group_get_my_uuid(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
+gboolean group_request_create_group(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gpointer user_data);
+
+gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data);
+
+gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data);
+
+gboolean group_request_delete_group(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gpointer user_data);
+
+gboolean group_start_invited_device_monitor(Group *group,
+                                       GDBusMethodInvocation *invocation, int start,
+                                       gpointer user_data);
+
+void notify_group_found(GVariant *group_data);
+void notify_group_find_finish(int ret);
+void notify_device_found(int device_count, GVariant *device_data);
+void notify_device_find_finish(int ret);
+void notify_group_device_invite_result(int ret);
+void notify_group_device_eject_result(int ret);
+void notify_mowned_device_found(int device_count, GVariant *device_data);
+void notify_mowned_device_find_finish(int ret);
+void notify_group_join(int result);
+void notify_send_data_finish(const char *resp_data, int ret);
+void notify_request_result(const char *cmd, const char *requester_id,
+                                                  unsigned char *arg, int len, int ret);
+void notify_device_monitor_result(const char *uuid, const char *group_name,
+                                                                 const char *status);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __MDGD_GDBUS_GROUP_H__ */
diff --git a/src/mdg-manager/include/mdgd_group.h b/src/mdg-manager/include/mdgd_group.h
new file mode 100644 (file)
index 0000000..88adbad
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_GROUP_H__
+#define __MDGD_GROUP_H__
+
+#include <mdgd_iot.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct {
+       char *uri_path; /**< URI path */
+       char *device_id; /**< Device ID */
+       char *host_addr; /**< Host address */
+       char *group_name; /**< Group name */
+       char *resource_type; /**< Resource type */
+       mdgd_group_type_e type; /**< Group yype */
+} mdgd_group_t;
+
+typedef struct {
+       char *device_id; /**< Device Id */
+       int adapter; /**< Adapter type */
+       int flags; /**< Flags */
+       int port; /**< Remtoe device is listening this port */
+       char *addr; /**< IP Address of remote device */
+       int ifindex; /**< Network interfce index of Remote device */
+       char *route_data; /**< Route data */
+       char *remote_id; /**< Remote Id */
+       int conn_type; /**< Connection type */
+       int secure_port; /**< Secured port once TLS handhaking complete */
+       int tcp_port; /**< TCP port when using CoAP over TCP */
+       char *sec_ver; /**< OCF Security specification version */
+       int dev_status; /**< Device status */
+       char *model_name; /**< Device ID */
+       char *device_name; /**< Host address */
+       char *platform_ver; /**< Group name */
+       char *vendor_id; /**< Resource type */
+       char *profile; /**< Group yype */
+       bool mowned;
+       mdgd_device_type_e type;
+} mdgd_mot_device_t;
+
+typedef struct {
+       char *group_name;
+       char *uuid_dev1; /**< Source device Id */
+       char *uuid_dev2; /**< Target device Id */
+       char *pin; /**< Random or pre-configured PIN */
+       char *uri_1; /**< URI at source resource */
+       char *rt_1; /**< Resource type at source resource */
+       char *interface_1; /**< Interface at source resource */
+       int permission_1; /**< CRUDN for target device */
+       char *uri_2; /**< URI at target resource */
+       char *rt_2; /**< Resource type at target resource */
+       char *interface_2; /**< Interface at target resource */
+       int permission_2; /**< CRUDN for source device */
+} mdgd_group_invite_info_t;
+
+typedef struct {
+       char *group_name; /**< Group Name */
+       char *uuid; /**< Device ID */
+       char *host; /**< Device Host Address */
+       int count; /**< Count of successful post method */
+} mdgd_invited_device_t;
+
+/* Called when daemon is start. */
+int mdgd_group_initialize();
+
+/* create group and destroy */
+int mdgd_group_create(const char* name);
+int mdgd_group_destroy(mdgd_group_t *handle);
+
+/* Find Remote groups */
+int mdgd_group_find(int timeout);
+GVariant *mdgd_group_get_found_groups();
+int mdgd_group_add_new(char *uri_path, char *device_id, char *device_name,
+                                char *host_addr, char *resource_type, mdgd_group_type_e type);
+
+/* Join the remote devices in my daemon */
+int mdgd_group_get_groups(mdgd_group_t ***handles, int *count); //Get all of group in my daemon
+int mdgd_group_get_remote_devices(/* callback */); //Get all of device in network (Async)
+
+int mdgd_group_add_new_mot_device(mdgd_mot_device_t *device);
+void mdgd_group_notify_mot_enable_device_done();
+int mdgd_group_find_mot_enabled_devices(int timeout);
+
+char *mdgd_group_invite_get_uuid();
+char *mdgd_group_invite_get_pin();
+
+/* Join to device in group (async) */
+int mdgd_group_invite(const char *group_name, const char *uuid,
+                                         const char *pin);
+mdgd_group_invite_info_t *mdgd_group_get_invite_info();
+void mdgd_group_free_invite_info();
+void mdgd_group_notify_group_invite(int result);
+
+/* eject from group (async) */
+int mdgd_group_eject(const gchar *group_name, gchar *uuid_dev1, const char *uuid_dev2);
+void mdgd_group_notify_group_dismiss(int result);
+
+int mdgd_group_pair_resource(char* target1, char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
+       char *uri2, char *rt2, char *interface2, int permission2);
+
+int mdgd_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2);
+int mdgd_group_send_data(gchar *uuid_dev, gchar *addr, int port,
+                                                unsigned char *data, int len);
+void mdgd_group_notify_keepalive_response(mdgd_command_t *cmd);
+
+GVariant *mdgd_group_get_remote_mot_enabled_devices();
+int mdgd_group_get_mot_device_count();
+
+int mdgd_group_add_new_mowned_device(mdgd_mot_device_t *device);
+void mdgd_group_notify_mowned_device_find_done();
+int mdgd_group_find_mowned_devices();
+GVariant *mdgd_group_get_mowned_devices();
+int mdgd_group_get_mowned_device_count();
+GVariant *mdgd_group_get_my_mowned_devices();
+void mdgd_group_change_mowned_device(mdgd_mot_device_t *device);
+
+/* Join to remote device group */
+int mdgd_group_join();
+int mdgd_group_leave_from(/* callback */); //leave from certain remote group (Async)
+
+/* Called when daemon is end. */
+int mdgd_group_deinitialize();
+
+/* Getter for a group */
+int mdgd_group_get_group_name(mdgd_group_t *handle, char **name);
+int mdgd_group_get_group_type(mdgd_group_t *handle, int *type);
+int mdgd_group_get_group_device_type(mdgd_group_t *handle);
+int mdgd_group_get_group_device_id(mdgd_group_t *handle);
+
+/* notify */
+int mdgd_group_event_handler(/*callback*/); // event hadnler
+int mdgd_group_add_device_in_group(const char *group_name, const char *uuid);
+int mdgd_group_remove_device_in_group(char *group_name, char *uuid);
+
+/* Group management */
+int mdgd_group_request_create_group(char *uuid, char *group_name);
+int mdgd_group_request_invite(char *uuid, char *group_name, char *target_uuid, char *PIN);
+int mdgd_group_request_eject(char *uuid, char *group_name, char *target_uuid);
+int mdgd_group_request_delete_group(char *uuid, char *group_name);
+
+int mdgd_group_start_invited_device_monitor(int start);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __MDGD_GROUP_H__ */
diff --git a/src/mdg-manager/include/mdgd_iot.h b/src/mdg-manager/include/mdgd_iot.h
new file mode 100644 (file)
index 0000000..b8b333f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_IOT_H__
+#define __MDGD_IOT_H__
+
+#include <mdgd_resource.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SVR_PATH "/tmp/.svr.dat" /**< For Temp */
+
+typedef struct _iot_discovery_t {
+       gchar *uuid; /**< Device Id */
+       gchar *data; /**< Data to send */
+       gchar *host; /**< Target host IP address + Port */
+} iot_discovery_t;
+
+typedef struct _mdgd_command_t {
+       int tid; /**< Timer ID */
+       int resource_type; /**< OCF resource type */
+       mdgd_request_type_e command; /**< Comments set for group management */
+       gchar *uuid; /**< Device UUID */
+       gchar *host; /**< Host address + Port */
+       gchar *arg1; /**< Arguement #1 */
+       gchar *arg2; /**< Arguement #2 */
+       gchar *arg3; /**< Arguement #3 */
+       gchar *arg4; /**< Arguement #4 */
+#ifdef SUPPORT_BASE64_ENCODING
+       unsigned char *data;
+       int data_len;
+#endif
+       void *user_data;
+} mdgd_command_t;
+
+int mdgd_iot_initialize();
+int mdgd_iot_add_resource(mdgd_resource_type_e resource_type, const char *uri);
+int mdgd_iot_delete_resource(mdgd_resource_type_e resource_type);
+int mdgd_iot_discovery_resource(mdgd_resource_type_e resource_type, int timeout, void *user_data);
+int mdgd_iot_send_data(mdgd_resource_type_e resource_type, int timeout,
+                                          mdgd_command_t *cmd);
+int mdgd_iot_deinitialize();
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __MDGD_IOT_H__ */
diff --git a/src/mdg-manager/include/mdgd_log.h b/src/mdg-manager/include/mdgd_log.h
new file mode 100644 (file)
index 0000000..ec4bc9b
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_LOG_H__
+#define __MDGD_LOG_H__
+
+#include <dlog.h>
+#include <mdgd_enum.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define COLOR_RED               "\033[0;31m"
+#define COLOR_GREEN             "\033[0;32m"
+#define COLOR_BROWN             "\033[0;33m"
+#define COLOR_BLUE              "\033[0;34m"
+#define COLOR_PURPLE            "\033[0;35m"
+#define COLOR_CYAN              "\033[0;36m"
+#define COLOR_LIGHTBLUE         "\033[0;37m"
+#define COLOR_END               "\033[0;m"
+
+#define LOG_TAG "MDGD_MANAGER"
+
+#define LOG_DEBUG(fmt, ...) \
+       do { \
+               LOGD(COLOR_BROWN" " fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+#define LOG_ERR(fmt, ...) \
+       do { \
+               LOGE(COLOR_RED" " fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+#define LOG_BEGIN() \
+       do { \
+               LOGD(COLOR_BLUE "BEGIN" COLOR_END); \
+       } while (0)
+#define LOG_END() \
+       do { \
+               LOGD(COLOR_BLUE "END" COLOR_END); \
+       } while (0)
+
+#define NOTUSED(var) (var = var)
+
+#define mdgd_check_null_ret_error(name, value, error) do { \
+       /* LCOV_EXCL_START */ \
+       if (G_UNLIKELY(NULL == (value))) { \
+                               LOGE("%s is NULL", name); \
+                               return error; \
+                       } \
+       /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+#define mdgd_check_null_ret(name, value) do { \
+       /* LCOV_EXCL_START */ \
+       if (G_UNLIKELY(NULL == (value))) { \
+                               LOGE("%s is NULL", name); \
+                               return; \
+                       } \
+       /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+const char *mdgd_log_get_error_string(int result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MDGD_LOG_H__ */
diff --git a/src/mdg-manager/include/mdgd_manager.h b/src/mdg-manager/include/mdgd_manager.h
new file mode 100644 (file)
index 0000000..3f2aaf5
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_MANAGER_H__
+#define __MDGD_MANAGER_H__
+
+#include <mdgd_log.h>
+#include <mdgd_group.h>
+#include <mdgd_resource.h>
+#include <mdgd_gdbus.h>
+#include <mdgd_db.h>
+
+#endif /* __MDGD_MANAGER_H__ */
diff --git a/src/mdg-manager/include/mdgd_mot_agent.h b/src/mdg-manager/include/mdgd_mot_agent.h
new file mode 100644 (file)
index 0000000..395525e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ #ifndef __MDGD_MOT_AGENT_H__
+ #define __MDGD_MOT_AGENT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int agent_dbus_start();
+int agent_dbus_stop();
+
+int agent_enable();
+int agent_disable();
+int agent_get_ownerid(char* deviceid);
+int agent_find_mot_enable_devices(int timeout);
+int agent_find_mowned_devices();
+int agent_mot(char* uuid_str, char *pin);
+int agent_resources_pairwise(char* target1, char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
+       char *uri2, char *rt2, char *interface2, int permission2);
+int agent_unlink_resources(char* uuid_str1, char *uuid_str2);
+int agent_remove_subowner(char* uuid_str);
+int agent_remove_subowned(char* uuid_str);
+int agent_pair(const char *pin, char* target1, const char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, const char* target2,
+       char *subject2, char *uri2, char *rt2, char *interface2, int permission2);
+int agent_unpair(char* uuid_str1, const char *uuid_str2);
+
+#ifdef __cplusplus
+}
+#endif
+
+ #endif /* __MDGD_MOT_AGENT_H__ */
diff --git a/src/mdg-manager/include/mdgd_resource.h b/src/mdg-manager/include/mdgd_resource.h
new file mode 100644 (file)
index 0000000..31658dc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_RESOURCE_H__
+#define __MDGD_RESOURCE_H__
+
+#include <mdgd_context.h>
+#include <octypes.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct {
+       mdgd_resource_type_e resource_type;
+       char *type;
+       char *uri_prefix;
+       unsigned char policies;
+} mdgd_rd_t;
+
+typedef struct {
+       char *uri;
+} mdgd_re_t;
+
+int mdgd_resource_append(mdgd_resource_type_e resource_type, const char *uri);
+char *mdgd_resource_get_type(mdgd_resource_type_e resource_type);
+char *mdgd_resource_get_uri_prefix(mdgd_resource_type_e resource_type);
+unsigned char mdgd_resource_get_policies(mdgd_resource_type_e resource_type);
+void mdgd_resource_print_list();
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __MDGD_RESOURCE_H__ */
diff --git a/src/mdg-manager/include/mdgd_util.h b/src/mdg-manager/include/mdgd_util.h
new file mode 100644 (file)
index 0000000..6e1ce35
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MDGD_UTIL_H__
+#define __MDGD_UTIL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define LOCAL_IP 1 /**< Local IP */
+#define REMOTE_IP 2 /**< Remote IP */
+
+void mdgd_remove_ip_info(void);
+int mdgd_make_ip_info(void);
+int mdgd_is_local_ip(char *ipdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MDGD_UTIL_H__ */
diff --git a/src/mdg-manager/oic_svr_db_mdg_manager.dat b/src/mdg-manager/oic_svr_db_mdg_manager.dat
new file mode 100644 (file)
index 0000000..bdc3480
Binary files /dev/null and b/src/mdg-manager/oic_svr_db_mdg_manager.dat differ
diff --git a/src/mdg-manager/oic_svr_db_mdg_manager.json b/src/mdg-manager/oic_svr_db_mdg_manager.json
new file mode 100644 (file)
index 0000000..943566f
--- /dev/null
@@ -0,0 +1,128 @@
+{\r
+    "cred":{\r
+        "creds": [\r
+            {\r
+                "credid": 1,\r
+                "subjectuuid": "*",\r
+                "credtype": 16,\r
+                "privatedata": {\r
+                    "encoding": "oic.sec.encoding.raw",\r
+                    "data": "12341234"\r
+                }\r
+            }\r
+        ],\r
+        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
+    },\r
+    "acl": {\r
+        "aclist": {\r
+            "aces": [\r
+                {\r
+                    "subjectuuid": "*",\r
+                    "resources": [\r
+                        {\r
+                            "href": "/oic/res",\r
+                            "rel": "",\r
+                            "rt": ["oic.wk.res"],\r
+                            "if": ["oic.if.ll"]\r
+                        },{\r
+                            "href": "/oic/d",\r
+                            "rel": "",\r
+                            "rt": ["oic.wk.d"],\r
+                            "if": ["oic.if.baseline", "oic.if.r"]\r
+                        },{\r
+                            "href": "/oic/p",\r
+                            "rel": "",\r
+                            "rt": ["oic.wk.p"],\r
+                            "if": ["oic.if.baseline", "oic.if.r"]\r
+                        }\r
+                    ],\r
+                    "permission": 2\r
+                },\r
+                {\r
+                    "subjectuuid": "*",\r
+                    "resources": [\r
+                        {\r
+                            "href": "/oic/sec/doxm",\r
+                            "rel": "",\r
+                            "rt": ["oic.r.doxm"],\r
+                            "if": ["oic.if.baseline"]\r
+                        },\r
+                        {\r
+                            "href": "/oic/sec/pstat",\r
+                            "rel": "",\r
+                            "rt": ["oic.r.pstat"],\r
+                            "if": ["oic.if.baseline"]\r
+                        },\r
+                        {\r
+                            "href": "/oic/sec/cred",\r
+                            "rel": "",\r
+                            "rt": ["oic.r.cred"],\r
+                            "if": ["oic.if.baseline"]\r
+                        }\r
+                    ],\r
+                    "permission": 6\r
+                },\r
+                {\r
+                    "subjectuuid": "*",\r
+                    "resources": [\r
+                        {\r
+                            "href": "/comp/group",\r
+                            "rel": "",\r
+                            "rt": ["core.comp.group"],\r
+                            "if": ["oic.if.ll"]\r
+                        },{\r
+                            "href": "/comp/device",\r
+                            "rel": "",\r
+                            "rt": ["core.comp.device"],\r
+                            "if": ["oic.if.baseline"]\r
+                        }, {\r
+                            "href": "/comp/operation",\r
+                            "rel": "",\r
+                            "rt": ["core.comp.operation"],\r
+                            "if": ["oic.if.baseline"]\r
+                        }\r
+                    ],\r
+                    "permission": 31\r
+                },\r
+                {\r
+                    "subjectuuid": "*",\r
+                    "resources": [\r
+                        {\r
+                            "href": "/oic/sec/pconf",\r
+                            "rel": "",\r
+                            "rt": ["oic.r.pconf"],\r
+                            "if": ["oic.if.baseline"]\r
+                        },\r
+                        {\r
+                            "href": "/oic/sec/dpairing",\r
+                            "rel": "",\r
+                            "rt": ["oic.r.dpairing"],\r
+                            "if": ["oic.if.baseline"]\r
+                        }\r
+                    ],\r
+                    "permission": 2\r
+                }\r
+            ]\r
+        },\r
+        "rowneruuid" : "00000000-0000-0000-0000-000000000000"\r
+    },\r
+    "pstat": {\r
+        "isop": false,\r
+        "cm": 2,\r
+        "tm": 0,\r
+        "om": 4,\r
+        "sm": 4,\r
+        "deviceuuid": "00000000-0000-0000-0000-000000000000",\r
+        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
+    },\r
+    "doxm": {\r
+        "oxms": [0, 65280],\r
+        "oxmsel": 65280,\r
+        "sct": 17,\r
+        "owned": false,\r
+        "x.org.iotivity.mom": 1,\r
+        "deviceuuid": "00000000-0000-0000-0000-000000000000",\r
+        "devowneruuid": "00000000-0000-0000-0000-000000000000",\r
+        "rowneruuid": "00000000-0000-0000-0000-000000000000"\r
+    }\r
+}\r
diff --git a/src/mdg-manager/src/gen.sh b/src/mdg-manager/src/gen.sh
new file mode 100755 (executable)
index 0000000..8db7387
--- /dev/null
@@ -0,0 +1,4 @@
+gdbus-codegen --interface-prefix org.tizen.mdg \
+        --generate-c-code mdg_gdbus \
+        --c-generate-object-manager \
+        mdg_gdbus.xml \
diff --git a/src/mdg-manager/src/mdg_gdbus.xml b/src/mdg-manager/src/mdg_gdbus.xml
new file mode 100644 (file)
index 0000000..5aa4c1e
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE node PUBLIC
+       "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
+       "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
+
+<node>
+       <interface name="org.tizen.mdg.enabler">
+               <method name="AddRef">
+                       <arg type="s" name="name" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.mdg.group">
+               <!-- Method definitions -->
+               <method name="Create">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="Find">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetFoundGroups">
+                       <arg type="i" name="result" direction="out" />
+                       <arg type="aa{sv}" name="groups" direction="out" />
+               </method>
+               <method name="Join">
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Leave">
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Delete">
+                       <arg type="i" name="group_count" direction="out" />
+                       <arg type="aa{sv}" name="groups" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="DeviceFind">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="Invite">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="s" name="uuid" direction="in"/>
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="Eject">
+                       <arg type="s" name="group_name" direction="in"/>
+                       <arg type="s" name="uuid" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="DeviceInvite">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="s" name="uri_1" direction="in"/>
+                       <arg type="s" name="rt_1" direction="in"/>
+                       <arg type="s" name="interface_1" direction="in"/>
+                       <arg type="i" name="permission_1" direction="in"/>
+                       <arg type="s" name="uri_2" direction="in"/>
+                       <arg type="s" name="rt_2" direction="in"/>
+                       <arg type="s" name="interface_2" direction="in"/>
+                       <arg type="i" name="permission_2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="DeviceEject">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetRemoteDevice">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="PairResource">
+                       <arg type="s" name="target_1" direction="in"/>
+                       <arg type="s" name="subject_1" direction="in"/>
+                       <arg type="s" name="uri_1" direction="in"/>
+                       <arg type="s" name="rt_1" direction="in"/>
+                       <arg type="s" name="interface_1" direction="in"/>
+                       <arg type="i" name="permission_1" direction="in"/>
+                       <arg type="s" name="target_2" direction="in"/>
+                       <arg type="s" name="subject_2" direction="in"/>
+                       <arg type="s" name="uri_2" direction="in"/>
+                       <arg type="s" name="rt_2" direction="in"/>
+                       <arg type="s" name="interface_2" direction="in"/>
+                       <arg type="i" name="permission_2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="UnpairResource">
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="SendData">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="addr" direction="in"/>
+                       <arg type="i" name="port" direction="in"/>
+                       <arg type="(iay)" name="data" direction="in"/>
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="FindMownedDevices">
+                       <arg type="i" name="timeout" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetMownedDevice">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyMownedDevice">
+                       <arg type="a{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyUuid">
+                       <arg type="s" name="uuid" direction="out" />
+               </method>
+               <method name="RequestCreateGroup">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestInvite">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="s" name="target_uuid" direction="in" />
+                       <arg type="s" name="pin" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestEject">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="s" name="target_uuid" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="RequestDeleteGroup">
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="group_name" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="StartInvitedDeviceMonitor">
+                       <arg type="i" name="start" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <!-- Signal (D-Bus) definitions -->
+               <signal name="GroupFound">
+                       <arg type="a{sv}" name="group_info" direction="out" />
+               </signal>
+               <signal name="GroupFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
+               <signal name="DeviceFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceInviteResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceEjectResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="MownedDeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
+               <signal name="MownedDeviceFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="JoinResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="SendDataFinish">
+                       <arg type="s" name="resp_data" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="RequestResult">
+                       <arg type="s" name="command" direction="out" />
+                       <arg type="s" name="device_id" direction="out" />
+                       <arg type="(iay)" name="arg" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceMonitorResult">
+                       <arg type="s" name="uuid" direct="out" />
+                       <arg type="s" name="group_name" direct="out" />
+                       <arg type="s" name="status" direct="out" />
+               </signal>
+       </interface>
+</node>
diff --git a/src/mdg-manager/src/mdgd_context.c b/src/mdg-manager/src/mdgd_context.c
new file mode 100644 (file)
index 0000000..0ed7778
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_context.h>
+
+static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
+static mdgd_context_t *mdgd_ctx;
+
+int mdgd_context_create()
+{
+       mdgd_ctx = g_new0(mdgd_context_t, 1);
+       if (!mdgd_ctx) {
+               LOG_DEBUG("create comp_context is failed");
+               return MDGD_ERROR_OUT_OF_MEMORY;
+       }
+       mdgd_ctx->mot_me = FALSE;
+
+       return MDGD_ERROR_NONE;
+}
+
+void mdgd_context_mutex_lock()
+{
+       LOG_DEBUG("context mutex lock");
+       pthread_mutex_lock(&context_lock);
+}
+
+void mdgd_context_mutex_unlock()
+{
+       LOG_DEBUG("context mutex unlock");
+       pthread_mutex_unlock(&context_lock);
+}
+
+int mdgd_context_destroy()
+{
+       return MDGD_ERROR_NONE;
+}
+
+mdgd_context_t *mdgd_context_get_context()
+{
+       return mdgd_ctx;
+}
+
diff --git a/src/mdg-manager/src/mdgd_db.c b/src/mdg-manager/src/mdgd_db.c
new file mode 100644 (file)
index 0000000..a8d1140
--- /dev/null
@@ -0,0 +1,345 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_db.h>
+#include <mdgd_context.h>
+#include <mdgd_group.h>
+
+static bool __is_table_existing(const char *table)
+{
+       bool result;
+       char *sql;
+       int ret;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       sql = sqlite3_mprintf("SELECT count(*) FROM sqlite_master WHERE type='table' AND name ='%s';", table);
+       if (sql != NULL) {
+               sqlite3_stmt *stmt = NULL;
+
+               ret = sqlite3_prepare_v2(mdgd_ctx->db, sql, strlen(sql), &stmt, NULL);
+               if (ret == SQLITE_OK) {
+                       ret = sqlite3_step(stmt);
+                       if (ret == SQLITE_ROW) {
+                               int count;
+
+                               count = sqlite3_column_int(stmt, 0);
+                               if (count > 0)
+                                       result = true;
+                               else
+                                       result = false;
+                       } else {
+                               LOG_ERR("sqlite3_step failed, [%d:%s]", ret, sqlite3_errmsg(mdgd_ctx->db));
+
+                               result = false;
+                       }
+
+                       sqlite3_finalize(stmt);
+               } else {
+                       LOG_ERR("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(mdgd_ctx->db));
+
+                       result = false;
+               }
+
+               sqlite3_free(sql);
+       } else {
+               LOG_ERR("sqlite3_mprintf failed");
+
+               result = false;
+       }
+
+       return result;
+}
+
+static int __create_table()
+{
+       int ret = 0;
+       int sql_ret;
+       char *sql = NULL;
+       char *error = NULL;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == NULL) {
+               LOG_ERR("mdgd_ctx->db is NULL");
+               return -1;
+       }
+
+       sql = sqlite3_mprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, group_name TEXT, device_id TEXT);",
+               MDGD_DB_TABLE);
+
+       if (sql != NULL) {
+               sql_ret = sqlite3_exec(mdgd_ctx->db, sql, NULL, NULL, &error);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
+                       ret = -1;
+                       sqlite3_free(error);
+               }
+               sqlite3_free(sql);
+       } else {
+               LOG_ERR("sql is NULL");
+               ret = -1;
+       }
+
+       return ret;
+}
+
+static void __prepare_table()
+{
+       if (__is_table_existing(MDGD_DB_TABLE) == false)
+               __create_table();
+}
+
+static int __check_integrity()
+{
+       sqlite3_stmt *stmt = NULL;
+       int result = 0;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == 0) {
+               LOG_ERR("failed to check handle");
+               return -1;
+       }
+
+       int ret = sqlite3_prepare_v2(mdgd_ctx->db, "PRAGMA integrity_check", -1, &stmt, NULL);
+       if (ret != SQLITE_OK && ret != SQLITE_BUSY) {
+               LOG_ERR("failed to check integrity: %s", sqlite3_errmsg(mdgd_ctx->db));
+               return -1;
+       } else {
+               ret = sqlite3_step(stmt);
+               if (ret == SQLITE_ROW) {
+                       const char *ret_val = (const char *)sqlite3_column_text(stmt, 0);
+                       LOG_ERR("ret_val: %s", ret_val);
+                       if (ret_val && strncmp(ret_val, "ok", strlen("ok")) == 0) {
+                               result = 0;
+                       } else {
+                               LOG_ERR("failed to check integrity");
+                               result = -1;
+                       }
+               } else {
+                       result = 0;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       return result;
+}
+
+int mdgd_db_init()
+{
+       int ret = 0;
+       int sql_ret;
+       char *error = NULL;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == NULL) {
+               sql_ret = sqlite3_open_v2(MDGD_DB_FILE, &(mdgd_ctx->db),
+                       SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_open_v2 failed, (%d)", sql_ret);
+                       goto ERR;
+               }
+
+               if (__check_integrity() < 0) {
+                       LOG_ERR("Failed to check integrity");
+                       unlink(MDGD_DB_FILE);
+                       mdgd_ctx->db = NULL;
+                       sql_ret = sqlite3_open_v2(MDGD_DB_FILE, &mdgd_ctx->db, SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+                       if (sql_ret != SQLITE_OK) {
+                               LOG_ERR("sqlite3_open_v2 failed, (%d)", sql_ret);
+                               goto ERR;
+                       }
+               }
+
+               /* Enable persist journal mode */
+               sql_ret = sqlite3_exec(mdgd_ctx->db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &error);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("Fail to change journal mode: (%d) %s", sql_ret, error);
+                       sqlite3_free(error);
+
+                       goto ERR;
+               }
+
+               __prepare_table();
+       }
+
+       if (mdgd_ctx->db != NULL) {
+               //iot activity per each column
+               LOG_ERR("comp db init");
+               //mdgd_group_create(group_name);
+       }
+
+       return ret;
+
+ERR:
+       if (mdgd_ctx->db != NULL) {
+               sql_ret = sqlite3_close(mdgd_ctx->db);
+               if (sql_ret == SQLITE_OK)
+                       mdgd_ctx->db = NULL;
+               else
+                       LOG_ERR("sqlite3_close failed, [%d]", sql_ret);
+       }
+
+       return ret;
+}
+int mdgd_db_deinit()
+{
+       int ret = 0;
+       int sql_ret;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db != NULL) {
+               sql_ret = sqlite3_close(mdgd_ctx->db);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_close failed, %d", sql_ret);
+                       return -1;
+               }
+               mdgd_ctx->db = NULL;
+       }
+
+       return ret;
+}
+
+int mdgd_db_insert(char *group_name, char *device_id)
+{
+       int ret = 0;
+       int sql_ret;
+       char *sql = NULL;
+       char *error = NULL;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == NULL) {
+               LOG_ERR("mtp_ctx->db is NULL");
+               return -1;
+       }
+
+       sql = sqlite3_mprintf("INSERT INTO %s (group_name, device_id) values(%Q, %Q);",
+               MDGD_DB_TABLE,
+               group_name,
+               device_id);
+
+       if (sql != NULL) {
+               sql_ret = sqlite3_exec(mdgd_ctx->db, sql, NULL, NULL, &error);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
+                       ret = -1;
+                       sqlite3_free(error);
+               }
+               sqlite3_free(sql);
+       } else {
+               LOG_ERR("sql is NULL");
+               ret = -1;
+       }
+
+       return ret;
+}
+
+int mdgd_db_delete_group(char *group_name)
+{
+       int ret = 0;
+       int sql_ret;
+       char *sql = NULL;
+       char *error = NULL;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == NULL) {
+               LOG_ERR("mdgd_ctx->db is NULL");
+               return -1;
+       }
+
+       if (group_name == NULL) {
+               LOG_ERR("group_name is NULL");
+               return -1;
+       }
+
+       sql = sqlite3_mprintf("DELETE FROM %s WHERE group_name=%Q",
+               MDGD_DB_TABLE,
+               group_name);
+
+       if (sql != NULL) {
+               sql_ret = sqlite3_exec(mdgd_ctx->db, sql, NULL, NULL, &error);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
+                       ret = -1;
+                       sqlite3_free(error);
+               }
+               sqlite3_free(sql);
+       } else {
+               LOG_ERR("sql is NULL");
+               ret = -1;
+       }
+
+       return ret;
+}
+
+int mdgd_db_delete_device(char *group_name, char *device_id)
+{
+       int ret = 0;
+       int sql_ret;
+       char *sql = NULL;
+       char *error = NULL;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->db == NULL) {
+               LOG_ERR("mdgd_ctx->db is NULL");
+               return -1;
+       }
+
+       if (group_name == NULL) {
+               LOG_ERR("group_name is NULL");
+               return -1;
+       }
+
+       if (device_id == NULL) {
+               LOG_ERR("device_id is NULL");
+               return -1;
+       }
+
+       sql = sqlite3_mprintf("DELETE FROM %s WHERE group_name=%Q and device_id=%Q",
+               MDGD_DB_TABLE,
+               group_name,
+               device_id);
+
+       if (sql != NULL) {
+               sql_ret = sqlite3_exec(mdgd_ctx->db, sql, NULL, NULL, &error);
+               if (sql_ret != SQLITE_OK) {
+                       LOG_ERR("sqlite3_exec failed, %d, %s", sql_ret, error);
+                       ret = -1;
+                       sqlite3_free(error);
+               }
+               sqlite3_free(sql);
+       } else {
+               LOG_ERR("sql is NULL");
+               ret = -1;
+       }
+
+       return ret;
+
+}
+
+int mdgd_db_print()
+{
+       return 0;
+}
+
diff --git a/src/mdg-manager/src/mdgd_gdbus.c b/src/mdg-manager/src/mdgd_gdbus.c
new file mode 100644 (file)
index 0000000..bf687ee
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_gdbus.h>
+#include <sys/types.h>
+
+#define DBUS_SERVICE_DBUS              "org.freedesktop.DBus"
+#define DBUS_INTERFACE_DBUS            "org.freedesktop.DBus"
+
+static Group *group_skeleton;
+static Enabler *enabler_skeleton;
+
+Group *group_dbus_get_object()
+{
+       return group_skeleton;
+}
+
+static bool __group_init(GDBusConnection *connection)
+{
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       GDBusObjectManagerServer *group;
+
+       // Add interface to default object path
+       group_skeleton = group_skeleton_new();
+
+       // Register for method callbacks as signal callbacks
+       g_signal_connect(group_skeleton,
+               "handle-create",
+               G_CALLBACK(group_create),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-find",
+               G_CALLBACK(group_find),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-found-groups",
+               G_CALLBACK(group_get_found_groups),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-join",
+               G_CALLBACK(group_join),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-leave",
+               G_CALLBACK(group_leave),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-delete",
+               G_CALLBACK(group_delete),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-device-find",
+               G_CALLBACK(group_device_find),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-invite",
+               G_CALLBACK(group_invite),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-eject",
+               G_CALLBACK(group_eject),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-device-invite",
+               G_CALLBACK(group_device_invite),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-device-eject",
+               G_CALLBACK(group_device_eject),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-remote-device",
+               G_CALLBACK(group_get_remote_device),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-pair-resource",
+               G_CALLBACK(group_pair_resource),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-unpair-resource",
+               G_CALLBACK(group_unpair_resource),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-send-data",
+               G_CALLBACK(group_send_data),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-find-mowned-devices",
+               G_CALLBACK(group_find_mowned_devices),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-mowned-device",
+               G_CALLBACK(group_get_mowned_device),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-my-mowned-device",
+               G_CALLBACK(group_get_my_mowned_device),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-my-uuid",
+               G_CALLBACK(group_get_my_uuid),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-request-create-group",
+               G_CALLBACK(group_request_create_group),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-request-invite",
+               G_CALLBACK(group_request_invite),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-request-eject",
+               G_CALLBACK(group_request_eject),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-request-delete-group",
+               G_CALLBACK(group_request_delete_group),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-start-invited-device-monitor",
+               G_CALLBACK(group_start_invited_device_monitor),
+               NULL);
+
+       group = g_dbus_object_manager_server_new(MDGD_DBUS_GROUP_PATH);
+
+       // Set connection to 'manager'
+       g_dbus_object_manager_server_set_connection(group, connection);
+
+       // Export 'group' interface on cmdgd DBUS
+       ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(group_skeleton),
+                               connection, MDGD_DBUS_GROUP_PATH, &error);
+
+       if (ret == FALSE) {
+               LOG_DEBUG("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return ret;
+}
+
+static void _app_conn_destroyed_cb(GDBusConnection *conn, const gchar *Name,
+                          const gchar *path, const gchar *interface, const gchar *sig,
+                          GVariant *param, gpointer user_data)
+{
+       gchar *name = NULL;
+       gchar *old = NULL;
+       gchar *new = NULL;
+       mdgd_conn_destroy_data *data = user_data;
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (param == NULL)
+               return;
+
+       g_variant_get(param, "(sss)", &name, &old, &new);
+
+       if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
+               LOG_DEBUG("App %s Destroyed: name %s id %d", data->conn_name, name,
+                       data->conn_id);
+
+               mdgd_ctx->ref_count -= 1;
+
+               g_dbus_connection_signal_unsubscribe(data->connection, data->conn_id);
+       }
+
+       g_free(name);
+       g_free(old);
+       g_free(new);
+       g_free(data->conn_name);
+       g_free(data);
+
+       if (mdgd_ctx->ref_count == 0) {
+               LOG_DEBUG("No app remaining quit comapnion-manager");
+               g_main_loop_quit(mdgd_ctx->main_loop);
+       }
+
+       return;
+}
+
+static gboolean _register_mdgd_conn_destroy_signal(Enabler *enabler,
+                                                                  gchar *name)
+{
+       mdgd_conn_destroy_data *data;
+       GDBusConnection *connection = NULL;
+
+       connection = g_dbus_interface_skeleton_get_connection(
+                                         (GDBusInterfaceSkeleton *)enabler_skeleton);
+       if (NULL == connection) {
+               LOG_ERR("Failed to get GDbus connection");
+               return FALSE;
+       }
+
+       data = g_try_malloc0(sizeof(mdgd_conn_destroy_data));
+       if (NULL == data) {
+               LOG_ERR("Failed to Allocate memory");
+               return FALSE;
+       }
+
+       data->conn_name = g_strdup(name);
+       data->connection = connection;
+
+       data->conn_id = g_dbus_connection_signal_subscribe(connection,
+                                                       DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
+                                                       "NameOwnerChanged", NULL, name,
+                                                       G_DBUS_SIGNAL_FLAGS_NONE, _app_conn_destroyed_cb,
+                                                       data, NULL);
+
+       return TRUE;
+}
+
+gboolean enabler_add_ref(Enabler *enabler, GDBusMethodInvocation *invocation,
+       gchar *name, gpointer user_data)
+{
+       LOG_DEBUG("Add Reference for %s", name);
+
+       if (TRUE == _register_mdgd_conn_destroy_signal(enabler, name)) {
+               mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+               mdgd_ctx->ref_count += 1;
+
+               enabler_complete_add_ref(enabler, invocation, 0);
+       } else {
+               LOG_ERR("Failed to register connection destroy signal");
+               enabler_complete_add_ref(enabler, invocation,
+                                        MDGD_ERROR_OPERATION_FAILED);
+       }
+
+       return TRUE;
+}
+
+static bool __enabler_init(GDBusConnection *connection)
+{
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       GDBusObjectManagerServer *enabler;
+
+       // Add interface to default object path
+       enabler_skeleton = enabler_skeleton_new();
+
+       // Register for method callbacks as signal callbacks
+       g_signal_connect(enabler_skeleton,
+               "handle-add-ref",
+               G_CALLBACK(enabler_add_ref),
+               NULL);
+
+       enabler = g_dbus_object_manager_server_new(MDGD_DBUS_ENABLER_PATH);
+
+       // Set connection to 'enabler'
+       g_dbus_object_manager_server_set_connection(enabler, connection);
+
+       // Export 'enabler' interface on mdg DBUS
+       ret = g_dbus_interface_skeleton_export(
+                               G_DBUS_INTERFACE_SKELETON(enabler_skeleton), connection,
+                               MDGD_DBUS_ENABLER_PATH, &error);
+
+       if (ret == FALSE) {
+               LOG_DEBUG("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return ret;
+}
+
+
+static void on_bus_acquired(GDBusConnection *connection, const gchar *path,
+       gpointer user_data)
+{
+       if (__group_init(connection) == false)
+               LOG_DEBUG("Can not signal connect");
+
+       if (__enabler_init(connection) == false)
+               LOG_ERR("Can't signal connect");
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name,
+       gpointer user_data)
+{
+       LOG_DEBUG("on_name_acquired : %s", name);
+}
+
+static void on_name_lost(GDBusConnection *connnection, const gchar *name,
+       gpointer user_data)
+{
+       LOG_DEBUG("on_name_lost : %s", name);
+}
+
+int mdgd_gdbus_init()
+{
+       g_bus_own_name(G_BUS_TYPE_SYSTEM, MDGD_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE,
+               on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
+
+       return 0;
+}
diff --git a/src/mdg-manager/src/mdgd_gdbus_group.c b/src/mdg-manager/src/mdgd_gdbus_group.c
new file mode 100644 (file)
index 0000000..b3224ff
--- /dev/null
@@ -0,0 +1,465 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_gdbus_group.h>
+
+/* GDBUS Group Layer */
+/* In this gdbus group layer, Please call the "fn_group" service layer function.*/
+
+gboolean group_create(Group *group, GDBusMethodInvocation *invocation,
+       gchar *group_name, gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("group create called using dbus successful");
+
+       result = mdgd_group_create(group_name);
+
+       group_complete_create(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gint timeout,
+       gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("group find called using dbus successful");
+
+       mdgd_group_find(timeout);
+
+       group_complete_find(group, invocation, result);
+       return TRUE;
+}
+
+gboolean group_get_found_groups(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data)
+{
+       gint result = 0;
+       GVariant *group_data;
+
+       LOG_DEBUG("get found groups called using dbus successful");
+
+       group_data = mdgd_group_get_found_groups();
+
+       group_complete_get_found_groups(group, invocation, result, group_data);
+       return TRUE;
+}
+
+gboolean group_join(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("join called using dbus successful");
+
+       result = mdgd_group_join();
+
+       group_complete_join(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_leave(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data)
+{
+       //group_complete_leave(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_delete(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data)
+{
+       //group_complete_delete(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation,
+       gint timeout, gpointer user_data)
+{
+       int result = 0;
+
+       result = mdgd_group_find_mot_enabled_devices(timeout);
+
+       group_complete_device_find(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gchar *pin, gchar *uri_1, gchar *rt_1,
+       gchar *interface_1, int permission_1, gchar *uri_2, gchar *rt_2,
+       gchar *interface_2, int permission_2, gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("group device invite called using dbus successful");
+/*
+       result = mdgd_group_invite(uuid_dev1, uuid_dev2, pin, uri_1, rt_1,
+                                       interface_1, permission_1, uri_2, rt_2, interface_2,
+                                       permission_2);
+*/
+       group_complete_device_invite(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("group device eject called using dbus successful");
+
+       result = mdgd_group_eject(NULL, uuid_dev1, uuid_dev2);
+
+       group_complete_device_eject(group, invocation, result);
+
+       return TRUE;
+}
+
+gboolean group_invite(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
+       gchar *uuid, gchar *pin, gpointer user_data)
+{
+       gint result = 0;
+
+       LOG_DEBUG("group invite called using dbus successful");
+
+       result = mdgd_group_invite(group_name, uuid, pin);
+
+       /* Now, for the sake of convenience, we change 'group_complete_invite' to 'group_complete_device_invite'. */
+#if 0
+       group_complete_invite(group, invocation, result);
+#else
+       group_complete_device_invite(group, invocation, result);
+#endif
+
+       return TRUE;
+}
+
+gboolean group_eject(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
+       gchar *uuid, gpointer user_data)
+{
+       gint result = 0;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       if (!mdgd_ctx) {
+               LOG_ERR("ctx is null");
+               return FALSE;
+       }
+
+       result = mdgd_group_eject(group_name, mdgd_ctx->device_uuid, uuid);
+
+       /* Now, for the sake of convenience, we change 'group_complete_eject' to 'group_complete_device_eject'. */
+#if 0
+       group_complete_invite(group, invocation, result);
+#else
+       group_complete_device_eject(group, invocation, result);
+#endif
+
+       return TRUE;
+}
+
+gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation,
+       gpointer user_data)
+{
+       int dev_count = 0;
+       GVariant *device_data;
+
+       LOG_DEBUG("get remote device called using dbus successful");
+
+       dev_count = mdgd_group_get_mot_device_count();
+       device_data = mdgd_group_get_remote_mot_enabled_devices();
+
+       group_complete_get_remote_device(group, invocation, dev_count, device_data);
+
+       return TRUE;
+}
+
+gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation,
+       gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1,
+       gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2,
+       gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2,
+       gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("pair resource called using dbus successful");
+
+       ret = mdgd_group_pair_resource(target_1, subject_1, uri_1, rt_1,
+                                          interface_1, permission_1, target_2, subject_2, uri_2,
+                                          rt_2, interface_2, permission_2);
+
+       group_complete_pair_resource(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("unpair resource called using dbus successful");
+
+       ret = mdgd_group_unpair_resource(uuid_dev1, uuid_dev2);
+
+       group_complete_unpair_resource(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid_dev, gchar *addr, int port, GVariant *params,
+       gpointer user_data)
+{
+       int ret = 0;
+       int length = 0;
+       int len;
+       unsigned char *data;
+       GVariantIter *iter;
+
+       LOG_DEBUG("send data called using dbus successful");
+
+       g_variant_get(params, "(iay)", &len, &iter);
+
+       data = g_try_malloc0(len + 1);
+       if (NULL == data) {
+               group_complete_send_data(group, invocation, -1);
+               LOG_ERR("Failed to allocate memory");
+               return TRUE;
+       }
+
+       while (g_variant_iter_loop(iter, "y", &data[length]))
+               length += 1;
+
+       g_variant_iter_free(iter);
+
+       ret = mdgd_group_send_data(uuid_dev, addr, port, data, len);
+
+       group_complete_send_data(group, invocation, 0);
+
+       g_free(data);
+
+       return ret;
+}
+
+gboolean group_find_mowned_devices(Group *group,
+       GDBusMethodInvocation *invocation, gint timeout, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("find mot owned devices called using dbus successful");
+
+       ret = mdgd_group_find_mowned_devices(timeout);
+
+       group_complete_find_mowned_devices(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_get_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int dev_count = 0;
+       GVariant *device_data;
+
+       LOG_DEBUG("get mowned device called using dbus successful");
+
+       dev_count = mdgd_group_get_mowned_device_count();
+       device_data = mdgd_group_get_mowned_devices();
+
+       group_complete_get_mowned_device(group, invocation, dev_count, device_data);
+
+       return TRUE;
+}
+
+gboolean group_get_my_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       GVariant *device_data;
+
+       LOG_DEBUG("get mowned device called using dbus successful");
+
+       device_data = mdgd_group_get_my_mowned_devices();
+       LOG_DEBUG("get mowned device called end ");
+
+       group_complete_get_my_mowned_device(group, invocation, device_data);
+
+       return TRUE;
+}
+
+gboolean group_get_my_uuid(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       LOG_DEBUG("get my uuid called using dbus successful");
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       group_complete_get_my_uuid(group, invocation, mdgd_ctx->device_uuid);
+
+       return TRUE;
+}
+
+gboolean group_request_create_group(Group *group, GDBusMethodInvocation
+       *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Request Create Group called using dbus successful");
+
+       ret = mdgd_group_request_create_group(uuid, group_name);
+
+       group_complete_request_create_group(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Request Invite called using dbus successful");
+
+       ret = mdgd_group_request_invite(uuid, group_name, target_uuid, PIN);
+
+       group_complete_request_invite(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Request Eject called using dbus successful");
+
+       ret = mdgd_group_request_eject(uuid, group_name, target_uuid);
+
+       group_complete_request_eject(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_request_delete_group(Group *group,
+       GDBusMethodInvocation *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Request Delete Group called using dbus successful");
+
+       ret = mdgd_group_request_delete_group(uuid, group_name);
+
+       group_complete_request_delete_group(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_start_invited_device_monitor(Group *group,
+                                       GDBusMethodInvocation *invocation, int start,
+                                       gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Start Myowned device monitor");
+
+       ret = mdgd_group_start_invited_device_monitor(start);
+
+       group_complete_start_invited_device_monitor(group, invocation, ret);
+
+       return TRUE;
+}
+
+void notify_group_found(GVariant *group_data)
+{
+       group_emit_group_found(group_dbus_get_object(), group_data);
+}
+
+void notify_group_find_finish(int ret)
+{
+       group_emit_group_find_finish(group_dbus_get_object(), ret);
+}
+
+void notify_device_found(int device_count, GVariant *device_data)
+{
+       group_emit_device_found(group_dbus_get_object(), device_count, device_data);
+}
+
+void notify_device_find_finish(int ret)
+{
+       group_emit_device_find_finish(group_dbus_get_object(), ret);
+}
+
+void notify_group_device_invite_result(int ret)
+{
+       group_emit_device_invite_result(group_dbus_get_object(), ret);
+}
+
+void notify_group_device_eject_result(int ret)
+{
+       group_emit_device_eject_result(group_dbus_get_object(), ret);
+}
+
+void notify_mowned_device_found(int device_count, GVariant *device_data)
+{
+       group_emit_mowned_device_found(group_dbus_get_object(), device_count, device_data);
+}
+
+void notify_mowned_device_find_finish(int ret)
+{
+       group_emit_mowned_device_find_finish(group_dbus_get_object(), ret);
+}
+void notify_group_join(int result)
+{
+       group_emit_join_result(group_dbus_get_object(), result);
+}
+
+void notify_send_data_finish(const char *resp_data, int ret)
+{
+       group_emit_send_data_finish(group_dbus_get_object(), resp_data, ret);
+}
+
+void notify_request_result(const char *cmd, const char *requester_id,
+                                                  unsigned char *arg, int len, int ret)
+{
+       GVariantBuilder *bytearray_builder = NULL;
+       GVariant *params = NULL;
+       int i;
+
+       bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+
+       for (i = 0; i < len; i++)
+               g_variant_builder_add(bytearray_builder, "y", arg[i]);
+
+       params = g_variant_new("(iay)", len, bytearray_builder);
+       g_variant_builder_unref(bytearray_builder);
+
+       group_emit_request_result(group_dbus_get_object(), cmd, requester_id,
+                                                         params, ret);
+}
+
+void notify_device_monitor_result(const char *uuid, const char *group_name,
+                                                                 const char *status)
+{
+       group_emit_device_monitor_result(group_dbus_get_object(), uuid, group_name,
+                                                                         status);
+}
+
diff --git a/src/mdg-manager/src/mdgd_group.c b/src/mdg-manager/src/mdgd_group.c
new file mode 100644 (file)
index 0000000..fed7a5e
--- /dev/null
@@ -0,0 +1,1354 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_enum.h>
+#include <mdgd_group.h>
+#include <mdgd_mot_agent.h>
+#include <mdgd_gdbus_group.h>
+#include <mdgd_db.h>
+#include <mdgd_util.h>
+
+GList *found_group_list;
+GList *mot_enb_dev_list = NULL;
+GList *mowned_dev_list = NULL;
+GList *invited_dev_list = NULL;
+mdgd_group_invite_info_t *group_invite_info = NULL;
+mdgd_mot_device_t *my_device = NULL;
+
+#define KEEPALIVE_MESSAGE_TIMEOUT 900
+#define CHECK_DEVICE_STATUS_TIMEOUT 3000
+
+/* Called when daemon is start. */
+int mdgd_group_initialize()
+{
+       //Initialize memory of context
+       //1. group creation
+       //db select
+       //2. device creation
+       //db select by group
+
+       return MDGD_ERROR_NONE;
+}
+
+typedef struct {
+       char *name; /**< Group name */
+       GList *device_list; /**< Remote device UUIDs. (char* type) */
+} mdgd_grp_t;
+
+void __print_foreach_device(gpointer data, gpointer user_data)
+{
+       char *uuid = (char *)data;
+       LOG_DEBUG("        - %s", uuid);
+}
+
+void __print_foreach_grp(gpointer data, gpointer user_data)
+{
+       mdgd_grp_t *grp = (mdgd_grp_t *)data;
+       LOG_DEBUG("Group name : %s", grp->name);
+       LOG_DEBUG("    <Device>");
+       g_list_foreach(grp->device_list, __print_foreach_device, NULL);
+       LOG_DEBUG("");
+}
+
+void __print_groups_information()
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret("mdgd_ctx", mdgd_ctx);
+
+       LOG_DEBUG("-------------------------------------------");
+       g_list_foreach(mdgd_ctx->grp_list, __print_foreach_grp, NULL);
+       LOG_DEBUG("-------------------------------------------");
+}
+
+/* create group and destroy */
+int mdgd_group_create(const char* name)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
+       GList *list = mdgd_ctx->grp_list;
+
+       GList *l;
+       for (l = list; l != NULL; l = l->next) {
+               mdgd_grp_t *grp = (mdgd_grp_t *)l->data;
+
+               if (strncmp(grp->name, name, strlen(name)) == 0) {
+                       LOG_ERR("already exists name in structure");
+                       return MDGD_ERROR_UNKNOWN;
+               }
+       }
+
+       ret = mdgd_iot_add_resource(MDGD_RESOURCE_TYPE_GROUP, name);
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("Add resource is failed : %s", mdgd_log_get_error_string(ret));
+       }
+
+       mdgd_grp_t *grp = g_new0(mdgd_grp_t, 1);
+       grp->name = strdup(name);
+
+       mdgd_ctx->grp_list = g_list_append(mdgd_ctx->grp_list, grp);
+
+       mdgd_group_add_device_in_group(name, mdgd_ctx->device_uuid);
+       mdgd_resource_print_list();
+       __print_groups_information();
+
+       LOG_END();
+
+       return MDGD_ERROR_NONE;
+}
+
+int mdgd_group_destroy(mdgd_group_t *handle)
+{
+       int ret = MDGD_ERROR_NONE;
+       NOTUSED(handle);
+       return ret;
+}
+
+static void _free_device_func(gpointer data)
+{
+       mdgd_check_null_ret("data", data);
+       g_free(data);
+       data = NULL;
+}
+
+static void _free_group_func(gpointer data)
+{
+       mdgd_group_t *group = (mdgd_group_t *)data;
+       mdgd_check_null_ret("group", group);
+
+       if (group->uri_path != NULL) {
+               g_free(group->uri_path);
+               group->uri_path = NULL;
+       }
+       if (group->device_id != NULL) {
+               g_free(group->device_id);
+               group->device_id = NULL;
+       }
+       if (group->group_name != NULL) {
+               g_free(group->group_name);
+               group->group_name = NULL;
+       }
+       if (group->host_addr != NULL) {
+               g_free(group->host_addr);
+               group->host_addr = NULL;
+       }
+       if (group->resource_type != NULL) {
+               g_free(group->resource_type);
+               group->resource_type = NULL;
+       }
+       g_free(group);
+       group = NULL;
+}
+
+static void _mot_enb_dev_list_free_func(gpointer data)
+{
+       mdgd_mot_device_t *device = (mdgd_mot_device_t *)data;
+       mdgd_check_null_ret("device", device);
+
+       if (device->device_id != NULL) {
+               g_free(device->device_id);
+               device->device_id = NULL;
+       }
+       if (device->addr != NULL) {
+               g_free(device->addr);
+               device->addr = NULL;
+       }
+       if (device->route_data != NULL) {
+               g_free(device->route_data);
+               device->route_data = NULL;
+       }
+       if (device->remote_id != NULL) {
+               g_free(device->remote_id);
+               device->remote_id = NULL;
+       }
+       if (device->sec_ver != NULL) {
+               g_free(device->sec_ver);
+               device->sec_ver = NULL;
+       }
+       g_free(device);
+       device = NULL;
+}
+
+int mdgd_group_find(int timeout)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       /* list freeing */
+       g_list_free_full(found_group_list, _free_group_func);
+       found_group_list = NULL;
+
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       mdgd_check_null_ret_error("cmd", cmd, MDGD_ERROR_INVALID_PARAMETER);
+       ret = mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_GROUP, timeout, cmd);
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("Failed to discover resource : %s", mdgd_log_get_error_string(ret));
+
+       LOG_END();
+
+       return ret;
+}
+
+GVariant *mdgd_group_get_found_groups()
+{
+       GVariantBuilder *builder;
+       GVariant *group_data;
+       GList *iter = NULL;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
+
+       iter = found_group_list;
+       while (iter != NULL) {
+               mdgd_group_t *group = (mdgd_group_t *)iter->data;
+
+               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
+               g_variant_builder_add(builder, "{sv}", "URI",
+                                                         g_variant_new_string(group->uri_path));
+               g_variant_builder_add(builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(group->device_id));
+               g_variant_builder_add(builder, "{sv}", "GroupName",
+                                                         g_variant_new_string(group->group_name));
+               g_variant_builder_add(builder, "{sv}", "HostAddress",
+                                                         g_variant_new_string(group->host_addr));
+               g_variant_builder_add(builder, "{sv}", "GroupDeviceType",
+                                                         g_variant_new_string(group->resource_type));
+               /*When we get found groups, we can get my groups also. */
+               g_variant_builder_add(builder, "{sv}", "GroupType",
+                                                         g_variant_new_int32(group->type));
+               g_variant_builder_close(builder);
+
+               iter = g_list_next(iter);
+       }
+
+       group_data = g_variant_builder_end(builder);
+       g_variant_builder_unref(builder);
+
+       return group_data;
+}
+
+int mdgd_group_add_new(char *uri_path, char *device_id, char *device_name,
+                                        char *host_addr, char *resource_type, mdgd_group_type_e type)
+{
+       mdgd_group_t *group;
+       GVariantBuilder *builder;
+       GVariant *group_data;
+
+       LOG_BEGIN();
+
+       group = g_try_malloc0(sizeof(mdgd_group_t));
+       group->uri_path = g_strdup(uri_path);
+       group->device_id = g_strdup(device_id);
+       group->group_name = g_strdup(device_name);
+       group->host_addr = g_strdup(host_addr);
+       group->resource_type =  g_strdup(resource_type);
+       group->type = type;
+
+       found_group_list = g_list_append(found_group_list, group);
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(builder, "{sv}", "URI",
+                                                 g_variant_new_string(group->uri_path));
+       g_variant_builder_add(builder, "{sv}", "DeviceID",
+                                                 g_variant_new_string(group->device_id));
+       g_variant_builder_add(builder, "{sv}", "GroupName",
+                                                 g_variant_new_string(group->group_name));
+       g_variant_builder_add(builder, "{sv}", "HostAddress",
+                                                 g_variant_new_string(group->host_addr));
+       g_variant_builder_add(builder, "{sv}", "GroupDeviceType",
+                                                 g_variant_new_string(group->resource_type));
+       g_variant_builder_add(builder, "{sv}", "GroupType",
+                                                 g_variant_new_int32(group->type));
+
+       group_data = g_variant_builder_end(builder);
+
+       notify_group_found(group_data);
+
+       g_variant_builder_unref(builder);
+
+       LOG_END();
+
+       return MDGD_ERROR_NONE;
+}
+
+/* Join the remote devices in my daemon */
+
+// Find MOT enabled devices
+int mdgd_group_add_new_mot_device(mdgd_mot_device_t *device)
+{
+       GList *iter = NULL;
+       gboolean is_exist = FALSE;
+
+       LOG_BEGIN();
+
+       iter = mot_enb_dev_list;
+       while (iter != NULL) {
+               mdgd_mot_device_t *temp = (mdgd_mot_device_t *)iter->data;
+
+               if (g_strcmp0(temp->device_id, device->device_id) == 0) {
+                       LOG_DEBUG("Device %s already exists in mot enable device list",
+                                         device->device_id);
+                       is_exist = TRUE;
+                       break;
+               }
+
+               iter = g_list_next(iter);
+       }
+
+       if (is_exist == FALSE) {
+               LOG_DEBUG("Add device with uuid %s to mot enabled device list",
+                                 device->device_id);
+               mot_enb_dev_list = g_list_append(mot_enb_dev_list, device);
+       }
+
+       LOG_END();
+
+       return is_exist;
+}
+
+
+GVariant *mdgd_group_get_remote_mot_enabled_devices()
+{
+       GVariantBuilder *builder;
+       GVariant *group_data;
+       GList *iter = NULL;
+
+       mdgd_remove_ip_info();
+       mdgd_make_ip_info();
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
+
+       iter = mot_enb_dev_list;
+       while (iter != NULL) {
+               mdgd_mot_device_t *device = (mdgd_mot_device_t *)iter->data;
+
+               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
+               g_variant_builder_add(builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(device->device_id));
+               g_variant_builder_add(builder, "{sv}", "Adapter",
+                                                         g_variant_new_int32(device->adapter));
+               g_variant_builder_add(builder, "{sv}", "Flags",
+                                                         g_variant_new_int32(device->flags));
+               g_variant_builder_add(builder, "{sv}", "Port",
+                                                         g_variant_new_uint16(device->port));
+               g_variant_builder_add(builder, "{sv}", "Address",
+                                                         g_variant_new_string(device->addr));
+               g_variant_builder_add(builder, "{sv}", "DeviceType",
+                                                         g_variant_new_uint16(mdgd_is_local_ip(device->addr)));
+               g_variant_builder_add(builder, "{sv}", "Ifindex",
+                                                         g_variant_new_int32(device->ifindex));
+               g_variant_builder_add(builder, "{sv}", "RouteData",
+                                                         g_variant_new_string(device->route_data));
+               g_variant_builder_add(builder, "{sv}", "ConnType",
+                                                         g_variant_new_int32(device->conn_type));
+               g_variant_builder_add(builder, "{sv}", "SecurePort",
+                                                         g_variant_new_uint16(device->secure_port));
+               g_variant_builder_add(builder, "{sv}", "TcpPort",
+                                                         g_variant_new_uint16(device->tcp_port));
+               g_variant_builder_add(builder, "{sv}", "SecVer",
+                                                         g_variant_new_string(device->sec_ver));
+               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
+                                                         g_variant_new_int32(device->dev_status));
+               LOG_DEBUG("%s", device->model_name);
+               g_variant_builder_add(builder, "{sv}", "ModelName",
+                                                         g_variant_new_string(device->model_name));
+               g_variant_builder_add(builder, "{sv}", "DeviceName",
+                                                         g_variant_new_string(device->device_name));
+               g_variant_builder_add(builder, "{sv}", "PlatformVer",
+                                                         g_variant_new_string(device->platform_ver));
+               g_variant_builder_add(builder, "{sv}", "VendorID",
+                                                         g_variant_new_string(device->vendor_id));
+               g_variant_builder_add(builder, "{sv}", "Profile",
+                                                         g_variant_new_string(device->profile));
+
+               g_variant_builder_close(builder);
+
+               iter = g_list_next(iter);
+       }
+
+       group_data = g_variant_builder_end(builder);
+       g_variant_builder_unref(builder);
+
+       return group_data;
+}
+
+int mdgd_group_get_mot_device_count()
+{
+       if (mot_enb_dev_list)
+               return g_list_length(mot_enb_dev_list);
+
+       return 0;
+}
+
+void mdgd_group_notify_mot_enable_device_done()
+{
+       GVariant *device_data;
+       int count = mdgd_group_get_mot_device_count();
+
+       LOG_BEGIN();
+
+       device_data = mdgd_group_get_remote_mot_enabled_devices();
+
+       notify_device_found(count, device_data);
+
+       LOG_END();
+}
+
+int mdgd_group_find_mot_enabled_devices(int timeout)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       /* list freeing */
+       g_list_free_full(mot_enb_dev_list, _mot_enb_dev_list_free_func);
+       mot_enb_dev_list = NULL;
+
+       ret = agent_find_mot_enable_devices(timeout);
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("Failed to find mot enable devices : %s",
+                                mdgd_log_get_error_string(ret));
+       }
+
+       LOG_END();
+
+       return ret;
+}
+
+void mdgd_group_notify_keepalive_response(mdgd_command_t *cmd)
+{
+       GList *iter = NULL;
+       gboolean is_exist = FALSE;
+       mdgd_invited_device_t *temp;
+
+       LOG_DEBUG("Response received from uuid %s", cmd->uuid);
+
+       iter = invited_dev_list;
+       while (iter != NULL) {
+               temp = (mdgd_invited_device_t *)iter->data;
+
+               if ((g_strcmp0(temp->group_name, cmd->arg1) == 0) &&
+                       (g_strcmp0(temp->uuid, cmd->uuid) == 0)) {
+                       LOG_DEBUG("Device %s count %d found in invited device list",
+                                         cmd->uuid, temp->count);
+                       is_exist = TRUE;
+                       break;
+               }
+
+               iter = g_list_next(iter);
+       }
+
+       if (is_exist == TRUE)
+               temp->count += 1;
+}
+
+int mdgd_group_request_keepalive(char *uuid, char *group_name, char *host)
+{
+       int ret = MDGD_ERROR_NONE;
+
+       LOG_DEBUG("[Request KeepAlive] to %s", uuid);
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       cmd->command = MDGD_REQ_KEEP_ALIVE;
+       cmd->uuid = g_strdup(uuid);
+       cmd->arg1 = g_strdup(group_name);
+       cmd->host = g_strdup(host);
+
+       ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 2, cmd);
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("Failed to send data : %s",
+                               mdgd_log_get_error_string(ret));
+               return ret;
+       }
+
+       return 0;
+}
+
+mdgd_group_invite_info_t *mdgd_group_get_invite_info()
+{
+       return group_invite_info;
+}
+
+void mdgd_group_free_invite_info()
+{
+       LOG_DEBUG("Remove Group Invite Information %p", group_invite_info);
+
+       if (group_invite_info) {
+               g_free(group_invite_info->group_name);
+               g_free(group_invite_info->uuid_dev1);
+               g_free(group_invite_info->uuid_dev2);
+               g_free(group_invite_info->pin);
+               g_free(group_invite_info->uri_1);
+               g_free(group_invite_info->rt_1);
+               g_free(group_invite_info->interface_1);
+               g_free(group_invite_info->uri_2);
+               g_free(group_invite_info->rt_2);
+               g_free(group_invite_info->interface_2);
+               g_free(group_invite_info);
+
+               group_invite_info = NULL;
+       }
+}
+
+static mdgd_mot_device_t *_check_device_in_mot_enb_dev_list(char *uuid)
+{
+       mdgd_mot_device_t *device;
+       GList *iter;
+
+       iter = mot_enb_dev_list;
+
+       while (iter != NULL) {
+               device = (mdgd_mot_device_t *)iter->data;
+
+               if (g_strcmp0(device->device_id, uuid) == 0) {
+                       LOG_DEBUG("Device %s is available in mot enable device list", uuid);
+                       return device;
+               }
+       }
+
+       return NULL;
+}
+
+static char *_addr2host(char *addr, int port)
+{
+       char ip[50];
+       char *percent;
+
+       g_strlcpy(ip, addr, strlen(addr) + 1);
+
+       /* Remove % from address */
+       percent = strchr(ip, '%');
+       if (percent)
+               percent[0] = '\0';
+
+       /* IPv6 Address should be encoded for RFC6874  */
+       if (strchr(ip, ':')) /* IPv6 Adress */
+               return g_strdup_printf("coaps://[%s%s%s]:%d", ip, "%25",
+                                                                       percent + 1, port);
+       else /* IPv4 Address */
+               return g_strdup_printf("coaps://%s:%d", ip, port);
+}
+
+void mdgd_group_notify_group_invite(int ret)
+{
+       /*
+        * ret = 0 OC_STACK_OK
+        * ret = 49 OC_STACK_DUPLICATE_UUID
+        */
+       if ((ret == 0 || ret == 49) && group_invite_info) {
+               mdgd_invited_device_t *device;
+               GList *iter = NULL;
+               gboolean is_exist = FALSE;
+
+               device = g_try_malloc0(sizeof(mdgd_invited_device_t));
+               device->group_name = g_strdup(group_invite_info->group_name);
+               device->uuid = g_strdup(group_invite_info->uuid_dev2);
+
+               iter = invited_dev_list;
+               while (iter != NULL) {
+                       mdgd_invited_device_t *temp = (mdgd_invited_device_t *)iter->data;
+
+                       if ((g_strcmp0(temp->group_name, device->group_name) == 0) &&
+                               (g_strcmp0(temp->uuid, device->uuid) == 0)) {
+                               LOG_DEBUG("Device %s already exists in invited device list",
+                                                 temp->uuid);
+                               is_exist = TRUE;
+                               break;
+                       }
+
+                       iter = g_list_next(iter);
+               }
+
+               if (is_exist == FALSE) {
+                       mdgd_mot_device_t *temp;
+                       temp = _check_device_in_mot_enb_dev_list(device->uuid);
+                       if (temp)
+                               device->host = _addr2host(temp->addr, temp->secure_port);
+
+                       device->count = 0;
+                       LOG_DEBUG("Add device %s group %s host %s to invited device list",
+                                         device->uuid, device->group_name, device->host);
+                       invited_dev_list = g_list_prepend(invited_dev_list, device);
+
+                       mdgd_group_request_keepalive(device->uuid, device->group_name,
+                                                                                device->host);
+
+                       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+                       mdgd_check_null_ret("mdgd_ctx", mdgd_ctx);
+
+                       if (mdgd_ctx->monitor_started == true) {
+                               notify_device_monitor_result(device->uuid, device->group_name,
+                                                                                        "Added");
+
+                               mdgd_group_start_invited_device_monitor(1);
+                       }
+
+               } else {
+                       g_free(device->uuid);
+                       g_free(device->group_name);
+                       g_free(device);
+               }
+       }
+
+       mdgd_group_free_invite_info();
+
+       notify_group_device_invite_result(ret);
+}
+
+
+#define FULL_PERMISSION 31
+
+int _is_pairwise_uuid(char *uuid)
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, -1);
+
+       GList *iter = NULL;
+
+       iter = mdgd_ctx->pairwise_list;
+       while (iter != NULL) {
+               char *pairwise_uuid = (char *)iter->data;
+
+               if (strncmp(pairwise_uuid, uuid, strlen(uuid)) == 0)
+                       return 0;
+
+               iter = g_list_next(iter);
+       }
+
+       return -1;
+}
+
+int mdgd_group_add_device_in_group(const char *group_name, const char *uuid)
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, -1);
+
+       GList *iter = NULL;
+
+       iter = mdgd_ctx->grp_list;
+       while (iter != NULL) {
+               mdgd_grp_t *group = (mdgd_grp_t *)iter->data;
+
+               if (strncmp(group_name, group->name, strlen(group_name)) == 0) {
+                       GList *device_iter = group->device_list;
+                       while (device_iter != NULL) {
+                               char *device_uuid = (char *)device_iter->data;
+                               if (strncmp(device_uuid, uuid, strlen(uuid)) == 0)
+                                       return -1;
+
+                               device_iter = g_list_next(device_iter);
+                       }
+
+                       group->device_list = g_list_append(group->device_list, strdup(uuid));
+                       mdgd_db_insert(group_name, uuid);
+
+                       __print_groups_information();
+                       return 0;
+               }
+
+               iter = g_list_next(iter);
+       }
+
+       return -1;
+}
+
+//Join to device in group (async)
+int mdgd_group_invite(const char *group_name, const char *uuid, const char *pin)
+{
+       int ret = MDGD_ERROR_NONE;
+
+       LOG_BEGIN();
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
+
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+       /*
+        * 1. Perform MOT
+        * 2. Discover Mowned devices
+        * 3. Pairwise
+        */
+       LOG_DEBUG("group name : %s, uuid : %s", group_name, uuid);
+
+       if (_is_pairwise_uuid(uuid) < 0) {
+
+               ret = agent_mot(uuid, pin);
+               if (ret == MDGD_ERROR_NONE) {
+                       group_invite_info = g_try_malloc0(sizeof(mdgd_group_invite_info_t));
+                       group_invite_info->uuid_dev1 = g_strdup(mdgd_ctx->device_uuid);
+                       group_invite_info->uuid_dev2 = g_strdup(uuid);
+                       group_invite_info->pin = g_strdup(pin);
+                       group_invite_info->uri_1 = g_strdup("/comp/data/1");
+                       group_invite_info->rt_1 = g_strdup("core.comp.data");
+                       group_invite_info->interface_1 = g_strdup("oic.if.baseline");
+                       group_invite_info->permission_1 = FULL_PERMISSION;
+                       group_invite_info->uri_2 = g_strdup("/comp/data/1");
+                       group_invite_info->rt_2 = g_strdup("core.comp.data");
+                       group_invite_info->interface_2 = g_strdup("oic.if.baseline");
+                       group_invite_info->permission_2 = FULL_PERMISSION;
+               }
+       }
+
+#else
+       group_invite_info = g_try_malloc0(sizeof(mdgd_group_invite_info_t));
+       group_invite_info->uuid_dev2 = g_strdup(uuid);
+       group_invite_info->group_name = g_strdup(group_name);
+
+       ret = agent_pair(pin, mdgd_ctx->device_uuid, uuid, "/comp/data/1",
+                                        "core.comp.data", "oic.if.baseline", FULL_PERMISSION, uuid,
+                                        mdgd_ctx->device_uuid, "/comp/data/1", "core.comp.data",
+                                        "oic.if.baseline", FULL_PERMISSION);
+#endif
+
+       if (mdgd_group_add_device_in_group(group_name, uuid) < 0)
+               return MDGD_ERROR_NONE;
+
+       LOG_END();
+
+       return ret;
+}
+
+void mdgd_group_notify_group_dismiss(int result)
+{
+       LOG_DEBUG("Notify group eject %d", result);
+
+       notify_group_device_eject_result(result);
+}
+
+int mdgd_group_remove_device_in_group(char *group_name, char *uuid)
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, -1);
+
+       GList *iter = NULL;
+
+       /* Find the device at every group in list */
+       iter = mdgd_ctx->grp_list;
+       while (iter != NULL) {
+               mdgd_grp_t *group = (mdgd_grp_t *)iter->data;
+               if (strncmp(group_name, group->name, strlen(group_name)) == 0) {
+                       GList *device_iter = group->device_list;
+
+                       device_iter = g_list_remove_all(device_iter, uuid);
+               }
+
+               iter = g_list_next(iter);
+       }
+       mdgd_db_delete_device(group_name, uuid);
+       __print_groups_information();
+
+       return 0;
+}
+
+//dismiss from group (async)
+int mdgd_group_eject(const gchar *group_name, gchar *uuid_dev1, const gchar *uuid_dev2)
+{
+       int ret;
+
+       LOG_BEGIN();
+ #ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+       ret = agent_remove_mo_at_device(uuid);
+       /*
+        * 1. Unpair device
+        * 2. Remove MOT at device #2
+        * 3. Remove cred at local (device #1)
+        * */
+#else
+       ret = agent_unpair(uuid_dev1, uuid_dev2);
+#endif
+       mdgd_group_remove_device_in_group(group_name, uuid_dev2);
+
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_group_pair_resource(char* target1, char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, char* target2, char *subject2,
+       char *uri2, char *rt2, char *interface2, int permission2)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       ret = agent_resources_pairwise(target1, subject1, uri1, rt1, interface1, permission1,
+                                                target2, subject2, uri2, rt2, interface2, permission2);
+
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       ret = agent_unlink_resources(uuid_dev1, uuid_dev2);
+
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_group_send_data(gchar *uuid_dev, gchar *addr, int port,
+                                                unsigned char *data, int len)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       mdgd_command_t *cmd = g_try_malloc0(sizeof(mdgd_command_t));
+       if (NULL == cmd) {
+               ret = MDGD_ERROR_OUT_OF_MEMORY;
+               LOG_ERR("Failed to alloc memory");
+               return ret;
+       }
+
+       cmd->command = MDGD_REQ_SEND_DATA;
+       cmd->uuid = g_strdup(uuid_dev);
+
+       cmd->host = _addr2host(addr, port);
+
+#ifdef SUPPORT_BASE64_ENCODING
+       cmd->data = g_try_malloc0(len + 1);
+       if (NULL == cmd->data) {
+               ret = MDGD_ERROR_OUT_OF_MEMORY;
+               LOG_ERR("Send Data Fail to uuid = %s host %s error=%s",
+                       cmd->uuid, cmd->host, mdgd_log_get_error_string(ret));
+               return ret;
+       }
+
+       memcpy(cmd->data, data, len);
+       cmd->data_len = len;
+#else
+       cmd->arg1 = g_try_malloc0(len + 1);
+       if (NULL == cmd->arg1) {
+               ret = MDGD_ERROR_OUT_OF_MEMORY;
+               LOG_ERR("Send Data Fail to uuid = %s host %s error=%s",
+                       cmd->uuid, cmd->host, mdgd_log_get_error_string(ret));
+               return ret;
+       }
+
+       memcpy(cmd->arg1, data, len);
+       cmd->arg1[len] = '\0';
+#endif
+
+       LOG_DEBUG("UUID %s host %s", cmd->uuid, cmd->host);
+
+       ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 3, cmd);
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("Failed to send data : %s",
+                               mdgd_log_get_error_string(ret));
+       }
+
+       LOG_END();
+
+       return ret;
+}
+
+int  mdgd_group_add_new_mowned_device(mdgd_mot_device_t *device)
+{
+       GList *iter = NULL;
+       gboolean is_exist = FALSE;
+
+       LOG_BEGIN();
+
+       iter = mowned_dev_list;
+       while (iter != NULL) {
+               mdgd_mot_device_t *temp = (mdgd_mot_device_t *)iter->data;
+
+               if (g_strcmp0(temp->device_id, device->device_id) == 0) {
+                       LOG_DEBUG("Device %s already exists in mowned device list",
+                                         device->device_id);
+                       is_exist = TRUE;
+                       break;
+               }
+
+               iter = g_list_next(iter);
+       }
+
+       if (is_exist == FALSE) {
+               LOG_DEBUG("Add device with uuid %s to mowned device list",
+                                 device->device_id);
+               mowned_dev_list = g_list_append(mowned_dev_list, device);
+       }
+
+       LOG_END();
+
+       return is_exist;
+}
+
+GVariant *mdgd_group_get_mowned_devices()
+{
+       GVariantBuilder *builder;
+       GVariant *group_data;
+       GList *iter = NULL;
+
+       mdgd_remove_ip_info();
+       mdgd_make_ip_info();
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
+
+       iter = mowned_dev_list;
+       while (iter != NULL) {
+               mdgd_mot_device_t *device = (mdgd_mot_device_t *)iter->data;
+
+               g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
+               g_variant_builder_add(builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(device->device_id));
+               g_variant_builder_add(builder, "{sv}", "Adapter",
+                                                         g_variant_new_int32(device->adapter));
+               g_variant_builder_add(builder, "{sv}", "Flags",
+                                                         g_variant_new_int32(device->flags));
+               g_variant_builder_add(builder, "{sv}", "Port",
+                                                         g_variant_new_uint16(device->port));
+               g_variant_builder_add(builder, "{sv}", "Address",
+                                                         g_variant_new_string(device->addr));
+               g_variant_builder_add(builder, "{sv}", "DeviceType",
+                                                         g_variant_new_uint16(mdgd_is_local_ip(device->addr)));
+               g_variant_builder_add(builder, "{sv}", "Ifindex",
+                                                         g_variant_new_int32(device->ifindex));
+               g_variant_builder_add(builder, "{sv}", "RouteData",
+                                                         g_variant_new_string(device->route_data));
+               g_variant_builder_add(builder, "{sv}", "ConnType",
+                                                         g_variant_new_int32(device->conn_type));
+               g_variant_builder_add(builder, "{sv}", "SecurePort",
+                                                         g_variant_new_uint16(device->secure_port));
+               g_variant_builder_add(builder, "{sv}", "TcpPort",
+                                                         g_variant_new_uint16(device->tcp_port));
+               g_variant_builder_add(builder, "{sv}", "SecVer",
+                                                         g_variant_new_string(device->sec_ver));
+               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
+                                                         g_variant_new_int32(device->dev_status));
+               g_variant_builder_add(builder, "{sv}", "ModelName",
+                                                         g_variant_new_string(device->model_name));
+               g_variant_builder_add(builder, "{sv}", "DeviceName",
+                                                         g_variant_new_string(device->device_name));
+               g_variant_builder_add(builder, "{sv}", "PlatformVer",
+                                                         g_variant_new_string(device->platform_ver));
+               g_variant_builder_add(builder, "{sv}", "VendorID",
+                                                         g_variant_new_string(device->vendor_id));
+               g_variant_builder_add(builder, "{sv}", "Profile",
+                                                         g_variant_new_string(device->profile));
+
+               g_variant_builder_close(builder);
+
+               iter = g_list_next(iter);
+       }
+
+       group_data = g_variant_builder_end(builder);
+       g_variant_builder_unref(builder);
+
+       return group_data;
+}
+
+void mdgd_group_change_mowned_device(mdgd_mot_device_t *device)
+{
+       LOG_BEGIN();
+
+       my_device = device;
+
+       LOG_END();
+}
+
+GVariant *mdgd_group_get_my_mowned_devices()
+{
+       GVariantBuilder *builder;
+       GVariant *group_data;
+
+       mdgd_remove_ip_info();
+       mdgd_make_ip_info();
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       if (my_device != NULL) {
+               g_variant_builder_add(builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(my_device->device_id));
+               g_variant_builder_add(builder, "{sv}", "Adapter",
+                                                         g_variant_new_int32(my_device->adapter));
+               g_variant_builder_add(builder, "{sv}", "Flags",
+                                                         g_variant_new_int32(my_device->flags));
+               g_variant_builder_add(builder, "{sv}", "Port",
+                                                         g_variant_new_uint16(my_device->port));
+               g_variant_builder_add(builder, "{sv}", "Address",
+                                                         g_variant_new_string(my_device->addr));
+               g_variant_builder_add(builder, "{sv}", "DeviceType",
+                                                         g_variant_new_uint16(mdgd_is_local_ip(my_device->addr)));
+               g_variant_builder_add(builder, "{sv}", "Ifindex",
+                                                         g_variant_new_int32(my_device->ifindex));
+               g_variant_builder_add(builder, "{sv}", "RouteData",
+                                                         g_variant_new_string(my_device->route_data));
+               g_variant_builder_add(builder, "{sv}", "ConnType",
+                                                         g_variant_new_int32(my_device->conn_type));
+               g_variant_builder_add(builder, "{sv}", "SecurePort",
+                                                         g_variant_new_uint16(my_device->secure_port));
+               g_variant_builder_add(builder, "{sv}", "TcpPort",
+                                                         g_variant_new_uint16(my_device->tcp_port));
+               g_variant_builder_add(builder, "{sv}", "SecVer",
+                                                         g_variant_new_string(my_device->sec_ver));
+               g_variant_builder_add(builder, "{sv}", "DeviceStatus",
+                                                         g_variant_new_int32(my_device->dev_status));
+               g_variant_builder_add(builder, "{sv}", "ModelName",
+                                                         g_variant_new_string(my_device->model_name));
+               g_variant_builder_add(builder, "{sv}", "DeviceName",
+                                                         g_variant_new_string(my_device->device_name));
+               g_variant_builder_add(builder, "{sv}", "PlatformVer",
+                                                         g_variant_new_string(my_device->platform_ver));
+               g_variant_builder_add(builder, "{sv}", "VendorID",
+                                                         g_variant_new_string(my_device->vendor_id));
+               g_variant_builder_add(builder, "{sv}", "Profile",
+                                                         g_variant_new_string(my_device->profile));
+       }
+
+       group_data = g_variant_builder_end(builder);
+       g_variant_builder_unref(builder);
+
+       return group_data;
+}
+
+int mdgd_group_get_mowned_device_count()
+{
+       if (mowned_dev_list)
+               return g_list_length(mowned_dev_list);
+
+       return 0;
+}
+
+void mdgd_group_notify_mowned_device_find_done()
+{
+       GVariant *device_data;
+       int count = g_list_length(mowned_dev_list);
+
+       LOG_BEGIN();
+
+       device_data = mdgd_group_get_mowned_devices();
+
+       notify_mowned_device_found(count, device_data);
+
+       LOG_END();
+}
+
+int mdgd_group_find_mowned_devices(int timeout)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       /* list freeing */
+       g_list_free_full(mowned_dev_list, _mot_enb_dev_list_free_func);
+       mowned_dev_list = NULL;
+
+       ret = agent_find_mowned_devices(timeout);
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("Failed to find mowned devices : %s",
+                                mdgd_log_get_error_string(ret));
+       }
+
+       LOG_END();
+
+       return ret;
+}
+
+/* Join to remote device group */
+
+int mdgd_group_join()
+{
+       int ret = MDGD_ERROR_NONE;
+
+       LOG_BEGIN();
+
+
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_group_leave_from(/* callback */) //leave from certain remote group (Async)
+{
+       int ret = MDGD_ERROR_NONE;
+       return ret;
+}
+
+/* Called when daemon is end. */
+int mdgd_group_deinitialize()
+{
+       int ret = MDGD_ERROR_NONE;
+       return ret;
+}
+
+int mdgd_group_get_group_name(mdgd_group_t *handle, char **name)
+{
+       int ret = MDGD_ERROR_NONE;
+       NOTUSED(handle);
+       NOTUSED(name);
+       return ret;
+}
+
+int mdgd_group_get_group_type(mdgd_group_t *handle, int *type)
+{
+       int ret = MDGD_ERROR_NONE;
+       NOTUSED(handle);
+       NOTUSED(type);
+       return ret;
+}
+
+int mdgd_group_get_group_device_type(mdgd_group_t *handle)
+{
+       int ret = MDGD_ERROR_NONE;
+       NOTUSED(handle);
+       return ret;
+}
+
+int mdgd_group_get_group_device_id(mdgd_group_t *handle)
+{
+       int ret = MDGD_ERROR_NONE;
+       NOTUSED(handle);
+       return ret;
+}
+
+int mdgd_group_request_create_group(char *uuid, char *group_name)
+{
+       int ret = MDGD_ERROR_NONE;
+       mdgd_mot_device_t *device;
+
+       LOG_ERR("[Request Create Group] %s", group_name);
+       LOG_ERR("[Request Create Group] to %s", uuid);
+
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       cmd->command = MDGD_REQ_CREATE_GROUP;
+       cmd->uuid = g_strdup(uuid);
+       cmd->arg1 = g_strdup(group_name);
+
+       device = _check_device_in_mot_enb_dev_list(uuid);
+       if (device) {
+               cmd->host = _addr2host(device->addr, device->secure_port);
+               ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to send data : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       } else {
+               ret = mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to discover resource : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       }
+
+       return ret;
+}
+
+int mdgd_group_request_invite(char *uuid, char *group_name, char *target_uuid, char *PIN)
+{
+       int ret = MDGD_ERROR_NONE;
+       mdgd_mot_device_t *device;
+
+       LOG_ERR("[Request Invite] %s, %s, %s", group_name, target_uuid, PIN);
+       LOG_ERR("[Request Invite] to %s", uuid);
+
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       cmd->command = MDGD_REQ_INVITE_DEVICE;
+       cmd->uuid = g_strdup(uuid);
+       cmd->arg1 = g_strdup(group_name);
+       cmd->arg2 = g_strdup(target_uuid);
+       cmd->arg3 = g_strdup(PIN);
+
+       device = _check_device_in_mot_enb_dev_list(uuid);
+       if (device) {
+               cmd->host = _addr2host(device->addr, device->secure_port);
+               ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to send data : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       } else {
+               ret = mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to discover resource : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       }
+
+       return ret;
+}
+
+
+int mdgd_group_request_eject(char *uuid, char *group_name, char *target_uuid)
+{
+       int ret = MDGD_ERROR_NONE;
+       mdgd_mot_device_t *device;
+
+       LOG_ERR("[Request Eject] %s, %s", group_name, target_uuid);
+       LOG_ERR("[Request Eject] to %s", uuid);
+
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       cmd->command = MDGD_REQ_EJECT_DEVICE;
+       cmd->uuid = g_strdup(uuid);
+       cmd->arg1 = g_strdup(group_name);
+       cmd->arg2 = g_strdup(target_uuid);
+
+       device = _check_device_in_mot_enb_dev_list(uuid);
+       if (device) {
+               cmd->host = _addr2host(device->addr, device->secure_port);
+               ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to send data : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       } else {
+               ret = mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to discover resource : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       }
+
+       return ret;
+
+}
+
+
+int mdgd_group_request_delete_group(char *uuid, char *group_name)
+{
+       int ret = MDGD_ERROR_NONE;
+       mdgd_mot_device_t *device;
+
+       LOG_ERR("[Request Delete Group] %s", group_name);
+       LOG_ERR("[Request Delete Group] to %s", uuid);
+
+       mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+       cmd->command = MDGD_REQ_DELETE_GROUP;
+       cmd->uuid = g_strdup(uuid);
+       cmd->arg1 = g_strdup(group_name);
+
+       device = _check_device_in_mot_enb_dev_list(uuid);
+       if (device) {
+               cmd->host = _addr2host(device->addr, device->secure_port);
+               ret = mdgd_iot_send_data(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to send data : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       } else {
+               ret = mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DATA, 5, cmd);
+               if (ret != MDGD_ERROR_NONE) {
+                       LOG_ERR("Failed to discover resource : %s",
+                                       mdgd_log_get_error_string(ret));
+               }
+       }
+
+       return ret;
+}
+
+static gboolean __send_keepalive_messages(gpointer user_data)
+{
+       GList *iter = NULL;
+
+       iter = invited_dev_list;
+       while (iter != NULL) {
+               mdgd_invited_device_t *temp = (mdgd_invited_device_t *)iter->data;
+
+               mdgd_group_request_keepalive(temp->uuid, temp->group_name, temp->host);
+
+               iter = g_list_next(iter);
+       }
+
+       return TRUE;
+}
+
+static gboolean __check_invited_device_status(gpointer user_data)
+{
+       int *t_id = (int *)user_data;
+       GList *iter = NULL;
+
+       g_source_remove(*t_id);
+       *t_id = 0;
+
+       iter = invited_dev_list;
+       while (iter != NULL) {
+               mdgd_invited_device_t *temp = (mdgd_invited_device_t *)iter->data;
+
+               iter = g_list_next(iter);
+
+               LOG_DEBUG("uuid %s count %d", temp->uuid, temp->count);
+
+               if (temp->count == 0) {
+                       LOG_DEBUG("Remove device with uuid %s", temp->uuid);
+                       invited_dev_list = g_list_remove(invited_dev_list, temp);
+
+                       notify_device_monitor_result(temp->uuid, temp->group_name,
+                                                                                "Removed");
+
+                       g_free(temp->host);
+                       g_free(temp->uuid);
+                       g_free(temp->group_name);
+                       g_free(temp);
+               } else {
+                       temp->count = 0;
+               }
+       }
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, FALSE);
+
+       if (mdgd_ctx->monitor_started == false) {
+               g_free(t_id);
+               return FALSE;
+       }
+
+       if (g_list_length(invited_dev_list) == 0) {
+               g_free(t_id);
+               return FALSE;
+       }
+
+       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
+                                                 NULL);
+
+       return TRUE;
+}
+
+int mdgd_group_start_invited_device_monitor(int start)
+{
+       int *t_id;
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx,
+                                                         MDGD_ERROR_INVALID_PARAMETER);
+
+       if (start) { /* Start Monitor */
+               mdgd_ctx->monitor_started = true;
+               LOG_DEBUG("Start invited device monitor");
+       } else { /* Stop Monitor */
+               mdgd_ctx->monitor_started = false;
+               LOG_DEBUG("Stop invited device monitor");
+               return MDGD_ERROR_NONE;
+       }
+
+       t_id = g_try_malloc0(sizeof(int));
+
+       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
+                                                 NULL);
+
+       g_timeout_add(CHECK_DEVICE_STATUS_TIMEOUT, __check_invited_device_status,
+                                                 t_id);
+
+       return MDGD_ERROR_NONE;
+}
diff --git a/src/mdg-manager/src/mdgd_iot.cpp b/src/mdg-manager/src/mdgd_iot.cpp
new file mode 100644 (file)
index 0000000..2a2fdf2
--- /dev/null
@@ -0,0 +1,1196 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <tzplatform_config.h>
+
+#include <utlist.h>
+#include <base64.h>
+#include <sys/utsname.h>
+
+#include <octypes.h>
+#include <pmtypes.h>
+#include <pmutility.h>
+#include <securevirtualresourcetypes.h>
+
+#include <iotivity_config.h>
+#include <platform_features.h>
+#include <ocprovisioningmanager.h>
+#include <doxmresource.h>
+#include <system_info.h>
+#include <vconf.h>
+#include <system_settings.h>
+
+#include <mdgd_iot.h>
+#include <mdgd_group.h>
+#include <mdgd_gdbus_group.h>
+#include <mdgd_mot_agent.h>
+
+#include "OCProvisioningManager.hpp"
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+
+#define MAX_FILE_PATH_LEN 1024
+#define SVR_DB_FILE_NAME "oic_svr_db_mdgd_manager.dat"
+#define SYSTEM_INFO_PLATFORM_VERSION "http://tizen.org/feature/platform.version"
+#define SYSTEM_INFO_MANUF_NAME "http://tizen.org/system/manufacturer"
+#define SYSTEM_INFO_MODEL_NAME "http://tizen.org/system/model_name"
+#define SYSTEM_INFO_BUILD_STRING "http://tizen.org/system/build.string"
+#define SYSTEM_INFO_TIZEN_ID "http://tizen.org/system/tizenid"
+#define SYSTEM_INFO_PROFILE "http://tizen.org/feature/profile"
+
+int last_get_result;
+OCPersistentStorage ps;
+
+static int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
+{
+       if (NULL == uuid || NULL == strUuid || NULL != *strUuid) {
+               LOG_ERR("ConvertUuidToStr : Invalid param");
+               return OC_STACK_INVALID_PARAM;
+       }
+
+       size_t uuidIdx = 0;
+       size_t urnIdx = 0;
+       const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
+       char* convertedUrn = (char*)calloc(urnBufSize, sizeof(char));
+       if (NULL == convertedUrn) {
+               LOG_ERR("Memory Allocation Failed");
+               goto exit;
+       }
+
+       for (uuidIdx = 0, urnIdx = 0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize;
+               uuidIdx++, urnIdx += 2) {
+               // canonical format for UUID has '8-4-4-4-12'
+               if (uuidIdx == 4 || uuidIdx == 6 || uuidIdx == 8 || uuidIdx == 10) {
+                       snprintf(convertedUrn + urnIdx, 2, "%c", '-');
+                       urnIdx++;
+               }
+               snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
+       }
+       convertedUrn[urnBufSize - 1] = '\0';
+
+       *strUuid = convertedUrn;
+       return OC_STACK_OK;
+
+exit:
+       return OC_STACK_NO_MEMORY;
+}
+
+#define CASE_TO_STR(x) case x: return #x;
+
+static const char *command2string(mdgd_request_type_e command)
+{
+       switch (command) {
+       CASE_TO_STR(MDGD_REQ_SEND_DATA)
+       CASE_TO_STR(MDGD_REQ_CREATE_GROUP)
+       CASE_TO_STR(MDGD_REQ_INVITE_DEVICE)
+       CASE_TO_STR(MDGD_REQ_EJECT_DEVICE)
+       CASE_TO_STR(MDGD_REQ_DELETE_GROUP)
+       default:
+               return "Unknown Command";
+       }
+}
+
+static mdgd_request_type_e string2command(char *command)
+{
+       if (g_strcmp0(command, "5") == 0)
+               return MDGD_REQ_SEND_DATA;
+       else if (g_strcmp0(command, "1") == 0)
+               return MDGD_REQ_CREATE_GROUP;
+       else if (g_strcmp0(command, "2") == 0)
+               return MDGD_REQ_INVITE_DEVICE;
+       else if (g_strcmp0(command, "3") == 0)
+               return MDGD_REQ_EJECT_DEVICE;
+       else if (g_strcmp0(command, "4") == 0)
+               return MDGD_REQ_DELETE_GROUP;
+       else
+               return MDGD_REQ_UNKNOWN_COMMAND;
+}
+
+static FILE* client_open(const char* /*path*/, const char *mode)
+{
+       char data_dir[MAX_FILE_PATH_LEN] = {0,};
+
+       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
+                       "/opt/usr/data", SVR_DB_FILE_NAME);
+
+       LOG_DEBUG("Open file %s", data_dir);
+
+    return fopen(data_dir, mode);
+}
+
+int __mdgd_iot_get_platform_info(OCPlatformInfo *platform_info)
+{
+       int ret;
+       char *tizen_id = NULL;
+       char *device_name = NULL;
+       char platform_id[1024];
+
+       device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+       if (device_name == NULL)
+               LOG_ERR("vconf_get_str() Fail");
+
+       ret = system_info_get_platform_string(SYSTEM_INFO_TIZEN_ID, &tizen_id);
+       if (SYSTEM_INFO_ERROR_NONE != ret)
+               LOG_ERR("system_info_get_platform_string() Fail(%d)", ret);
+
+       snprintf(platform_id, sizeof(platform_id), "%s(%s)",
+                        device_name ? device_name : "", tizen_id ? tizen_id : "");
+
+       free(device_name);
+       free(tizen_id);
+       LOG_DEBUG("platform_id: %s", platform_id);
+
+       /* Mandatory (oic.wk.p) */
+       platform_info->platformID = strdup(platform_id);
+
+       /* Mandatory (oic.wk.p) */
+       ret = system_info_get_platform_string(SYSTEM_INFO_MANUF_NAME,
+                       &platform_info->manufacturerName);
+       if (SYSTEM_INFO_ERROR_NONE != ret) {
+               LOG_ERR("system_info_get_platform_string(manufacturer) Fail(%d)", ret);
+               free(platform_info->platformID);
+               return -1;
+       }
+
+       ret = system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME,
+                       &platform_info->modelNumber);
+       if (SYSTEM_INFO_ERROR_NONE != ret)
+               LOG_ERR("system_info_get_platform_string(model_name) Fail(%d)", ret);
+
+       ret = system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION,
+                       &platform_info->platformVersion);
+       if (SYSTEM_INFO_ERROR_NONE != ret)
+               LOG_ERR("system_info_get_platform_string(platform_version) Fail(%d)", ret);
+
+       ret = system_info_get_platform_string(SYSTEM_INFO_BUILD_STRING,
+                       &platform_info->firmwareVersion);
+       if (SYSTEM_INFO_ERROR_NONE != ret)
+               LOG_ERR("system_info_get_platform_string(build_string) Fail(%d)", ret);
+
+       platform_info->manufacturerUrl = g_strdup("NONE");
+       platform_info->dateOfManufacture = g_strdup("NONE");
+
+       struct utsname uts;
+
+       if (!uname(&uts))
+               platform_info->operatingSystemVersion = g_strdup(uts.sysname);
+       else
+               platform_info->operatingSystemVersion = g_strdup("NONE");
+
+       platform_info->hardwareVersion = g_strdup("0-0");
+       platform_info->supportUrl = g_strdup("NONE");
+       platform_info->systemTime = g_strdup("NONE");
+
+       return 0;
+}
+
+static void _clean_platform_info(OCPlatformInfo *platform_info)
+{
+       mdgd_check_null_ret("platform_info", platform_info);
+
+       if (platform_info->platformID) {
+               free(platform_info->platformID);
+               platform_info->platformID = NULL;
+       }
+       if (platform_info->manufacturerName) {
+               free(platform_info->manufacturerName);
+               platform_info->manufacturerName = NULL;
+       }
+       if (platform_info->modelNumber) {
+               free(platform_info->modelNumber);
+               platform_info->modelNumber = NULL;
+       }
+       if (platform_info->platformVersion) {
+               free(platform_info->platformVersion);
+               platform_info->platformVersion = NULL;
+       }
+       if (platform_info->firmwareVersion) {
+               free(platform_info->firmwareVersion);
+               platform_info->firmwareVersion = NULL;
+       }
+       if (platform_info->manufacturerUrl) {
+               free(platform_info->manufacturerUrl);
+               platform_info->manufacturerUrl = NULL;
+       }
+       if (platform_info->dateOfManufacture) {
+               free(platform_info->dateOfManufacture);
+               platform_info->dateOfManufacture = NULL;
+       }
+       if (platform_info->operatingSystemVersion) {
+               free(platform_info->operatingSystemVersion);
+               platform_info->operatingSystemVersion = NULL;
+       }
+       if (platform_info->hardwareVersion) {
+               free(platform_info->hardwareVersion);
+               platform_info->hardwareVersion = NULL;
+       }
+       if (platform_info->supportUrl) {
+               free(platform_info->supportUrl);
+               platform_info->supportUrl = NULL;
+       }
+       if (platform_info->systemTime) {
+               free(platform_info->systemTime);
+               platform_info->systemTime = NULL;
+       }
+}
+
+int mdgd_iot_initialize()
+{
+       char *device_id = NULL;
+       int ret;
+       OCPlatformInfo platform_info = {0};
+
+       ps.open = client_open;
+       ps.read = fread;
+       ps.write = fwrite;
+       ps.close = fclose;
+       ps.unlink = unlink;
+
+       PlatformConfig cfg {
+               OC::ServiceType::InProc,
+                       OC::ModeType::Both,
+                       (OCTransportAdapter)(OCTransportAdapter::OC_ADAPTER_IP),
+                       OC::QualityOfService::LowQos,
+                       &ps
+       };
+
+       OCPlatform::Configure(cfg);
+
+       ret = __mdgd_iot_get_platform_info(&platform_info);
+       if (ret != 0) {
+               _clean_platform_info(&platform_info);
+               LOG_ERR("Failed to get platform info %d", ret);
+               return MDGD_ERROR_NONE;
+       }
+
+       ret = OCPlatform::registerPlatformInfo(platform_info);
+       if (ret != OC_STACK_OK)
+       {
+               _clean_platform_info(&platform_info);
+               LOG_ERR("Platform Registration failed");
+               return MDGD_ERROR_NONE;
+    }
+       _clean_platform_info(&platform_info);
+
+       OCDeviceInfo device_info = {0};
+       device_info.deviceName = g_strdup("UNKNOWN");
+
+       ret = OCPlatform::registerDeviceInfo(device_info);
+
+       if (ret != OC_STACK_OK)
+       {
+               LOG_ERR("Device Registration failed");
+               return MDGD_ERROR_NONE;
+    }
+
+       g_free(device_info.deviceName);
+
+       OicUuid_t uuid;
+
+       ret = GetDoxmDeviceID(&uuid);
+       if      (OC_STACK_OK != ret)
+               LOG_DEBUG("GetDoxmDevOwnerId failed = [%d][%s]", ret, get_error_message(ret));
+
+       ret = ConvertUuidToStr(&uuid, &device_id);
+       if (OC_STACK_OK != ret)
+               LOG_DEBUG("ConvertUuidToStr failed = [%d][%s]", ret, get_error_message(ret));
+
+       LOG_DEBUG("device_id : %s", device_id);
+
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
+
+       mdgd_ctx->device_uuid = g_strdup(device_id);
+
+       /* Do Self-Ownership Transfer */
+       ret = OCSecure::configSelfOwnership();
+       if (OC_STACK_OK != ret ) {
+               LOG_ERR( "OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret));
+       }
+
+       /*
+               "Device" resource
+               For get peer description.
+               ex) /comp/device
+       */
+       mdgd_iot_add_resource(MDGD_RESOURCE_TYPE_DEVICE, "");
+
+       /*
+               "operation" resource
+               The operation resource is a control command channel between daemon and daemon.
+               resource type is core.comp.operation
+               Within this function we create a default operation resource. (uri is /comp/operation/1)
+               If we need more control channels, increase the number.
+               ex) /comp/operation/2, /comp/operation/3
+       */
+       mdgd_iot_add_resource(MDGD_RESOURCE_TYPE_OPERATION, "1");
+
+       /*
+               "DATA" resource
+               To show the send data to remote daemon.
+               It can be used when the remote device is mot enable and pairwise.
+               ex) /comp/data/1
+       */
+       mdgd_iot_add_resource(MDGD_RESOURCE_TYPE_DATA, "1");
+
+       return MDGD_ERROR_NONE;
+}
+
+static void _print_oc_representation(OCRepresentation rep)
+{
+       /* attribute.type() is an enum class AttributeType defined in
+        * AttributeValue.h header file of IoTivity */
+       for (auto& attribute : rep) {
+               LOG_DEBUG("%s of type %d with value %s", attribute.attrname().c_str(),
+                                 attribute.type(),
+                                 attribute.getValueToString().c_str());
+       }
+}
+
+OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> request)
+{
+       LOG_DEBUG("_request_handler is called");
+
+       if (request) {
+               std::string requestType = request->getRequestType();
+               int requestFlag = request->getRequestHandlerFlag();
+
+               LOG_DEBUG("request type %s flag %x", requestType.c_str(), requestFlag);
+
+               if (requestType == "GET") {
+                       //Send Peer Description
+                       LOG_DEBUG("requestFlag : GET");
+                       auto pResponse = std::make_shared<OC::OCResourceResponse>();
+                       OCRepresentation rep;
+
+                       /* Set Peer Description */
+
+                       char *device_name = NULL;
+                       char *model_name = NULL;
+                       char *platform_ver = NULL;
+                       char *profile = NULL;
+                       char *vendor_id = NULL;
+
+                       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
+                       system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
+                       system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
+                       system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
+                       /* How to get the vendor id? */
+
+                       LOG_DEBUG("device name : %s", device_name);
+                       LOG_DEBUG("model name : %s", model_name);
+                       LOG_DEBUG("platform ver name : %s", platform_ver);
+                       LOG_DEBUG("profile : %s", profile);
+
+                       rep.setValue("model_name", std::string(model_name));
+                       rep.setValue("platform_ver", std::string(platform_ver));
+                       rep.setValue("profile", std::string(profile));
+                       rep.setValue("device_name", std::string(device_name));
+                       rep.setValue("vendor_id", std::string("6FFF"));
+
+                       pResponse->setRequestHandle(request->getRequestHandle());
+                       pResponse->setResourceHandle(request->getResourceHandle());
+                       pResponse->setErrorCode(200);
+                       pResponse->setResponseResult(OC_EH_OK);
+                       pResponse->setResourceRepresentation(rep, DEFAULT_INTERFACE);
+                       OCPlatform::sendResponse(pResponse);
+               } else if (requestType == "POST") {
+                       if (requestFlag & RequestHandlerFlag::RequestFlag) {
+                               LOG_DEBUG("requestFlag : Request");
+                               auto pResponse = std::make_shared<OC::OCResourceResponse>();
+                               unsigned char *arg = NULL;
+                               int arg_len = 0;
+                               int result;
+                               int cmd;
+                               std::string requester_id, group_name, uuid, data;
+#ifdef SUPPORT_BASE64_ENCODING
+                               int payload_len;
+                               size_t outSize;
+                               uint8_t *out;
+                               uint32_t len = 0;
+#endif
+                               mdgd_context_t *mdgd_ctx;
+
+                               try {
+                                       OCRepresentation rep = request->getResourceRepresentation();
+
+                                       _print_oc_representation(rep);
+
+                                       ObservationInfo observationInfo = request->getObservationInfo();
+                                       LOG_DEBUG("Received request from %s:%d",
+                                                 observationInfo.address.c_str(), observationInfo.port);
+
+                                       if (!rep.getValue("CMD", cmd))
+                                               LOG_ERR("CMD not found in representation");
+                                       else
+                                               LOG_DEBUG("Command received %d", cmd);
+
+                                       if (!rep.getValue("device_id", requester_id))
+                                               LOG_ERR("device_id not found in representation");
+                                       else
+                                               LOG_DEBUG("device_id received %s", requester_id.c_str());
+
+                                       switch(cmd) {
+                                       case MDGD_REQ_SEND_DATA:
+                                               LOG_DEBUG("Receive Data");
+#ifdef SUPPORT_BASE64_ENCODING
+                                               if (!rep.getValue("data", data))
+                                                       LOG_ERR("data not found");
+
+                                               /*
+                                                * BASE64 encoding/decoding system use '=' as padding byte
+                                                * But, query parameter does not allow use '=' character.Basically,
+                                                * So, in order to use BASE64 as query parameters, we need additioinal length param
+                                                * such as 'len=xx'
+                                                */
+                                               payload_len = strlen(data.c_str()); /* This data may be cliped the last padding 1~2 bytes ('='/'==') */
+
+                                               LOG_DEBUG("data = %s payload_len = %d", data.c_str(),
+                                                                 payload_len);
+
+                                               outSize = B64DECODE_OUT_SAFESIZE(payload_len + 1);
+                                               out = (uint8_t *)g_try_malloc0(outSize);
+                                               if (NULL == out) {
+                                                       LOG_ERR("Can't allocate memory for base64 str");
+                                                       return OC_EH_OK;
+                                               }
+
+                                               if (B64_OK != b64Decode(data.c_str(), payload_len, out,
+                                                                                          outSize, &len)) {
+                                                       LOG_ERR("Base64 decoding failed.");
+                                                       g_free(out);
+                                                       return OC_EH_OK;
+                                               }
+
+                                               arg = (unsigned char *) g_try_malloc0(len);
+                                               memcpy(arg, out, len);
+                                               arg_len = len;
+
+                                               g_free(out);
+
+                                               LOG_DEBUG("Successfully decoded from base64");
+#else
+                                               if (!rep.getValue("data", data))
+                                                       LOG_ERR("data not found");
+
+                                               LOG_DEBUG("Receive Data = %s", data.c_str());
+                                               arg = (unsigned char *) g_strdup(data.c_str());
+                                               arg_len = strlen(data.c_str());
+#endif
+                                               break;
+                                       case MDGD_REQ_CREATE_GROUP:
+                                               LOG_DEBUG("Request create group");
+
+                                               if (rep.getValue("name", group_name)) {
+                                                       LOG_DEBUG("group_name : %s", group_name.c_str());
+                                                       result = mdgd_group_create(group_name.c_str());
+                                                       arg = (unsigned char *) g_strdup(group_name.c_str());
+                                                       arg_len = strlen(group_name.c_str());
+                                               }
+                                               break;
+                                       case MDGD_REQ_INVITE_DEVICE:
+                                               LOG_DEBUG("Request invite device");
+
+                                               if (!rep.getValue("name", group_name))
+                                                       LOG_ERR("Group name not found");
+                                               if (!rep.getValue("id", uuid))
+                                                       LOG_ERR("UUID not found");
+
+                                               LOG_DEBUG("group name : %s, UUID : %s", group_name.c_str(),
+                                                                 uuid.c_str());
+
+                                               result = mdgd_group_invite(group_name.c_str(),
+                                                                          uuid.c_str(), "12341234");
+                                               arg = (unsigned char *) g_strdup(uuid.c_str());
+                                               arg_len = strlen(uuid.c_str());
+                                               break;
+                                       case MDGD_REQ_EJECT_DEVICE:
+                                               LOG_DEBUG("Request eject device");
+
+                                               mdgd_ctx = mdgd_context_get_context();
+
+                                               if (!rep.getValue("name", group_name))
+                                                       LOG_ERR("Group name not found");
+                                               if (!rep.getValue("id", uuid))
+                                                       LOG_ERR("UUID not found");
+
+                                               LOG_DEBUG("group name : %s Self UUID : %s Target UUID : %s",
+                                                                 group_name.c_str(),mdgd_ctx->device_uuid,
+                                                                 uuid.c_str());
+
+                                               result = mdgd_group_eject(group_name.c_str(), mdgd_ctx->device_uuid,
+                                                                          uuid.c_str());
+                                               arg = (unsigned char *) g_strdup(uuid.c_str());
+                                               arg_len = strlen(uuid.c_str());
+                                               break;
+                                       case MDGD_REQ_DELETE_GROUP:
+                                               LOG_DEBUG("Request delete group");
+                                               arg = (unsigned char *) g_strdup("DELETED");
+                                               arg_len = strlen("DELETED");
+                                               break;
+                                       case MDGD_REQ_KEEP_ALIVE:
+                                               LOG_DEBUG("Keep Alive message");
+
+                                               if (rep.getValue("group_name", group_name)) {
+                                                       LOG_DEBUG("group_name : %s", group_name.c_str());
+                                               }
+                                               break;
+                                       default:
+                                               LOG_ERR("Unknown request command %d", cmd);
+                                               break;
+                                       }
+
+                                       if (cmd != MDGD_REQ_KEEP_ALIVE) {
+                                               const char *cmd_str;
+                                               cmd_str = command2string((mdgd_request_type_e) cmd);
+                                               notify_request_result(cmd_str, requester_id.c_str(), arg,
+                                                                                         arg_len, result);
+                                       }
+
+                                       g_free(arg);
+
+                                       pResponse->setRequestHandle(request->getRequestHandle());
+                                       pResponse->setResourceHandle(request->getResourceHandle());
+                                       pResponse->setErrorCode(200);
+                                       pResponse->setResponseResult(OC_EH_OK);
+                                       OCPlatform::sendResponse(pResponse);
+                               } catch (std::exception& e) {
+                                       LOG_ERR("Exceptioin occured %s", e.what());
+                               }
+                       }
+               } else {
+                       LOG_ERR("Invalid Request Type");
+                       return OC_EH_OK;
+               }
+       }
+
+       return OC_EH_OK;
+}
+
+int mdgd_iot_add_resource(mdgd_resource_type_e resource_type, const char *uri)
+{
+       OCResourceHandle resourceHandle;
+       std::string uri_path;
+
+       uri_path =  std::string(mdgd_resource_get_uri_prefix(resource_type)) +
+                               std::string(uri);
+
+       LOG_DEBUG("[ADD] resource uri is %s", uri_path.c_str());
+
+       OCStackResult result = OCPlatform::registerResource(resourceHandle,
+                                                       uri_path,
+                                                       std::string(mdgd_resource_get_type(resource_type)),
+                                                       std::string(DEFAULT_INTERFACE), &_request_handler,
+                                                       mdgd_resource_get_policies(resource_type));
+       if (result != OC_STACK_OK) {
+               LOG_ERR("Failed to create resource");
+               return MDGD_ERROR_NONE;
+       }
+
+       LOG_DEBUG("Successfully created resource");
+
+       //Append to resource list
+       mdgd_resource_append(resource_type, uri_path.c_str());
+
+       return MDGD_ERROR_NONE;
+}
+
+int found_group_count = 0;
+
+static void _clear_user_data(void *user_data)
+{
+       mdgd_command_t *cmd = (mdgd_command_t *)user_data;
+
+       if (NULL == cmd)
+               return;
+
+       if (cmd->tid) {
+               g_source_remove(cmd->tid);
+       }
+
+       if (cmd->uuid) {
+               g_free(cmd->uuid);
+               cmd->uuid = NULL;
+       }
+       if (cmd->host) {
+               g_free(cmd->host);
+               cmd->host = NULL;
+       }
+       if (cmd->arg1) {
+               g_free(cmd->arg1);
+               cmd->arg1 = NULL;
+       }
+       if (cmd->arg2) {
+               g_free(cmd->arg2);
+               cmd->arg2 = NULL;
+       }
+       if (cmd->arg3) {
+               g_free(cmd->arg3);
+               cmd->arg3 = NULL;
+       }
+       if (cmd->arg4) {
+               g_free(cmd->arg4);
+               cmd->arg4 = NULL;
+       }
+
+#ifdef SUPPORT_BASE64_ENCODING
+       if (cmd->data) {
+               g_free(cmd->data);
+               cmd->data = NULL;
+       }
+#endif
+
+       g_free(cmd);
+       cmd = NULL;
+}
+
+static void _on_post(const HeaderOptions& /*headerOptions*/,
+                                        const OCRepresentation& rep, const int eCode,
+                                        void *user_data)
+{
+       int ret;
+       mdgd_command_t *cmd = (mdgd_command_t *)user_data;
+
+       try {
+               if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED ||
+                       eCode == OC_STACK_RESOURCE_CHANGED) {
+                       last_get_result = 0;
+                       LOG_DEBUG("Post request is successful");
+
+                       if (cmd->command == MDGD_REQ_KEEP_ALIVE) {
+                               mdgd_group_notify_keepalive_response(cmd);
+                               return;
+                       }
+               } else {
+                       last_get_result = eCode;
+                       LOG_ERR("_on_post Response error %d", eCode);
+               }
+       } catch(std::exception& e) {
+               LOG_ERR("Exception %s in on post", e.what());
+       }
+
+       notify_send_data_finish("RESP_DATA", last_get_result);
+
+       //_clear_user_data(cmd);
+}
+
+static void _on_get(const HeaderOptions& /*headerOptions*/,
+                               const OCRepresentation& rep, const int eCode,
+                               void *user_data)
+{
+       int ret;
+       LOG_DEBUG("On get function.");
+
+       try {
+               if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED ||
+                       eCode == OC_STACK_RESOURCE_CHANGED) {
+                       gchar *key;
+                       GVariant *val;
+                       gsize len = 0;
+                       mdgd_mot_device_t *device = (mdgd_mot_device_t *)user_data;
+                       mdgd_check_null_ret("device", device);
+
+                       std::string modelName;
+                       std::string platformVer;
+                       std::string Profile;
+                       std::string deviceName;
+                       std::string vendorID;
+
+                       rep.getValue("model_name", modelName);
+                       rep.getValue("platform_ver", platformVer);
+                       rep.getValue("profile", Profile);
+                       rep.getValue("device_name", deviceName);
+                       rep.getValue("vendor_id", vendorID);
+
+                       mdgd_check_null_ret("modelName", modelName.c_str());
+                       mdgd_check_null_ret("platformVer", platformVer.c_str());
+                       mdgd_check_null_ret("Profile", Profile.c_str());
+                       mdgd_check_null_ret("deviceName", deviceName.c_str());
+                       mdgd_check_null_ret("vendorID", vendorID.c_str());
+
+                       device->model_name = g_strdup(modelName.c_str());
+                       device->platform_ver= g_strdup(platformVer.c_str());
+                       device->profile = g_strdup(Profile.c_str());
+                       device->device_name = g_strdup(deviceName.c_str());
+                       device->vendor_id = g_strdup(vendorID.c_str());
+
+                       if (device->mowned == false)
+                               mdgd_group_add_new_mot_device(device);
+                       else
+                               mdgd_group_add_new_mowned_device(device);
+               } else {
+                       LOG_ERR("_on_get Response error %d", eCode);
+               }
+       } catch(std::exception& e) {
+               LOG_ERR("Exception %s in on get", e.what());
+       }
+}
+
+static int _perform_mot_me(gpointer data)
+{
+       int ret;
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, FALSE);
+
+       ret = agent_mot(mdgd_ctx->device_uuid, "12341234");
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("agent_mot(%s) Failed", mdgd_ctx->device_uuid);
+
+       return FALSE;
+}
+
+static bool _found_resource(std::shared_ptr<OCResource> resource,
+                                                       void *user_data)
+{
+       int ret;
+       char *resource_uri_path;
+       char *resource_device_id = NULL;
+       char *resource_host;
+       char *resource_type = NULL;
+       mdgd_group_type_e group_type;
+       std::string resourceURI;
+       std::string hostAddress;
+
+       LOG_DEBUG("Found Resource");
+       try {
+               if (resource) {
+                       resource_host = g_strdup(resource->host().c_str());
+
+                       resource_uri_path = g_strdup(resource->uri().c_str());
+                       resource_device_id = g_strdup(resource->sid().c_str());
+
+                       LOG_DEBUG("Resource URI : %s", resource_uri_path);
+                       LOG_DEBUG("Host Address : %s", resource_host);
+
+                       LOG_DEBUG("Resource Device ID : %s", resource_device_id);
+
+                       for(auto &resourceTypes : resource->getResourceTypes()) {
+                               resource_type = g_strdup(resourceTypes.c_str());
+                               LOG_DEBUG("Resource Type : %s", resource_type);
+                       }
+
+                       if (g_strcmp0(resource_type, "core.comp.group") == 0) {
+                               mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+                               if (g_strcmp0(resource_device_id, mdgd_ctx->device_uuid) == 0)
+                                       group_type = MDGD_GROUP_GROUP_LOCAL;
+                               else
+                                       group_type = MDGD_GROUP_GROUP_REMOTE;
+
+                               char *temp = g_strdup(resource_uri_path);
+                               char *ptr = strtok(temp, "/");
+                               ptr = strtok(NULL, "/");
+                               ptr = strtok(NULL, "/");
+
+                               LOG_DEBUG("group name is %s", ptr);
+                               mdgd_group_add_new(resource_uri_path, resource_device_id, ptr,
+                                                                  resource_host, resource_type, group_type);
+                               found_group_count++;
+
+                               g_free(temp);
+
+                       } else if (g_strcmp0(resource_type, "core.comp.device") == 0) {
+                               mdgd_command_t *cmd = (mdgd_command_t *)user_data;
+                               GVariant *parameters = (GVariant *)cmd->user_data;
+                               GVariant *device_info;
+                               bool mowned;
+                               GVariantIter *iter = NULL;
+                               gchar *key;
+                               mdgd_mot_device_t *device = NULL;
+
+                               if (NULL == parameters) {
+                                       LOG_ERR("No Multiple Owned devices found");
+                                       return TRUE;
+                               }
+
+                               if (strncmp(cmd->arg1, "disc_mot_enb_devs_done", strlen(cmd->arg1)) == 0)
+                                       mowned = false;
+                               else
+                                       mowned = true;
+
+                               g_variant_get(parameters, "(aa{sv})", &iter);
+                               while ((device_info = g_variant_iter_next_value(iter))) {
+                                       GVariant *val = g_variant_lookup_value(device_info, "deviceId", G_VARIANT_TYPE_STRING);
+                                       gsize len = 0;
+                                       const char *device_id = g_variant_get_string(val, &len);
+                                       if (g_strcmp0(resource_device_id, device_id) == 0) {
+                                               device = (mdgd_mot_device_t *)g_try_malloc0(sizeof(mdgd_mot_device_t));
+
+                                               LOG_DEBUG("deviceId = %s", device_id);
+                                               device->device_id = g_strdup(device_id);
+
+                                               val = g_variant_lookup_value(device_info, "adapter", G_VARIANT_TYPE_INT32);
+                                               int adapter = g_variant_get_int32(val);
+                                               device->adapter = adapter;
+
+                                               val = g_variant_lookup_value(device_info, "flags", G_VARIANT_TYPE_INT32);
+                                               int flags = g_variant_get_int32(val);
+                                               LOG_DEBUG("flags = %d", flags);
+                                               device->flags = flags;
+
+                                               val = g_variant_lookup_value(device_info, "port", G_VARIANT_TYPE_UINT16);
+                                               int port = g_variant_get_uint16(val);
+                                               LOG_DEBUG("port = %d", port);
+                                               device->port = port;
+
+                                               val = g_variant_lookup_value(device_info, "addr", G_VARIANT_TYPE_STRING);
+                                               const char *addr = g_variant_get_string(val, &len);
+                                               LOG_DEBUG("addr = %s", addr);
+                                               device->addr = g_strdup(addr);
+
+                                               val = g_variant_lookup_value(device_info, "ifindex", G_VARIANT_TYPE_INT32);
+                                               int ifindex = g_variant_get_int32(val);
+                                               LOG_DEBUG("ifindex = %d", ifindex);
+                                               device->ifindex = ifindex;
+
+                                               val = g_variant_lookup_value(device_info, "routeData", G_VARIANT_TYPE_STRING);
+                                               const char *routeData = g_variant_get_string(val, &len);
+                                               LOG_DEBUG("routeData = %s", routeData);
+                                               device->route_data = g_strdup(routeData);
+
+                                               val = g_variant_lookup_value(device_info, "remoteId", G_VARIANT_TYPE_STRING);
+                                               const char *remoteId = g_variant_get_string(val, &len);
+                                               LOG_DEBUG("remoteId = %s", remoteId);
+                                               device->remote_id = g_strdup(remoteId);
+
+                                               val = g_variant_lookup_value(device_info, "connType", G_VARIANT_TYPE_UINT32);
+                                               int connType = g_variant_get_uint32(val);
+                                               LOG_DEBUG("connType = %d", connType);
+                                               device->conn_type = connType;
+
+                                               val = g_variant_lookup_value(device_info, "securePort", G_VARIANT_TYPE_UINT16);
+                                               int securePort = g_variant_get_uint16(val);
+                                               LOG_DEBUG("securePort = %d", securePort);
+                                               device->secure_port = securePort;
+#ifdef WITH_TCP
+                                               val = g_variant_lookup_value(device_info, "tcpPort", G_VARIANT_TYPE_UINT16);
+                                               int tcpPort = g_variant_get_uint16(val);
+                                               LOG_DEBUG("tcpPort = %d", tcpPort);
+                                               device->tcp_port = tcpPort;
+#endif
+                                               val = g_variant_lookup_value(device_info, "secVer", G_VARIANT_TYPE_STRING);
+                                               const char *secVer = g_variant_get_string(val, &len);
+                                               LOG_DEBUG("secVer = %s", secVer);
+                                               device->sec_ver = g_strdup(secVer);
+
+                                               val = g_variant_lookup_value(device_info, "devStatus", G_VARIANT_TYPE_UINT32);
+                                               int devStatus = g_variant_get_uint32(val);
+                                               LOG_DEBUG("devStatus = %d", devStatus);
+                                               device->dev_status = devStatus;
+
+                                               device->mowned = mowned;
+                                       }
+                               }
+
+                               mdgd_check_null_ret_error("device", device, TRUE);
+
+                               if (strncmp(cmd->uuid, resource_device_id, strlen(resource_device_id)) != 0) {
+                                       LOG_DEBUG("Get peer description from another device");
+                                       /* Get Peer Description using "Get" operation */
+                                       device->type = MDGD_GROUP_DEVICE_REMOTE;
+                                       resource->get(QueryParamsMap(), std::bind(&_on_get, std::placeholders::_1,
+                                               std::placeholders::_2, std::placeholders::_3, device));
+                               } else {
+                                       LOG_DEBUG("It's me. Get peer description myself");
+                                       device->type = MDGD_GROUP_DEVICE_LOCAL;
+
+                                       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+                                       if (mdgd_ctx && (FALSE == mdgd_ctx->mot_me)) {
+                                               g_timeout_add(10, _perform_mot_me, NULL);
+                                               mdgd_ctx->mot_me = TRUE;
+                                       }
+
+                                       char *device_name = NULL;
+                                       char *model_name = NULL;
+                                       char *platform_ver = NULL;
+                                       char *profile = NULL;
+                                       char *vendor_id = NULL;
+
+                                       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
+                                       system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
+                                       system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
+                                       system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
+                                       /* How to get the vendor id? */
+
+                                       device->model_name = g_strdup(device_name);
+                                       device->platform_ver= g_strdup(model_name);
+                                       device->profile = g_strdup(platform_ver);
+                                       device->device_name = g_strdup(profile);
+                                       device->vendor_id = g_strdup("6FFF");
+
+                                       mdgd_group_change_mowned_device(device);
+                               }
+                       } else if (g_strcmp0(resource_type, "core.comp.data") == 0) {
+                               mdgd_command_t *cmd = (mdgd_command_t *)user_data;
+
+                               LOG_DEBUG("Resource Type %s", resource_type);
+                               LOG_DEBUG("Command Device ID: %s", cmd ? cmd->uuid : "NULL");
+
+                               if (cmd != NULL && strncmp(cmd->uuid, resource_device_id,
+                                       strlen(resource_device_id)) == 0) {
+                                       OCRepresentation rep;
+
+                                       LOG_DEBUG("Request to Remote Device");
+
+                                       LOG_DEBUG("CMD = %s", command2string(cmd->command));
+
+                                       rep.setValue("CMD", cmd->command);
+
+                                       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+                                       rep.setValue("device_id", std::string(mdgd_ctx->device_uuid));
+
+                                       if (cmd->command == MDGD_REQ_CREATE_GROUP) { //request create group
+                                               rep.setValue("name", std::string(cmd->arg1));
+                                       } else if (cmd->command == MDGD_REQ_INVITE_DEVICE) { //request invite
+                                               rep.setValue("name", std::string(cmd->arg1));
+                                               rep.setValue("id", std::string(cmd->arg2));
+                                               rep.setValue("PIN", std::string(cmd->arg3));
+                                       } else if (cmd->command == MDGD_REQ_EJECT_DEVICE) { //request eject
+                                               rep.setValue("name", std::string(cmd->arg1));
+                                               rep.setValue("id", std::string(cmd->arg2));
+                                       } else if (cmd->command == MDGD_REQ_DELETE_GROUP) { //request delete group
+                                               rep.setValue("name", std::string(cmd->arg1));
+                                       } else { /* Send Data */
+#ifdef SUPPORT_BASE64_ENCODING
+                                               uint32_t outSize = 0;
+                                               size_t b64BufSize = B64ENCODE_OUT_SAFESIZE(
+                                                                          (cmd->data_len + 1));
+                                               char *b64Buf = (char *) g_malloc0(b64BufSize);
+                                               if (NULL == b64Buf) {
+                                                       _clear_user_data(cmd);
+                                                       return TRUE;
+                                               }
+                                               b64Encode(cmd->data, cmd->data_len,
+                                                                 b64Buf, b64BufSize, &outSize);
+                                               b64Buf[b64BufSize] = '\0';
+                                               rep.setValue("data", std::string(b64Buf));
+                                               LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s",
+                                                                 b64BufSize, outSize, b64Buf);
+                                               g_free(b64Buf);
+#else
+                                               rep.setValue("data", std::string(cmd->arg1));
+#endif
+                                       }
+                                       resource->post(rep, QueryParamsMap(),
+                                                  std::bind (&_on_post, std::placeholders::_1,
+                                                  std::placeholders::_2, std::placeholders::_3, cmd));
+                               }
+                       }
+
+                       g_free(resource_uri_path);
+                       g_free(resource_host);
+                       g_free(resource_type);
+                       g_free(resource_device_id);
+               }
+               else {
+                       LOG_ERR("Resource is invalid");
+               }
+       }
+       catch(std::exception& e)
+       {
+               LOG_ERR("Exception in foundResource: %s", e.what());
+       }
+
+       return TRUE;
+}
+
+static gboolean _timeout_cb(gpointer data)
+{
+       int ret = -1;
+       mdgd_command_t *cmd = (mdgd_command_t *)data;
+
+       if (cmd->resource_type == MDGD_RESOURCE_TYPE_GROUP) {
+               if (found_group_count > 0)
+                       ret = 0;
+
+               notify_group_find_finish(ret);
+
+       } else if (cmd->resource_type == MDGD_RESOURCE_TYPE_DATA) {
+               if (cmd->command != MDGD_REQ_KEEP_ALIVE)
+                       notify_send_data_finish("RESP_DATA", last_get_result);
+       } else if (cmd->resource_type == MDGD_RESOURCE_TYPE_DEVICE) {
+               if (strncmp(cmd->arg1, "disc_mot_enb_devs_done", strlen(cmd->arg1)) == 0) {
+                       LOG_DEBUG("Device Find Done. notified");
+                       mdgd_group_notify_mot_enable_device_done();
+
+                       if (mdgd_group_get_mot_device_count() > 0)
+                               ret = 0;
+
+                       notify_device_find_finish(ret);
+               } else {
+                       LOG_DEBUG("MOT Device Find Done. notified");
+                       mdgd_group_notify_mowned_device_find_done();
+
+                       if (mdgd_group_get_mowned_device_count() > 0)
+                               ret = 0;
+
+                       notify_mowned_device_find_finish(ret);
+               }
+       }
+
+       _clear_user_data(data);
+
+       return false;
+}
+
+int mdgd_iot_discovery_resource(mdgd_resource_type_e resource_type, int timeout,
+       void *user_data)
+{
+       int ret;
+       std::ostringstream requestURI;
+       mdgd_command_t *cmd = (mdgd_command_t *) user_data;
+       mdgd_check_null_ret_error("cmd", cmd, MDGD_ERROR_INVALID_PARAMETER);
+
+       found_group_count = 0;
+
+       try {
+               requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" <<
+                       mdgd_resource_get_type(resource_type);
+
+               auto found_cb = std::bind (&_found_resource, std::placeholders::_1,
+                                                                  cmd);
+               if (cmd) {
+                       LOG_DEBUG("Querying for Resource host address  %s",
+                                         cmd->host ? cmd->host : "NULL");
+
+                       if (cmd->host)
+                               ret = OCPlatform::findResource(cmd->host, requestURI.str(),
+                                                                                          CT_ADAPTER_IP,
+                                                                                          found_cb);
+                       else
+                               ret = OCPlatform::findResource("", requestURI.str(),
+                                                                                          CT_ADAPTER_IP,
+                                                                                          found_cb);
+               }
+       } catch (OCException &e) {
+               LOG_ERR("Failed to find resource %s", e.what());
+               ret = e.code();
+       }
+
+       cmd->resource_type = resource_type;
+       cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
+
+       LOG_DEBUG("find resource : %s", get_error_message(ret));
+
+       return ret;
+}
+
+int mdgd_iot_send_data(mdgd_resource_type_e resource_type, int timeout,
+                                          mdgd_command_t *cmd)
+{
+       int ret;
+       OCResource::Ptr resource;
+       std::string requestURI;
+       std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
+       std::vector<std::string> resource_types;
+       resource_types = {mdgd_resource_get_type(resource_type)};
+
+       try {
+               requestURI = std::string(mdgd_resource_get_uri_prefix(resource_type)) +
+                                                       "1";
+
+               LOG_DEBUG("Request URI %s", requestURI.c_str());
+
+               resource = OCPlatform::constructResourceObject(std::string(cmd->host),
+                                                          requestURI, CT_ADAPTER_IP, false,
+                                                          resource_types, ifaces);
+               if (!resource) {
+                       LOG_ERR("Failed to construct resource");
+                       return -1;
+               }
+
+               OCRepresentation rep;
+               rep.setValue("CMD", cmd->command);
+
+               mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+               rep.setValue("device_id", std::string(mdgd_ctx->device_uuid));
+
+#ifdef SUPPORT_BASE64_ENCODING
+               uint32_t outSize = 0;
+               size_t b64BufSize;
+               char *b64Buf;
+#endif
+               switch (cmd->command) {
+               case MDGD_REQ_SEND_DATA:
+#ifdef SUPPORT_BASE64_ENCODING
+                       b64BufSize = B64ENCODE_OUT_SAFESIZE((cmd->data_len + 1));
+                       b64Buf = (char *) g_try_malloc0(b64BufSize + 1);
+                       if (NULL == b64Buf) {
+                               _clear_user_data(cmd);
+                               return TRUE;
+                       }
+                       b64Encode(cmd->data, cmd->data_len,
+                                         b64Buf, b64BufSize, &outSize);
+                       rep.setValue("data", std::string(b64Buf));
+                       LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s",
+                                         b64BufSize, outSize, b64Buf);
+                       g_free(b64Buf);
+#else
+                       rep.setValue("data", std::string(cmd->arg1));
+#endif
+                       break;
+               case MDGD_REQ_CREATE_GROUP:
+               case MDGD_REQ_DELETE_GROUP:
+                       rep.setValue("name", std::string(cmd->arg1));
+                       break;
+               case MDGD_REQ_INVITE_DEVICE:
+                       rep.setValue("name", std::string(cmd->arg1));
+                       rep.setValue("id", std::string(cmd->arg2));
+                       rep.setValue("PIN", std::string(cmd->arg3));
+                       break;
+               case MDGD_REQ_EJECT_DEVICE:
+                       rep.setValue("name", std::string(cmd->arg1));
+                       rep.setValue("id", std::string(cmd->arg2));
+                       break;
+               case MDGD_REQ_KEEP_ALIVE:
+                       rep.setValue("group_name", std::string(cmd->arg1));
+                       break;
+               default:
+                       LOG_ERR("Invalid command %d", cmd->command);
+                       return -1;
+               }
+
+               ret = resource->post(rep, QueryParamsMap(),
+                                                  std::bind (&_on_post, std::placeholders::_1,
+                                                  std::placeholders::_2, std::placeholders::_3, cmd));
+
+       } catch (OCException &e) {
+               LOG_ERR("Failed to send data %s", e.what());
+               ret = e.code();
+       }
+
+       cmd->resource_type = resource_type;
+       cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
+
+       LOG_DEBUG("Send Data : %s", get_error_message(ret));
+
+       return ret;
+}
+
+int mdgd_iot_delete_resource(mdgd_resource_type_e resource_type)
+{
+       //delete resource from resource list using resource_type and index
+       //delete DB
+       return MDGD_ERROR_NONE;
+}
+
+int mdgd_iot_deinitialize()
+{
+       return MDGD_ERROR_NONE;
+}
diff --git a/src/mdg-manager/src/mdgd_log.c b/src/mdg-manager/src/mdgd_log.c
new file mode 100644 (file)
index 0000000..7f9d851
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_log.h>
+
+const char *mdgd_log_get_error_string(int result)
+{
+       switch (result) {
+       case MDGD_ERROR_NONE:
+               return "MDGD_ERROR_NONE";
+       case MDGD_ERROR_IO_ERROR:
+               return "MDGD_ERROR_IO_ERROR";
+       case MDGD_ERROR_INVALID_PARAMETER:
+               return "MDGD_ERROR_INVALID_PARAMETER";
+       case MDGD_ERROR_OUT_OF_MEMORY:
+               return "MDGD_ERROR_OUT_OF_MEMORY";
+       case MDGD_ERROR_PERMISSION_DENIED:
+               return "MDGD_ERROR_PERMISSION_DENIED";
+       case MDGD_ERROR_NOT_SUPPORTED:
+               return "MDGD_ERROR_NOT_SUPPORTED";
+       case MDGD_ERROR_COMM_ERROR:
+               return "MDGD_ERROR_COMM_ERROR";
+       case MDGD_ERROR_RX:
+               return "MDGD_ERROR_RX";
+       case MDGD_ERROR_TX:
+               return "MDGD_ERROR_RX";
+       case MDGD_ERROR_PLUGIN_FAIL:
+               return "MDGD_ERROR_PLUGIN_FAIL";
+       case MDGD_ERROR_OPERATION_FAILED:
+               return "MDGD_ERROR_OPERATION_FAILED";
+       default:
+               return "UNKNOWN";
+       }
+}
diff --git a/src/mdg-manager/src/mdgd_manager.c b/src/mdg-manager/src/mdgd_manager.c
new file mode 100644 (file)
index 0000000..93976d1
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_manager.h>
+#include <mdgd_mot_agent.h>
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       LOG_DEBUG("COMP Manager start");
+
+       //1. create & get context
+       ret = mdgd_context_create();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("COMP context create failed : %s", mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+
+       //2. iotivity iniatlize
+       ret = mdgd_iot_initialize();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("COMP iot initialize failed : %s", mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+
+       //3. Initializing Data
+       ret = mdgd_db_init();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("COMP db initialize failed : %s", mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+
+       //4. dbus interface initialize
+       ret = mdgd_gdbus_init();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("COMP gdbus initialize failed : %s", mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+
+       //5. Make TX interface
+
+       //example code
+       //6. group mgr initialize
+       ret = mdgd_group_initialize();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("COMP group initialize failed : %s", mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+
+       //7. operation mgr initialize
+       ret = agent_dbus_start();
+       if (ret != MDGD_ERROR_NONE) {
+               LOG_ERR("MOT agent interface initialize failed : %s",
+                       mdgd_log_get_error_string(ret));
+               goto EXIT;
+       }
+       agent_enable();
+
+       //8. g main loop run
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
+
+       mdgd_ctx->main_loop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(mdgd_ctx->main_loop);
+
+EXIT:
+       //9. deinitialize phase
+       agent_disable();
+       ret = agent_dbus_stop();
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("MOT agent interface deinitialize failed : %s",
+                       mdgd_log_get_error_string(ret));
+
+       ret = mdgd_group_deinitialize();
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("COMP group deinitialize failed : %s", mdgd_log_get_error_string(ret));
+
+       ret = mdgd_db_deinit();
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("COMP db deinitialize failed : %s", mdgd_log_get_error_string(ret));
+
+       ret = mdgd_iot_deinitialize();
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("COMP iot deinitialize failed : %s", mdgd_log_get_error_string(ret));
+
+       ret = mdgd_context_destroy();
+       if (ret != MDGD_ERROR_NONE)
+               LOG_ERR("COMP context destroy failed : %s", mdgd_log_get_error_string(ret));
+
+       LOG_DEBUG("COMP Manager exit");
+
+       return 0;
+}
diff --git a/src/mdg-manager/src/mdgd_mot_agent.c b/src/mdg-manager/src/mdgd_mot_agent.c
new file mode 100644 (file)
index 0000000..aee73cf
--- /dev/null
@@ -0,0 +1,839 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <error.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <mdgd_log.h>
+#include <mdgd_enum.h>
+#include <mdgd_group.h>
+#include <mdgd_gdbus_group.h>
+
+#define AGENT_SERVER_NAME "net.ma"
+#define AGENT_OBJECT_PATH "/net/ma"
+#define AGENT_SERVICE_INTERFACE "net.ma"
+
+#define AGENT_ENABLER_NAME "net.ma.enabler"
+#define AGENT_ENABLER_OBJ_PATH "/net/ma/enabler"
+#define AGENT_ENABLER_INTERFACE "net.ma.enabler"
+
+#define AGENT_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */
+
+struct agent_s {
+       GDBusProxy *gproxy_agent_service; /**< Proxy for MOT agent */
+       gpointer dbus_connection; /**< Dbus connection for MOT agent */
+       GCancellable *ca; /**< Cancellable for MOT agent */
+       GList *dbus_sub_ids; /**< DBus ID for MOT agent */
+};
+struct agent_s agent; /**< MOT agent context */
+
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+static bool mot_dev2 = false;
+static char *device_uuid1 = NULL;
+static char *device_uuid2 = NULL;
+#endif
+
+int agent_get_ownerid(char* deviceid)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "get_ownerid",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(si)", deviceid, &result);
+               LOGD("get_ownerid status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_find_mot_enable_devices(int timeout)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_UNKNOWN;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mot_enb_devs",
+                               g_variant_new("(i)", timeout), G_DBUS_CALL_FLAGS_NONE,  -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("disc_mot_enb_devs status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_find_mowned_devices(int timeout)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_UNKNOWN;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mowned_devs",
+                               g_variant_new("(i)", timeout), G_DBUS_CALL_FLAGS_NONE,  -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("disc_mowned_devs status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_mot(char* uuid_str, char *pin)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "mot",
+                       g_variant_new("(ss)", uuid_str, pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("mot status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_resources_pairwise(char* target1, char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, char* target2, char *subject2, char *uri2,
+       char *rt2, char *interface2, int permission2)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "pairwise",
+                       g_variant_new("(sssssisssssi)",
+                               target1, subject1, uri1, rt1, interface1, permission1,
+                               target2, subject2, uri2, rt2, interface2, permission2),
+                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("pairwise status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_unlink_resources(char* uuid_str1, char *uuid_str2)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unlink",
+                       g_variant_new("(ss)", uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE,
+                       -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("remove_subowner status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+       if (result == MDGD_ERROR_NONE) {
+               device_uuid1 = g_strdup(uuid_str1);
+               device_uuid2 = g_strdup(uuid_str2);
+       }
+#endif
+       return result;
+}
+
+int agent_remove_subowner(char* uuid_str)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_subowner",
+                       g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("remove_subowner status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_remove_subowned(char* uuid_str)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_device",
+                       g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("remove_cred_cocal status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_pair(const char *pin, char* target1, const char *subject1, char *uri1,
+       char *rt1, char *interface1, int permission1, const char* target2,
+       char *subject2, char *uri2, char *rt2, char *interface2, int permission2)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "pair",
+                       g_variant_new("(ssssssisssssi)", pin,
+                               target1, subject1, uri1, rt1, interface1, permission1,
+                               target2, subject2, uri2, rt2, interface2, permission2),
+                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("pair status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_unpair(char* uuid_str1, const char *uuid_str2)
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unpair",
+                       g_variant_new("(ss)", uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE,
+                       -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("remove_subowner status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_enable()
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_connection_call_sync(agent.dbus_connection,
+                       AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
+                       "enable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOG_DEBUG("MOT Agent Enabled status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+int agent_disable()
+{
+       GVariant *variant = NULL;
+       int result = MDGD_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_connection_call_sync(agent.dbus_connection,
+                       AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
+                       "disable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOG_DEBUG("MOT Agent Disabled status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MDGD_ERROR_IO_ERROR;
+       }
+       return result;
+}
+
+static int _close_gdbus_call()
+{
+       /* CHECK: is connection ref count required? */
+       g_object_unref(agent.dbus_connection);
+       agent.dbus_connection = NULL;
+
+       return MDGD_ERROR_NONE;
+}
+
+static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
+               gpointer *userdata)
+{
+       GDBusProxy *proxy = G_DBUS_PROXY(object);
+       gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
+
+       NOTUSED(userdata);
+
+       LOG_DEBUG("Name owner notify [%s]", name_owner);
+
+       if (NULL == name_owner)
+               _close_gdbus_call();
+
+       g_free(name_owner);
+}
+
+static int _create_gdbus_call()
+{
+       int id;
+       GError *error = NULL;
+
+       if (agent.dbus_connection != NULL)
+               return MDGD_ERROR_ALREADY_IN_PROGRESS;
+
+       agent.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (NULL == agent.dbus_connection) {
+               if (error != NULL) {
+                       LOG_ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
+                       g_error_free(error);
+               }
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       id = g_signal_connect(agent.dbus_connection, "notify::g-name-owner",
+                       G_CALLBACK(_dbus_name_owner_notify), &agent);
+       if (0 == id) {
+               LOGE("g_signal_connect() Fail");
+               g_object_unref(agent.dbus_connection);
+               agent.dbus_connection = NULL;
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       return MDGD_ERROR_NONE;
+}
+
+static GDBusProxy *_get_proxy_service()
+{
+       GDBusProxy *proxy = NULL;
+
+       if (NULL == agent.gproxy_agent_service) {
+               proxy = g_dbus_proxy_new_sync(agent.dbus_connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       AGENT_SERVER_NAME, AGENT_OBJECT_PATH, AGENT_SERVICE_INTERFACE,
+                       NULL, NULL);
+       } else
+               proxy = agent.gproxy_agent_service;
+
+       return proxy;
+}
+
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+static gboolean __perform_agent_pairwise(gpointer data)
+{
+       int ret;
+
+       mot_dev2 = false;
+
+       mdgd_group_invite_info_t *group_invite_info;
+
+       group_invite_info = mdgd_group_get_invite_info();
+
+       if (!group_invite_info) {
+               LOG_ERR("group_invite_info is null");
+               return FALSE;
+       }
+
+       ret = agent_pairwise(group_invite_info->uuid_dev1, group_invite_info->uuid_dev2,
+                                                group_invite_info->uri_1, group_invite_info->rt_1,
+                                                group_invite_info->interface_1,
+                                                group_invite_info->permission_1,
+                                                group_invite_info->uuid_dev2, group_invite_info->uuid_dev1,
+                                                group_invite_info->uri_2, group_invite_info->rt_2,
+                                                group_invite_info->interface_2,
+                                                group_invite_info->permission_2);
+       if (ret != MDGD_ERROR_NONE)
+               mdgd_group_notify_group_invite(ret);
+
+       return FALSE;
+}
+
+static gboolean __perform_remove_mot_dev2(gpointer data)
+{
+       int ret;
+
+       ret = agent_remove_subowner(device_uuid2);
+       if (ret != MDGD_ERROR_NONE) {
+               mdgd_group_notify_group_dismiss(ret);
+               g_free(device_uuid1);
+               device_uuid1 = NULL;
+               g_free(device_uuid2);
+               device_uuid1 = NULL;
+       }
+
+       return FALSE;
+}
+
+static gboolean __perform_remove_cred_at_local(gpointer data)
+{
+       int ret;
+
+       ret = agent_remove_subowned(device_uuid2);
+       if (ret != MDGD_ERROR_NONE) {
+               mdgd_group_notify_group_dismiss(ret);
+               g_free(device_uuid1);
+               device_uuid1 = NULL;
+               g_free(device_uuid2);
+               device_uuid1 = NULL;
+       }
+       return FALSE;
+}
+#endif
+
+static void _free_device_info(mdgd_mot_device_t *device)
+{
+       if (!device)
+               return;
+
+       if (device->device_id != NULL) {
+               g_free(device->device_id);
+               device->device_id = NULL;
+       }
+       if (device->addr != NULL) {
+               g_free(device->addr);
+               device->addr = NULL;
+       }
+       if (device->route_data != NULL) {
+               g_free(device->route_data);
+               device->route_data = NULL;
+       }
+       if (device->remote_id != NULL) {
+               g_free(device->remote_id);
+               device->remote_id = NULL;
+       }
+       if (device->sec_ver != NULL) {
+               g_free(device->sec_ver);
+               device->sec_ver = NULL;
+       }
+       g_free(device);
+       device = NULL;
+}
+
+static void _agent_signal_handler(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
+               const gchar *signal_name, GVariant *parameters, gpointer userdata)
+{
+       int result = MDGD_ERROR_NONE;
+       struct agent_s *h = userdata;
+
+       if (NULL == h) {
+               LOG_ERR("user_data is null");
+               return;
+       }
+
+       LOG_DEBUG("signal received = %s", signal_name);
+
+       if (0 == g_strcmp0(signal_name, "subowner_enabled")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+       } else if (0 == g_strcmp0(signal_name, "disc_mot_enb_devs_done") ||
+               0 == g_strcmp0(signal_name, "disc_mowned_devs_done")) {
+               mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+               mdgd_check_null_ret("mdgd_ctx", mdgd_ctx);
+
+               if (NULL == parameters) {
+                       LOG_ERR("No MOT enabled devices found");
+                       return;
+               }
+
+               mdgd_command_t *cmd = g_new0(mdgd_command_t, 1);
+               cmd->uuid = g_strdup(mdgd_ctx->device_uuid);
+               cmd->user_data = (void *)g_variant_ref(parameters);
+               cmd->arg1 = g_strdup(signal_name);
+
+               mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, 2, cmd);
+               LOG_DEBUG("Peer description discovery Start");
+       } else if (0 == g_strcmp0(signal_name, "acl_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+       } else if (0 == g_strcmp0(signal_name, "cred_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+       } else if (0 == g_strcmp0(signal_name, "mot_done")) {
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+               mdgd_mot_device_t *device;
+               mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+               mdgd_check_null_ret("mdgd_ctx", mdgd_ctx);
+
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+
+               if (result != 0 && result != 49 &&
+                       (mdgd_group_get_invite_info() != NULL))
+                       mdgd_group_notify_group_invite(result);
+
+               if (mdgd_ctx && (TRUE == mdgd_ctx->mot_me))
+                       g_timeout_add(10, __perform_agent_pairwise, NULL);
+#endif
+       } else if (0 == g_strcmp0(signal_name, "remove_mo_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+               g_timeout_add(10, __perform_remove_cred_at_local, NULL);
+#endif
+       } else if (0 == g_strcmp0(signal_name, "remove_cred_local_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+               mdgd_group_notify_group_dismiss(result);
+               g_free(device_uuid1);
+               device_uuid1 = NULL;
+               g_free(device_uuid2);
+               device_uuid1 = NULL;
+#endif
+       } else if (0 == g_strcmp0(signal_name, "pairwise_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+
+               if (mdgd_group_get_invite_info() != NULL)
+                       mdgd_group_notify_group_invite(result);
+       } else if (0 == g_strcmp0(signal_name, "unlink_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
+               if (result != 0) {
+                       mdgd_group_notify_group_dismiss(result);
+                       g_free(device_uuid1);
+                       device_uuid1 = NULL;
+                       g_free(device_uuid2);
+                       device_uuid1 = NULL;
+               }
+
+               g_timeout_add(10, __perform_remove_mot_dev2, NULL);
+#endif
+       } else if (0 == g_strcmp0(signal_name, "pair_done")) {
+
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+
+               mdgd_group_notify_group_invite(result);
+       } else if (0 == g_strcmp0(signal_name, "unpair_done")) {
+
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
+
+               mdgd_group_notify_group_dismiss(result);
+       }
+}
+static int _subscribe_event()
+{
+       unsigned int id;
+       struct agent_s *h = &agent;
+
+       /* subowner_enabled */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "subowner_enabled", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(subowner_enabled) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (subowner_enabled) signal %d", id);
+
+       /* disc_mot_enb_devs_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "disc_mot_enb_devs_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(disc_mot_enb_devs_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (disc_mot_enb_devs_done) signal %d", id);
+
+       /* disc_mowned_devs_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "disc_mowned_devs_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(disc_mowned_devs_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (disc_mowned_devs_done) signal %d", id);
+
+       /* mot_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "mot_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(mot_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (mot_done) signal %d", id);
+
+       /* acl_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "acl_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(acl_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (acl_done) signal %d", id);
+
+       /*cred_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "cred_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(cred_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (cred_done) signal %d", id);
+
+       /*pairwise_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "pairwise_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(pairwise_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (pairwise_done) signal %d", id);
+
+       /*unlink_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "unlink_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(unlink_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (unlink_done) signal %d", id);
+
+       /* remove_mo_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "remove_mo_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(remove_mo_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (remove_mo_done) signal %d", id);
+
+       /* remove_cred_local_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "remove_cred_local_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(remove_cred_local_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (remove_cred_local_done) signal %d", id);
+
+       /*pair_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "pair_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(pair_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (pair_done) signal %d", id);
+
+       /*unpair_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "unpair_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(unpair_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (unpair_done) signal %d", id);
+
+       return 0;
+}
+
+static void _on_unsubscribe_ids(gpointer data, gpointer userdata)
+{
+       unsigned int id = GPOINTER_TO_UINT(data);
+       struct agent_s *h = (struct agent_s*)userdata;
+       if (NULL == h) {
+               LOG_ERR("Invaild parameter");
+               return;
+       }
+       LOG_DEBUG("[Signal unsubscribe] : %d", id);
+       g_dbus_connection_signal_unsubscribe(h->dbus_connection, id);
+}
+static void _unsubscribe_event()
+{
+       g_list_foreach(agent.dbus_sub_ids, _on_unsubscribe_ids, &agent);
+       g_list_free(agent.dbus_sub_ids);
+       agent.dbus_sub_ids = NULL;
+}
+
+int agent_dbus_start()
+{
+       int ret = MDGD_ERROR_NONE;
+
+       ret = _create_gdbus_call();
+       if (MDGD_ERROR_NONE != ret)
+               return ret;
+
+       agent.ca = g_cancellable_new();
+
+       /* Create all proxies here */
+       agent.gproxy_agent_service = _get_proxy_service();
+       if (NULL == agent.gproxy_agent_service) {
+               LOG_ERR("Couldn't get _get_proxy_service");
+               return MDGD_ERROR_IO_ERROR;
+       }
+
+       g_dbus_proxy_set_default_timeout(
+               G_DBUS_PROXY(agent.gproxy_agent_service), AGENT_DBUS_PROXY_TIMEOUT);
+
+       /* Subscribe events */
+       _subscribe_event();
+
+       return MDGD_ERROR_NONE;
+}
+
+int agent_dbus_stop()
+{
+       int ret = MDGD_ERROR_NONE;
+
+       _unsubscribe_event();
+
+       /* Unref all proxies here */
+       if (agent.gproxy_agent_service) {
+               g_object_unref(agent.gproxy_agent_service);
+               agent.gproxy_agent_service = NULL;
+       }
+
+       g_cancellable_cancel(agent.ca);
+       g_object_unref(agent.ca);
+       agent.ca = NULL;
+
+       ret = _close_gdbus_call();
+       return ret;
+}
+
diff --git a/src/mdg-manager/src/mdgd_resource.c b/src/mdg-manager/src/mdgd_resource.c
new file mode 100644 (file)
index 0000000..122764f
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <mdgd_resource.h>
+
+/* resource_type, type, uri, policies */
+static mdgd_rd_t mdgd_rds[] = {
+       {MDGD_RESOURCE_TYPE_GROUP, "core.comp.group", "/comp/group/",
+               OC_DISCOVERABLE | OC_OBSERVABLE},
+       {MDGD_RESOURCE_TYPE_DEVICE, "core.comp.device", "/comp/device",
+               OC_DISCOVERABLE | OC_OBSERVABLE},
+       {MDGD_RESOURCE_TYPE_OPERATION, "core.comp.operation", "/comp/operation/",
+               OC_DISCOVERABLE | OC_OBSERVABLE},
+       {MDGD_RESOURCE_TYPE_DATA, "core.comp.data", "/comp/data/",
+               OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE},
+};
+
+int mdgd_resource_append(mdgd_resource_type_e resource_type, const char *uri)
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       GList *list = mdgd_ctx->resource_list[resource_type];
+
+       //append resource handle / name to list
+       mdgd_re_t *element = g_new0(mdgd_re_t, 1);
+       element->uri = g_strdup(uri);
+       list = g_list_append(list, element);
+
+       mdgd_ctx->resource_list[resource_type] = list;
+
+       return 0;
+}
+
+char *mdgd_resource_get_type(mdgd_resource_type_e resource_type)
+{
+       return mdgd_rds[resource_type].type;
+}
+
+char *mdgd_resource_get_uri_prefix(mdgd_resource_type_e resource_type)
+{
+       return mdgd_rds[resource_type].uri_prefix;
+}
+
+unsigned char mdgd_resource_get_policies(mdgd_resource_type_e resource_type)
+{
+       return mdgd_rds[resource_type].policies;
+}
+
+void __print_foreach_resource(gpointer data, gpointer user_data)
+{
+       mdgd_re_t *re = (mdgd_re_t *)data;
+       LOG_DEBUG("    ** uri : %s", re->uri);
+}
+
+void mdgd_resource_print_list()
+{
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       LOG_DEBUG("-------------------Print resource list-----------------------");
+
+       for (int i = 0; i < MDGD_RESOURCE_TYPE_MAX; i++) {
+               LOG_DEBUG("Resource type %d list length : %d",
+                       i, g_list_length(mdgd_ctx->resource_list[i]));
+               g_list_foreach(mdgd_ctx->resource_list[i], __print_foreach_resource, NULL);
+       }
+
+       LOG_DEBUG("-------------------Print resource list end-------------------");
+}
+
diff --git a/src/mdg-manager/src/mdgd_util.c b/src/mdg-manager/src/mdgd_util.c
new file mode 100644 (file)
index 0000000..b9648f3
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <dirent.h>
+#include <glib.h>
+
+#include <mdgd_log.h>
+#include <mdgd_util.h>
+
+#define IPV6_ADDR_GLOBAL 0x0000U
+#define IPV6_ADDR_LOOPBACK 0x0010U
+#define IPV6_ADDR_LINKLOCAL 0x0020U
+#define IPV6_ADDR_SITELOCAL 0x0040U
+#define IPV6_ADDR_COMPATv4 0x0080U
+
+typedef struct _ipv4_info_s {
+       char *ifname; /**< Network interface name */
+       char *mac; /**< MAC address */
+       bool active; /**< interface active or not */
+       int mtu; /**< MTU size */
+       char *ip; /**< IPv4 address */
+       char *broadcast; /**< Broadcast address */
+       char *mask; /**< Net-mask */
+} ipv4_info_s;
+
+typedef struct _ipv6_info_s {
+       char *ifname; /**< Network interface name */
+       char *ip; /**< IPv6 address */
+       int prefix; /**< Prefix length  */
+       char *scope; /**< Scope */
+} ipv6_info_s;
+
+typedef struct _ip_info_s {
+       GList *ipv4_list; /**< IPv4 address list */
+       GList *ipv6_list; /**< IPv6 address list */
+} ip_info_s;
+
+ip_info_s g_ip_info; /**< Local IP address list */
+
+static void __free_ipv4_info(gpointer data)
+{
+       ipv4_info_s *ipv4info = (ipv4_info_s *)data;
+       if (NULL == data)
+               return;
+
+       if (ipv4info->ifname) {
+               free(ipv4info->ifname);
+               ipv4info->ifname = NULL;
+       }
+       if (ipv4info->mac) {
+               free(ipv4info->mac);
+               ipv4info->mac = NULL;
+       }
+       if (ipv4info->ip) {
+               free(ipv4info->ip);
+               ipv4info->ip = NULL;
+       }
+       if (ipv4info->broadcast) {
+               free(ipv4info->broadcast);
+               ipv4info->broadcast = NULL;
+       }
+       if (ipv4info->mask) {
+               free(ipv4info->mask);
+               ipv4info->mask = NULL;
+       }
+       free(ipv4info);
+       ipv4info = NULL;
+}
+
+static void __free_ipv6_info(gpointer data)
+{
+       ipv6_info_s *ipv6info = (ipv6_info_s *)data;
+       if (NULL == data)
+               return;
+
+       if (ipv6info->ifname) {
+               free(ipv6info->ifname);
+               ipv6info->ifname = NULL;
+       }
+       if (ipv6info->ip) {
+               free(ipv6info->ip);
+               ipv6info->ip = NULL;
+       }
+       if (ipv6info->scope) {
+               free(ipv6info->scope);
+               ipv6info->scope= NULL;
+       }
+       free(ipv6info);
+       ipv6info = NULL;
+}
+
+void mdgd_remove_ip_info(void)
+{
+       if (g_ip_info.ipv4_list) {
+               g_list_free_full(g_ip_info.ipv4_list, __free_ipv4_info);
+               g_ip_info.ipv4_list = NULL;
+       }
+       if (g_ip_info.ipv6_list) {
+               g_list_free_full(g_ip_info.ipv6_list, __free_ipv6_info);
+               g_ip_info.ipv6_list = NULL;
+       }
+}
+
+static void _parse_inet6(const char *ifname) {
+    FILE *f;
+    int scope, prefix;
+    unsigned char ipv6[16];
+    char dname[IFNAMSIZ];
+    char address[INET6_ADDRSTRLEN];
+    char *scopestr;
+
+    f = fopen("/proc/net/if_inet6", "r");
+    if (f == NULL) {
+               LOGE("Failed to access /proc/net/if_inet6");
+        return;
+    }
+
+    while (19 == fscanf(f," %2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" \
+               "%2hhx%2hhx%2hhx%2hhx%2hhx %*x %x %x %*x %s",
+               &ipv6[0], &ipv6[1], &ipv6[2], &ipv6[3], &ipv6[4], &ipv6[5], &ipv6[6], &ipv6[7],
+               &ipv6[8], &ipv6[9], &ipv6[10], &ipv6[11], &ipv6[12], &ipv6[13], &ipv6[14],
+               &ipv6[15], &prefix, &scope, dname)) {
+
+        if (strcmp(ifname, dname) != 0)
+            continue;
+
+        if (inet_ntop(AF_INET6, ipv6, address, sizeof(address)) == NULL)
+            continue;
+
+               ipv6_info_s *_ipv6 = calloc(1, sizeof(ipv6_info_s));
+               if (NULL == _ipv6) {
+                       LOGE("Memory allocation failed");
+                        goto FINISH_READING_IPV6;
+               }
+               _ipv6->ifname = g_strdup(ifname);
+
+        switch (scope) {
+        case IPV6_ADDR_GLOBAL:
+            scopestr = "Global";
+            break;
+        case IPV6_ADDR_LINKLOCAL:
+            scopestr = "Link";
+            break;
+        case IPV6_ADDR_SITELOCAL:
+            scopestr = "Site";
+            break;
+        case IPV6_ADDR_COMPATv4:
+            scopestr = "Compat";
+            break;
+        case IPV6_ADDR_LOOPBACK:
+            scopestr = "Host";
+            break;
+        default:
+            scopestr = "Unknown";
+        }
+               _ipv6->ip = g_strdup(address); /* ex) fe80::212:34ff:fe5a:ec0e */
+               _ipv6->prefix = prefix; /* ex) 64 */
+               _ipv6->scope = g_strdup(scopestr); /* Link */
+
+               g_ip_info.ipv6_list = g_list_append(g_ip_info.ipv6_list, _ipv6);
+    }
+FINISH_READING_IPV6:
+    fclose(f);
+}
+
+static void _parse_ioctl(const char *ifname)
+{
+    int sock;
+    struct ifreq ifr;
+    struct sockaddr_in *ipaddr;
+    char address[INET_ADDRSTRLEN];
+    size_t ifnamelen;
+
+    /* copy ifname to ifr object */
+    ifnamelen = strlen(ifname);
+    if (ifnamelen >= sizeof(ifr.ifr_name)) {
+        return ;
+    }
+    memcpy(ifr.ifr_name, ifname, ifnamelen);
+    ifr.ifr_name[ifnamelen] = '\0';
+
+    /* open socket */
+    sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+    if (sock < 0) {
+               LOGE("socket creation faild");
+        return;
+    }
+
+       ipv4_info_s *_ipv4 = calloc(1, sizeof(ipv4_info_s));
+       if (NULL == _ipv4) {
+               LOGE("Memory allocation failed");
+                goto FINISH_READING_IPV4;
+       }
+       _ipv4->ifname = g_strdup(ifname); /* ex) wlan0 */
+
+    /* process mac */
+    if (ioctl(sock, SIOCGIFHWADDR, &ifr) != -1) {
+               char buf[64] = {0,};
+               snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
+                       ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
+                       ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
+                       ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+               _ipv4->mac = g_strdup(buf); /* ex) 00:12:34:5a:ec:0e */
+    }
+
+    /* process mtu */
+    if (ioctl(sock, SIOCGIFMTU, &ifr) != -1) {
+               _ipv4->mtu = ifr.ifr_mtu; /* ex) 1492 */
+    }
+
+    /* die if cannot get address */
+    if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) {
+               _ipv4->active = false;
+        goto FINISH_READING_IPV4;
+    }
+
+    /* process ip */
+    ipaddr = (struct sockaddr_in *)&ifr.ifr_addr;
+    if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+               _ipv4->ip = g_strdup(address); /* ex) 192.168.86.111 */
+    }
+
+    /* try to get broadcast */
+    if (ioctl(sock, SIOCGIFBRDADDR, &ifr) != -1) {
+        ipaddr = (struct sockaddr_in *)&ifr.ifr_broadaddr;
+        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+                       _ipv4->broadcast = g_strdup(address); /* ex) 192.168.86.255 */
+        }
+    }
+
+    /* try to get mask */
+    if (ioctl(sock, SIOCGIFNETMASK, &ifr) != -1) {
+        ipaddr = (struct sockaddr_in *)&ifr.ifr_netmask;
+        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+                       _ipv4->mask = g_strdup(address); /* ex) 255.255.255.0 */
+        }
+    }
+FINISH_READING_IPV4:
+    close(sock);
+       g_ip_info.ipv4_list = g_list_append(g_ip_info.ipv4_list, _ipv4);
+}
+
+
+int mdgd_make_ip_info(void)
+{
+    DIR *d;
+    struct dirent *de;
+
+    d = opendir("/sys/class/net/");
+    if (d == NULL) {
+               LOGE("Failed to access /sys/class/net/");
+        return -1;
+    }
+
+    while (NULL != (de = readdir(d))) {
+        if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
+            continue;
+
+        _parse_ioctl(de->d_name);
+        _parse_inet6(de->d_name);
+    }
+    closedir(d);
+
+    return 0;
+}
+
+int mdgd_is_local_ip(char *ipdata)
+{
+       char *ip = NULL;
+       char *ifname = NULL;
+       char *save_str = NULL;
+       char *addr = NULL;
+       GList *iter = NULL;
+       ipv6_info_s *ipv6info = NULL;
+       ipv4_info_s *ipv4info = NULL;
+
+       addr = g_strdup(ipdata);
+
+       ip = strtok_r(addr, "%", &save_str);
+       ifname = strtok_r(NULL, "%", &save_str);
+
+       iter = g_list_first(g_ip_info.ipv6_list);
+       while (NULL != iter) {
+               ipv6info = iter->data;
+               if (ipv6info && ipv6info->ip && !strncmp(ipv6info->ip, ip,
+                                                                                                INET6_ADDRSTRLEN)) {
+                       g_free(addr);
+                       return LOCAL_IP;
+               }
+               iter = g_list_next(iter);
+       }
+
+       iter = g_list_first(g_ip_info.ipv4_list);
+       while (NULL != iter) {
+               ipv4info = iter->data;
+               if (ipv4info && ipv4info->ip && !strncmp(ipv4info->ip, ip,
+                                                                                                INET_ADDRSTRLEN)) {
+                       g_free(addr);
+                       return LOCAL_IP;
+               }
+               iter = g_list_next(iter);
+       }
+
+       g_free(addr);
+       return REMOTE_IP;
+}
+
index b475e20d9c3fe688a71d961cc054a2632d9c619c..272903ea563128cc908e6067ab37b5b9a29cd188 100644 (file)
@@ -18,7 +18,7 @@ ADD_CUSTOM_COMMAND(
 MESSAGE(" - Check cmake packagesion")
 pkg_check_modules(ma_pkgs REQUIRED ${COMMON_DEPS} ${TIZEN_DEPS}
        capi-network-wifi-manager
-       sqlite3
+       #       sqlite3
        )
 
 ADD_CUSTOM_TARGET(GENERATED_MA_DBUS_CODE DEPENDS dbus1)