Add Peer Description discovery implemntation
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 19 Apr 2018 08:17:42 +0000 (17:17 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:50 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
16 files changed:
CMakeLists.txt
capi/demo/comp-manager.c [changed mode: 0644->0755]
capi/include/companion.h
capi/src/companion.c
capi/src/companion_dbus.c [changed mode: 0644->0755]
capi/src/companion_private.h
capi/src/companion_util.c
capi/src/companion_util.h
packaging/d2d-manager.spec
src/companion-manager/include/comp_enum.h
src/companion-manager/include/comp_group.h
src/companion-manager/include/comp_iot.h
src/companion-manager/src/comp_group.c [changed mode: 0644->0755]
src/companion-manager/src/comp_iot.cpp
src/companion-manager/src/comp_mot_agent.c
src/companion-manager/src/comp_resource.c

index 542da00..639ea95 100644 (file)
@@ -11,7 +11,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/capi/include)
 
 MESSAGE(" - Checking...packages dependency")
-SET(COMMON_DEPS glib-2.0 gio-2.0 gio-unix-2.0 dlog dbus-1 iotivity uuid capi-base-common capi-system-info vconf boost gmock sqlite3)
+SET(COMMON_DEPS glib-2.0 gio-2.0 gio-unix-2.0 dlog dbus-1 iotivity uuid capi-base-common capi-system-info vconf boost gmock sqlite3 capi-system-system-settings)
 IF (LINUX)
     PKG_CHECK_MODULES(daemon_pkgs REQUIRED ${COMMON_DEPS})
     ADD_DEFINITIONS("-DLINUX")
old mode 100644 (file)
new mode 100755 (executable)
index 7d0392b..9e103e5
@@ -484,6 +484,7 @@ 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;
@@ -491,6 +492,7 @@ bool _device_found_cb(companion_device_h device, void *user_data)
        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) {
@@ -512,8 +514,8 @@ bool _device_found_cb(companion_device_h device, void *user_data)
 
        if (is_exist == FALSE) {
                found_device_list = g_list_append(found_device_list, device);
-               msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
-                       __device_type_to_string(device_type));
+               msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, ip,
+                       __device_type_to_string(device_type), model_name);
        }
 
        if (device_id)
index e533cb7..00ff83e 100644 (file)
@@ -1220,6 +1220,9 @@ int companion_device_information_get_ip(companion_device_h device, char **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);
+
 /**
  * @}
  */
index ba075ac..f61658e 100644 (file)
@@ -386,6 +386,11 @@ EXPORT_API int companion_device_get_found_devices(companion_h handle,
                        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)
@@ -398,10 +403,21 @@ EXPORT_API int companion_device_get_found_devices(companion_h handle,
                                        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);
+                       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;
                }
@@ -450,6 +466,11 @@ EXPORT_API int companion_device_get_found_mowned_devices(
                        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)
@@ -462,10 +483,21 @@ EXPORT_API int companion_device_get_found_mowned_devices(
                                        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);
+                       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;
                }
@@ -506,6 +538,11 @@ EXPORT_API int companion_device_information_get_my_device(companion_h handle,
        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);
 
@@ -527,14 +564,24 @@ EXPORT_API int companion_device_information_get_my_device(companion_h handle,
                        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);
+       *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);
 
@@ -911,6 +958,18 @@ EXPORT_API int companion_device_information_get_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)
old mode 100644 (file)
new mode 100755 (executable)
index f713cd0..8d4924f
@@ -109,6 +109,11 @@ static void __device_found_cb(Group *object, gint count, GVariant *va,
                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)
@@ -121,11 +126,21 @@ static void __device_found_cb(Group *object, gint count, GVariant *va,
                                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);
+                                       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);
        }
