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 static void _destroy_mdg_device_info(gpointer data)
65 mdg_device_info_destroy((mdg_device_h)data);
68 void receive_request_result(char *cmd, char *device_id, unsigned char *arg,
69 int len, int ret, void *user_data)
71 msg("_request_result_cb is called command %s Requester id %s", cmd,
75 msgp("cmd is null [%s(0x%X)]", mdg_error_to_string(ret), ret);
79 if (strncmp("COMP_REQ_CREATE_GROUP", cmd, strlen(cmd)) == 0) {
80 msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret),
82 if (ret == MDG_ERROR_NONE && arg != NULL) {
83 msgb("Created Group name is %s", arg);
84 run_group_find(NULL, NULL);
85 run_devices_find(NULL, NULL);
87 } else if (strncmp("COMP_REQ_INVITE_DEVICE", cmd, strlen(cmd)) == 0) {
88 msgp("[CMD] Request Invite [%s(0x%X)]", mdg_error_to_string(ret), ret);
89 if (ret == MDG_ERROR_NONE && arg != NULL)
90 msgb("Invited Device ID is %s", arg);
91 } else if (strncmp("COMP_REQ_EJECT_DEVICE", cmd, strlen(cmd)) == 0) {
92 msgp("[CMD] Request Eject [%s(0x%X)]", mdg_error_to_string(ret), ret);
93 if (ret == MDG_ERROR_NONE && arg != NULL)
94 msgb("Ejected Device ID is %s", arg);
95 } else if (strncmp("COMP_REQ_DELETE_GROUP", cmd, strlen(cmd)) == 0) {
96 msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret),
98 if (ret == MDG_ERROR_NONE && arg != NULL)
99 msgb("Deleted Group name is %s", arg);
100 } else if (strncmp("COMP_REQ_SEND_DATA", cmd, strlen(cmd)) == 0) {
101 msgp("Received data [%d] %s", strlen((char *)arg), arg);
103 msgp("[Recv][%d] %s", strlen((char *) arg), arg);
107 void _device_eject_result_cb(int result, void *user_data)
109 msgb("\rEject Device Complete [%s]", mdg_error_to_string(result));
112 static int run_device_eject(MManager *mm, struct menu_data *menu)
116 mdg_group_h group = NULL;
117 mdg_device_h device = NULL;
121 if (strlen(group_idx)) {
122 idx = (unsigned short)strtol(group_idx, NULL, 10);
124 msgp("Invalid index. set to 1");
129 if (found_group_list) {
130 group = g_list_nth_data(found_group_list, idx - 1);
132 msgr("Failed to g_hash_table_find");
137 if (strlen(device_idx)) {
138 idx = (unsigned short)strtol(device_idx, NULL, 10);
140 msgp("Invalid index. set to 1");
145 if (NULL == found_invited_device_list) {
146 msgr("Find device first");
150 device = g_list_nth_data(found_invited_device_list, idx - 1);
151 if (NULL == device) {
152 msgr("Failed to g_hash_table_find");
156 ret = mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL);
157 if (MDG_ERROR_NONE != ret) {
158 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
161 msg(" - mdg_group_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
166 bool __group_foreach_cb(mdg_device_h device, void *user_data)
170 mdg_device_info_get_device_id(device, &device_id);
171 msgb("\rDevice is [%s]", device_id);
173 found_invited_device_list = g_list_append(found_invited_device_list, device);
178 static int run_group_foreach_device(MManager *mm, struct menu_data *menu)
182 mdg_group_h group = NULL;
184 msg("Foreach Device");
186 if (strlen(group_idx)) {
187 idx = (unsigned short)strtol(group_idx, NULL, 10);
189 msgp("Invalid index. set to 1");
194 if (found_group_list) {
195 group = g_list_nth_data(found_group_list, idx - 1);
197 msgr("Failed to g_hash_table_find");
202 if (found_invited_device_list) {
203 g_list_free_full(found_device_list, _destroy_mdg_device_info);
204 found_invited_device_list = NULL;
207 ret = mdg_group_foreach_device(handle, group, __group_foreach_cb, NULL);
208 if (MDG_ERROR_NONE != ret) {
209 msgr("Failed to foreach device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
212 msg(" - mdg_group_foreach_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
217 void _device_invite_result_cb(int result, mdg_device_h device, void *user_data)
220 mdg_device_info_is_invited(device, &is_invited);
221 msgb("\rInvite Device Finished [%s]", mdg_error_to_string(result));
222 msgb("\rThe device invited is : %d", is_invited);
225 static int run_device_invite(MManager *mm, struct menu_data *menu)
229 mdg_group_h group = NULL;
230 mdg_device_h device = NULL;
232 msg("Invite Device");
234 if (strlen(group_idx)) {
235 idx = (unsigned short)strtol(group_idx, NULL, 10);
237 msgp("Invalid index. set to 1");
242 if (found_group_list) {
243 group = g_list_nth_data(found_group_list, idx - 1);
245 msgr("Failed to g_hash_table_find");
250 if (strlen(device_idx)) {
251 idx = (unsigned short)strtol(device_idx, NULL, 10);
253 msgp("Invalid index. set to 1");
258 if (NULL == found_device_list) {
259 msgr("Find device first");
263 device = g_list_nth_data(found_device_list, idx - 1);
264 if (NULL == device) {
265 msgr("Failed to g_hash_table_find");
269 ret = mdg_group_invite_device(handle, group, device, pin, _device_invite_result_cb, NULL);
270 if (MDG_ERROR_NONE != ret) {
271 msgr("Failed to device invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
274 msg(" - mdg_group_invite_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
280 static int run_devices_show(MManager *mm, struct menu_data *menu)
287 /* Get a first item */
289 iter = g_list_first(found_device_list);
290 while (NULL != iter) {
293 msgr("device is null");
299 mdg_device_info_get_model_name(device, &model_name);
300 mdg_device_info_get_device_id(device, &device_id);
302 msgp("[%d] Model : %s, Device ID : %s", i+1, model_name, device_id);
304 mdg_device_h cloned_device;
305 char *cloned_model_name;
306 char *cloned_device_id;
308 mdg_device_info_clone(&cloned_device, device);
309 mdg_device_info_get_model_name(cloned_device, &cloned_model_name);
310 mdg_device_info_get_device_id(cloned_device, &cloned_device_id);
312 msgp("*Cloned* [%d] Model : %s, Device ID : %s", i+1, cloned_model_name, cloned_device_id);
320 if (cloned_model_name)
321 free(cloned_model_name);
323 if (cloned_device_id)
324 free(cloned_device_id);
326 mdg_device_info_destroy(cloned_device);
329 iter = g_list_next(iter);
336 static int run_invited_devices_show(MManager *mm, struct menu_data *menu)
343 /* Get a first item */
345 iter = g_list_first(found_invited_device_list);
346 while (NULL != iter) {
349 msgr("device is null");
356 mdg_device_info_get_device_id(device, &device_id);
357 mdg_device_info_get_model_name(device, &model_name);
359 msgp("[%d] Device : %s, Model : %s", i+1, device_id, model_name);
368 iter = g_list_next(iter);
375 typedef struct _channel_t {
376 char *device_id; /**< User callback to be called */
377 char *channel_id; /**< User data pointer */
380 static int run_channels_show(MManager *mm, struct menu_data *menu)
387 /* Get a first item */
389 iter = g_list_first(found_channel_list);
390 while (NULL != iter) {
391 channel = iter->data;
393 msgr("channel is null");
397 msgp("[%d] device id : %s, channel id : %s,", i+1, channel->device_id, channel->channel_id);
400 iter = g_list_next(iter);
408 static int run_group_get_members(MManager *mm, struct menu_data *menu)
413 mdg_group_h group = NULL;
414 mdg_device_h **devices = NULL;
416 msg("Get Group Members");
418 if (strlen(group_idx)) {
419 idx = (unsigned short)strtol(group_idx, NULL, 10);
421 msgp("Invalid index. set to 1");
426 if (found_group_list) {
427 group = g_list_nth_data(found_group_list, idx - 1);
429 msgr("Failed to g_hash_table_find");
434 ret = mdg_group_get_member_devices(group, devices, &count);
435 if (MDG_ERROR_NONE != ret) {
436 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
439 msg(" - mdg_group_get_member_devices() ret: [0x%X] [%s]", ret,
440 mdg_error_to_string(ret));
442 for (int i = 0; i < count; i++) {
444 char *device_id = NULL;
446 mdg_device_type_e device_type;
448 mdg_device_info_get_device_id(devices[i], &device_id);
449 mdg_device_info_get_ip(devices[i], &ip);
450 mdg_device_info_get_device_type(devices[i], &device_type);
452 msgp("device_id : %s, name : %s, type : %s", device_id, ip,
453 __device_type_to_string(device_type));
465 static int run_group_delete(MManager *mm, struct menu_data *menu)
473 if (strlen(group_idx)) {
474 idx = (unsigned short)strtol(group_idx, NULL, 10);
476 msgp("Invalid index. set to 1");
481 if (found_group_list) {
482 group = g_list_nth_data(found_group_list, idx - 1);
484 msgr("Failed to g_hash_table_find");
489 ret = mdg_group_delete(handle, group);
490 if (MDG_ERROR_NONE != ret) {
491 msgr("Failed to Delete Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
494 msg(" - mdg_group_delete() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
499 void _device_finish_cb(int result, void *user_data)
501 msgb("\rFind Device Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
504 bool _device_found_cb(mdg_device_h device, void *user_data)
507 char *device_id = NULL;
508 char *model_name = NULL;
509 mdg_device_type_e device_type;
511 gboolean is_exist = FALSE;
513 mdg_device_info_get_device_id(device, &device_id);
514 mdg_device_info_get_model_name(device, &model_name);
515 mdg_device_info_get_type(device, &device_type);
517 iter = found_device_list;
518 while (iter != NULL) {
519 mdg_device_h temp = (mdg_device_h)iter->data;
520 char *temp_device_id;
522 mdg_device_info_get_device_id(temp, &temp_device_id);
524 if (g_strcmp0(device_id, temp_device_id) == 0) {
526 free(temp_device_id);
527 mdg_device_info_destroy(device);
531 free(temp_device_id);
532 iter = g_list_next(iter);
535 if (is_exist == FALSE) {
536 found_device_list = g_list_append(found_device_list, device);
537 msgp("\r[ID] %s [Type] %s [Name] %s", device_id,
538 __device_type_to_string(device_type), model_name);
549 static int run_devices_find(MManager *mm, struct menu_data *menu)
556 duration = (unsigned short)strtol(timeout, NULL, 10);
558 ret = mdg_device_find(handle, duration, false, _device_found_cb, _device_finish_cb, NULL);
559 if (MDG_ERROR_NONE != ret) {
560 msgr("Failed to Find Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret);
563 msg(" - mdg_device_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
565 if (found_device_list) {
566 g_list_free_full(found_device_list, _destroy_mdg_device_info);
567 found_device_list = NULL;
573 void __receive_file_cb(int result, char *device_id, const char *file_path, void *user_data)
575 msgb("The %s is stored by %s", file_path, device_id);
578 int run_device_show_local_device(MManager *mm, struct menu_data *menu)
581 mdg_device_h device = NULL;
583 msg("Get Local Device");
585 ret = mdg_device_get_local_device(handle, &device);
586 if (MDG_ERROR_NONE != ret) {
587 msgr("Failed to Get My Device: [%s(0x%X)]", mdg_error_to_string(ret), ret);
590 msg(" - mdg_device_info_get_local_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
593 char *device_id = NULL;
600 mdg_device_type_e type;
602 mdg_device_info_get_device_id(device, &device_id);
603 mdg_device_info_get_model_name(device, &model_name);
604 mdg_device_info_get_device_name(device, &device_name);
605 mdg_device_info_get_platform_ver(device, &platform_ver);
606 mdg_device_info_get_vendor_id(device, &vendor_id);
607 mdg_device_info_get_profile(device, &profile);
608 mdg_device_info_is_invited(device, &is_invited);
609 mdg_device_info_get_type(device, &type);
611 msgb("\n[ID] %s", device_id);
612 msgb("[Model Name] %s", model_name);
613 msgb("[Device Name] %s", device_name);
614 msgb("[Platform Ver.] %s", platform_ver);
615 msgb("[Vendor ID] %s", vendor_id);
616 msgb("[Profile] %s", profile);
617 msgb("[Is Invited] %d", is_invited);
618 msgb("[Type] %s\n", __device_type_to_string(type));
631 mdg_device_info_destroy(device);
636 mdg_set_receive_file_cb(handle, __receive_file_cb, NULL);
641 static int run_group_show(MManager *mm, struct menu_data *menu)
648 /* Get a first item */
650 iter = g_list_first(found_group_list);
651 while (NULL != iter) {
654 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_name(group, &name);
664 mdg_group_info_get_type(group, &type);
666 msgp("[%d] type: %s, name: %s", i+1, mdg_group_type_to_string(type), name);
667 msgp(" device_id: %s\n", device_id);
669 mdg_group_h cloned_group;
670 char *cloned_device_id;
672 mdg_group_type_e cloned_type;
674 mdg_group_info_clone(&cloned_group, group);
675 mdg_group_info_get_device_id(cloned_group, &cloned_device_id);
676 mdg_group_info_get_name(cloned_group, &cloned_name);
677 mdg_group_info_get_type(cloned_group, &cloned_type);
679 msgp("*Cloned* [%d] type: %s, name: %s", i+1, mdg_group_type_to_string(cloned_type), cloned_name);
680 msgp(" device_id: %s\n", cloned_device_id);
687 if (cloned_device_id)
688 free(cloned_device_id);
692 mdg_group_info_destroy(cloned_group);
695 iter = g_list_next(iter);
702 static void _destroy_mdg_group_info(gpointer data)
704 mdg_group_info_destroy((mdg_group_h)data);
707 bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data)
711 mdg_group_info_get_name(group, &group_name);
713 if (type == MDG_GROUP_TYPE_LOCAL)
714 msgp("\rfound group type : MINE, name : %s", group_name);
716 msgp("\rfound group type : REMOTE, name : %s", group_name);
718 found_group_list = g_list_append(found_group_list, group);
723 void _group_finish_cb(int result, void *user_data)
725 msgb("\rFind Group Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result));
728 static int run_group_find(MManager *mm, struct menu_data *menu)
735 duration = (unsigned short)strtol(timeout, NULL, 10);
737 if (found_group_list) {
738 g_list_free_full(found_group_list, _destroy_mdg_group_info);
739 found_group_list = NULL;
742 ret = mdg_group_find(handle, duration, _group_found_cb, _group_finish_cb, NULL);
743 if (MDG_ERROR_NONE != ret) {
744 msgr("Failed to Find Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
747 msg(" - mdg_group_find() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
752 static int run_group_create(MManager *mm, struct menu_data *menu)
757 ret = mdg_group_create(handle, groupid);
758 if (MDG_ERROR_NONE != ret) {
759 msgr("Failed to Create Group: [%s(0x%X)]", mdg_error_to_string(ret), ret);
762 msg(" - mdg_group_create() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
763 msgb("Create Group Successfully");
768 void _send_data_finish_cb(int result, void *user_data)
770 msgb("\rFind Send Data Finished = %d", result);
773 static int __send_data(int devidx, int chaidx)
776 char *deviceid = NULL;
777 char *address = NULL;
778 mdg_device_h device = NULL;
779 channel_t *channel = NULL;
780 if (found_invited_device_list) {
781 device = g_list_nth_data(found_invited_device_list, devidx - 1);
782 if (NULL == device) {
783 msgr("Find local device first");
788 if (found_channel_list) {
789 channel = g_list_nth_data(found_channel_list, chaidx - 1);
790 if (NULL == channel) {
791 msgr("Find local device first");
796 mdg_device_info_get_device_id(device, &deviceid);
797 msgp("Sent to [ID] %s [CHANNEL ID] %s", deviceid, channel->channel_id);
807 ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message,
808 strlen(message), _send_data_finish_cb, NULL);
809 if (MDG_ERROR_NONE != ret)
810 msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
815 static int run_send_data(MManager *mm, struct menu_data *menu)
819 int count = g_list_length(found_invited_device_list);
826 if (strlen(device_idx)) {
827 devidx = (unsigned short)strtol(device_idx, NULL, 10);
829 msgp("Invalid index. set to 1");
833 if (strlen(channel_idx)) {
834 chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
836 msgp("Invalid index. set to 1");
840 return __send_data(devidx, chaidx);
843 void __send_file_progress_cb(const char *file_path, long send_size,
844 long total_size, int percent, void *user_data)
846 msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size);
848 void __send_file_finish_cb(int result, mdg_device_h device, void *user_data)
852 mdg_device_info_get_device_id(device, &device_id);
854 msgp("Send file to %s Finished [%s]", device_id, mdg_error_to_string(result));
857 static int __send_file(int devidx)
860 char *deviceid = NULL;
861 char *address = NULL;
862 mdg_device_h device = NULL;
864 if (found_invited_device_list) {
865 device = g_list_nth_data(found_invited_device_list, devidx - 1);
866 if (NULL == device) {
867 msgr("Find local device first");
872 mdg_device_info_get_device_id(device, &deviceid);
873 msgp("Sent to [ID] %s", deviceid);
883 ret = mdg_device_send_file(handle, device, file_path,
884 __send_file_progress_cb, __send_file_finish_cb, NULL);
885 if (MDG_ERROR_NONE != ret)
886 msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
891 static int run_send_file(MManager *mm, struct menu_data *menu)
894 int count = g_list_length(found_invited_device_list);
901 if (strlen(device_idx)) {
902 devidx = (unsigned short)strtol(device_idx, NULL, 10);
904 msgp("Invalid index. set to 1");
909 return __send_file(devidx);
912 void _invited_device_finish_cb(int result, void *user_data)
914 msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result,
915 mdg_error_to_string(result));
918 bool _invited_device_found_cb(mdg_device_h device, void *user_data)
920 char *device_id = NULL;
921 mdg_device_type_e device_type;
923 mdg_device_info_get_device_id(device, &device_id);
924 mdg_device_info_get_type(device, &device_type);
926 msgp("\r[ID] %s [Type] %s", device_id, __device_type_to_string(device_type));
931 found_invited_device_list = g_list_append(found_invited_device_list, device);
936 static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu)
940 msg("Find My Owned Devices");
943 duration = (unsigned short)strtol(timeout, NULL, 10);
945 ret = mdg_device_find(handle, duration, true, _invited_device_found_cb,
946 _invited_device_finish_cb, NULL);
947 if (MDG_ERROR_NONE != ret) {
948 msgr("Failed to Find My Owned Devices: [%s(0x%X)]",
949 mdg_error_to_string(ret), ret);
953 msg(" - mdg_device_find_invited_device() ret: [0x%X] [%s]",
954 ret, mdg_error_to_string(ret));
956 if (found_invited_device_list) {
957 g_list_free_full(found_invited_device_list, _destroy_mdg_device_info);
958 found_invited_device_list = NULL;
964 static int run_request_create_group(MManager *mm, struct menu_data *menu)
968 mdg_device_h device = NULL;
970 msg("Request create group");
972 dev_count = g_list_length(found_invited_device_list);
974 if (0 >= dev_count) {
980 if (device_idx != NULL && strlen(device_idx)) {
981 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
983 msgp("Invalid index. set to 1");
988 if (found_invited_device_list) {
989 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
990 if (NULL == device) {
991 msgr("Failed to g_hash_table_find");
996 ret = mdg_request_create_group(handle, device, request_groupid,
997 receive_request_result, NULL);
998 if (MDG_ERROR_NONE != ret) {
999 msgr("Failed to Request Create Group: [%s(0x%X)]",
1000 mdg_error_to_string(ret), ret);
1004 msg(" - mdg_request_create_group() ret: [0x%X] [%s]",
1005 ret, mdg_error_to_string(ret));
1010 static int run_request_invite(MManager *mm, struct menu_data *menu)
1015 mdg_device_h device = NULL;
1016 mdg_group_h group = NULL;
1018 dev_count = g_list_length(found_invited_device_list);
1019 grp_count = g_list_length(found_group_list);
1021 if (0 >= dev_count || 0 >= grp_count) {
1027 if (group_idx != NULL && strlen(group_idx)) {
1028 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1030 msgp("Invalid index. set to 1");
1035 if (found_group_list) {
1036 group = g_list_nth_data(found_group_list, grp_idx - 1);
1037 if (NULL == group) {
1038 msgr("Failed to g_hash_table_find");
1044 if (device_idx != NULL && strlen(device_idx)) {
1045 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1047 msgp("Invalid index. set to 1");
1052 if (found_invited_device_list) {
1053 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1054 if (NULL == device) {
1055 msgr("Failed to g_hash_table_find");
1060 ret = mdg_request_invite_device(handle, group, device, pin,
1061 receive_request_result, NULL);
1062 if (MDG_ERROR_NONE != ret) {
1063 msgr("Failed to Request Invite: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1067 msg(" - mdg_request_invite_device() ret: [0x%X] [%s]",
1068 ret, mdg_error_to_string(ret));
1073 static int run_request_eject(MManager *mm, struct menu_data *menu)
1078 mdg_device_h device = NULL;
1079 mdg_group_h group = NULL;
1081 dev_count = g_list_length(found_invited_device_list);
1082 grp_count = g_list_length(found_group_list);
1084 if (0 >= dev_count || 0 >= grp_count) {
1090 if (group_idx != NULL && strlen(group_idx)) {
1091 grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
1093 msgp("Invalid index. set to 1");
1098 if (found_group_list) {
1099 group = g_list_nth_data(found_group_list, grp_idx - 1);
1100 if (NULL == group) {
1101 msgr("Failed to g_hash_table_find");
1107 if (device_idx != NULL && strlen(device_idx)) {
1108 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1110 msgp("Invalid index. set to 1");
1115 if (found_invited_device_list) {
1116 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1117 if (NULL == device) {
1118 msgr("Failed to g_hash_table_find");
1123 ret = mdg_request_eject_device(handle, group, device, receive_request_result,
1125 if (MDG_ERROR_NONE != ret) {
1126 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1130 msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1135 void __req_channel_list_finish_cb(char *device_id, char *channel_id, void *user_data)
1137 msgp("\rDevice ID : [%s], Channel ID : [%s]", device_id, channel_id);
1139 channel_t *channel = g_new0(channel_t, 1);
1140 channel->device_id = g_strdup(device_id);
1141 channel->channel_id = g_strdup(channel_id);
1143 found_channel_list = g_list_append(found_channel_list, channel);
1148 static int run_request_channel_list(MManager *mm, struct menu_data *menu)
1152 mdg_device_h device = NULL;
1154 dev_count = g_list_length(found_invited_device_list);
1156 if (0 >= dev_count) {
1162 if (device_idx != NULL && strlen(device_idx)) {
1163 dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
1165 msgp("Invalid index. set to 1");
1170 if (found_invited_device_list) {
1171 device = g_list_nth_data(found_invited_device_list, dev_idx - 1);
1172 if (NULL == device) {
1173 msgr("Failed to g_hash_table_find");
1178 ret = mdg_request_channel_list(handle, device, __req_channel_list_finish_cb, NULL);
1179 if (MDG_ERROR_NONE != ret) {
1180 msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret);
1184 msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1189 void __channel_cb(int result, char *device_id, char *channel_id,
1190 unsigned char *arg, int len, void *user_data)
1192 msg("[%s] channel callback is called by [%s]'s send message", channel_id, device_id);
1193 msg("arg : %s, len : %d", arg, len);
1194 msg("result is %d", result);
1197 static int run_regist_channel(MManager *mm, struct menu_data *menu)
1201 ret = mdg_device_regist_channel(handle, channel_id, __channel_cb, NULL);
1203 msg(" - mdg_device_regist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1208 static int run_unregist_channel(MManager *mm, struct menu_data *menu)
1212 ret = mdg_device_unregist_channel(handle, channel_id);
1214 msg(" - mdg_unregist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret));
1219 static struct menu_data menu_group_create[] = {
1220 { "0", "Group Name", NULL, NULL, groupid },
1221 { "1", "Run", NULL, run_group_create, NULL },
1225 static struct menu_data menu_group_find[] = {
1226 { "0", "Timeout", NULL, NULL, timeout },
1227 { "1", "Run", NULL, run_group_find, NULL },
1231 static struct menu_data menu_group_delete[] = {
1232 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1233 { "1", "Index", NULL, NULL, group_idx },
1234 { "2", "Run", NULL, run_group_delete, NULL },
1238 static struct menu_data menu_devices_find[] = {
1239 { "0", "Timeout", NULL, NULL, timeout },
1240 { "1", "Run", NULL, run_devices_find, NULL },
1244 static struct menu_data menu_group_invite_device[] = {
1245 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1246 { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
1247 { "2", "Group Index", NULL, NULL, group_idx },
1248 { "3", "Device Index", NULL, NULL, device_idx },
1249 { "4", "PIN", NULL, NULL, pin },
1250 { "5", "Run", NULL, run_device_invite, NULL },
1254 static struct menu_data menu_group_eject_device[] = {
1255 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1256 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1257 { "2", "Group Index", NULL, NULL, group_idx },
1258 { "3", "Device Index", NULL, NULL, device_idx },
1259 { "4", "Run", NULL, run_device_eject, NULL },
1263 static struct menu_data menu_group_foreach_device[] = {
1264 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1265 { "1", "Group Index", NULL, NULL, group_idx },
1266 { "2", "Run", NULL, run_group_foreach_device, NULL },
1270 static struct menu_data menu_send_data[] = {
1271 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1272 { "1", "Show Channel List", NULL, run_channels_show, NULL },
1273 { "2", "Message", NULL, NULL, message },
1274 { "3", "Device Index", NULL, NULL, device_idx },
1275 { "4", "Channel Index", NULL, NULL, channel_idx },
1276 { "5", "Send", NULL, run_send_data, NULL },
1280 static struct menu_data menu_send_file[] = {
1281 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1282 { "1", "File Path", NULL, NULL, file_path },
1283 { "2", "Device Index", NULL, NULL, device_idx },
1284 { "3", "Send", NULL, run_send_file, NULL },
1288 static struct menu_data menu_devices_find_invited_device[] = {
1289 { "0", "Timeout", NULL, NULL, timeout },
1290 { "1", "Run", NULL, run_devices_find_invited_device, NULL },
1294 static struct menu_data menu_request_create_group[] = {
1295 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1296 { "1", "Device Index", NULL, NULL, device_idx },
1297 { "2", "Request Group Name", NULL, NULL, request_groupid },
1298 { "3", "Run", NULL, run_request_create_group, NULL },
1302 static struct menu_data menu_request_invite[] = {
1303 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1304 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1305 { "2", "Group Index", NULL, NULL, group_idx },
1306 { "3", "Device Index", NULL, NULL, device_idx },
1307 { "4", "PIN", NULL, NULL, pin },
1308 { "5", "Run", NULL, run_request_invite, NULL },
1312 static struct menu_data menu_request_eject[] = {
1313 { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
1314 { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1315 { "2", "Group Index", NULL, NULL, group_idx },
1316 { "3", "Device Index", NULL, NULL, device_idx },
1317 { "4", "Run", NULL, run_request_eject, NULL },
1321 static struct menu_data menu_request_channel_list[] = {
1322 { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
1323 { "1", "Device Index", NULL, NULL, device_idx },
1324 { "2", "Run", NULL, run_request_channel_list, NULL },
1328 static struct menu_data menu_regist_channel[] = {
1329 { "0", "Channel ID", NULL, NULL, channel_id },
1330 { "1", "Run", NULL, run_regist_channel, NULL },
1334 static struct menu_data menu_unregist_channel[] = {
1335 { "0", "Channel ID", NULL, NULL, channel_id },
1336 { "1", "Run", NULL, run_unregist_channel, NULL },
1340 struct menu_data menu_mdg_manager[] = {
1341 { "1", "Show Local Device", NULL, run_device_show_local_device, NULL }, // O
1342 { "2", "Create Group", menu_group_create, NULL, NULL }, // 0
1343 { "3", "Find Group(s)", menu_group_find, NULL, NULL }, // 0
1344 { "4", "Show Group(s)", NULL, run_group_show, NULL }, // 0
1345 { "5", "Delete Group", menu_group_delete, NULL, NULL }, // 0
1346 { "6", "Find Device(s)", menu_devices_find, NULL, NULL }, // 0
1347 { "7", "Show Device(s)", NULL, run_devices_show, NULL }, // 0
1348 { "8", "Invite Device", menu_group_invite_device, NULL, NULL }, // 0
1349 { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0
1350 { "10", "Foreach Device", menu_group_foreach_device, NULL, NULL },
1351 { "11", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0
1352 { "12", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0
1353 { "13", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0
1354 { "14", "Request Invite", menu_request_invite, NULL, NULL }, // 0
1355 { "15", "Request Eject", menu_request_eject, NULL, NULL }, // 0
1356 { "16", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0
1357 { "17", "Regist Channel", menu_regist_channel, NULL, NULL },
1358 { "18", "Unregist Channel", menu_unregist_channel, NULL, NULL },
1359 { "19", "Send Message", menu_send_data, NULL, NULL }, // 0
1360 { "20", "Send File", menu_send_file, NULL, NULL }, // 0