comp-manager: Fixed issue in sending message using unicast message
authorSaurav Babu <saurav.babu@samsung.com>
Thu, 25 Jan 2018 07:49:21 +0000 (13:19 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:47 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/include/comp_iot.h
src/companion-manager/src/comp_group.c
src/companion-manager/src/comp_iot.c

index b037033..85bafba 100755 (executable)
@@ -14,6 +14,7 @@ typedef struct _iot_discovery_t {
 typedef struct _comp_command_t {
        gchar *command;
        gchar *uuid;
+       gchar *host;
        gchar *arg1;
        gchar *arg2;
        gchar *arg3;
index 4e9f813..271efdb 100644 (file)
@@ -588,7 +588,8 @@ int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2)
        return ret;
 }
 
-int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port, gchar *data, int len)
+int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port, gchar *data,
+                                                int len)
 {
        int ret;
        char ip[50];
@@ -603,28 +604,30 @@ int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port, gchar *data, in
        if (percent)
                percent[0] = '\0';
 
-       iot_discovery_t *iot = g_new0(iot_discovery_t, 1);
-       iot->uuid = g_strdup(uuid_dev);
+       comp_command_t *cmd = g_new0(comp_command_t, 1);
+       cmd->command = g_strdup("3");
+       cmd->uuid = g_strdup(uuid_dev);
 
-       if (strchr(ip, ':'))
-               iot->host = g_strdup_printf("coap://[%s]:%d", ip, port);
-       else
-               iot->host = g_strdup_printf("coap://%s:%d", ip, port);
+       if (strchr(ip, ':')) /* IPv6 Adress */
+               cmd->host = g_strdup_printf("coap://[%s]:%d", ip, port);
+       else /* IPv4 Address */
+               cmd->host = g_strdup_printf("coap://%s:%d", ip, port);
 
-       iot->data = g_malloc0(len);
-       if (NULL == iot->data) {
+       cmd->arg1 = g_malloc0(len);
+       if (NULL == cmd->arg1) {
                ret = COMP_ERROR_OUT_OF_MEMORY;
                LOG_ERR("Send Data Fail to uuid = %s host %s error=%s",
-                       iot->uuid, iot->host, comp_log_get_error_string(ret));
+                       cmd->uuid, cmd->host, comp_log_get_error_string(ret));
                return ret;
        }
-       memcpy(iot->data, data, len);
+       memcpy(cmd->arg1, data, len);
 
-       LOG_DEBUG("UUID %s host %s", iot->uuid, iot->host);
+       LOG_DEBUG("UUID %s host %s", cmd->uuid, cmd->host);
 
-       ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 1, iot);
+       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));
+               LOG_ERR("Failed to discover resource : %s",
+                               comp_log_get_error_string(ret));
        }
 
        LOG_END();
index 1772285..c164831 100644 (file)
@@ -340,6 +340,10 @@ static bool _found_resource(iotcon_remote_resource_h resource,
                                iotcon_query_add(query, "CMD", cmd->command);
                                iotcon_query_add(query, "name", cmd->arg1);
                                iotcon_query_add(query, "id", cmd->arg2);
+                       } else if (strcmp(cmd->command, "3") == 0) {
+                               LOG_DEBUG("CMD : %s, UUID : %s", cmd->command, cmd->uuid);
+                               iotcon_query_add(query, "CMD", cmd->command);
+                               iotcon_query_add(query, "data", cmd->arg1);
                        }
 
                        ret = iotcon_remote_resource_get(resource_clone, query, _on_get, NULL);
@@ -376,7 +380,7 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
 {
        int ret;
        iotcon_query_h query;
-       iot_discovery_t *iot = user_data;
+       comp_command_t *cmd = user_data;
 
        found_device_count = 0;
 
@@ -401,8 +405,8 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
 
        LOG_DEBUG("Set Resource Type : %s", get_error_message(ret));
 
-       if (timeout == 1)
-               ret = iotcon_find_resource(iot->host,
+       if (cmd && (g_strcmp0(cmd->command, "3") == 0))
+               ret = iotcon_find_resource(cmd->host,
                        IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
                        query, _found_resource, user_data);
        else