@@ -165,6 +180,11 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                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)
@@ -177,11 +197,21 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                                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);
+               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);
index 9046704..5879841 100644 (file)
@@ -189,6 +189,11 @@ typedef struct _companion_device_s {
        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;
 
 
index 2866fd2..82e32b4 100644 (file)
@@ -78,7 +78,8 @@ CREATE_GROUP_HANDLER_ERROR:
 }
 
 companion_device_s *create_device_handle(char *device_id, char *ip,
-       int device_type, int port, int sec_port)
+       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) {
@@ -93,8 +94,14 @@ companion_device_s *create_device_handle(char *device_id, char *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->device_type) {
+       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;
@@ -110,6 +117,26 @@ CREATE_DEVICE_HANDLER_ERROR:
                        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;
index dfcf4a3..c4803af 100644 (file)
@@ -28,7 +28,8 @@ extern "C"
 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);
+       int port, int sec_port, char *model_name, char *device_name,
+       char *platform_ver, char *vendor_id, char *profile);
 
 #ifdef __cplusplus
 }
index 72842e8..e63f343 100755 (executable)
@@ -31,7 +31,7 @@ BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(gmock)
 BuildRequires: pkgconfig(sqlite3)
-
+BuildRequires: pkgconfig(capi-system-system-settings)
 %description
 D2D Manager
 
index 2a4830b..4ca0046 100644 (file)
@@ -69,6 +69,12 @@ typedef enum {
        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.
  *
index 4b434b9..e5d6ac4 100755 (executable)
@@ -48,6 +48,13 @@ typedef struct {
        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 {
index c0b7c77..97472ec 100644 (file)
@@ -47,6 +47,7 @@ typedef struct _comp_command_t {
        unsigned char *data;
        int data_len;
 #endif
+       void *user_data;
 } comp_command_t;
 
 int comp_iot_initialize();
old mode 100644 (file)
new mode 100755 (executable)
index 51942a3..7a4665d
@@ -364,6 +364,18 @@ GVariant *comp_group_get_remote_mot_enabled_devices()
                                                          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);
@@ -912,6 +924,17 @@ GVariant *comp_group_get_mowned_devices()
                                                          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);
@@ -969,6 +992,16 @@ GVariant *comp_group_get_my_mowned_devices()
                                                          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);
index 9d7beae..32fcbad 100755 (executable)
 #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"
@@ -51,6 +53,7 @@ using namespace std;
 #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;
@@ -323,6 +326,13 @@ int comp_iot_initialize()
        }
 
        /*
+               "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
@@ -364,173 +374,210 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> reques
 
                LOG_DEBUG("request type %s flag %x", requestType.c_str(), requestFlag);
 
-               if (requestType != "POST") {
-                       LOG_ERR("Invalid Request Type");
-                       return OC_EH_OK;
-               }
-
-               if (requestFlag & RequestHandlerFlag::RequestFlag) {
-                       LOG_DEBUG("requestFlag : Request");
+               if (requestType == "GET") {
+                       //Send Peer Description
+                       LOG_DEBUG("requestFlag : GET");
                        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;
+                       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;
+                               int payload_len;
+                               size_t outSize;
+                               uint8_t *out;
+                               uint32_t len = 0;
 #endif
-                       comp_context_t *comp_ctx;
+                               comp_context_t *comp_ctx;
 
-                       try {
-                               OCRepresentation rep = request->getResourceRepresentation();
+                               try {
+                                       OCRepresentation rep = request->getResourceRepresentation();
 
-                               _print_oc_representation(rep);
+                                       _print_oc_representation(rep);
 
-                               ObservationInfo observationInfo = request->getObservationInfo();
-                               LOG_DEBUG("Received request from %s:%d",
-                                         observationInfo.address.c_str(), observationInfo.port);
+                                       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("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());
+                                       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");
+                                       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 (!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;
-                                       }
+                                               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;
+                                               arg = (unsigned char *) g_try_malloc0(len);
+                                               memcpy(arg, out, len);
+                                               arg_len = len;
 
-                                       g_free(out);
+                                               g_free(out);
 
-                                       LOG_DEBUG("Successfully decoded from base64");
+                                               LOG_DEBUG("Successfully decoded from base64");
 #else
-                                       if (!rep.getValue("data", data))
-                                               LOG_ERR("data not found");
+                                               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());
+                                               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;
+                                       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;
                                        }
-                                       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);
-                               }
+                                       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);
+                                       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());
+                                       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;
                }
        }
 
@@ -644,6 +691,71 @@ static void _on_post(const HeaderOptions& /*headerOptions*/,
        //_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)
 {
@@ -693,6 +805,137 @@ static bool _found_resource(std::shared_ptr<OCResource> resource,
 
                                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;
 
@@ -780,6 +1023,24 @@ static gboolean _timeout_cb(gpointer data)
        } 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);
