Add file transfer impl (Not reliable) 02/184602/1
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 19 Jul 2018 06:40:29 +0000 (15:40 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Thu, 19 Jul 2018 06:40:59 +0000 (15:40 +0900)
Change-Id: Ieb7fa7dfd51925d0c66291688ca70fe41ba746f7
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
test/mdg-manager.c

index 0d21f01..f06cd8e 100755 (executable)
@@ -42,7 +42,7 @@ static char channel_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 channel_id[MENU_DATA_SIZE + 1] = "Channel1";
-//static char monitor[MENU_DATA_SIZE + 1] = "1";
+static char file_path[MENU_DATA_SIZE + 1] = "/path/to/file";
 
 static int run_group_find(MManager *mm, struct menu_data *menu);
 static int run_devices_find(MManager *mm, struct menu_data *menu);
@@ -799,6 +799,77 @@ static int run_send_data(MManager *mm, struct menu_data *menu)
        return __send_data(devidx, chaidx);
 }
 
+static int __send_file(int devidx, int chaidx)
+{
+       int ret = 0;
+       char *deviceid = NULL;
+       char *address = NULL;
+       mdg_device_h device = NULL;
+       channel_t *channel = NULL;
+       if (found_invited_device_list) {
+               device = g_list_nth_data(found_invited_device_list, devidx - 1);
+               if (NULL == device) {
+                       msgr("Find local device first");
+                       return RET_FAILURE;
+               }
+       }
+
+       if (found_channel_list) {
+               channel = g_list_nth_data(found_channel_list, chaidx - 1);
+               if (NULL == channel) {
+                       msgr("Find local device first");
+                       return RET_FAILURE;
+               }
+       }
+
+       mdg_device_info_get_device_id(device, &deviceid);
+       mdg_device_info_get_addr(device, &address);
+       msgp("Sent to [ID] %s [ADDR] %s [CHANNEL ID] %s", deviceid, address, channel->channel_id);
+       if (deviceid) {
+               free(deviceid);
+               deviceid = NULL;
+       }
+       if (address) {
+               free(address);
+               address = NULL;
+       }
+
+       ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)file_path,
+                                                strlen(file_path), _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_file(MManager *mm, struct menu_data *menu)
+{
+       int devidx = 0;
+       int chaidx = 0;
+       int count = g_list_length(found_invited_device_list);
+
+       if (0 >= count) {
+               msgr("No Device");
+               return RET_SUCCESS;
+       }
+
+       if (strlen(device_idx)) {
+               devidx = (unsigned short)strtol(device_idx, NULL, 10);
+               if (0 >= devidx) {
+                       msgp("Invalid index. set to 1");
+                       devidx = 1;
+               }
+       }
+       if (strlen(channel_idx)) {
+               chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
+               if (0 >= chaidx) {
+                       msgp("Invalid index. set to 1");
+                       chaidx = 1;
+               }
+       }
+       return __send_file(devidx, chaidx);
+}
+
 void _invited_device_finish_cb(int result, void *user_data)
 {
        msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
@@ -1165,6 +1236,16 @@ static struct menu_data menu_send_data[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data menu_send_file[] = {
+       { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
+       { "1", "Show Channel List", NULL, run_channels_show, NULL },
+       { "2", "File Path", NULL, NULL, file_path },
+       { "3", "Device Index", NULL, NULL, device_idx },
+       { "4", "Channel Index", NULL, NULL, channel_idx },
+       { "5", "Send", NULL, run_send_file, NULL },
+       { NULL, NULL, },
+};
+
 static struct menu_data menu_devices_find_invited_device[] = {
        { "0", "Timeout", NULL, NULL, timeout },
        { "1", "Run", NULL, run_devices_find_invited_device, NULL },
@@ -1236,4 +1317,5 @@ struct menu_data menu_mdg_manager[] = {
        { "16", "Regist Channel", menu_regist_channel, NULL, NULL },
        { "17", "Unregist Channel", menu_unregist_channel, NULL, NULL },
        { "18", "Send Message", menu_send_data, NULL, NULL }, // 0
+       { "19", "Send File", menu_send_file, NULL, NULL }, // 0
 };