From 4a032edb0197b2a1ea032a10cb3ccb882f12f335 Mon Sep 17 00:00:00 2001 From: Jin Yoon Date: Fri, 14 Jul 2017 12:15:30 +0900 Subject: [PATCH] Connectivity APIs, First version Change-Id: I9d3df7e6b5bd6b02f8fa351223d43ff996699493 --- inc/connectivity.h | 15 ++++++++++----- inc/connectivity_internal.h | 28 ++++++++++++++++++++++++++++ src/connectivity.c | 15 +++++---------- 3 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 inc/connectivity_internal.h diff --git a/inc/connectivity.h b/inc/connectivity.h index 58dd87f..18479c6 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -22,13 +22,18 @@ #ifndef __POSITION_FINDER_CONNECTIVITY_H__ #define __POSITION_FINDER_CONNECTIVITY_H__ +#include "connectivity_internal.h" + +struct connectivity_resource { + iotcon_resource_h res; + iotcon_observers_h observers; +}; + typedef struct connectivity_resource connectivity_resource_s; -extern int connectivity_notify(connectivity_resource_s *user_data, int value); -extern int connectivity_init(const char *device_name); -extern int connectivity_fini(void); +extern int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info); +extern void connectivity_unset_resource(connectivity_resource_s *resource); -extern void connectivity_destroy_resource(connectivity_resource_s *resource); -extern int connectivity_create_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource); +extern int connectivity_notify(connectivity_resource_s *resource_info, int value); #endif /* __POSITION_FINDER_CONNECTIVITY_H__ */ diff --git a/inc/connectivity_internal.h b/inc/connectivity_internal.h new file mode 100644 index 0000000..1f1ff14 --- /dev/null +++ b/inc/connectivity_internal.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __POSITION_FINDER_CONNECTIVITY_INTERNAL_H__ +#define __POSITION_FINDER_CONNECTIVITY_INTERNAL_H__ + +extern int connectivity_init(const char *device_name); +extern int connectivity_fini(void); + +#endif /* __POSITION_FINDER_CONNECTIVITY_INTERNAL_H__ */ diff --git a/src/connectivity.c b/src/connectivity.c index b772625..c27234e 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -32,10 +32,6 @@ #define ULTRASONIC_RESOURCE_2_URI "/door/2" #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" -struct connectivity_resource { - iotcon_resource_h res; - iotcon_observers_h observers; -}; static bool _resource_created; static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data); @@ -184,10 +180,9 @@ error: return -1; } -int connectivity_notify(connectivity_resource_s *user_data, int value) +int connectivity_notify(connectivity_resource_s *resource_info, int value) { iotcon_representation_h representation; - connectivity_resource_s *resource_info = user_data; int ret = -1; retv_if(!resource_info, -1); @@ -223,7 +218,7 @@ static int _handle_post_request(connectivity_resource_s *resource_info, iotcon_r new_resource_info = calloc(1, sizeof(connectivity_resource_s)); retv_if(!new_resource_info, -1); - ret = connectivity_create_resource(ULTRASONIC_RESOURCE_2_URI, ULTRASONIC_RESOURCE_TYPE, &new_resource_info); + ret = connectivity_set_resource(ULTRASONIC_RESOURCE_2_URI, ULTRASONIC_RESOURCE_TYPE, &new_resource_info); retv_if(0 != ret, -1); _resource_created = true; @@ -380,7 +375,7 @@ int connectivity_init(const char *device_name) { int ret = -1; - ret = iotcon_initialize("../res/iotcon-test-svr-db-server.dat"); + ret = iotcon_initialize("/usr/apps/org.tizen.position-finder-server/res/iotcon-test-svr-db-server.dat"); retv_if(IOTCON_ERROR_NONE != ret, -1); ret = iotcon_set_device_name(device_name); @@ -402,7 +397,7 @@ int connectivity_fini(void) return 0; } -void connectivity_destroy_resource(connectivity_resource_s *resource_info) +void connectivity_unset_resource(connectivity_resource_s *resource_info) { ret_if(!resource_info); if (resource_info->observers) iotcon_observers_destroy(resource_info->observers); @@ -410,7 +405,7 @@ void connectivity_destroy_resource(connectivity_resource_s *resource_info) free(resource_info); } -int connectivity_create_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info) +int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info) { iotcon_resource_types_h resource_types = NULL; iotcon_resource_interfaces_h ifaces = NULL; -- 2.7.4