index 6e44f1f..94cdfc7 100644 (file)
@@ -50,9 +50,6 @@ static char *device_uuid1 = NULL;
 static char *device_uuid2 = NULL;
 #endif
 
-int found_device_count; /**< Number of MOT enabled devices */
-int found_mowned_device_count; /**< Number of My Sub-Owned devices */
-
 int agent_get_ownerid(char* deviceid)
 {
        GVariant *variant = NULL;
@@ -78,18 +75,6 @@ int agent_get_ownerid(char* deviceid)
        return result;
 }
 
-static gboolean _find_device_timeout_cb(gpointer data)
-{
-       int ret = COMP_ERROR_UNKNOWN;
-
-       if (found_device_count > 0)
-               ret = 0;
-
-       notify_device_find_finish(ret);
-
-       return false;
-}
-
 int agent_find_mot_enable_devices(int timeout)
 {
        GVariant *variant = NULL;
@@ -101,8 +86,6 @@ int agent_find_mot_enable_devices(int timeout)
                return COMP_ERROR_IO_ERROR;
        }
 
-       found_device_count = 0;
-
        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) {
@@ -113,24 +96,10 @@ int agent_find_mot_enable_devices(int timeout)
                g_error_free(error);
                return COMP_ERROR_IO_ERROR;
        }
-       if (COMP_ERROR_NONE == result)
-               g_timeout_add_seconds(timeout + 1, _find_device_timeout_cb, NULL);
 
        return result;
 }
 
-static gboolean _find_mowned_device_timeout_cb(gpointer data)
-{
-       int ret = -1;
-
-       if (found_mowned_device_count > 0)
-               ret = 0;
-
-       notify_mowned_device_find_finish(ret);
-
-       return false;
-}
-
 int agent_find_mowned_devices(int timeout)
 {
        GVariant *variant = NULL;
@@ -152,8 +121,6 @@ int agent_find_mowned_devices(int timeout)
                g_error_free(error);
                return COMP_ERROR_IO_ERROR;
        }
-       if (COMP_ERROR_NONE == result)
-               g_timeout_add_seconds(timeout + 1, _find_mowned_device_timeout_cb, NULL);
 
        return result;
 }
@@ -531,19 +498,6 @@ static gboolean __perform_remove_cred_at_local(gpointer data)
 }
 #endif
 
-static gboolean __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 void _free_device_info(comp_mot_device_t *device)
 {
        if (!device)
@@ -590,16 +544,8 @@ static void _agent_signal_handler(GDBusConnection *connection,
        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")) {
-               GVariantIter *iter = NULL;
-               GVariantIter *iter_row = NULL;
-
-               gchar *key;
-               GVariant *val;
-               gsize len = 0;
-               int mot_enb_devs_cnt = 0;
-               comp_mot_device_t *device;
-
+       } 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);
 
@@ -608,199 +554,13 @@ static void _agent_signal_handler(GDBusConnection *connection,
                        return;
                }
 
