comp-manager: modify send-data functionality
authorsaerome.kim <saerome.kim@samsung.com>
Tue, 30 Jan 2018 05:03:23 +0000 (14:03 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:47 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
capi/demo/comp-manager.c
capi/src/companion.c
src/companion-manager/include/comp_enum.h [changed mode: 0755->0644]
src/companion-manager/src/comp_iot.c
src/companion-manager/src/comp_mot_agent.c
test.pcap [new file with mode: 0644]

index 9cf2303d6fa24639749401e30f7c4025f5afc2af..182bb03ed433922a907f6b2f03a85a7cc65464ff 100644 (file)
@@ -69,7 +69,7 @@ void receive_request_result(char *cmd, char *arg, int ret, void *user_data)
                        if (ret == 0 && arg != NULL)
                                msgb("Deleted Group name is %s", arg);
                } else {
-                       msgb("[DATA] %s", arg);
+                       msgb("[Recv] %s", arg);
                }
        }
 }
@@ -791,7 +791,7 @@ void _send_data_finish_cb(int result, char *resp_data, void *user_data)
        }
 }
 
-static int run_send_data(MManager *mm, struct menu_data *menu)
+static int __send_data(int idx)
 {
        int ret = 0;
        int count = 0;
@@ -806,28 +806,59 @@ static int run_send_data(MManager *mm, struct menu_data *menu)
                return RET_SUCCESS;
        }
 
-       for (int i = 0; i < count; i++) {
-               device = (companion_device_h)(my_devices_list[i].data);
-               if (!device)
-                       continue;
+       device = (companion_device_h)(my_devices_list[idx-1].data);
+       if (!device) {
+               msgr("Find my device first");
+       }
+       companion_device_information_get_device_id(device, &deviceid);
+       companion_device_information_get_ip(device, &address);
+       msgb("Send Data: [ID] %s [IP] %s", deviceid, address);
+       if (deviceid) {
+               free(deviceid);
+               deviceid= NULL;
+       }
+       if (address) {
+               free(address);
+               address= NULL;
+       }
 
-               companion_device_information_get_device_id(device, &deviceid);
-               companion_device_information_get_ip(device, &address);
-               msgb("Send Data: [ID] %s [IP] %s", deviceid, address);
-               if (deviceid) {
-                       free(deviceid);
-                       deviceid= NULL;
-               }
-               if (address) {
-                       free(address);
-                       address= NULL;
-               }
+       ret = companion_send_data(device, message, strlen(message), _send_data_finish_cb, NULL);
+       if (COMP_ERROR_NONE != ret) {
+               msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
+       }
 
-               ret = companion_send_data(device, message, strlen(message), _send_data_finish_cb, NULL);
-               if (COMP_ERROR_NONE != ret) {
-                       msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
+       return ret;
+}
+
+static int run_send_data(MManager *mm, struct menu_data *menu)
+{
+       int idx = 0;
+
+       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 ret = 0;
+       int count = 0;
+
+       count = g_list_length(my_devices_list);
+
+       if (0 >= count ) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       for (int i = 1; i <= count; i++)
+               __send_data(i);
+
        return RET_SUCCESS;
 }
 
@@ -1192,8 +1223,11 @@ static struct menu_data menu_group_eject_device[] = {
 };
 
 static struct menu_data menu_send_data[] = {
-       { "0", "Message", NULL, NULL, message },
-       { "1", "Send (Broadcast)", NULL, run_send_data, NULL },
+       { "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, },
 };
 
@@ -1236,6 +1270,7 @@ static struct menu_data menu_request_delete_group[] = {
        { "2", "Run", NULL, run_request_delete_group, NULL },
        { NULL, NULL, },
 };
+
 struct menu_data menu_comp_manager[] = {
        { "0", "Show My Device ID", NULL, run_get_my_id, NULL },
        { "1", "Create Group", menu_group_create, NULL, NULL },
index 3acba29fde77043b7d28dd14b34c2711ac43f773..79a27976c352f8b24bc491027838096880d3765d 100644 (file)
@@ -946,7 +946,7 @@ int companion_request_create_group(companion_device_h device, char *group_name)
 int companion_request_invite(companion_group_h group, companion_device_h device, char *PIN)
 {
        int ret = 0;
-       GError *error = NULL;
+
        companion_group_t *grp = (companion_group_t *)group;
        companion_device_t *dev = (companion_device_t *)device;
 
@@ -954,7 +954,8 @@ int companion_request_invite(companion_group_h group, companion_device_h device,
        _ERR("%s", grp->group_name);
        _ERR("%s", dev->device_id);
 
-       group_call_request_invite(group_proxy, grp->device_id, grp->group_name, dev->device_id, PIN, &ret, NULL, &error);
+       group_call_request_invite(group_proxy, grp->device_id, grp->group_name, dev->device_id, PIN,
+               NULL, NULL, NULL);
 
        return ret;
 }
@@ -970,19 +971,25 @@ int companion_request_eject(companion_group_h group, companion_device_h device)
        _ERR("%s", grp->group_name);
        _ERR("%s", dev->device_id);
 
-       group_call_request_eject(group_proxy, grp->device_id, grp->group_name, dev->device_id, &ret, NULL, &error);
+       group_call_request_eject(group_proxy, grp->device_id, grp->group_name, dev->device_id,
+               NULL, NULL, NULL);
 
        return ret;
 }
 
 int companion_request_delete_group(companion_group_h group)
 {
-
+       int ret = 0;
+       return ret;
 }
 
 int companion_request_result_callback(companion_request_result_cb result_cb, void *user_data)
 {
+       int ret = 0;
+
        request_result_cb.result_cb = result_cb;
        request_result_cb.user_data = user_data;
+
+       return ret;
 }
 
old mode 100755 (executable)
new mode 100644 (file)
index 7ce1963..1ad069a
@@ -51,6 +51,7 @@ typedef enum {
        COMP_REQ_INVITE_DEVICE, /**< Invite Device */
        COMP_REQ_EJECT_DEVICE, /**< Exile Device */
        COMP_REQ_DELETE_GROUP, /**< Delete Group */
+       COMP_REQ_SEND_DATA_ALL, /**< Send data in subnet */
 } comp_request_type_e;
 
 #endif
index 9b107f572a59d017d7b3b41252d84d4a81365225..0ba533c366f51d6ec1c5bed43d3ce1a01ef4bccd 100644 (file)
@@ -6,6 +6,7 @@
 #include <iotivity_config.h>
 #include <platform_features.h>
 #include <ocprovisioningmanager.h>
+#include <doxmresource.h>
 
 #include <comp_iot.h>
 #include <comp_group.h>
@@ -593,13 +594,12 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
                LOG_ERR("iotcon_set_timeout: Failed %s", get_error_message(ret));
        }
 
-       if (cmd && (cmd->command == COMP_REQ_CREATE_GROUP ||
-                                        cmd->command == COMP_REQ_SEND_DATA))
-               ret = iotcon_find_resource(cmd->host,
+       if (cmd && (cmd->command == COMP_REQ_SEND_DATA_ALL))
+               ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
                        IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
                        query, _found_resource, user_data);
        else
-               ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
+               ret = iotcon_find_resource(cmd->host,
                        IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
                        query, _found_resource, user_data);
 
index 10a504c2195b961ad0514a8992d7551ae42c7d81..13d8353c1f1745834a63b21ace2ef215c385ad90 100644 (file)
@@ -27,6 +27,7 @@
 #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"
diff --git a/test.pcap b/test.pcap
new file mode 100644 (file)
index 0000000..8614349
Binary files /dev/null and b/test.pcap differ