int comp_iot_add_resource(comp_resource_type_e resource_type, const char *uri)
{
- //char uri_path[PATH_MAX] = {0,};
OCResourceHandle resourceHandle;
std::string uri_path;
- uri_path = std::string(comp_resource_get_uri_prefix(resource_type)) + std::string(uri);
- //strncpy(uri_path, comp_resource_get_uri_prefix(resource_type), PATH_MAX);
- //strncat(uri_path, uri, PATH_MAX);
+ uri_path = std::string(comp_resource_get_uri_prefix(resource_type)) +
+ std::string(uri);
LOG_DEBUG("[ADD] resource uri is %s", uri_path.c_str());
- EntityHandler cb = std::bind(&_request_handler, std::placeholders::_1);
-
OCStackResult result = OCPlatform::registerResource(resourceHandle,
uri_path,
std::string(comp_resource_get_type(resource_type)),
- std::string(DEFAULT_INTERFACE), cb,
+ std::string(DEFAULT_INTERFACE), &_request_handler,
comp_resource_get_policies(resource_type));
if (result != OC_STACK_OK) {
LOG_ERR("Failed to create resource");
}
LOG_DEBUG("Successfully created resource");
- return COMP_ERROR_NONE;
-#if 0
- iotcon_resource_h resource = NULL;
- iotcon_resource_types_h resource_types = NULL;
- iotcon_resource_interfaces_h resource_ifaces = NULL;
- char uri_path[PATH_MAX] = {0,};
-
- int ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_types_create failed! : %s", get_error_message(ret));
- goto EXIT;
- }
-
- ret = iotcon_resource_types_add(resource_types, comp_resource_get_type(resource_type));
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_types_add failed! : %s", get_error_message(ret));
- goto EXIT;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_interfaces_create failed! : %s", get_error_message(ret));
- goto EXIT;
- }
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_interfaces_add failed! : %s", get_error_message(ret));
- goto EXIT;
- }
-
- strncpy(uri_path, comp_resource_get_uri_prefix(resource_type), PATH_MAX);
- strncat(uri_path, uri, PATH_MAX);
-
- LOG_DEBUG("[ADD] resource uri is %s", uri_path);
- //name duplication check
-
- ret = iotcon_resource_create(uri_path, resource_types, resource_ifaces,
- comp_resource_get_policies(resource_type), _request_handler, NULL, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_create failed! : %s", get_error_message(ret));
- goto EXIT;
- }
-
- //get resource list of resource type
- ret = comp_resource_append(resource_type, uri, resource);
- if (COMP_ERROR_NONE != ret) {
- LOG_ERR("comp_resource_append failed! : %s", comp_log_get_error_string(ret));
- goto EXIT;
- }
-
-EXIT:
- if (resource_types != NULL)
- iotcon_resource_types_destroy(resource_types);
-
- if (resource_ifaces != NULL)
- iotcon_resource_interfaces_destroy(resource_ifaces);
+ //Append to resource list
+ comp_resource_append(resource_type, uri_path.c_str());
return COMP_ERROR_NONE;
-#endif
}
static bool _get_res_type_cb(const char *string, void *user_data)
IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE | IOTCON_RESOURCE_SECURE},
};
-int comp_resource_append(comp_resource_type_e resource_type, char *uri, iotcon_resource_h resource)
+int comp_resource_append(comp_resource_type_e resource_type, const char *uri)
{
comp_context_t *comp_ctx = comp_context_get_context();
GList *list = comp_ctx->resource_list[resource_type];
//append resource handle / name to list
comp_re_t *element = g_new0(comp_re_t, 1);
- element->resource = resource;
element->uri = g_strdup(uri);
list = g_list_append(list, element);
return 0;
}
-int comp_resource_get_resource_from_uri(comp_resource_type_e resource_type,
- char *uri, iotcon_resource_h *parent_resource)
-{
- comp_context_t *comp_ctx = comp_context_get_context();
- GList *list = comp_ctx->resource_list[resource_type];
-
- GList *l;
- for (l = list; l != NULL; l = l->next) {
- comp_re_t *re = (comp_re_t *)l->data;
-
- if (strcmp(re->uri, uri) == 0) {
- LOG_DEBUG("Resource found - type : %d uri : %s", resource_type, uri);
- *parent_resource = re->resource;
- return 0;
- }
- }
-
- return -1;
-}
-
char *comp_resource_get_type(comp_resource_type_e resource_type)
{
return comp_rds[resource_type].type;
void __print_foreach_resource(gpointer data, gpointer user_data)
{
comp_re_t *re = (comp_re_t *)data;
- LOG_DEBUG(" ** resource : %x, uri : %s", re->resource, re->uri);
+ LOG_DEBUG(" ** uri : %s", re->uri);
}
void comp_resource_print_list()
LOG_DEBUG("-------------------Print resource list-----------------------");
for (int i = 0; i < COMP_RESOURCE_TYPE_MAX; i++) {
- LOG_DEBUG("Resource type %d list length : %d", i, g_list_length(comp_ctx->resource_list[i]));
- g_list_foreach(comp_ctx->resource_list[i], __print_foreach_resource, NULL);
+ LOG_DEBUG("Resource type %d list length : %d", i,
+ g_list_length(comp_ctx->resource_list[i]));
+ g_list_foreach(comp_ctx->resource_list[i], __print_foreach_resource,
+ NULL);
}
LOG_DEBUG("-------------------Print resource list end-------------------");