GList *found_group_list;
GList *mot_enb_dev_list = NULL;
GList *mowned_dev_list = NULL;
+GList *invited_dev_list = NULL;
comp_group_invite_info_t *group_invite_info = NULL;
comp_mot_device_t *my_device = NULL;
return ret;
}
+void comp_group_notify_keepalive_response(comp_command_t *cmd)
+{
+ GList *iter = NULL;
+ gboolean is_exist = FALSE;
+ comp_invited_device_t *temp;
+
+ LOG_DEBUG("Response received from uuid %s", cmd->uuid);
+
+ iter = invited_dev_list;
+ while (iter != NULL) {
+ temp = (comp_invited_device_t *)iter->data;
+
+ if ((g_strcmp0(temp->group_name, cmd->arg1) == 0) &&
+ (g_strcmp0(temp->uuid, cmd->uuid) == 0)) {
+ LOG_DEBUG("Device %s count %d found in invited device list",
+ cmd->uuid, temp->count);
+ is_exist = TRUE;
+ break;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ if (is_exist == TRUE)
+ temp->count += 1;
+}
+
+int comp_group_request_keepalive(char *uuid, char *group_name, char *host)
+{
+ int ret = COMP_ERROR_NONE;
+
+ LOG_DEBUG("[Request KeepAlive] to %s", uuid);
+ comp_command_t *cmd = g_new0(comp_command_t, 1);
+ cmd->command = COMP_REQ_KEEP_ALIVE;
+ cmd->uuid = g_strdup(uuid);
+ cmd->arg1 = g_strdup(group_name);
+ cmd->host = g_strdup(host);
+
+ ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 2, cmd);
+ if (ret != COMP_ERROR_NONE) {
+ LOG_ERR("Failed to send data : %s",
+ comp_log_get_error_string(ret));
+ return ret;
+ }
+
+ return 0;
+}
+
comp_group_invite_info_t *comp_group_get_invite_info()
{
return group_invite_info;
LOG_DEBUG("Remove Group Invite Information %p", group_invite_info);
if (group_invite_info) {
+ g_free(group_invite_info->group_name);
g_free(group_invite_info->uuid_dev1);
g_free(group_invite_info->uuid_dev2);
g_free(group_invite_info->pin);
}
}
+static comp_mot_device_t *_check_device_in_mot_enb_dev_list(char *uuid)
+{
+ comp_mot_device_t *device;
+ GList *iter;
+
+ iter = mot_enb_dev_list;
+
+ while (iter != NULL) {
+ device = (comp_mot_device_t *)iter->data;
+
+ if (g_strcmp0(device->device_id, uuid) == 0) {
+ LOG_DEBUG("Device %s is available in mot enable device list", uuid);
+ return device;
+ }
+ }
+
+ return NULL;
+}
+
+static char *_addr2host(char *addr, int port)
+{
+ char ip[50];
+ char *percent;
+
+ g_strlcpy(ip, addr, strlen(addr) + 1);
+
+ /* Remove % from address */
+ percent = strchr(ip, '%');
+ if (percent)
+ percent[0] = '\0';
+
+ /* IPv6 Address should be encoded for RFC6874 */
+ if (strchr(ip, ':')) /* IPv6 Adress */
+ return g_strdup_printf("coaps://[%s%s%s]:%d", ip, "%25",
+ percent + 1, port);
+ else /* IPv4 Address */
+ return g_strdup_printf("coaps://%s:%d", ip, port);
+}
+
void comp_group_notify_group_invite(int ret)
{
+ /*
+ * ret = 0 OC_STACK_OK
+ * ret = 49 OC_STACK_DUPLICATE_UUID
+ */
+ if ((ret == 0 || ret == 49) && group_invite_info) {
+ comp_invited_device_t *device;
+ GList *iter = NULL;
+ gboolean is_exist = FALSE;
+
+ device = g_try_malloc0(sizeof(comp_invited_device_t));
+ device->group_name = g_strdup(group_invite_info->group_name);
+ device->uuid = g_strdup(group_invite_info->uuid_dev2);
+
+ iter = invited_dev_list;
+ while (iter != NULL) {
+ comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
+
+ if ((g_strcmp0(temp->group_name, device->group_name) == 0) &&
+ (g_strcmp0(temp->uuid, device->uuid) == 0)) {
+ LOG_DEBUG("Device %s already exists in invited device list",
+ temp->uuid);
+ is_exist = TRUE;
+ break;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ if (is_exist == FALSE) {
+ comp_mot_device_t *temp;
+ temp = _check_device_in_mot_enb_dev_list(device->uuid);
+ if (temp)
+ device->host = _addr2host(temp->addr, temp->secure_port);
+
+ device->count = 0;
+ LOG_DEBUG("Add device %s group %s host %s to invited device list",
+ device->uuid, device->group_name, device->host);
+ invited_dev_list = g_list_prepend(invited_dev_list, device);
+
+ comp_group_request_keepalive(device->uuid, device->group_name,
+ device->host);
+ } else {
+ g_free(device->uuid);
+ g_free(device->group_name);
+ g_free(device);
+ }
+ }
+
comp_group_free_invite_info();
notify_group_device_invite_result(ret);
}
#else
+ group_invite_info = g_try_malloc0(sizeof(comp_group_invite_info_t));
+ group_invite_info->uuid_dev2 = g_strdup(uuid);
+ group_invite_info->group_name = g_strdup(group_name);
+
ret = agent_pair(pin, comp_ctx->device_uuid, uuid, "/comp/data/1",
"core.comp.data", "oic.if.baseline", FULL_PERMISSION, uuid,
comp_ctx->device_uuid, "/comp/data/1", "core.comp.data",
return ret;
}
-static char *_addr2host(char *addr, int port)
-{
- char ip[50];
- char *percent;
-
- g_strlcpy(ip, addr, strlen(addr) + 1);
-
- /* Remove % from address */
- percent = strchr(ip, '%');
- if (percent)
- percent[0] = '\0';
-
- /* IPv6 Address should be encoded for RFC6874 */
- if (strchr(ip, ':')) /* IPv6 Adress */
- return g_strdup_printf("coaps://[%s%s%s]:%d", ip, "%25",
- percent + 1, port);
- else /* IPv4 Address */
- return g_strdup_printf("coaps://%s:%d", ip, port);
-}
-
int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port,
unsigned char *data, int len)
{
return ret;
}
-static comp_mot_device_t *_check_device_in_mot_enb_dev_list(char *uuid)
-{
- comp_mot_device_t *device;
- GList *iter;
-
- iter = mot_enb_dev_list;
-
- while (iter != NULL) {
- device = (comp_mot_device_t *)iter->data;
-
- if (g_strcmp0(device->device_id, uuid) == 0) {
- LOG_DEBUG("Device %s is available in mot enable device list", uuid);
- return device;
- }
- }
-
- return NULL;
-}
-
int comp_group_request_create_group(char *uuid, char *group_name)
{
int ret = COMP_ERROR_NONE;
arg = (unsigned char *) g_strdup("DELETED");
arg_len = strlen("DELETED");
break;
+ case COMP_REQ_KEEP_ALIVE:
+ LOG_DEBUG("Keep Alive message");
+
+ if (rep.getValue("group_name", group_name)) {
+ LOG_DEBUG("group_name : %s", group_name.c_str());
+ }
+ break;
default:
LOG_ERR("Unknown request command %d", cmd);
break;
}
- notify_request_result(command2string((comp_request_type_e) cmd),
- requester_id.c_str(), arg, arg_len, result);
+ if (cmd != COMP_REQ_KEEP_ALIVE) {
+ const char *cmd_str;
+ cmd_str = command2string((comp_request_type_e) cmd);
+ notify_request_result(cmd_str, requester_id.c_str(), arg,
+ arg_len, result);
+ }
g_free(arg);
eCode == OC_STACK_RESOURCE_CHANGED) {
last_get_result = 0;
LOG_DEBUG("Post request is successful");
+
+ if (cmd->command == COMP_REQ_KEEP_ALIVE) {
+ comp_group_notify_keepalive_response(cmd);
+ return;
+ }
} else {
last_get_result = eCode;
LOG_ERR("_on_post Response error %d", eCode);
notify_group_find_finish(ret);
} else if (cmd->resource_type == COMP_RESOURCE_TYPE_DATA) {
- notify_send_data_finish("RESP_DATA", last_get_result);
+ if (cmd->command != COMP_REQ_KEEP_ALIVE)
+ notify_send_data_finish("RESP_DATA", last_get_result);
}
_clear_user_data(data);
rep.setValue("name", std::string(cmd->arg1));
rep.setValue("id", std::string(cmd->arg2));
break;
+ case COMP_REQ_KEEP_ALIVE:
+ rep.setValue("group_name", std::string(cmd->arg1));
+ break;
default:
LOG_ERR("Invalid command %d", cmd->command);
return -1;