2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
31 GList *found_group_list;
32 GList *found_device_list;
33 GList *found_invited_device_list;
34 GList *found_channel_list;
36 static char groupid[MENU_DATA_SIZE + 1] = "mygroup";
37 static char request_groupid[MENU_DATA_SIZE + 1] = "subgroup";
38 static char timeout[MENU_DATA_SIZE + 1] = "2";
39 static char group_idx[MENU_DATA_SIZE + 1] = "1";
40 static char device_idx[MENU_DATA_SIZE + 1] = "1";
41 static char channel_idx[MENU_DATA_SIZE + 1] = "1";
42 static char pin[MENU_DATA_SIZE + 1] = "12341234";
43 static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
44 static char channel_id[MENU_DATA_SIZE + 1] = "Channel1";
45 static char file_path[MENU_DATA_SIZE + 1] = "/path/to/file";
47 static int run_group_find(MManager *mm, struct menu_data *menu);
48 static int run_devices_find(MManager *mm, struct menu_data *menu);
50 static const char* __device_type_to_string(mdg_device_type_e type)
53 /* CHECK: List all enum values here */
54 case MDG_DEVICE_TYPE_LOCAL:
56 case MDG_DEVICE_TYPE_REMOTE:
63 void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
64 int len, int ret, void *user_data)
66 msg("_request_result_cb is called command %s Requester id %s", cmd,
70 msgp("cmd is null [%s(0x%X)]", mdg_error_to_string(ret), ret);
74 if (strncmp("COMP_REQ_CREATE_GROUP", cmd, strlen(cmd)) == 0) {
75 msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret),
77 if (ret == MDG_ERROR_NONE && arg != NULL) {
78 msgb("Created Group name is %s", arg);
79 run_group_find(NULL, NULL);
80 run_devices_find(NULL, NULL);
82 } else if (strncmp("COMP_REQ_INVITE_DEVICE", cmd, strlen(cmd)) == 0) {
83 msgp("[CMD] Request Invite [%s(0x%X)]", mdg_error_to_string(ret), ret);
84 if (ret == MDG_ERROR_NONE && arg != NULL)
85 msgb("Invited Device ID is %s", arg);
86 } else if (strncmp("COMP_REQ_EJECT_DEVICE", cmd, strlen(cmd)) == 0) {
87 msgp("[CMD] Request Eject [%s(0x%X)]", mdg_error_to_string(ret), ret);
88 if (ret == MDG_ERROR_NONE && arg != NULL)
89 msgb("Ejected Device ID is %s", arg);
90 } else if (strncmp("COMP_REQ_DELETE_GROUP", cmd, strlen(cmd)) == 0) {
91 msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret),
93 if (ret == MDG_ERROR_NONE && arg != NULL)
94 msgb("Deleted Group name is %s", arg);
95 } else if (strncmp("COMP_REQ_SEND_DATA", cmd, strlen(cmd)) == 0) {
96 msgp("Received data [%d] %s", strlen((char *)arg), arg);
98 msgp("[Recv][%d] %s", strlen((char *) arg), arg);
102 void _device_eject_result_cb(int result, void *user_data)
104 msgb("\rEject Device Complete [%s]", mdg_error_to_string(result));
107 static int run_device_eject(MManager *mm, struct menu_data *menu)
111 mdg_group_h group = NULL;
112 mdg_device_h device = NULL;
116 if (strlen(group_idx)) {
117 idx = (unsigned short)strtol(group_idx, NULL, 10);
119 msgp("Invalid index. set to 1");
124 if (found_group_list) {
125 group = g_list_nth_data(found_group_list, idx - 1);
127 msgr("Failed to g_hash_table_find");
132 if (strlen(device_idx)) {
133 idx = (unsigned short)strtol(device_idx, NULL, 10);
135 msgp("Invalid index. set to 1");
140 if (NULL == found_invited_device_list) {
141 msgr("Find device first");
145 device = g_list_nth_data(found_invited_device_list, idx - 1);
146 if (NULL == device) {
147 msgr("Failed to g_hash_table_find");
151 ret = mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
152 if (MDG_ERROR_NONE != ret) {
153 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
156 msg(" - mdg_group_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
161 bool __group_foreach_cb(mdg_device_h device, void *user_data)
166 mdg_device_info_get_addr(device, &addr);
167 mdg_device_info_get_device_id(device, &device_id);
168 msgb("\rDevice is [%s], ADDR [%s]", device_id, addr);
173 static int run_group_foreach_device(MManager *mm, struct menu_data *menu)
177 mdg_group_h group = NULL;
179 msg("Foreach Device");
181 if (strlen(group_idx)) {
182 idx = (unsigned short)strtol(group_idx, NULL, 10);
184 msgp("Invalid index. set to 1");
189 if (found_group_list) {
190 group = g_list_nth_data(found_group_list, idx - 1);
192 msgr("Failed to g_hash_table_find");
197 ret = mdg_group_foreach_device(handle, group, __group_foreach_cb, NULL);
198 if (MDG_ERROR_NONE != ret) {
199 msgr("Failed to foreach device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
202 msg(" - mdg_group_foreach_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
207 void _device_invite_result_cb(int result, mdg_device_h device, void *user_data)
210 mdg_device_info_is_invited(device, &is_invited);
211 msgb("\rInvite Device Finished [%s]", mdg_error_to_string(result));
212 msgb("\rThe device invited is : %d", is_invited);
215 static int run_device_invite(MManager *mm, struct menu_data *menu)
219 mdg_group_h group = NULL;
220 mdg_device_h device = NULL;
222 msg("Invite Device");
224 if (strlen(group_idx)) {
225 idx = (unsigned short)strtol(group_idx, NULL, 10);
227 msgp("Invalid index. set to 1");
232 if (found_group_list) {
233 group = g_list_nth_data(found_group_list, idx - 1);
235 msgr("Failed to g_hash_table_find");
240 if (strlen(device_idx)) {
241 idx = (unsigned short)strtol(device_idx, NULL, 10);
243 msgp("Invalid index. set to 1");
248 if (NULL == found_device_list) {
249 msgr("Find device first");
253 device = g_list_nth_data(found_device_list, idx - 1);
254 if (NULL == device) {
255 msgr("Failed to g_hash_table_find");
259 ret = mdg_group_invite_device(handle, group, device, pin, _device_invite_result_cb, NULL);
260 if (MDG_ERROR_NONE != ret) {
261 msgr("Failed to device invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
264 msg(" - mdg_group_invite_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
269 static void _destroy_mdg_device_info(gpointer data)
271 mdg_device_info_destroy((mdg_device_h)data);
274 static int run_devices_show(MManager *mm, struct menu_data *menu)
281 /* Get a first item */
283 iter = g_list_first(found_device_list);
284 while (NULL != iter) {
287 msgr("device is null");
293 mdg_device_info_get_model_name(device, &model_name);
294 mdg_device_info_get_addr(device, &addr);
296 msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr);
298 mdg_device_h cloned_device;
299 char *cloned_model_name;
302 mdg_device_info_clone(&cloned_device, device);
303 mdg_device_info_get_model_name(cloned_device, &cloned_model_name);
304 mdg_device_info_get_addr(cloned_device, &cloned_addr);
306 msgp("*Cloned* [%d] Model : %s, Addr : %s", i+1, cloned_model_name, cloned_addr);
314 if (cloned_model_name)
315 free(cloned_model_name);
320 mdg_device_info_destroy(cloned_device);
323 iter = g_list_next(iter);
330 static int run_invited_devices_show(MManager *mm, struct menu_data *menu)
337 /* Get a first item */
339 iter = g_list_first(found_invited_device_list);
340 while (NULL != iter) {
343 msgr("device is null");
349 mdg_device_info_get_model_name(device, &model_name);
350 mdg_device_info_get_addr(device, &addr);
352 msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr);
361 iter = g_list_next(iter);
368 typedef struct _channel_t {
369 char *device_id; /**< User callback to be called */
370 char *channel_id; /**< User data pointer */
373 static int run_channels_show(MManager *mm, struct menu_data *menu)
380 /* Get a first item */
382 iter = g_list_first(found_channel_list);
383 while (NULL != iter) {
384 channel = iter->data;
386 msgr("channel is null");
390 msgp("[%d] device id : %s, channel id : %s,", i+1, channel->device_id, channel->channel_id);
393 iter = g_list_next(iter);
401 static int run_group_get_members(MManager *mm, struct menu_data *menu)
406 mdg_group_h group = NULL;
407 mdg_device_h **devices = NULL;
409 msg("Get Group Members");
411 if (strlen(group_idx)) {
412 idx = (unsigned short)strtol(group_idx, NULL, 10);
414 msgp("Invalid index. set to 1");
419 if (found_group_list) {
420 group = g_list_nth_data(found_group_list, idx - 1);
422 msgr("Failed to g_hash_table_find");
427 ret = mdg_group_get_member_devices(group, devices, &count);
428 if (MDG_ERROR_NONE != ret) {
429 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
432 msg(" - mdg_group_get_member_devices() ret: [0x%X] [%s]", ret,
433 mdg_error_to_string(ret));
435 for (int i = 0; i < count; i++) {
437 char *device_id = NULL;
439 mdg_device_type_e device_type;
441 mdg_device_info_get_device_id(devices[i], &device_id);
442 mdg_device_info_get_ip(devices[i], &ip);
443 mdg_device_info_get_device_type(devices[i], &device_type);
445 msgp("device_id : %s, name : %s, type : %s", device_id, ip,
446 __device_type_to_string(device_type));
458 static int run_group_delete(MManager *mm, struct menu_data *menu)
466 if (strlen(group_idx)) {
467 idx = (unsigned short)strtol(group_idx, NULL, 10);
469 msgp("Invalid index. set to 1");
474 if (found_group_list) {
475 group = g_list_nth_data(found_group_list, idx - 1);
477 msgr("Failed to g_hash_table_find");
482 ret = mdg_group_delete(handle, group);
483 if (MDG_ERROR_NONE != ret) {
484 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
487 msg(" - mdg_group_delete() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
492 void _device_finish_cb(int result, void *user_data)
494 msgb("\rFind Device Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
497 bool _device_found_cb(mdg_device_h device, void *user_data)
500 char *device_id = NULL;
501 char *model_name = NULL;
502 mdg_device_type_e device_type;
504 gboolean is_exist = FALSE;
506 mdg_device_info_get_device_id(device, &device_id);
507 mdg_device_info_get_addr(device, &addr);
508 mdg_device_info_get_model_name(device, &model_name);
509 mdg_device_info_get_type(device, &device_type);
511 iter = found_device_list;
512 while (iter != NULL) {
513 mdg_device_h temp = (mdg_device_h)iter->data;
514 char *temp_device_id;
516 mdg_device_info_get_device_id(temp, &temp_device_id);
518 if (g_strcmp0(device_id, temp_device_id) == 0) {
520 free(temp_device_id);
521 mdg_device_info_destroy(device);
525 free(temp_device_id);
526 iter = g_list_next(iter);
529 if (is_exist == FALSE) {
530 found_device_list = g_list_append(found_device_list, device);
531 msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, addr,
532 __device_type_to_string(device_type), model_name);
543 static int run_devices_find(MManager *mm, struct menu_data *menu)
550 duration = (unsigned short)strtol(timeout, NULL, 10);
552 ret = mdg_device_find(handle, duration, false, _device_found_cb, _device_finish_cb, NULL);
553 if (MDG_ERROR_NONE != ret) {
554 msgr("Failed to Find Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret);
557 msg(" - mdg_device_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
559 if (found_device_list) {
560 g_list_free_full(found_device_list, _destroy_mdg_device_info);
561 found_device_list = NULL;
567 int run_device_show_local_device(MManager *mm, struct menu_data *menu)
570 mdg_device_h device = NULL;
572 msg("Get Local Device");
574 ret = mdg_device_get_local_device(handle, &device);
575 if (MDG_ERROR_NONE != ret) {
576 msgr("Failed to Get My Device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
579 msg(" - mdg_device_info_get_local_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
582 char *device_id = NULL;
592 mdg_device_type_e type;
594 mdg_device_info_get_device_id(device, &device_id);
595 mdg_device_info_get_addr(device, &addr);
596 mdg_device_info_get_port(device, &port);
597 mdg_device_info_get_secure_port(device, &secure_port);
598 mdg_device_info_get_model_name(device, &model_name);
599 mdg_device_info_get_device_name(device, &device_name);
600 mdg_device_info_get_platform_ver(device, &platform_ver);
601 mdg_device_info_get_vendor_id(device, &vendor_id);
602 mdg_device_info_get_profile(device, &profile);
603 mdg_device_info_is_invited(device, &is_invited);
604 mdg_device_info_get_type(device, &type);
606 msgb("\n[ID] %s", device_id);
607 msgb("[ADDR] %s", addr);
608 msgb("[PORT] %d", port);
609 msgb("[S.PORT] %d", secure_port);
610 msgb("[Model Name] %s", model_name);
611 msgb("[Device Name] %s", device_name);
612 msgb("[Platform Ver.] %s", platform_ver);
613 msgb("[Vendor ID] %s", vendor_id);
614 msgb("[Profile] %s", profile);
615 msgb("[Is Invited] %d", is_invited);
616 msgb("[Type] %s\n", __device_type_to_string(type));
633 mdg_device_info_destroy(device);
640 static int run_group_show(MManager *mm, struct menu_data *menu)
647 /* Get a first item */
649 iter = g_list_first(found_group_list);
650 while (NULL != iter) {
653 msgr("groups is null");
660 mdg_group_type_e type;
662 mdg_group_info_get_device_id(group, &device_id);
663 mdg_group_info_get_host_addr(group, &host_addr);
664 mdg_group_info_get_name(group, &name);
665 mdg_group_info_get_type(group, &type);
667 msgp("[%d] type: %s, name: %s", i+1, mdg_group_type_to_string(type), name);
668 msgp(" host_addr: %s, device_id: %s\n", host_addr, device_id);
670 mdg_group_h cloned_group;
671 char *cloned_device_id;
672 char *cloned_host_addr;
674 mdg_group_type_e cloned_type;
676 mdg_group_info_clone(&cloned_group, group);
677 mdg_group_info_get_device_id(cloned_group, &cloned_device_id);
678 mdg_group_info_get_host_addr(cloned_group, &cloned_host_addr);
679 mdg_group_info_get_name(cloned_group, &cloned_name);
680 mdg_group_info_get_type(cloned_group, &cloned_type);
682 msgp("*Cloned* [%d] type: %s, name: %s", i+1, mdg_group_type_to_string(cloned_type), cloned_name);
683 msgp(" host_addr: %s, device_id: %s\n", cloned_host_addr, cloned_device_id);
692 if (cloned_device_id)
693 free(cloned_device_id);
694 if (cloned_host_addr)
695 free(cloned_host_addr);
699 mdg_group_info_destroy(cloned_group);
702 iter = g_list_next(iter);
709 static void _destroy_mdg_group_info(gpointer data)
711 mdg_group_info_destroy((mdg_group_h)data);
714 bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data)
718 mdg_group_info_get_name(group, &group_name);
720 if (type == MDG_GROUP_TYPE_LOCAL)
721 msgp("\rfound group type : MINE, name : %s", group_name);
723 msgp("\rfound group type : REMOTE, name : %s", group_name);
725 found_group_list = g_list_append(found_group_list, group);
730 void _group_finish_cb(int result, void *user_data)
732 msgb("\rFind Group Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
735 static int run_group_find(MManager *mm, struct menu_data *menu)
742 duration = (unsigned short)strtol(timeout, NULL, 10);
744 if (found_group_list) {
745 g_list_free_full(found_group_list, _destroy_mdg_group_info);
746 found_group_list = NULL;
749 ret = mdg_group_find(handle, duration, _group_found_cb, _group_finish_cb, NULL);
750 if (MDG_ERROR_NONE != ret) {
751 msgr("Failed to Find Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
754 msg(" - mdg_group_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
759 static int run_group_create(MManager *mm, struct menu_data *menu)
764 ret = mdg_group_create(handle, groupid);
765 if (MDG_ERROR_NONE != ret) {
766 msgr("Failed to Create Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
769 msg(" - mdg_group_create() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
770 msgb("Create Group Successfully");
775 void _send_data_finish_cb(int result, void *user_data)
777 msgb("\rFind Send Data Finished = %d", result);
780 static int __send_data(int devidx, int chaidx)
783 char *deviceid = NULL;
784 char *address = NULL;
785 mdg_device_h device = NULL;
786 channel_t *channel = NULL;
787 if (found_invited_device_list) {
788 device = g_list_nth_data(found_invited_device_list, devidx - 1);
789 if (NULL == device) {
790 msgr("Find local device first");
795 if (found_channel_list) {
796 channel = g_list_nth_data(found_channel_list, chaidx - 1);
797 if (NULL == channel) {
798 msgr("Find local device first");
803 mdg_device_info_get_device_id(device, &deviceid);
804 mdg_device_info_get_addr(device, &address);
805 msgp("Sent to [ID] %s [ADDR] %s [CHANNEL ID] %s", deviceid, address, channel->channel_id);
815 ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message,
816 strlen(message), _send_data_finish_cb, NULL);
817 if (MDG_ERROR_NONE != ret)
818 msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
823 static int run_send_data(MManager *mm, struct menu_data *menu)
827 int count = g_list_length(found_invited_device_list);
834 if (strlen(device_idx)) {
835 devidx = (unsigned short)strtol(device_idx, NULL, 10);
837 msgp("Invalid index. set to 1");
841 if (strlen(channel_idx)) {
842 chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
844 msgp("Invalid index. set to 1");
848 return __send_data(devidx, chaidx);
851 void __send_file_progress_cb(const char *file_path, long send_size,
852 long total_size, int percent, void *user_data)
854 msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size);
856 void __send_file_finish_cb(int result, mdg_device_h device, void *user_data)
860 mdg_device_info_get_addr(device, &addr);
862 msgp("Send file to %s Finished [%s]", addr, mdg_error_to_string(result));
865 static int __send_file(int devidx)
868 char *deviceid = NULL;
869 char *address = NULL;
870 mdg_device_h device = NULL;
872 if (found_invited_device_list) {
873 device = g_list_nth_data(found_invited_device_list, devidx - 1);
874 if (NULL == device) {
875 msgr("Find local device first");
880 mdg_device_info_get_device_id(device, &deviceid);
881 mdg_device_info_get_addr(device, &address);
882 msgp("Sent to [ID] %s [ADDR] %s", deviceid, address);
892 ret = mdg_device_send_file(handle, device, file_path,
893 __send_file_progress_cb, __send_file_finish_cb, NULL);
894 if (MDG_ERROR_NONE != ret)
895 msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
900 static int run_send_file(MManager *mm, struct menu_data *menu)
903 int count = g_list_length(found_invited_device_list);
910 if (strlen(device_idx)) {
911 devidx = (unsigned short)strtol(device_idx, NULL, 10);
913 msgp("Invalid index. set to 1");
918 return __send_file(devidx);
921 void _invited_device_finish_cb(int result, void *user_data)
923 msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
924 mdg_error_to_string(result));
927 bool _invited_device_found_cb(mdg_device_h device, void *user_data)
930 char *device_id = NULL;
931 mdg_device_type_e device_type;
933 mdg_device_info_get_device_id(device, &device_id);
934 mdg_device_info_get_addr(device, &addr);
935 mdg_device_info_get_type(device, &device_type);
937 msgp("\r[ID] %s [IP] %s [Type] %s", device_id, addr,
938 __device_type_to_string(device_type));
945 found_invited_device_list = g_list_append(found_invited_device_list, device);
950 static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu)
954 msg("Find My Owned Devices");
957 duration = (unsigned short)strtol(timeout, NULL, 10);
959 ret = mdg_device_find(handle, duration, true, _invited_device_found_cb,
960 _invited_device_finish_cb, NULL);
961 if (MDG_ERROR_NONE != ret) {
962 msgr("Failed to Find My Owned Devices: [%s(0x%X)]",
963 mdg_error_to_string(ret), ret);
967 msg(" - mdg_device_find_invited_device() ret: [0x%X] [%s]",
968 ret, mdg_error_to_string(ret));
970 if (found_invited_device_list) {
971 g_list_free_full(found_invited_device_list, _destroy_mdg_device_info);
972 found_invited_device_list = NULL;
978 static int run_request_create_group(MManager *mm, struct menu_data *menu)
982 mdg_device_h device = NULL;
984 msg("Request create group");
986 dev_count = g_list_length(found_invited_device_list);
988 if (0 >= dev_count) {
994 if (device_idx != NULL && strlen(device_idx)) {
995 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
997 msgp("Invalid index. set to 1");
1002 if (found_invited_device_list) {
1003 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1004 if (NULL == device) {
1005 msgr("Failed to g_hash_table_find");
1010 ret = mdg_request_create_group(handle, device, request_groupid,
1011 receive_request_result, NULL);
1012 if (MDG_ERROR_NONE != ret) {
1013 msgr("Failed to Request Create Group: [%s(0x%X)]",
1014 mdg_error_to_string(ret), ret);
1018 msg(" - mdg_request_create_group() ret: [0x%X] [%s]",
1019 ret, mdg_error_to_string(ret));
1024 static int run_request_invite(MManager *mm, struct menu_data *menu)
1029 mdg_device_h device = NULL;
1030 mdg_group_h group = NULL;
1032 dev_count = g_list_length(found_invited_device_list);
1033 grp_count = g_list_length(found_group_list);
1035 if (0 >= dev_count || 0 >= grp_count) {
1041 if (group_idx != NULL && strlen(group_idx)) {
1042 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1044 msgp("Invalid index. set to 1");
1049 if (found_group_list) {
1050 group = g_list_nth_data(found_group_list, grp_idx - 1);
1051 if (NULL == group) {
1052 msgr("Failed to g_hash_table_find");
1058 if (device_idx != NULL && strlen(device_idx)) {
1059 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1061 msgp("Invalid index. set to 1");
1066 if (found_invited_device_list) {
1067 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1068 if (NULL == device) {
1069 msgr("Failed to g_hash_table_find");
1074 ret = mdg_request_invite_device(handle, group, device, pin,
1075 receive_request_result, NULL);
1076 if (MDG_ERROR_NONE != ret) {
1077 msgr("Failed to Request Invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1081 msg(" - mdg_request_invite_device() ret: [0x%X] [%s]",
1082 ret, mdg_error_to_string(ret));
1087 static int run_request_eject(MManager *mm, struct menu_data *menu)
1092 mdg_device_h device = NULL;
1093 mdg_group_h group = NULL;
1095 dev_count = g_list_length(found_invited_device_list);
1096 grp_count = g_list_length(found_group_list);
1098 if (0 >= dev_count || 0 >= grp_count) {
1104 if (group_idx != NULL && strlen(group_idx)) {
1105 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1107 msgp("Invalid index. set to 1");
1112 if (found_group_list) {
1113 group = g_list_nth_data(found_group_list, grp_idx - 1);
1114 if (NULL == group) {
1115 msgr("Failed to g_hash_table_find");
1121 if (device_idx != NULL && strlen(device_idx)) {
1122 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1124 msgp("Invalid index. set to 1");
1129 if (found_invited_device_list) {
1130 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1131 if (NULL == device) {
1132 msgr("Failed to g_hash_table_find");
1137 ret = mdg_request_eject_device(handle, group, device, receive_request_result,
1139 if (MDG_ERROR_NONE != ret) {
1140 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1144 msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1149 void __req_channel_list_finish_cb(char *device_id, char *channel_id, void *user_data)
1151 msgp("\rDevice ID : [%s], Channel ID : [%s]", device_id, channel_id);
1153 channel_t *channel = g_new0(channel_t, 1);
1154 channel->device_id = g_strdup(device_id);
1155 channel->channel_id = g_strdup(channel_id);
1157 found_channel_list = g_list_append(found_channel_list, channel);
1162 static int run_request_channel_list(MManager *mm, struct menu_data *menu)
1166 mdg_device_h device = NULL;
1168 dev_count = g_list_length(found_invited_device_list);
1170 if (0 >= dev_count) {
1176 if (device_idx != NULL && strlen(device_idx)) {
1177 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1179 msgp("Invalid index. set to 1");
1184 if (found_invited_device_list) {
1185 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1186 if (NULL == device) {
1187 msgr("Failed to g_hash_table_find");
1192 ret = mdg_request_channel_list(handle, device, __req_channel_list_finish_cb, NULL);
1193 if (MDG_ERROR_NONE != ret) {
1194 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1198 msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1203 void __channel_cb(int result, char *device_id, char *channel_id,
1204 unsigned char *arg, int len, void *user_data)
1206 msg("[%s] channel callback is called by [%s]'s send message", channel_id, device_id);
1207 msg("arg : %s, len : %d", arg, len);
1208 msg("result is %d", result);
1211 static int run_regist_channel(MManager *mm, struct menu_data *menu)
1215 ret = mdg_device_regist_channel(handle, channel_id, __channel_cb, NULL);
1217 msg(" - mdg_device_regist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1222 static int run_unregist_channel(MManager *mm, struct menu_data *menu)
1226 ret = mdg_device_unregist_channel(handle, channel_id);
1228 msg(" - mdg_unregist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1233 static struct menu_data menu_group_create[] = {
1234 { "0", "Group Name", NULL, NULL, groupid },
1235 { "1", "Run", NULL, run_group_create, NULL },
1239 static struct menu_data menu_group_find[] = {
1240 { "0", "Timeout", NULL, NULL, timeout },
1241 { "1", "Run", NULL, run_group_find, NULL },
1245 static struct menu_data menu_group_delete[] = {
1246 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1247 { "1", "Index", NULL, NULL, group_idx },
1248 { "2", "Run", NULL, run_group_delete, NULL },
1252 static struct menu_data menu_devices_find[] = {
1253 { "0", "Timeout", NULL, NULL, timeout },
1254 { "1", "Run", NULL, run_devices_find, NULL },
1258 static struct menu_data menu_group_invite_device[] = {
1259 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1260 { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
1261 { "2", "Group Index", NULL, NULL, group_idx },
1262 { "3", "Device Index", NULL, NULL, device_idx },
1263 { "4", "PIN", NULL, NULL, pin },
1264 { "5", "Run", NULL, run_device_invite, NULL },
1268 static struct menu_data menu_group_eject_device[] = {
1269 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1270 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1271 { "2", "Group Index", NULL, NULL, group_idx },
1272 { "3", "Device Index", NULL, NULL, device_idx },
1273 { "4", "Run", NULL, run_device_eject, NULL },
1277 static struct menu_data menu_group_foreach_device[] = {
1278 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1279 { "1", "Group Index", NULL, NULL, group_idx },
1280 { "2", "Run", NULL, run_group_foreach_device, NULL },
1284 static struct menu_data menu_send_data[] = {
1285 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1286 { "1", "Show Channel List", NULL, run_channels_show, NULL },
1287 { "2", "Message", NULL, NULL, message },
1288 { "3", "Device Index", NULL, NULL, device_idx },
1289 { "4", "Channel Index", NULL, NULL, channel_idx },
1290 { "5", "Send", NULL, run_send_data, NULL },
1294 static struct menu_data menu_send_file[] = {
1295 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1296 { "1", "File Path", NULL, NULL, file_path },
1297 { "2", "Device Index", NULL, NULL, device_idx },
1298 { "3", "Send", NULL, run_send_file, NULL },
1302 static struct menu_data menu_devices_find_invited_device[] = {
1303 { "0", "Timeout", NULL, NULL, timeout },
1304 { "1", "Run", NULL, run_devices_find_invited_device, NULL },
1308 static struct menu_data menu_request_create_group[] = {
1309 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1310 { "1", "Device Index", NULL, NULL, device_idx },
1311 { "2", "Request Group Name", NULL, NULL, request_groupid },
1312 { "3", "Run", NULL, run_request_create_group, NULL },
1316 static struct menu_data menu_request_invite[] = {
1317 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1318 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1319 { "2", "Group Index", NULL, NULL, group_idx },
1320 { "3", "Device Index", NULL, NULL, device_idx },
1321 { "4", "PIN", NULL, NULL, pin },
1322 { "5", "Run", NULL, run_request_invite, NULL },
1326 static struct menu_data menu_request_eject[] = {
1327 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1328 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1329 { "2", "Group Index", NULL, NULL, group_idx },
1330 { "3", "Device Index", NULL, NULL, device_idx },
1331 { "4", "Run", NULL, run_request_eject, NULL },
1335 static struct menu_data menu_request_channel_list[] = {
1336 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1337 { "1", "Device Index", NULL, NULL, device_idx },
1338 { "2", "Run", NULL, run_request_channel_list, NULL },
1342 static struct menu_data menu_regist_channel[] = {
1343 { "0", "Channel ID", NULL, NULL, channel_id },
1344 { "1", "Run", NULL, run_regist_channel, NULL },
1348 static struct menu_data menu_unregist_channel[] = {
1349 { "0", "Channel ID", NULL, NULL, channel_id },
1350 { "1", "Run", NULL, run_unregist_channel, NULL },
1354 struct menu_data menu_mdg_manager[] = {
1355 { "1", "Show Local Device", NULL, run_device_show_local_device, NULL }, // O
1356 { "2", "Create Group", menu_group_create, NULL, NULL }, // 0
1357 { "3", "Find Group(s)", menu_group_find, NULL, NULL }, // 0
1358 { "4", "Show Group(s)", NULL, run_group_show, NULL }, // 0
1359 { "5", "Delete Group", menu_group_delete, NULL, NULL }, // 0
1360 { "6", "Find Device(s)", menu_devices_find, NULL, NULL }, // 0
1361 { "7", "Show Device(s)", NULL, run_devices_show, NULL }, // 0
1362 { "8", "Invite Device", menu_group_invite_device, NULL, NULL }, // 0
1363 { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0
1364 { "10", "Foreach Device", menu_group_foreach_device, NULL, NULL },
1365 { "11", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0
1366 { "12", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0
1367 { "13", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0
1368 { "14", "Request Invite", menu_request_invite, NULL, NULL }, // 0
1369 { "15", "Request Eject", menu_request_eject, NULL, NULL }, // 0
1370 { "16", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0
1371 { "17", "Regist Channel", menu_regist_channel, NULL, NULL },
1372 { "18", "Unregist Channel", menu_unregist_channel, NULL, NULL },
1373 { "19", "Send Message", menu_send_data, NULL, NULL }, // 0
1374 { "20", "Send File", menu_send_file, NULL, NULL }, // 0