// resource list
GList *resource_list[FN_RESOURCE_TYPE_MAX];
+
+ char *device_uuid;
+ int operation_resource_count;
} fn_context_t;
int fn_context_create();
/* resource type enum */
typedef enum {
FN_RESOURCE_TYPE_GROUP = 0,
- FN_RESOURCE_TYPE_GROUP_DEVICE = 0,
+ FN_RESOURCE_TYPE_GROUP_DEVICE,
FN_RESOURCE_TYPE_OPERATION,
FN_RESOURCE_TYPE_MAX
} fn_resource_type_e;
#define SVR_PATH "/tmp/.svr.dat"
int fn_iot_initialize();
-int fn_iot_add_resource(fn_resource_type_e resource_type, char *name);
+int fn_iot_add_resource(fn_resource_type_e resource_type, char *uri);
int fn_iot_delete_resource(fn_resource_type_e resource_type);
int fn_iot_discovery_resource(fn_resource_type_e resource_type);
int fn_iot_deinitialize();
typedef struct {
fn_resource_type_e resource_type;
char *type;
- char *uri;
+ char *uri_prefix;
uint8_t policies;
} fn_rd_t;
typedef struct {
iotcon_resource_h resource;
- char *name;
+ char *uri;
} fn_re_t;
-int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_resource_h resource);
+int fn_resource_append(fn_resource_type_e resource_type, char *uri, iotcon_resource_h resource);
char *fn_resource_get_type(fn_resource_type_e resource_type);
-char *fn_resource_get_uri(fn_resource_type_e resource_type);
+char *fn_resource_get_uri_prefix(fn_resource_type_e resource_type);
uint8_t fn_resource_get_policies(fn_resource_type_e resource_type);
void fn_resource_print_list();
+int fn_resource_get_resource_from_uri(fn_resource_type_e resource_type,
+ char *uri, iotcon_resource_h *parent_resource);
#endif
LOG_DEBUG("create mtp_context is failed");
return FN_ERROR_UNKNOWN;
}
+ _fn_ctx->device_uuid = g_strdup("123123");
return FN_ERROR_NONE;
}
LOG_BEGIN();
+
ret = fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP, name);
if (ret != FN_ERROR_NONE) {
LOG_ERR("Add resource is failed : %s", fn_log_get_error_string(ret));
}
+
+ /* A own group device is included in the created group by default. */
+ /* I would like to use multiple group device resource bindings for this created group resources.
+ If there is a better way, please change it.
+
+ Group/Jihoon (Group (In this daemon))
+ - Group/Device123123 (Group Device (In this daemon))
+ - Group/Device3321 (Group Device (remote))
+ - Group/Device1101 (Group Device (remote))
+ */
+
+ fn_context_t *fn_ctx = fn_context_get_context();
+
+ ret = fn_iot_bind_resource(FN_RESOURCE_TYPE_GROUP, name, FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid);
+ if (ret != FN_ERROR_NONE) {
+ LOG_ERR("Bind resource is failed : %s", fn_log_get_error_string(ret));
+ }
+
LOG_END();
return FN_ERROR_NONE;
int ret = iotcon_initialize(SVR_PATH);
LOG_DEBUG("iotcon_initialize : %s", get_error_message(ret));
+ fn_context_t *fn_ctx = fn_context_get_context();
+
+ /*
+ "Group device" resource
+ The Group device resource is only one per device.
+ resource type is core.fn.group.device
+ This resource has device information as an attribute.
+ The resource uri is /fn/group/device + certain uuid.
+ ex) /fn/group/device123123
+ */
+ fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid);
+
+ /*
+ "operation" resource
+ The operation resource is a control command channel between daemon and daemon.
+ resource type is core.fn.operation
+ Within this function we create a default operation resource. (uri is /fn/operation/1)
+ If we need more control channels, increase the number.
+ ex) /fn/operation/2, /fn/operation/3
+ */
+ fn_iot_add_resource(FN_RESOURCE_TYPE_OPERATION, "1");
+
return FN_ERROR_NONE;
}
//resource type "operation" don't have "get" request type.
}
-int fn_iot_add_resource(fn_resource_type_e resource_type, char *name)
+int fn_iot_add_resource(fn_resource_type_e resource_type, char *uri)
{
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,};
- fn_context_mutex_lock();
-
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;
}
- strncpy(uri_path, fn_resource_get_uri(resource_type), PATH_MAX);
- strncat(uri_path, name, PATH_MAX);
+ strncpy(uri_path, fn_resource_get_uri_prefix(resource_type), PATH_MAX);
+ strncat(uri_path, uri, PATH_MAX);
- LOG_DEBUG("resource uri is %s", uri_path);
+ LOG_DEBUG("[ADD] resource uri is %s", uri_path);
//name duplication check
ret = iotcon_resource_create(uri_path, resource_types, resource_ifaces,
}
//get resource list of resource type
- ret = fn_resource_append(resource_type, name, resource);
+ ret = fn_resource_append(resource_type, uri, resource);
if (FN_ERROR_NONE != ret) {
LOG_ERR("fn_resource_append failed! : %s", fn_log_get_error_string(ret));
goto EXIT;
if (resource_ifaces != NULL)
iotcon_resource_interfaces_destroy(resource_ifaces);
- fn_context_mutex_unlock();
+ return FN_ERROR_NONE;
+}
+
+int fn_iot_bind_resource(fn_resource_type_e parent_resource_type, char *parent_uri,
+ fn_resource_type_e child_resource_type, char *child_uri)
+{
+ int ret;
+
+ iotcon_resource_h parent_resource = NULL;
+ iotcon_resource_h child_resource = NULL;
+
+ ret = fn_resource_get_resource_from_uri(parent_resource_type, parent_uri, &parent_resource);
+ if (ret != 0) {
+ LOG_DEBUG("parent Resource can't found");
+ return FN_ERROR_UNKNOWN;
+ }
+
+ ret = fn_resource_get_resource_from_uri(child_resource_type, child_uri, &child_resource);
+ if (ret != 0) {
+ LOG_DEBUG("child Resource can't found");
+ return FN_ERROR_UNKNOWN;
+ }
+
+ ret = iotcon_resource_bind_child_resource(parent_resource, child_resource);
+ if (ret != 0) {
+ LOG_DEBUG("bind resource failed");
+ return FN_ERROR_UNKNOWN;
+ }
+
+ unsigned int *count = 0;
+ ret = iotcon_resource_get_child_count(parent_resource, &count);
+ if (ret != 0) {
+ LOG_DEBUG("get child count failed");
+ return FN_ERROR_UNKNOWN;
+ }
+
+ LOG_DEBUG("Now, resource type %d, uri %s has child count %d", parent_resource_type, parent_uri, count);
return FN_ERROR_NONE;
}
{
int ret;
- LOG_DEBUG("FN Manager start. thread id");
+ LOG_DEBUG("FN Manager start");
//1. create & get context
ret = fn_context_create();
IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
};
-int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_resource_h resource)
+int fn_resource_append(fn_resource_type_e resource_type, char *uri, iotcon_resource_h resource)
{
fn_context_t *fn_ctx = fn_context_get_context();
GList *list = fn_ctx->resource_list[resource_type];
//append resource handle / name to list
fn_re_t *element = g_new0(fn_re_t, 1);
element->resource = resource;
- element->name = g_strdup(name);
+ element->uri = g_strdup(uri);
list = g_list_append(list, element);
fn_ctx->resource_list[resource_type] = list;
return 0;
}
+int fn_resource_get_resource_from_uri(fn_resource_type_e resource_type,
+ char *uri, iotcon_resource_h *parent_resource)
+{
+ fn_context_t *fn_ctx = fn_context_get_context();
+ GList *list = fn_ctx->resource_list[resource_type];
+
+ GList *l;
+ for (l = list; l != NULL; l = l->next) {
+ fn_re_t *re = (fn_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 *fn_resource_get_type(fn_resource_type_e resource_type)
{
return fn_rds[resource_type].type;
}
-char *fn_resource_get_uri(fn_resource_type_e resource_type)
+char *fn_resource_get_uri_prefix(fn_resource_type_e resource_type)
{
- return fn_rds[resource_type].uri;
+ return fn_rds[resource_type].uri_prefix;
}
uint8_t fn_resource_get_policies(fn_resource_type_e resource_type)
void __print_foreach_resource(gpointer data, gpointer user_data)
{
fn_re_t *re = (fn_re_t *)data;
- LOG_DEBUG(" ** resource : %x, name : %s", re->resource, re->name);
+ LOG_DEBUG(" ** resource : %x, uri : %s", re->resource, re->uri);
}
void fn_resource_print_list()