From: saerome.kim Date: Fri, 12 Jan 2018 05:43:37 +0000 (+0900) Subject: comp-manager: change SVR DB of comp-manager to support MOT feature X-Git-Tag: submit/tizen/20190131.065036~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f3916d672e48fb25f02b054de5546743879e8a9;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git comp-manager: change SVR DB of comp-manager to support MOT feature Signed-off-by: saerome.kim --- diff --git a/packaging/d2d-manager.spec b/packaging/d2d-manager.spec index d38e223..99df841 100644 --- a/packaging/d2d-manager.spec +++ b/packaging/d2d-manager.spec @@ -133,6 +133,7 @@ rm -rf %{NETWORK_FW_DATADIR}/oic_pdm_d2ds.db-journal %attr(644,root,root) %{_unitdir}/fnm.service %attr(644,root,root) %{_unitdir}/d2ds.service %attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_d2ds.dat +%attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_comp_manager.dat %files devel %manifest %{name}-devel.manifest diff --git a/src/companion-manager/CMakeLists.txt b/src/companion-manager/CMakeLists.txt old mode 100755 new mode 100644 index c9a8c0d..d3e1723 --- a/src/companion-manager/CMakeLists.txt +++ b/src/companion-manager/CMakeLists.txt @@ -19,3 +19,4 @@ SET(COMP_MANAGER "companion-manager") ADD_EXECUTABLE(${COMP_MANAGER} ${COMP_MANAGER_SRCS}) TARGET_LINK_LIBRARIES(${COMP_MANAGER} ${daemon_pkgs_LIBRARIES} pthread) INSTALL(TARGETS ${COMP_MANAGER} DESTINATION bin) +INSTALL(FILES oic_svr_db_comp_manager.dat DESTINATION ${NETWORK_FW_DATADIR}) diff --git a/src/companion-manager/oic_svr_db_comp_manager.dat b/src/companion-manager/oic_svr_db_comp_manager.dat new file mode 100644 index 0000000..f449223 Binary files /dev/null and b/src/companion-manager/oic_svr_db_comp_manager.dat differ diff --git a/src/companion-manager/oic_svr_db_comp_manager.json b/src/companion-manager/oic_svr_db_comp_manager.json new file mode 100644 index 0000000..208d4a3 --- /dev/null +++ b/src/companion-manager/oic_svr_db_comp_manager.json @@ -0,0 +1,123 @@ +{ + "cred":{ + "creds": [ + { + "credid": 1, + "subjectuuid": "*", + "credtype": 16, + "privatedata": { + "encoding": "oic.sec.encoding.raw", + "data": "12341234" + } + } + ], + "rowneruuid": "00000000-0000-0000-0000-000000000000" + }, + "acl": { + "aclist": { + "aces": [ + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/res", + "rel": "", + "rt": ["oic.wk.res"], + "if": ["oic.if.ll"] + },{ + "href": "/oic/d", + "rel": "", + "rt": ["oic.wk.d"], + "if": ["oic.if.baseline", "oic.if.r"] + },{ + "href": "/oic/p", + "rel": "", + "rt": ["oic.wk.p"], + "if": ["oic.if.baseline", "oic.if.r"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/doxm", + "rel": "", + "rt": ["oic.r.doxm"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/pstat", + "rel": "", + "rt": ["oic.r.pstat"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/cred", + "rel": "", + "rt": ["oic.r.cred"], + "if": ["oic.if.baseline"] + } + ], + "permission": 6 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/fn/group", + "rel": "", + "rt": ["core.fn.group"], + "if": ["oic.if.ll"] + },{ + "href": "/fn/operation", + "rel": "", + "rt": ["core.fn.operation"], + "if": ["oic.if.baseline", "oic.if.r"] + } + ], + "permission": 31 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/pconf", + "rel": "", + "rt": ["oic.r.pconf"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/dpairing", + "rel": "", + "rt": ["oic.r.dpairing"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + } + ] + }, + "rowneruuid" : "00000000-0000-0000-0000-000000000000" + }, + "pstat": { + "isop": false, + "cm": 2, + "tm": 0, + "om": 4, + "sm": 4, + "deviceuuid": "00000000-0000-0000-0000-000000000000", + "rowneruuid": "00000000-0000-0000-0000-000000000000" + }, + "doxm": { + "oxms": [0, 65280], + "oxmsel": 65280, + "sct": 17, + "owned": false, + "x.org.iotivity.mom": 1, + "deviceuuid": "00000000-0000-0000-0000-000000000000", + "devowneruuid": "00000000-0000-0000-0000-000000000000", + "rowneruuid": "00000000-0000-0000-0000-000000000000" + } +} diff --git a/src/companion-manager/src/comp_iot.c b/src/companion-manager/src/comp_iot.c index da0961d..adfdc52 100755 --- a/src/companion-manager/src/comp_iot.c +++ b/src/companion-manager/src/comp_iot.c @@ -1,6 +1,13 @@ +#include +#include + #include #include +#define MAX_FILE_PATH_LEN 1024 +#define SVR_DB_FILE_NAME "oic_svr_db_comp_manager.dat" + + static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e result, void *user_data) { @@ -34,7 +41,12 @@ static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e resul int comp_iot_initialize() { - int ret = iotcon_initialize(SVR_PATH); + char data_dir[MAX_FILE_PATH_LEN] = {0,}; + + snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s", + tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_FILE_NAME); + + int ret = iotcon_initialize(data_dir); if (IOTCON_ERROR_NONE != ret) { LOG_ERR("iotcon_initialize: Failed %s", get_error_message(ret)); return false; @@ -49,6 +61,12 @@ int comp_iot_initialize() return false; } + /* Do Self-Ownership Transfer */ + ret = OCConfigSelfOwnership(); + if (OC_STACK_OK != ret ) { + LOG_ERR( "OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret)); + } + /* "operation" resource The operation resource is a control command channel between daemon and daemon. diff --git a/src/fn-manager/src/fn_iot.c b/src/fn-manager/src/fn_iot.c deleted file mode 100755 index ccafe4b..0000000 --- a/src/fn-manager/src/fn_iot.c +++ /dev/null @@ -1,287 +0,0 @@ -#include -#include - -static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e result, - void *user_data) -{ - int ret; - char *device_id = NULL; - - LOG_DEBUG("device info found"); - - ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_ID, &device_id); - if (IOTCON_ERROR_NONE != ret) { - return false; - } - - LOG_DEBUG("device_id : %s", device_id); - - fn_context_t *fn_ctx = fn_context_get_context(); - fn_ctx->device_uuid = g_strdup(device_id); - - /* - "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); - - return false; -} - -int fn_iot_initialize() -{ - int ret = iotcon_initialize(SVR_PATH); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("iotcon_initialize: Failed %s", get_error_message(ret)); - return false; - } - - LOG_DEBUG("iotcon_initialize : %s", get_error_message(ret)); - ret = iotcon_find_device_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL, - NULL, _request_device_info, NULL); - - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("iotcon_find_device_info: Failed %s", get_error_message(ret)); - return false; - } - - /* - "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; -} - -static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, - void *user_data) -{ - LOG_DEBUG("thread id is "); - //get resource element from fn resource list or, parsing resource uri - - //if request type is "get" and resource type is "group", - //then OWNER send device information to CLIENT(Device info Exchange) - //if request type is "put" and resource type is "operation", - //then It is join request. CLIENT send device information to OWNER(Device info Exchange) - //resource type "operation" don't have "get" request type. -} - -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,}; - - 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, fn_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, fn_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, - fn_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 = 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; - } - -EXIT: - if (resource_types != NULL) - iotcon_resource_types_destroy(resource_types); - - if (resource_ifaces != NULL) - iotcon_resource_interfaces_destroy(resource_ifaces); - - return FN_ERROR_NONE; -} - -static bool _get_res_type_cb(const char *string, void *user_data) -{ - char **resource_type = user_data; - - *resource_type = g_strdup(string); - - LOG_DEBUG("resource type : %s", *resource_type); - - return IOTCON_FUNC_CONTINUE; -} - -int found_device_count = 0; - -static bool _found_resource(iotcon_remote_resource_h resource, - iotcon_error_e result, void *user_data) -{ - int ret; - char *resource_uri_path = NULL; - iotcon_resource_types_h resource_types; - char *resource_device_id; - char *resource_device_name; - char *resource_host; - char *resource_type; - fn_group_type_e group_type; - - LOG_DEBUG("Resource Found"); - - /* get the resource URI */ - ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get resource uri path"); - return IOTCON_FUNC_CONTINUE; - } - LOG_DEBUG("resource uri : %s", resource_uri_path); - - /* get the resource device id */ - ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get resource device id"); - return IOTCON_FUNC_CONTINUE; - } - LOG_DEBUG("resource device id : %s", resource_device_id); - - /* get the resource device name */ - ret = iotcon_remote_resource_get_device_name(resource, - &resource_device_name); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get resource device name"); - return IOTCON_FUNC_CONTINUE; - } - LOG_DEBUG("resource device name : %s", resource_device_name); - - /* get the resource host address */ - ret = iotcon_remote_resource_get_host_address(resource, &resource_host); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get resource host address"); - return IOTCON_FUNC_CONTINUE; - } - LOG_DEBUG("resource host : %s", resource_host); - - ret = iotcon_remote_resource_get_types(resource, &resource_types); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get resource types"); - return IOTCON_FUNC_CONTINUE; - } - - ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb, - &resource_type); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to get foreach resource types"); - return IOTCON_FUNC_CONTINUE; - } - - fn_context_t *fn_ctx = fn_context_get_context(); - if (strcmp(resource_device_id, fn_ctx->device_uuid) == 0) - group_type = FN_GROUP_DEVICE; - else - group_type = FN_GROUP_REMOTE_DEVICE; - - fn_group_add_new(resource_uri_path, resource_device_id, - resource_device_name, resource_host, resource_type, group_type); - found_device_count++; - - g_free(resource_type); - - return IOTCON_FUNC_CONTINUE; -} - -static gboolean _timeout_cb(gpointer data) -{ - int ret = -1; - if (found_device_count > 0) - ret = 0; - - notify_group_finish(ret); - - return false; -} - -int fn_iot_discovery_resource(fn_resource_type_e resource_type, int timeout) -{ - int ret; - iotcon_query_h query; - - found_device_count = 0; - - ret = iotcon_set_timeout(timeout); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to set timeout value"); - return FN_ERROR_OPERATION_FAILED; - } - - ret = iotcon_query_create(&query); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to create iotcon query"); - return FN_ERROR_OPERATION_FAILED; - } - - ret = iotcon_query_set_resource_type(query, - fn_resource_get_type(resource_type)); - if (IOTCON_ERROR_NONE != ret) { - LOG_ERR("Failed to set iotcon query resource type"); - return FN_ERROR_OPERATION_FAILED; - } - - LOG_DEBUG("find resource : %s", get_error_message(ret)); - - ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, - IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP, - query, _found_resource, NULL); - - g_timeout_add_seconds(timeout + 1, _timeout_cb, NULL); - - LOG_DEBUG("find resource : %s", get_error_message(ret)); - - return ret; -} - -int fn_iot_delete_resource(fn_resource_type_e resource_type) -{ - //delete resource from resource list using resource_type and index - //delete DB - return FN_ERROR_NONE; -} - -int fn_iot_deinitialize() -{ - return FN_ERROR_NONE; -}