static int run_group_find(MManager *mm, struct menu_data *menu);
static int run_devices_find(MManager *mm, struct menu_data *menu);
-void _request_result_cb(char *cmd, char *arg, int ret, void *user_data)
+void receive_request_result(char *cmd, char *arg, int ret, void *user_data)
{
msg("_request_result_cb is called");
msgb("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret), ret);
if (ret == 0 && arg != NULL)
msgb("Deleted Group name is %s", arg);
+ } else {
+ msgb("[DATA] %s", arg);
}
}
}
char *uuid;
ret = companion_device_get_my_uuid(&uuid);
- companion_request_result_callback(_request_result_cb, NULL);
-
if (COMP_ERROR_NONE != ret) {
msgr("Failed to Get My Device ID: [%s(0x%X)]", comp_error_to_string(ret), ret);
return RET_FAILURE;
result = comp_group_create(group_name);
arg = g_strdup(group_name);
+
+ free(group_name);
} else if (strcmp(command, "2") == 0) {
LOG_DEBUG("Request invite");
char *group_name;
result = comp_group_invite(group_name, uuid, "12341234");
arg = g_strdup(uuid);
+
+ free(group_name);
+ free(uuid);
} else if (strcmp(command, "3") == 0) {
LOG_DEBUG("Request eject");
char *group_name;
result = comp_group_dismiss(group_name, uuid);
arg = g_strdup(uuid);
+
+ free(group_name);
+ free(uuid);
} else if (strcmp(command, "4") == 0) {
LOG_DEBUG("Request delete group");
arg = g_strdup("DELETED");
+ } else {
+ char *data = NULL;
+ LOG_DEBUG("Receive Data");
+ iotcon_query_lookup(query, "data", &data);
+ arg = g_strdup(data);
+ free(data);
}
notify_request_result(command, arg, result);
+
+ free(arg);
}
ret = iotcon_response_create(request, &response);
int found_group_count = 0;
+static void _clear_user_data(void *user_data)
+{
+ comp_command_t *cmd = user_data;
+
+ if (NULL == cmd)
+ return;
+
+ if (cmd->tid) {
+ g_source_remove(cmd->tid);
+ }
+
+ if (cmd->command) {
+ g_free(cmd->command);
+ cmd->command = NULL;
+ }
+ if (cmd->uuid) {
+ g_free(cmd->uuid);
+ cmd->uuid = NULL;
+ }
+ if (cmd->host) {
+ g_free(cmd->host);
+ cmd->host = NULL;
+ }
+ if (cmd->arg1) {
+ g_free(cmd->arg1);
+ cmd->arg1 = NULL;
+ }
+ if (cmd->arg2) {
+ g_free(cmd->arg2);
+ cmd->arg2 = NULL;
+ }
+ if (cmd->arg3) {
+ g_free(cmd->arg3);
+ cmd->arg3 = NULL;
+ }
+ if (cmd->arg4) {
+ g_free(cmd->arg4);
+ cmd->arg4 = NULL;
+ }
+}
+
static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
{
last_get_result = err;
+ iotcon_remote_resource_destroy(resource);
+
+ _clear_user_data(user_data);
+
LOG_DEBUG("iotcon error : %d", err);
- if (IOTCON_ERROR_NONE != err)
- return;
+ if (IOTCON_ERROR_NONE != err)
+ return;
}
iotcon_query_add(query, "id", cmd->arg2);
} else if (strcmp(cmd->command, "4") == 0) { //request delete group
iotcon_query_add(query, "name", cmd->arg1);
+ } else if (strcmp(cmd->command, "5") == 0) { /* Send Data */
+ iotcon_query_add(query, "data", cmd->arg1);
}
- ret = iotcon_remote_resource_get(resource_clone, query, _on_get, NULL);
+ ret = iotcon_remote_resource_get(resource_clone, query, _on_get, cmd);
if (IOTCON_ERROR_NONE != ret) {
iotcon_remote_resource_destroy(resource_clone);
+ _clear_user_data(cmd);
return IOTCON_FUNC_CONTINUE;
}
}
static gboolean _timeout_cb(gpointer data)
{
int ret = -1;
+ comp_command_t *cmd = (comp_command_t *)data;
- comp_resource_type_e resource_type = (comp_resource_type_e)data;
-
- if (resource_type == COMP_RESOURCE_TYPE_GROUP) {
+ if (cmd->resource_type == COMP_RESOURCE_TYPE_GROUP) {
if (found_group_count > 0)
ret = 0;
notify_group_find_finish(ret);
- } else if (resource_type == COMP_RESOURCE_TYPE_DATA) {
+
+ } else if (cmd->resource_type == COMP_RESOURCE_TYPE_DATA) {
notify_send_data_finish("RESP_DATA", last_get_result);
}
+ _clear_user_data(data);
+
return false;
}
ret = iotcon_set_timeout(timeout);
if (IOTCON_ERROR_NONE != ret) {
LOG_ERR("Failed to set timeout value");
+ _clear_user_data(user_data);
return COMP_ERROR_OPERATION_FAILED;
}
ret = iotcon_query_create(&query);
if (IOTCON_ERROR_NONE != ret) {
LOG_ERR("Failed to create iotcon query");
+ _clear_user_data(user_data);
return COMP_ERROR_OPERATION_FAILED;
}
comp_resource_get_type(resource_type));
if (IOTCON_ERROR_NONE != ret) {
LOG_ERR("Failed to set iotcon query resource type");
+ _clear_user_data(user_data);
return COMP_ERROR_OPERATION_FAILED;
}
IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
query, _found_resource, user_data);
- g_timeout_add_seconds(timeout + 1, _timeout_cb, (gpointer)resource_type);
+ cmd->resource_type = resource_type;
+ cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
LOG_DEBUG("find resource : %s", get_error_message(ret));