-               g_variant_get(parameters, "(aa{sv})", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-                       device = g_try_malloc0(sizeof(comp_mot_device_t));
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) {
-                               if (strcasecmp(key, "deviceId") == 0)  {
-                                       const char *deviceid = g_variant_get_string(val, &len);
-                                       if (comp_ctx && (FALSE == comp_ctx->mot_me) &&
-                                               strcasecmp(deviceid, comp_ctx->device_uuid) == 0) {
-                                               g_timeout_add(10, __perform_mot_me, NULL);
-                                               comp_ctx->mot_me = TRUE;
-                                       }
-                                       LOG_DEBUG("deviceId = %s", deviceid);
-                                       device->device_id = g_strdup(deviceid);
-
-                               } else if (strcasecmp(key, "adapter") == 0)  {
-                                       int adapter = g_variant_get_uint32(val);
-                                       LOG_DEBUG("adapter = %d", adapter);
-                                       device->adapter = adapter;
-                               } else if (strcasecmp(key, "flags") == 0)  {
-                                       int flags = g_variant_get_int32(val);
-                                       LOG_DEBUG("flags = %d", flags);
-                                       device->flags = flags;
-                               } else if (strcasecmp(key, "port") == 0)  {
-                                       int port = g_variant_get_uint16(val);
-                                       LOG_DEBUG("port = %d", port);
-                                       device->port = port;
-                               } else if (strcasecmp(key, "addr") == 0)  {
-                                       const char *addr = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("addr = %s", addr);
-                                       device->addr = g_strdup(addr);
-                               } else if (strcasecmp(key, "ifindex") == 0)  {
-                                       int ifindex = g_variant_get_int32(val);
-                                       LOG_DEBUG("ifindex = %d", ifindex);
-                                       device->ifindex = ifindex;
-                               } else if (strcasecmp(key, "routeData") == 0)  {
-                                       const char *routeData = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("routeData = %s", routeData);
-                                       device->route_data = g_strdup(routeData);
-                               } else if (strcasecmp(key, "remoteId") == 0)  {
-                                       const char *remoteId = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("remoteId = %s", remoteId);
-                                       device->remote_id = g_strdup(remoteId);
-                               } else if (strcasecmp(key, "connType") == 0)  {
-                                       int connType = g_variant_get_uint32(val);
-                                       LOG_DEBUG("connType = %d", connType);
-                                       device->conn_type = connType;
-                               } else if (strcasecmp(key, "securePort") == 0)  {
-                                       int securePort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("securePort = %d", securePort);
-                                       device->secure_port = securePort;
-#ifdef WITH_TCP
-                               } else if (strcasecmp(key, "tcpPort") == 0)  {
-                                       int tcpPort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("tcpPort = %d", tcpPort);
-                                       device->tcp_port = tcpPort;
-                               }
-#endif
-                               else if (strcasecmp(key, "secVer") == 0)  {
-                                       const char *secVer = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("secVer = %s", secVer);
-                                       device->sec_ver = g_strdup(secVer);
-                               } else if (strcasecmp(key, "devStatus") == 0)  {
-                                       int devStatus = g_variant_get_uint32(val);
-                                       LOG_DEBUG("devStatus = %d", devStatus);
-                                       device->dev_status = devStatus;
-
-                               }
-                       }
-                       g_variant_iter_free(iter_row);
-
-                       if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
-
-                               /* Is new device */
-                               if (FALSE == comp_group_add_new_mot_device(device)) {
-                                       mot_enb_devs_cnt += 1;
-                               } else  {
-                                       /* We have this device already */
-                                       _free_device_info(device);
-                               }
-                       } else {
-                               LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
-                               comp_group_change_mowned_device(device);
-                       }
-               }
-               g_variant_iter_free(iter);
-
-               LOG_DEBUG("mot_enb_devs_cnt = %d", mot_enb_devs_cnt);
-               found_device_count = mot_enb_devs_cnt;
-               comp_group_notify_mot_enable_device_done();
-       } else if (0 == g_strcmp0(signal_name, "disc_mowned_devs_done")) {
-               GVariantIter *iter = NULL;
-               GVariantIter *iter_row = NULL;
-
-               gchar *key;
-               GVariant *val;
-               gsize len = 0;
-               int mowned_devs_cnt = 0;
-               comp_mot_device_t *device = NULL;
-
-               if (NULL == parameters) {
-                       LOG_ERR("No Multiple Owned devices found");
-                       return;
-               }
-
-               g_variant_get(parameters, "(aa{sv})", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-
-                       device = g_try_malloc0(sizeof(comp_mot_device_t));
-                       comp_check_null_ret("device", device);
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) {
-                               if (strcasecmp(key, "deviceId") == 0)  {
-                                       const char *deviceid = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("deviceId = %s", deviceid);
-                                       device->device_id = g_strdup(deviceid);
-                               } else if (strcasecmp(key, "adapter") == 0)  {
-                                       int adapter = g_variant_get_uint32(val);
-                                       LOG_DEBUG("adapter = %d", adapter);
-                                       device->adapter = adapter;
-                               } else if (strcasecmp(key, "flags") == 0)  {
-                                       int flags = g_variant_get_int32(val);
-                                       LOG_DEBUG("flags = %d", flags);
-                                       device->flags = flags;
-                               } else if (strcasecmp(key, "port") == 0)  {
-                                       int port = g_variant_get_uint16(val);
-                                       LOG_DEBUG("port = %d", port);
-                                       device->port = port;
-                               } else if (strcasecmp(key, "addr") == 0)  {
-                                       const char *addr = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("addr = %s", addr);
-                                       device->addr = g_strdup(addr);
-                               } else if (strcasecmp(key, "ifindex") == 0)  {
-                                       int ifindex = g_variant_get_int32(val);
-                                       LOG_DEBUG("ifindex = %d", ifindex);
-                                       device->ifindex = ifindex;
-                               } else if (strcasecmp(key, "routeData") == 0)  {
-                                       const char *routeData = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("routeData = %s", routeData);
-                                       device->route_data = g_strdup(routeData);
-                               } else if (strcasecmp(key, "remoteId") == 0)  {
-                                       const char *remoteId = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("remoteId = %s", remoteId);
-                                       device->remote_id = g_strdup(remoteId);
-                               } else if (strcasecmp(key, "connType") == 0)  {
-                                       int connType = g_variant_get_uint32(val);
-                                       LOG_DEBUG("connType = %d", connType);
-                                       device->conn_type = connType;
-                               } else if (strcasecmp(key, "securePort") == 0)  {
-                                       int securePort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("securePort = %d", securePort);
-                                       device->secure_port = securePort;
-#ifdef WITH_TCP
-                               } else if (strcasecmp(key, "tcpPort") == 0)  {
-                                       int tcpPort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("tcpPort = %d", tcpPort);
-                                       device->tcp_port = tcpPort;
-                               }
-#endif
-                               else if (strcasecmp(key, "secVer") == 0)  {
-                                       const char *secVer = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("secVer = %s", secVer);
-                                       device->sec_ver = g_strdup(secVer);
-                               } else if (strcasecmp(key, "devStatus") == 0)  {
-                                       int devStatus = g_variant_get_uint32(val);
-                                       LOG_DEBUG("devStatus = %d", devStatus);
-                                       device->dev_status = devStatus;
-                               }
-                       }
-                       g_variant_iter_free(iter_row);
-
-                       comp_context_t *comp_ctx = comp_context_get_context();
-                       comp_check_null_ret("comp_ctx", comp_ctx);
-
-                       if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
-
-                               /* Is new device */
-                               if (FALSE == comp_group_add_new_mowned_device(device)) {
-                                       mowned_devs_cnt += 1;
-                               } else  {
-                                       /* We have this device already */
-                                       _free_device_info(device);
-                               }
-                       } else {
-                               LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
-                               comp_group_change_mowned_device(device);
-                       }
-               }
-               g_variant_iter_free(iter);
+               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);
 
-               LOG_DEBUG("mowned_devs_cnt = %d", mowned_devs_cnt);
-               found_mowned_device_count = mowned_devs_cnt;
-               comp_group_notify_mowned_device_find_done(mowned_devs_cnt);
+               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);
index 1c189fa..76338dd 100644 (file)
@@ -21,7 +21,7 @@
 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/",
+       {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},