#define DOOR_RESOURCE_URI_PREFIX "/door"
#define DOOR_RESOURCE_TYPE "org.tizen.door"
+struct _connectivity_observe_resource_cb_s {
+ connectivity_observe_resource_cb cb;
+ void *user_data;
+};
+typedef struct _connectivity_observe_resource_cb_s connectivity_observe_resource_cb_s;
+
struct _connectivity_resource_s {
char *device_id;
char *host_address;
char *uri_path;
iotcon_presence_h presence;
iotcon_remote_resource_h resource;
+ connectivity_observe_resource_cb_s *cb_info;
};
static struct {
iotcon_attributes_h attributes = NULL;
iotcon_representation_h repr = NULL;
iotcon_response_result_e response_result;
+ connectivity_resource_s *resource_info = user_data;
+ ret_if(!resource_info);
+ ret_if(!resource_info->cb_info);
+ ret_if(!resource_info->cb_info->cb);
ret_if(IOTCON_ERROR_NONE != err);
ret = iotcon_response_get_result(response, &response_result);
ret = iotcon_attributes_get_bool(attributes, "opened", &opened);
ret_if(IOTCON_ERROR_NONE != ret);
+ resource_info->cb_info->cb(resource_info, (void *)(int) opened, resource_info->cb_info->user_data);
if (opened) _I("[Door] opened.");
else _I("[Door] closed.");
}
IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER,
NULL,
_observe_cb,
- NULL);
+ info);
retv_if(IOTCON_ERROR_NONE != ret, -1);
return 0;
int ret = -1;
connectivity_resource_s *info = NULL;
- _D("HELLO");
/* We should know where we get wrong results */
/* Can attackers send wrong messages to stop this? */
retv_if(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP);
if (1 == ret) return IOTCON_FUNC_CONTINUE;
info = calloc(1, sizeof(connectivity_resource_s));
- retv_if(!info, IOTCON_FUNC_CONTINUE);
-
- ret = _add_resource_info_into_list(info);
- goto_if(-1 == ret, error);
+ retv_if(!info, -1);
+ info->cb_info = user_data;
ret = _retrieve_resource_info(resource, info);
goto_if(-1 == ret, error);
_E("Cannot request query");
}
+ ret = _add_resource_info_into_list(info);
+ goto_if(-1 == ret, error);
+
return IOTCON_FUNC_CONTINUE;
error:
- connectivity_info.list = eina_list_remove(connectivity_info.list, info);
if (info) _free_resource_info(info);
return IOTCON_FUNC_CONTINUE;
}
return 0;
}
-int connectivity_find_resource(void)
+int connectivity_observe_resource(connectivity_observe_resource_cb cb, void *user_data)
{
int ret = -1;
iotcon_query_h query = NULL;
+ connectivity_observe_resource_cb_s *cb_info = NULL;
- _D("HELLO");
+ cb_info = calloc(1, sizeof(connectivity_observe_resource_cb_s));
+ retv_if(!cb_info, -1);
+ cb_info->cb = cb;
+ cb_info->user_data = user_data;
ret = iotcon_query_create(&query);
- retv_if(IOTCON_ERROR_NONE != ret, -1);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_query_set_resource_type(query, DOOR_RESOURCE_TYPE);
goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
- query,
- _found_resource_cb,
- NULL);
+ query,
+ _found_resource_cb,
+ cb_info);
goto_if(IOTCON_ERROR_NONE != ret, error);
- _D("HELLO");
iotcon_query_destroy(query);
return 0;
error:
iotcon_query_destroy(query);
+ if (cb_info) free(cb_info);
return -1;
}