static char groupid[MENU_DATA_SIZE + 1] = "mygroup";
static char timeout[MENU_DATA_SIZE + 1] = "5";
static char group_idx[MENU_DATA_SIZE + 1] = "1";
+static char group_idx_a[MENU_DATA_SIZE + 1] = "1";
+static char group_idx_b[MENU_DATA_SIZE + 1] = "2";
+static char device_idx[MENU_DATA_SIZE + 1] = "1";
+static char pin[MENU_DATA_SIZE + 1] = "11223344";
+
+void _device_invite_result_cb(int result, void *user_data)
+{
+ msg("Invite Device Finished [%s]", comp_error_to_string(result) );
+}
+
+static int run_device_invite(MManager *mm, struct menu_data *menu)
+{
+ int ret;
+ int idx;
+ companion_group_h group = NULL;
+ companion_device_h device = NULL;
+
+ msg("Invite Device");
+
+ if (strlen(group_idx)) {
+ idx = (unsigned short)strtol(group_idx, NULL, 10);
+ if (0 >= idx) {
+ msgp("Invalid index. set to 1");
+ idx = 1;
+ }
+ }
+
+ if (found_group_list) {
+ group = g_list_nth_data(found_group_list, idx - 1);
+ if (NULL == group) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+ if (strlen(device_idx)) {
+ idx = (unsigned short)strtol(device_idx, NULL, 10);
+ if (0 >= idx) {
+ msgp("Invalid index. set to 1");
+ idx = 1;
+ }
+ }
+
+ if (found_device_list) {
+ device = g_list_nth_data(found_device_list, idx - 1);
+ if (NULL == device) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+ ret = companion_device_invite(group, device, pin,_device_invite_result_cb, NULL );
+ if (COMP_ERROR_NONE != ret) {
+ msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
+ return RET_FAILURE;
+ }
+ msg(" - companion_device_invite() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+ return RET_SUCCESS;
+}
+
+static int run_devices_show(MManager *mm, struct menu_data *menu)
+{
+ char *deviceid = NULL;
+ char *name = NULL;
+ char *devicetype = NULL;
+ companion_device_h device;
+
+ int i;
+ GList *iter = NULL;
+
+ /* Get a first item */
+ i = 0;
+ iter = g_list_first(found_device_list);
+ while (NULL != iter) {
+ device = iter->data;
+ if (device) {
+ msgr("device list is null");
+ break;
+ }
+ companion_device_information_get_device_id(device, &deviceid);
+ companion_device_information_get_friendly_name(device, &name);
+ companion_device_information_get_device_type(device, &devicetype);
+ msgb("[%d] type:%s, name: %s type: %s", i+1, deviceid, name, devicetype);
+
+ if (deviceid) {
+ free(deviceid);
+ deviceid = NULL;
+ }
+ if (name) {
+ free(name);
+ name = NULL;
+ }
+ if (devicetype) {
+ free(devicetype);
+ devicetype = NULL;
+ }
+ /* Next item */
+ iter = g_list_next(iter);
+ i++;
+ }
+
+ return RET_SUCCESS;
+}
+
+static int run_group_get_members(MManager *mm, struct menu_data *menu)
+{
+ int ret;
+ int idx;
+ int count;
+ companion_group_h group = NULL;
+ companion_device_h **devices = NULL;
+
+ msg("Get Group Members");
+
+ if (strlen(group_idx)) {
+ idx = (unsigned short)strtol(group_idx, NULL, 10);
+ if (0 >= idx) {
+ msgp("Invalid index. set to 1");
+ idx = 1;
+ }
+ }
+
+ if (found_group_list) {
+ group = g_list_nth_data(found_group_list, idx - 1);
+ if (NULL == group) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+ ret = companion_group_get_member_devices(group, devices, &count);
+ if (COMP_ERROR_NONE != ret) {
+ msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
+ return RET_FAILURE;
+ }
+ msg(" - companion_group_get_member_devices() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+ for (int i = 0; i < count; i++) {
+
+ char *device_id = NULL;
+ char *friendly_name = NULL;
+ char *device_type = NULL;
+
+ companion_device_information_get_device_id(devices[i], &device_id);
+ companion_device_information_get_friendly_name(devices[i], &friendly_name);
+ companion_device_information_get_device_type(devices[i], &device_type);
+
+ msgb("device_id : %s, name : %s, type : %s", device_id, friendly_name, device_type);
+
+ if (device_id)
+ free(device_id);
+ if (friendly_name)
+ free(friendly_name);
+ if (device_type)
+ free(device_type);
+ }
+
+ return RET_SUCCESS;
+}
+
+static int run_group_merge(MManager *mm, struct menu_data *menu)
+{
+ int ret;
+ int a, b;
+ companion_group_h group_a;
+ companion_group_h group_b;
+
+ msg("Merge Group");
+
+ if (strlen(group_idx_a)) {
+ a = (unsigned short)strtol(group_idx_a, NULL, 10);
+ if (0 >= a) {
+ msgp("Invalid index. set to 1");
+ a = 1;
+ }
+ }
+
+ if (found_group_list) {
+ group_a = g_list_nth_data(found_group_list, a - 1);
+ if (NULL == group_a) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+ if (strlen(group_idx_b)) {
+ b = (unsigned short)strtol(group_idx_b, NULL, 10);
+ if (0 >= b) {
+ msgp("Invalid index. set to 2");
+ b = 1;
+ }
+ }
+
+ if (found_group_list) {
+ group_b = g_list_nth_data(found_group_list, b - 1);
+ if (NULL == group_b) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+
+ ret = companion_group_merge(group_a, group_b);
+ if (COMP_ERROR_NONE != ret) {
+ msgr("Failed to Merge Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
+ return RET_FAILURE;
+ }
+ msg(" - companion_group_merge() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+ return RET_SUCCESS;
+}
+
+static int run_group_delete(MManager *mm, struct menu_data *menu)
+{
+ int ret;
+ int idx;
+ companion_group_h group;
+
+ msg("Delete Group");
+
+ if (strlen(group_idx)) {
+ idx = (unsigned short)strtol(group_idx, NULL, 10);
+ if (0 >= idx) {
+ msgp("Invalid index. set to 1");
+ idx = 1;
+ }
+ }
+
+ if (found_group_list) {
+ group = g_list_nth_data(found_group_list, idx - 1);
+ if (NULL == group) {
+ msgr("Failed to g_hash_table_find");
+ return RET_FAILURE;
+ }
+ }
+
+ ret = companion_group_delete(group);
+ if (COMP_ERROR_NONE != ret) {
+ msgr("Failed to Delete Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
+ return RET_FAILURE;
+ }
+ msg(" - companion_group_delete() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+ return RET_SUCCESS;
+}
void _device_finish_cb(int result, void *user_data)
{
- msgb("Find Devices Finished");
+ msgb("Find Devices Finished [%s]", comp_error_to_string(result) );
}
bool _device_found_cb(companion_device_h device, void *user_data)
{
- char *device_id;
- char *friendly_name;
- char *device_type;
+ char *device_id = NULL;
+ char *friendly_name = NULL;
+ char *device_type = NULL;
companion_device_information_get_device_id(device, &device_id);
companion_device_information_get_friendly_name(device, &friendly_name);
companion_device_information_get_device_type(device, &device_type);
+ msg("");
msgb("device_id : %s, name : %s, type : %s", device_id, friendly_name, device_type);
if (device_id)
}
msg(" - companion_device_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
- if (found_device_list)
+ if (found_device_list) {
g_list_free(found_device_list);
+ found_device_list = NULL;
+ }
msg("");
{
int ret;
int idx;
- companion_group_h *group;
+ companion_group_h group;
msg("Leave Group");
if (group) {
msgr("groups is null");
break;
- }
- companion_group_information_get_type(group, &type);
+ }
+ companion_group_information_get_type(group, &type);
companion_group_information_get_uri_path(group, &uri);
companion_group_information_get_resource_type(group, &rt);
- msgb("[%d] type:%s, URI: %s RT: %s", i+1,
- comp_group_type_to_string(type), uri, rt);
- free(uri);
- free(rt);
+ msgb("[%d] type:%s, URI: %s RT: %s", i+1, comp_group_type_to_string(type), uri, rt);
+ if (uri) {
+ free(uri);
+ uri = NULL;
+ }
+ if (rt) {
+ free(rt);
+ rt = NULL;
+ }
/* Next item */
iter = g_list_next(iter);
i++;
{
int ret;
int idx;
- companion_group_h *group;
+ companion_group_h group;
msg("Join Group");
companion_group_information_get_uri_path(group, &uri_path);
+ msg("");
msgb("found group type : %d, uri : %s", type, uri_path);
found_group_list = g_list_prepend(found_group_list, group);
}
msg(" - companion_group_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
- if (found_group_list)
+ if (found_group_list) {
g_list_free(found_group_list);
+ found_group_list = NULL;
+ }
return RET_SUCCESS;
}
{ NULL, NULL, },
};
+static struct menu_data menu_group_delete[] = {
+ { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+ { "1", "Index", NULL, NULL, group_idx },
+ { "2", "Run", NULL, run_group_delete, NULL },
+ { NULL, NULL, },
+};
+
+static struct menu_data menu_group_merge[] = {
+ { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+ { "1", "A Index", NULL, NULL, group_idx_a },
+ { "1", "B Index", NULL, NULL, group_idx_b },
+ { "2", "Run", NULL, run_group_merge, NULL },
+ { NULL, NULL, },
+};
+
+static struct menu_data menu_group_get_members[] = {
+ { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+ { "1", "Index", NULL, NULL, group_idx },
+ { "2", "Run", NULL, run_group_get_members, NULL },
+ { NULL, NULL, },
+};
+
+static struct menu_data menu_group_invite_device[] = {
+ { "0", "Show Found Device(s)", NULL, run_devices_show, NULL },
+ { "1", "Index", NULL, NULL, group_idx },
+ { "2", "Run", NULL, run_group_get_members, NULL },
+ { NULL, NULL, },
+};
+
+static struct menu_data menu_group_eject_device[] = {
+ { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
+ { "1", "Show Found Device(s)", NULL, run_devices_show, NULL },
+ { "2", "Group Index", NULL, NULL, group_idx },
+ { "3", "Device Index", NULL, NULL, device_idx },
+ { "4", "Run", NULL, run_device_invite, NULL },
+ { NULL, NULL, },
+};
+
struct menu_data menu_comp_manager[] = {
{ "1", "Group Create", menu_group_create, NULL, NULL },
{ "2", "Find Groups", menu_group_find, NULL, NULL },
{ "3", "Get Found Groups", NULL, run_group_get_found , NULL },
{ "4", "Join Group", menu_group_join, NULL, NULL },
{ "5", "Leave Group", menu_group_leave, NULL, NULL },
- { "6", "Delete Group", NULL, NULL, NULL },
- { "7", "Merge Group", NULL, NULL, NULL },
- { "8", "Get Group Member Devices", NULL, NULL, NULL },
+ { "6", "Delete Group", menu_group_delete, NULL, NULL },
+ { "7", "Merge Group B to A", menu_group_merge, NULL, NULL },
+ { "8", "Get Group Member Devices", menu_group_get_members, NULL, NULL },
{ "9", "Find Devices", menu_devices_find, NULL, NULL },
- { "10", "Invite Device", NULL, NULL, NULL },
- { "11", "Eject Device", NULL, NULL, NULL },
+ { "10", "Invite Device", menu_group_invite_device, NULL, NULL },
+ { "11", "Eject Device", menu_group_eject_device, NULL, NULL },
{ NULL, NULL, },
};
g_variant_get(va, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "URI") == 0) {
- uri_path = g_variant_get_string(key_value, NULL);
+ uri_path = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "DeviceID") == 0) {
- device_id = g_variant_get_string(key_value, NULL);
+ device_id = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupName") == 0) {
- group_name = g_variant_get_string(key_value, NULL);
+ group_name = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "HostAddress") == 0) {
- host_addr = g_variant_get_string(key_value, NULL);
+ host_addr = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupDeviceType") == 0) {
- resource_type = g_variant_get_string(key_value, NULL);
+ resource_type = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupType") == 0) {
type = g_variant_get_int32(key_value);
}
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "DeviceID") == 0) {
- device_id = g_variant_get_string(key_value, NULL);
+ device_id = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "FriendlyName") == 0) {
- friendly_name = g_variant_get_string(key_value, NULL);
+ friendly_name = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "DeviceType") == 0) {
device_type = g_variant_get_string(key_value, NULL);
}
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "URI") == 0) {
- uri_path = g_variant_get_string(key_value, NULL);
+ uri_path = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "DeviceID") == 0) {
- device_id = g_variant_get_string(key_value, NULL);
+ device_id = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupName") == 0) {
- group_name = g_variant_get_string(key_value, NULL);
+ group_name = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "HostAddress") == 0) {
- host_addr = g_variant_get_string(key_value, NULL);
+ host_addr = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupDeviceType") == 0) {
- resource_type = g_variant_get_string(key_value, NULL);
+ resource_type = (char *)g_variant_get_string(key_value, NULL);
} else if (g_strcmp0(key, "GroupType") == 0) {
type = g_variant_get_int32(key_value);
}
return 0;
}
+int companion_group_delete(companion_group_h group)
+{
+ return 0;
+}
+
+int companion_group_get_member_devices(companion_group_h group,
+ companion_device_h **devices, int *count)
+{
+ return 0;
+}
+
int companion_device_invite(companion_group_h group,
companion_device_h device, char *PIN, companion_device_invite_result_cb result_cb, void *user_data)
{