From: Jin Yoon Date: Thu, 24 Aug 2017 23:38:34 +0000 (+0900) Subject: Merge with master X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F146070%2F1;p=apps%2Fnative%2Fposition-finder-server.git Merge with master Change-Id: Ia642f1e9d29f766900c65e01103f8ead2b553844 --- diff --git a/inc/connectivity.h b/inc/connectivity.h index 9312fcc..ca1aa2f 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -22,27 +22,26 @@ #ifndef __POSITION_FINDER_CONNECTIVITY_H__ #define __POSITION_FINDER_CONNECTIVITY_H__ -#include - #include "connectivity_internal.h" struct connectivity_resource { iotcon_resource_h res; iotcon_observers_h observers; + char *path; }; typedef struct connectivity_resource connectivity_resource_s; /** * @brief Create connectivity resource and registers the resource in server. - * @param[in] uri_path The URI path of the resource + * @param[in] path The path of the resource * @param[in] type The string data to insert into the resource types (e.g. "org.tizen.light") * @param[out] out_resource_info A structure containing information about connectivity resource * @return 0 on success, otherwise a negative error value * @see uri_path length must be less than 128. * @see You must destroy resource by calling connectivity_unset_resource() if resource is no longer needed. */ -extern int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info); +extern int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info); /** * @brief Releases all resource about connectivity. diff --git a/inc/connectivity_internal.h b/inc/connectivity_internal.h index 33ea0e4..d3da902 100644 --- a/inc/connectivity_internal.h +++ b/inc/connectivity_internal.h @@ -22,6 +22,8 @@ #ifndef __POSITION_FINDER_CONNECTIVITY_INTERNAL_H__ #define __POSITION_FINDER_CONNECTIVITY_INTERNAL_H__ +#include + extern int connectivity_init(void); extern int connectivity_fini(void); diff --git a/src/connectivity.c b/src/connectivity.c index 7eeafd7..0856966 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -31,6 +31,9 @@ #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" #define BUFSIZE 1024 +#define URI_PATH_LEN 64 +#define URI_PATH "/door/1" +#define PATH "path" static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data); @@ -66,14 +69,14 @@ static void _destroy_representation(iotcon_representation_h representation) iotcon_representation_destroy(representation); } -static iotcon_representation_h _create_representation_with_bool(iotcon_resource_h res, const char *key, bool value) +static iotcon_representation_h _create_representation_with_bool(connectivity_resource_s *resource_info, const char *key, bool value) { iotcon_attributes_h attributes = NULL; iotcon_representation_h representation = NULL; char *uri_path = NULL; int ret = -1; - ret = iotcon_resource_get_uri_path(res, &uri_path); + ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path); retv_if(IOTCON_ERROR_NONE != ret, NULL); ret = iotcon_representation_create(&representation); @@ -85,6 +88,9 @@ static iotcon_representation_h _create_representation_with_bool(iotcon_resource_ ret = iotcon_representation_set_uri_path(representation, uri_path); goto_if(IOTCON_ERROR_NONE != ret, error); + ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path); + goto_if(IOTCON_ERROR_NONE != ret, error); + ret = iotcon_attributes_add_bool(attributes, key, value); goto_if(IOTCON_ERROR_NONE != ret, error); @@ -102,14 +108,14 @@ error: return NULL; } -static iotcon_representation_h _create_representation_with_int(iotcon_resource_h res, const char *key, int value) +static iotcon_representation_h _create_representation_with_int(connectivity_resource_s *resource_info, const char *key, int value) { iotcon_attributes_h attributes = NULL; iotcon_representation_h representation = NULL; char *uri_path = NULL; int ret = -1; - ret = iotcon_resource_get_uri_path(res, &uri_path); + ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path); retv_if(IOTCON_ERROR_NONE != ret, NULL); ret = iotcon_representation_create(&representation); @@ -121,7 +127,10 @@ static iotcon_representation_h _create_representation_with_int(iotcon_resource_h ret = iotcon_representation_set_uri_path(representation, uri_path); goto_if(IOTCON_ERROR_NONE != ret, error); - ret = iotcon_attributes_add_int(attributes, "opened", value); + ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path); + goto_if(IOTCON_ERROR_NONE != ret, error); + + ret = iotcon_attributes_add_int(attributes, key, value); goto_if(IOTCON_ERROR_NONE != ret, error); ret = iotcon_representation_set_attributes(representation, attributes); @@ -138,14 +147,14 @@ error: return NULL; } -static iotcon_representation_h _create_representation_with_double(iotcon_resource_h res, const char *key, double value) +static iotcon_representation_h _create_representation_with_double(connectivity_resource_s *resource_info, const char *key, double value) { iotcon_attributes_h attributes = NULL; iotcon_representation_h representation = NULL; char *uri_path = NULL; int ret = -1; - ret = iotcon_resource_get_uri_path(res, &uri_path); + ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path); retv_if(IOTCON_ERROR_NONE != ret, NULL); ret = iotcon_representation_create(&representation); @@ -157,7 +166,10 @@ static iotcon_representation_h _create_representation_with_double(iotcon_resourc ret = iotcon_representation_set_uri_path(representation, uri_path); goto_if(IOTCON_ERROR_NONE != ret, error); - ret = iotcon_attributes_add_double(attributes, "opened", value); + ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path); + goto_if(IOTCON_ERROR_NONE != ret, error); + + ret = iotcon_attributes_add_double(attributes, key, value); goto_if(IOTCON_ERROR_NONE != ret, error); ret = iotcon_representation_set_attributes(representation, attributes); @@ -184,7 +196,7 @@ int connectivity_notify_bool(connectivity_resource_s *resource_info, const char _D("Notify the value[%d]", value); - representation = _create_representation_with_bool(resource_info->res, key, value); + representation = _create_representation_with_bool(resource_info, key, value); retv_if(!representation, -1); ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH); @@ -205,7 +217,7 @@ int connectivity_notify_int(connectivity_resource_s *resource_info, const char * _D("Notify the value[%d]", value); - representation = _create_representation_with_int(resource_info->res, key, value); + representation = _create_representation_with_int(resource_info, key, value); retv_if(!representation, -1); ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH); @@ -226,7 +238,7 @@ int connectivity_notify_double(connectivity_resource_s *resource_info, const cha _D("Notify the value[%f]", value); - representation = _create_representation_with_double(resource_info->res, key, value); + representation = _create_representation_with_double(resource_info, key, value); retv_if(!representation, -1); ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH); @@ -381,10 +393,11 @@ void connectivity_unset_resource(connectivity_resource_s *resource_info) ret_if(!resource_info); if (resource_info->observers) iotcon_observers_destroy(resource_info->observers); if (resource_info->res) iotcon_resource_destroy(resource_info->res); + if (resource_info->path) free(resource_info->path); free(resource_info); } -int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info) +int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info) { iotcon_resource_types_h resource_types = NULL; iotcon_resource_interfaces_h ifaces = NULL; @@ -392,9 +405,17 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi uint8_t policies; int ret = -1; + retv_if(!path, -1); + retv_if(!type, -1); + retv_if(!out_resource_info, -1); + resource_info = calloc(1, sizeof(connectivity_resource_s)); retv_if(!resource_info, -1); - *out_resource_info = resource_info; + + resource_info->path = strdup(path); + goto_if(!resource_info->path, error); + + _D("Path : [%s]", resource_info->path); ret = iotcon_resource_types_create(&resource_types); goto_if(IOTCON_ERROR_NONE != ret, error); @@ -416,7 +437,7 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi IOTCON_RESOURCE_OBSERVABLE | IOTCON_RESOURCE_SECURE; - ret = iotcon_resource_create(uri_path, + ret = iotcon_resource_create(URI_PATH, resource_types, ifaces, policies, @@ -430,6 +451,7 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi iotcon_resource_types_destroy(resource_types); iotcon_resource_interfaces_destroy(ifaces); + *out_resource_info = resource_info; return 0; @@ -437,6 +459,7 @@ error: if (ifaces) iotcon_resource_interfaces_destroy(ifaces); if (resource_types) iotcon_resource_types_destroy(resource_types); if (resource_info->res) iotcon_resource_destroy(resource_info->res); + if (resource_info->path) free(resource_info->path); if (resource_info) free(resource_info); return -1; diff --git a/src/controller.c b/src/controller.c index 4b5eb02..de1ec4e 100644 --- a/src/controller.c +++ b/src/controller.c @@ -27,11 +27,12 @@ #include "log.h" #include "resource.h" -#include "controller.h" #include "connectivity.h" +#include "controller.h" #define GPIO_INFRARED_MOTION_NUM 20 #define CONNECTIVITY_KEY "opened" +#define SENSORING_TIME_INTERVAL 1.0f typedef struct app_data_s { Ecore_Timer *getter_timer; @@ -79,7 +80,7 @@ static bool service_app_create(void *data) * Creates a timer to call the given function in the given period of time. * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor. */ - ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad); + ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, control_sensors_cb, ad); if (!ad->getter_timer) { _E("Failed to add infrared motion getter timer"); return false; diff --git a/src/controller_internal.c b/src/controller_internal.c index 3508321..cd24bad 100644 --- a/src/controller_internal.c +++ b/src/controller_internal.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#include + #include "log.h" #include "connectivity.h" #include "resource.h"