Initial version
authorJin Yoon <jinny.yoon@samsung.com>
Mon, 26 Jun 2017 04:23:10 +0000 (13:23 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Mon, 26 Jun 2017 04:23:10 +0000 (13:23 +0900)
18 files changed:
CMakeLists.txt [new file with mode: 0644]
inc/controller.h [new file with mode: 0644]
inc/log.h [new file with mode: 0644]
inc/model.h [new file with mode: 0644]
inc/model/model_infrared_motion_sensor.h [new file with mode: 0644]
inc/model/model_infrared_obstacle_avoidance_sensor.h [new file with mode: 0644]
inc/model/model_ultrasonic_sensor.h [new file with mode: 0644]
org.tizen.position-finder-server.manifest [new file with mode: 0755]
packaging/org.tizen.position-finder-server.spec [new file with mode: 0644]
shared/res/position_finder_server.png [new file with mode: 0755]
src/connectivity.c [new file with mode: 0644]
src/controller.c [new file with mode: 0644]
src/main.c [new file with mode: 0644]
src/model.c [new file with mode: 0644]
src/model/model_infrared_motion_sensor.c [new file with mode: 0644]
src/model/model_infrared_obstacle_avoidance_sensor.c [new file with mode: 0644]
src/model/model_ultrasonic_sensor.c [new file with mode: 0644]
tizen-manifest.xml [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..606be9b
--- /dev/null
@@ -0,0 +1,53 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(position-finder-server C)
+
+SET(INSTALL_EXEC_PREFIX "${INSTALL_PREFIX}/bin")
+SET(INSTALL_RESDIR "${INSTALL_PREFIX}/res")
+SET(CMAKE_VERBOSE_MAKEFILE 0)
+
+SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}")
+SET(PROJECT_RESOURCES_DIR "${PROJECT_ROOT_DIR}/res")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(APP_PKGS REQUIRED
+       dlog
+       aul
+       capi-appfw-application
+       capi-appfw-service-application
+       capi-system-peripheral-io
+       ecore
+       eina
+       iotcon
+)
+
+FOREACH (flag ${APP_PKGS_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline -g -fno-builtin-malloc -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc)
+
+ADD_EXECUTABLE(${PROJECT_NAME}
+       ${PROJECT_ROOT_DIR}/src/controller.c
+       ${PROJECT_ROOT_DIR}/src/model.c
+       ${PROJECT_ROOT_DIR}/src/main.c
+       ${PROJECT_ROOT_DIR}/src/model/model_ultrasonic_sensor.c
+       ${PROJECT_ROOT_DIR}/src/model/model_infrared_motion_sensor.c
+       ${PROJECT_ROOT_DIR}/src/model/model_infrared_obstacle_avoidance_sensor.c
+)
+#${PROJECT_ROOT_DIR}/src/connectivity.c
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS})
+
+# Install
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX})
+
+INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.position-finder-server.xml)
+INSTALL(DIRECTORY DESTINATION ${PREFIX}/data)
+INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/position_finder_server.png DESTINATION ${SYS_ICONS_DIR})
+
+# End of a file
diff --git a/inc/controller.h b/inc/controller.h
new file mode 100644 (file)
index 0000000..aef6e47
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_CONTROLLER_H__
+#define __POSITION_FINDER_CONTROLLER_H__
+
+typedef int (*controller_event_cb)(const char *event_name, void *event_info, void *data);
+
+extern int controller_register_event_cb(const char *event_name, controller_event_cb event_cb, void *data);
+extern int controller_unregister_event_cb(const char *event_name, controller_event_cb event_cb);
+extern int controller_send_event(const char *event_name, void *event_info);
+
+#endif /* __POSITION_FINDER_CONTROLLER_H__ */
diff --git a/inc/log.h b/inc/log.h
new file mode 100644 (file)
index 0000000..e154be1
--- /dev/null
+++ b/inc/log.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_SERVER_H__
+#define __POSITION_FINDER_SERVER_H__
+
+#include <dlog.h>
+
+#ifdef  LOG_TAG
+#undef  LOG_TAG
+#endif
+#define LOG_TAG "POSITION_FINDER_SERVER"
+
+#if !defined(_D)
+#define _D(fmt, arg...) dlog_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_I)
+#define _I(fmt, arg...) dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_W)
+#define _W(fmt, arg...) dlog_print(DLOG_WARN, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_E)
+#define _E(fmt, arg...) dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#define retvm_if(expr, val, fmt, arg...) do { \
+       if(expr) { \
+               _E(fmt, ##arg); \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return val; \
+       } \
+} while (0)
+
+#define retv_if(expr, val) do { \
+       if(expr) { \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return (val); \
+       } \
+} while (0)
+
+#define retm_if(expr, fmt, arg...) do { \
+       if(expr) { \
+               _E(fmt, ##arg); \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return; \
+       } \
+} while (0)
+
+#define ret_if(expr) do { \
+       if(expr) { \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return; \
+       } \
+} while (0)
+
+#define goto_if(expr, val) do { \
+       if(expr) { \
+               _E("(%s) -> goto", #expr); \
+               goto val; \
+       } \
+} while (0)
+
+#define break_if(expr) { \
+       if(expr) { \
+               _E("(%s) -> break", #expr); \
+               break; \
+       } \
+}
+
+#define continue_if(expr) { \
+       if(expr) { \
+               _E("(%s) -> continue", #expr); \
+               continue; \
+       } \
+}
+
+
+
+#endif /* __POSITION_FINDER_SERVER_H__ */
diff --git a/inc/model.h b/inc/model.h
new file mode 100644 (file)
index 0000000..f564175
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_MODEL_H__
+#define __POSITION_FINDER_MODEL_H__
+
+enum sensor_type {
+       SENSOR_TYPE_ULTRASONIC,
+       SENSOR_TYPE_INFRARED_MOTION, /* HC_SR501 */
+       SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE, /* HC_SR501 */
+};
+typedef enum sensor_type sensor_type_e;
+
+extern int model_init(sensor_type_e sensor_type);
+extern void model_fini(void);
+
+extern int model_alloc(void **data);
+
+extern int model_read_int_value(int *out_value);
+extern int model_write(void *data);
+
+#endif /* __POSITION_FINDER_MODEL_H__ */
diff --git a/inc/model/model_infrared_motion_sensor.h b/inc/model/model_infrared_motion_sensor.h
new file mode 100644 (file)
index 0000000..4ff90c7
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_MODEL_INFRARED_MOTION_SENSOR_H__
+#define __POSITION_FINDER_MODEL_INFRARED_MOTION_SENSOR_H__
+
+typedef struct infrared_motion_event infrared_motion_event_s;
+
+extern int model_init_infrared_motion_sensor(void);
+extern void model_fini_infrared_motion_sensor(void);
+
+extern int model_read_infrared_motion_sensor(int *out_value);
+
+#endif /* __POSITION_FINDER_MODEL_INFRARED_MOTION_SENSOR_H__ */
diff --git a/inc/model/model_infrared_obstacle_avoidance_sensor.h b/inc/model/model_infrared_obstacle_avoidance_sensor.h
new file mode 100644 (file)
index 0000000..bfba8f9
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
+#define __POSITION_FINDER_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
+
+typedef struct infrared_obstacle_avoidance_event infrared_obstacle_avoidance_event_s;
+
+extern int model_init_infrared_obstacle_avoidance_sensor(void);
+extern void model_fini_infrared_obstacle_avoidance_sensor(void);
+
+extern int model_read_infrared_obstacle_avoidance_sensor(int *out_value);
+
+#endif /* __POSITION_FINDER_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
diff --git a/inc/model/model_ultrasonic_sensor.h b/inc/model/model_ultrasonic_sensor.h
new file mode 100644 (file)
index 0000000..e0c9f56
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_MODEL_ULTRASONIC_SENSOR_H__
+#define __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__
+
+#endif /* __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__ */
diff --git a/org.tizen.position-finder-server.manifest b/org.tizen.position-finder-server.manifest
new file mode 100755 (executable)
index 0000000..af9b883
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>\r
+       <request>\r
+               <domain name="_" />\r
+       </request>\r
+</manifest>\r
diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec
new file mode 100644 (file)
index 0000000..876d6f5
--- /dev/null
@@ -0,0 +1,74 @@
+Name:       org.tizen.position-finder-server
+%define alias org.tizen.position-finder-server
+Summary:    IoTivity Application
+Group:      Applications/Core Applications
+Version:    0.0.1
+Release:    1
+License:    Apache-2.0
+Provides:   org.tizen.position-finder-server = %{version}-%{release}
+Source0:    %{name}-%{version}.tar.gz
+
+BuildRequires:  cmake
+BuildRequires:  hash-signer
+BuildRequires:  pkgconfig(capi-appfw-application)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(capi-appfw-service-application)
+BuildRequires: pkgconfig(capi-system-peripheral-io)
+BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(eina)
+BuildRequires: pkgconfig(iotcon)
+
+%description
+Server for Position Finder
+
+%prep
+%setup -q
+
+%build
+
+%define _pkg_dir %{TZ_SYS_RO_APP}/%{alias}
+%define _pkg_shared_dir %{_pkg_dir}/shared
+%define _pkg_data_dir %{_pkg_dir}/data
+%define _sys_icons_dir %{_pkg_shared_dir}/res
+%define _sys_packages_dir %{TZ_SYS_RO_PACKAGES}
+%define _sys_license_dir %{TZ_SYS_SHARE}/license
+
+%ifarch %{arm}
+export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_BUILD_TARGET"
+export FFLAGS="$FFLAGS -DTIZEN_BUILD_TARGET"
+%else
+export CFLAGS="$CFLAGS -DTIZEN_BUILD_EMULATOR"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_BUILD_EMULATOR"
+export FFLAGS="$FFLAGS -DTIZEN_BUILD_EMULATOR"
+%endif
+
+cmake . -DINSTALL_PREFIX=%{_pkg_dir} \
+       -DSYS_ICONS_DIR=%{_sys_icons_dir} \
+       -DSYS_PACKAGES_DIR=%{_sys_packages_dir}
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+
+%define tizen_sign 1
+%define tizen_sign_base %{_pkg_dir}
+%define tizen_sign_level platform
+%define tizen_author_sign 1
+%define tizen_dist_sign 1
+#%find_lang position-finder-server
+
+%post
+/sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest org.tizen.position-finder-server.manifest
+%defattr(-,root,root,-)
+%{_pkg_dir}/bin/position-finder-server
+%{_sys_packages_dir}/org.tizen.position-finder-server.xml
+%{_sys_icons_dir}/position_finder_server.png
+%{_pkg_dir}/author-signature.xml
+%{_pkg_dir}/signature1.xml
diff --git a/shared/res/position_finder_server.png b/shared/res/position_finder_server.png
new file mode 100755 (executable)
index 0000000..9765b1b
Binary files /dev/null and b/shared/res/position_finder_server.png differ
diff --git a/src/connectivity.c b/src/connectivity.c
new file mode 100644 (file)
index 0000000..79ea6e2
--- /dev/null
@@ -0,0 +1,627 @@
+/*
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+
+#include <iotcon.h>
+#include "log.h"
+
+#define ULTRASONIC_RESOURCE_1_URI "/door/1"
+#define ULTRASONIC_RESOURCE_2_URI "/door/2"
+#define ULTRASONIC_RESOURCE_TYPE "org.tizen.door"
+
+/* Door Resource */
+struct _ultrasonic_resource_s {
+       bool attributes;
+       char *uri_path;
+       char *type;
+       uint8_t policies;
+       iotcon_resource_interfaces_h ifaces;
+       iotcon_resource_h handle;
+       iotcon_observers_h observers;
+       iotcon_representation_h repr;
+};
+typedef struct _ultrasonic_resource_s ultrasonic_resource_s;
+
+static bool _resource_created;
+
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
+
+static int _set_door_resource(ultrasonic_resource_s *door)
+{
+       int ret;
+
+       door->attributes = false;
+
+       door->uri_path = strdup(ULTRASONIC_RESOURCE_1_URI);
+       if (NULL == door->uri_path) {
+               _E("strdup(%s) Fail", ULTRASONIC_RESOURCE_1_URI);
+               return -1;
+       }
+
+       door->type = strdup(ULTRASONIC_RESOURCE_TYPE);
+       if (NULL == door->type) {
+               _E("strdup(%s) Fail", ULTRASONIC_RESOURCE_TYPE);
+               free(door->uri_path);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_create(&door->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               free(door->type);
+               free(door->uri_path);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(door->ifaces);
+               free(door->type);
+               free(door->uri_path);
+               return -1;
+       }
+
+       door->policies = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE
+               | IOTCON_RESOURCE_SECURE;
+
+       ret = iotcon_observers_create(&door->observers);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_observers_create() Fail");
+               iotcon_resource_interfaces_destroy(door->ifaces);
+               free(door->type);
+               free(door->uri_path);
+               return -1;
+       }
+
+       return 0;
+}
+
+static void _free_door_resource(ultrasonic_resource_s *door)
+{
+       iotcon_observers_destroy(door->observers);
+       iotcon_resource_interfaces_destroy(door->ifaces);
+       free(door->type);
+       free(door->uri_path);
+}
+
+static void _check_door_attributes(ultrasonic_resource_s door)
+{
+       if (false == door.attributes)
+               _D("[Door] closed.");
+       else
+               _D("[Door] opened.");
+}
+
+static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
+               iotcon_resource_interfaces_h ifaces, uint8_t policies, void *user_data)
+{
+       int ret;
+       iotcon_resource_h handle;
+       iotcon_resource_types_h resource_types;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_types_create() Fail(%d)", ret);
+               return NULL;
+       }
+
+       ret = iotcon_resource_types_add(resource_types, type);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_types_add() Fail(%d)", ret);
+               iotcon_resource_types_destroy(resource_types);
+               return NULL;
+       }
+
+       /* register door resource */
+       ret = iotcon_resource_create(uri_path, resource_types, ifaces, policies,
+                       _request_handler, user_data, &handle);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_create() Fail");
+               iotcon_resource_types_destroy(resource_types);
+               return NULL;
+       }
+
+       iotcon_resource_types_destroy(resource_types);
+
+       return handle;
+}
+
+static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
+               iotcon_response_result_e result)
+{
+       int ret;
+       iotcon_response_h response;
+
+       ret = iotcon_response_create(request, &response);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_response_create() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_response_set_result(response, result);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_response_set_result() Fail(%d)", ret);
+               iotcon_response_destroy(response);
+               return -1;
+       }
+
+       ret = iotcon_response_set_representation(response, repr);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_response_set_representation() Fail(%d)", ret);
+               iotcon_response_destroy(response);
+               return -1;
+       }
+
+       /* send Representation to the client */
+       ret = iotcon_response_send(response);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_response_send() Fail(%d)", ret);
+               iotcon_response_destroy(response);
+               return -1;
+       }
+
+       iotcon_response_destroy(response);
+
+       return 0;
+}
+
+static iotcon_representation_h _get_door_representation(ultrasonic_resource_s *door)
+{
+       int ret;
+       iotcon_attributes_h attributes;
+       iotcon_representation_h repr;
+
+       /* create a door Representation */
+       ret = iotcon_representation_create(&repr);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_create() Fail(%d)", ret);
+               return NULL;
+       }
+
+       /* create a door attributes */
+       ret = iotcon_attributes_create(&attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_attributes_create() Fail(%d)", ret);
+               iotcon_representation_destroy(repr);
+               return NULL;
+       }
+
+       ret = iotcon_representation_set_uri_path(repr, door->uri_path);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_set_uri_path() Fail(%d)", ret);
+               iotcon_attributes_destroy(attributes);
+               iotcon_representation_destroy(repr);
+               return NULL;
+       }
+
+       ret = iotcon_attributes_add_bool(attributes, "opened", door->attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_attributes_add_bool() Fail(%d)", ret);
+               iotcon_attributes_destroy(attributes);
+               iotcon_representation_destroy(repr);
+               return NULL;
+       }
+
+       ret = iotcon_representation_set_attributes(repr, attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_set_attributes() Fail(%d)", ret);
+               iotcon_attributes_destroy(attributes);
+               iotcon_representation_destroy(repr);
+               return NULL;
+       }
+
+       iotcon_attributes_destroy(attributes);
+
+       return repr;
+}
+
+static int _request_handler_get(ultrasonic_resource_s *door, iotcon_request_h request)
+{
+       int ret;
+       iotcon_representation_h resp_repr;
+       _D("GET request");
+
+       resp_repr = _get_door_representation(door);
+       if (NULL == resp_repr) {
+               _E("_get_door_representation() Fail");
+               return -1;
+       }
+
+       ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
+       if (0 != ret) {
+               _E("_send_response() Fail(%d)", ret);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       iotcon_representation_destroy(resp_repr);
+
+       return 0;
+}
+
+static int _set_door_representation(ultrasonic_resource_s *door,
+               iotcon_representation_h repr)
+{
+       int ret;
+       bool bval;
+       iotcon_attributes_h attributes;
+
+       ret = iotcon_representation_get_attributes(repr, &attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_get_attributes() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_attributes_get_bool(attributes, "opened", &bval);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_attributes_get_bool() Fail(%d)", ret);
+               return -1;
+       }
+
+       door->attributes = bval;
+
+       return 0;
+}
+
+static int _request_handler_put(ultrasonic_resource_s *door, iotcon_request_h request)
+{
+       int ret;
+       iotcon_representation_h req_repr, resp_repr;
+       _D("PUT request");
+
+       ret = iotcon_request_get_representation(request, &req_repr);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_request_get_representation() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = _set_door_representation(door, req_repr);
+       if (0 != ret) {
+               _E("_set_door_representation() Fail(%d)", ret);
+               return -1;
+       }
+
+       _check_door_attributes(*door);
+
+       resp_repr = _get_door_representation(door);
+       if (NULL == resp_repr) {
+               _E("_get_door_representation() Fail");
+               return -1;
+       }
+
+       ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
+       if (0 != ret) {
+               _E("_send_response() Fail(%d)", ret);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       /* notify */
+       ret = iotcon_resource_notify(door->handle, resp_repr, door->observers, IOTCON_QOS_HIGH);
+       if (IOTCON_ERROR_NONE != ret)
+               _E("iotcon_resource_notify() Fail(%d)", ret);
+
+       iotcon_representation_destroy(resp_repr);
+
+       return 0;
+}
+
+static gboolean _door_attributes_changer(gpointer user_data)
+{
+       int ret;
+       static int i = 0;
+       iotcon_representation_h repr;
+       ultrasonic_resource_s *door = user_data;
+
+       if ((5 == i++) || NULL == door->observers)
+               return G_SOURCE_REMOVE;
+
+       if (false == door->attributes) {
+               door->attributes = true;
+               _D("[Door] closed -> opened");
+       } else {
+               door->attributes = false;
+               _D("[Door] opened -> closed");
+       }
+
+       _D("NOTIFY!");
+
+       repr = _get_door_representation(door);
+       if (NULL == repr) {
+               _E("_get_door_representation() Fail");
+               return G_SOURCE_REMOVE;
+       }
+
+       ret = iotcon_resource_notify(door->handle, repr, door->observers, IOTCON_QOS_HIGH);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_notify() Fail(%d)", ret);
+               iotcon_representation_destroy(repr);
+               return G_SOURCE_REMOVE;
+       }
+
+       iotcon_representation_destroy(repr);
+       return G_SOURCE_CONTINUE;
+}
+
+static int _request_handler_post(ultrasonic_resource_s *door, iotcon_request_h request)
+{
+       int ret;
+       iotcon_attributes_h resp_attributes;
+       iotcon_representation_h resp_repr = NULL;
+       iotcon_resource_h new_door_handle;
+       _D("POST request");
+
+       if (_resource_created) {
+               _E("Resource(%s) is already created", ULTRASONIC_RESOURCE_2_URI);
+               return -1;
+       }
+
+       new_door_handle = _create_door_resource(ULTRASONIC_RESOURCE_2_URI, door->type,
+                       door->ifaces, IOTCON_RESOURCE_SECURE, door);
+       if (NULL == new_door_handle) {
+               _E("_create_door_resource() Fail");
+               return -1;
+       }
+       _resource_created = true;
+
+       /* send information that new resource was created */
+       ret = iotcon_representation_create(&resp_repr);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_create() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_attributes_create(&resp_attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_attributes_create() Fail(%d)", ret);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       ret = iotcon_attributes_add_str(resp_attributes, "createduripath", ULTRASONIC_RESOURCE_2_URI);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_attributes_add_str() Fail(%d)", ret);
+               iotcon_attributes_destroy(resp_attributes);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       ret = iotcon_representation_set_attributes(resp_repr, resp_attributes);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_representation_set_attributes() Fail(%d)", ret);
+               iotcon_attributes_destroy(resp_attributes);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       iotcon_attributes_destroy(resp_attributes);
+
+       ret = _send_response(request, resp_repr, IOTCON_RESPONSE_RESOURCE_CREATED);
+       if (0 != ret) {
+               _E("_send_response() Fail(%d)", ret);
+               iotcon_representation_destroy(resp_repr);
+               return -1;
+       }
+
+       iotcon_representation_destroy(resp_repr);
+
+       return 0;
+}
+
+static int _request_handler_delete(iotcon_resource_h resource,
+               iotcon_request_h request)
+{
+       int ret;
+       _D("DELETE request");
+
+       ret = iotcon_resource_destroy(resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_destroy() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = _send_response(request, NULL, IOTCON_RESPONSE_RESOURCE_DELETED);
+       if (0 != ret) {
+               _E("_send_response() Fail(%d)", ret);
+               return -1;
+       }
+
+       return 0;
+}
+
+static bool _query_cb(const char *key, const char *value, void *user_data)
+{
+       _D("key : %s, value : %s", key, value);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       ultrasonic_resource_s *door;
+       iotcon_query_h query;
+       int ret, observe_id;
+       iotcon_request_type_e type;
+       iotcon_observe_type_e observe_type;
+       char *host_address;
+
+       ret_if(NULL == request);
+
+       ret = iotcon_request_get_host_address(request, &host_address);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_request_get_host_address() Fail(%d)", ret);
+               _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
+               return;
+       }
+       _D("host_address : %s", host_address);
+
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_request_get_query() Fail(%d)", ret);
+               _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
+               return;
+       }
+       if (query)
+               iotcon_query_foreach(query, _query_cb, NULL);
+
+       ret = iotcon_request_get_request_type(request, &type);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_request_get_request_type() Fail(%d)", ret);
+               _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
+               return;
+       }
+
+       door = user_data;
+
+       if (IOTCON_REQUEST_GET == type)
+               ret = _request_handler_get(door, request);
+
+       else if (IOTCON_REQUEST_PUT == type)
+               ret = _request_handler_put(door, request);
+
+       else if (IOTCON_REQUEST_POST == type)
+               ret = _request_handler_post(door, request);
+
+       else if (IOTCON_REQUEST_DELETE == type)
+               ret = _request_handler_delete(resource, request);
+
+       if (0 != ret) {
+               _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
+               return;
+       }
+
+       ret = iotcon_request_get_observe_type(request, &observe_type);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_request_get_observe_type() Fail(%d)", ret);
+               return;
+       }
+
+       if (IOTCON_OBSERVE_REGISTER == observe_type) {
+               ret = iotcon_request_get_observe_id(request, &observe_id);
+               if (IOTCON_ERROR_NONE != ret) {
+                       _E("iotcon_request_get_observe_id() Fail(%d)", ret);
+                       return;
+               }
+
+               ret = iotcon_observers_add(door->observers, observe_id);
+               if (IOTCON_ERROR_NONE != ret) {
+                       _E("iotcon_observers_add() Fail(%d)", ret);
+                       return;
+               }
+       } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
+               ret = iotcon_request_get_observe_id(request, &observe_id);
+               if (IOTCON_ERROR_NONE != ret) {
+                       _E("iotcon_request_get_observe_id() Fail(%d)", ret);
+                       return;
+               }
+               ret = iotcon_observers_remove(door->observers, observe_id);
+               if (IOTCON_ERROR_NONE != ret) {
+                       _E("iotcon_observers_remove() Fail(%d)", ret);
+                       return;
+               }
+       }
+}
+
+static gboolean _presence_timer(gpointer user_data)
+{
+       static int i = 0;
+       i++;
+       if (i % 2)
+               iotcon_stop_presence();
+       else
+               iotcon_start_presence(10);
+
+       if (3 == i)
+               return G_SOURCE_REMOVE;
+
+       return G_SOURCE_CONTINUE;
+}
+
+int main(int argc, char **argv)
+{
+       int ret;
+       GMainLoop *loop;
+       ultrasonic_resource_s my_door = {0};
+
+       loop = g_main_loop_new(NULL, FALSE);
+
+       /* initialize iotcon */
+       ret = iotcon_initialize("/usr/bin/iotcon-test-svr-db-server.dat");
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_initialize() Fail(%d)", ret);
+               return -1;
+       }
+
+       /* set device name */
+       ret = iotcon_set_device_name("iotcon-test-basic-server");
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_set_device_name() Fail(%d)", ret);
+               iotcon_deinitialize();
+               return -1;
+       }
+
+       /* set local door resource */
+       ret = _set_door_resource(&my_door);
+       if (0 != ret) {
+               _E("_set_door_resource() Fail");
+               iotcon_deinitialize();
+               return -1;
+       }
+
+       /* add resource options */
+       ret = iotcon_resource_interfaces_add(my_door.ifaces, IOTCON_INTERFACE_BATCH);
+       if (IOTCON_ERROR_NONE != ret) {
+               _E("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               _free_door_resource(&my_door);
+               iotcon_deinitialize();
+               return -1;
+       }
+
+       /* add presence */
+       g_timeout_add_seconds(10, _presence_timer, NULL);
+       iotcon_start_presence(10);
+
+       /* create new door resource */
+       my_door.handle = _create_door_resource(my_door.uri_path, my_door.type, my_door.ifaces,
+                       my_door.policies, &my_door);
+       if (NULL == my_door.handle) {
+               _E("_create_door_resource() Fail");
+               _free_door_resource(&my_door);
+               iotcon_deinitialize();
+               return -1;
+       }
+
+       _check_door_attributes(my_door);
+
+       /* add observe */
+       g_timeout_add_seconds(5, _door_attributes_changer, &my_door);
+
+       g_main_loop_run(loop);
+       g_main_loop_unref(loop);
+
+       iotcon_resource_destroy(my_door.handle);
+
+       _free_door_resource(&my_door);
+
+       /* deinitialize iotcon */
+       iotcon_deinitialize();
+
+       return 0;
+}
diff --git a/src/controller.c b/src/controller.c
new file mode 100644 (file)
index 0000000..7950f7b
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <Eina.h>
+
+#include "log.h"
+#include "controller.h"
+
+struct controller_s {
+       Eina_List *event_cb_list;
+};
+static struct controller_s controller_info;
+
+struct _controller_event_cb_info_s {
+       char *event_name;
+       controller_event_cb event_cb;
+       void *data;
+};
+typedef struct _controller_event_cb_info_s controller_event_cb_info_s;
+
+
+int controller_register_event_cb(const char *event_name, controller_event_cb event_cb, void *data)
+{
+       controller_event_cb_info_s *event_cb_info = NULL;
+
+       retv_if(!event_name, -1);
+       retv_if(!event_cb, -1);
+
+       event_cb_info = calloc(1, sizeof(controller_event_cb_info_s));
+       retv_if(!event_cb_info, -1);
+
+       event_cb_info->event_name = strdup(event_name);
+       goto_if(!event_cb_info->event_name, error);
+
+       event_cb_info->event_cb = event_cb;
+       event_cb_info->data = data;
+
+       controller_info.event_cb_list = eina_list_append(controller_info.event_cb_list, event_cb_info);
+
+       return 0;
+
+error:
+       if (event_cb_info) free(event_cb_info);
+
+       return -1;
+}
+
+int controller_unregister_event_cb(const char *event_name, controller_event_cb event_cb)
+{
+       controller_event_cb_info_s *event_cb_info = NULL;
+       const Eina_List *l = NULL;
+       const Eina_List *ln = NULL;
+
+       retv_if(!event_name, -1);
+       retv_if(!event_cb, -1);
+
+       EINA_LIST_FOREACH_SAFE(controller_info.event_cb_list, l, ln, event_cb_info) {
+               if (event_cb_info->event_name 
+                       && strcmp(event_cb_info->event_name, event_name)
+                       && event_cb_info->event_cb == event_cb)
+               {
+                       controller_info.event_cb_list = eina_list_remove(controller_info.event_cb_list, event_cb_info);
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+int controller_send_event(const char *event_name, void *event_info)
+{
+       controller_event_cb_info_s *event_cb_info = NULL;
+       const Eina_List *l = NULL;
+       const Eina_List *ln = NULL;
+
+       retv_if(!event_name, -1);
+
+       EINA_LIST_FOREACH_SAFE(controller_info.event_cb_list, l, ln, event_cb_info) {
+               if (event_cb_info->event_name 
+                       && strcmp(event_cb_info->event_name, event_name))
+               {
+                       int ret = -1;
+                       ret = event_cb_info->event_cb(event_name, event_info, event_cb_info->data);
+                       if (ret < 0) _E("There were errors sending an event");
+                       break;
+               }
+       }
+
+       return 0;
+}
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..f9119b3
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <tizen.h>
+#include <Ecore.h>
+#include <service_app.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "log.h"
+#include "model.h"
+
+typedef struct app_data_s {
+       Ecore_Timer *getter_timer;
+       void *event;
+} app_data;
+
+static Eina_Bool _getter_timer(void *data)
+{
+       int value = 0;
+       retv_if(model_read_int_value(&value) == -1, ECORE_CALLBACK_CANCEL);
+
+       _I("Value is [%d]", value);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+static bool service_app_create(void *data)
+{
+       app_data *ad = (app_data *)data;
+
+       retv_if(model_init(SENSOR_TYPE_INFRARED_MOTION) == -1, false);
+
+       ad->getter_timer = ecore_timer_add(1.0, _getter_timer, NULL);
+       if (!ad->getter_timer) {
+               _D("Failed to add getter timer");
+               return false;
+       }
+
+    return true;
+}
+
+static void service_app_terminate(void *data)
+{
+       app_data *ad = (app_data *)data;
+       ecore_timer_del(ad->getter_timer);
+       model_fini();
+       free(ad);
+}
+
+static void service_app_control(app_control_h app_control, void *data)
+{
+    // Todo: add your code here.
+}
+
+static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LANGUAGE_CHANGED*/
+}
+
+static void service_app_region_changed(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_REGION_FORMAT_CHANGED*/
+}
+
+static void service_app_low_battery(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LOW_BATTERY*/
+}
+
+static void service_app_low_memory(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LOW_MEMORY*/
+}
+
+int main(int argc, char* argv[])
+{
+       app_data *ad = NULL;
+       int ret = 0;
+       service_app_lifecycle_callback_s event_callback;
+       app_event_handler_h handlers[5] = {NULL, };
+
+       ad = (app_data *)calloc(1, sizeof(app_data));
+
+       event_callback.create = service_app_create;
+       event_callback.terminate = service_app_terminate;
+       event_callback.app_control = service_app_control;
+
+       service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
+
+       ret = service_app_main(argc, argv, &event_callback, ad);
+
+       return ret;
+}
diff --git a/src/model.c b/src/model.c
new file mode 100644 (file)
index 0000000..afb7f17
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+#include "model.h"
+#include "model/model_infrared_motion_sensor.h"
+#include "model/model_infrared_obstacle_avoidance_sensor.h"
+
+struct _model_s {
+       sensor_type_e sensor_type;
+};
+static struct _model_s model_s;
+
+void model_fini(void)
+{
+       switch (model_s.sensor_type) {
+       case SENSOR_TYPE_ULTRASONIC:
+               break;
+       case SENSOR_TYPE_INFRARED_MOTION:
+               model_fini_infrared_motion_sensor();
+               break;
+       case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
+               model_fini_infrared_obstacle_avoidance_sensor();
+               break;
+       default:
+               break;
+       }
+}
+
+int model_init(sensor_type_e sensor_type)
+{
+       int ret = 0;
+       model_s.sensor_type = sensor_type;
+
+       switch (sensor_type) {
+       case SENSOR_TYPE_ULTRASONIC:
+               break;
+       case SENSOR_TYPE_INFRARED_MOTION:
+               ret = model_init_infrared_motion_sensor();
+               break;
+       case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
+               ret = model_init_infrared_obstacle_avoidance_sensor();
+               break;
+       default:
+               break;
+       }
+
+       goto_if(ret != 0, error);
+
+       return 0;
+
+error:
+       model_fini();
+       return -1;
+}
+
+int model_alloc(void **data)
+{
+       switch (model_s.sensor_type) {
+       case SENSOR_TYPE_ULTRASONIC:
+               break;
+       case SENSOR_TYPE_INFRARED_MOTION:
+       case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
+               _E("No function for allocation");
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+int model_read_int_value(int *out_value)
+{
+       int ret = 0;
+
+       switch (model_s.sensor_type) {
+       case SENSOR_TYPE_ULTRASONIC:
+               ret = model_read_infrared_obstacle_avoidance_sensor(out_value);
+               break;
+       case SENSOR_TYPE_INFRARED_MOTION:
+               ret = model_read_infrared_motion_sensor(out_value);
+               break;
+       default:
+               break;
+       }
+
+       if (ret < 0) {
+               _E("Something wrong in the result[%d]", ret);
+               return -1;
+       }
+
+       return 0;
+}
+
+int model_write(void *data)
+{
+       switch (model_s.sensor_type) {
+       case SENSOR_TYPE_ULTRASONIC:
+       case SENSOR_TYPE_INFRARED_MOTION:
+               _E("No function for writing");
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
diff --git a/src/model/model_infrared_motion_sensor.c b/src/model/model_infrared_motion_sensor.c
new file mode 100644 (file)
index 0000000..3236792
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+#include "model/model_infrared_motion_sensor.h"
+
+#define GPIO_NUM 4
+
+struct model_infrared_motion_sensor {
+       peripheral_gpio_h gpio;
+};
+static struct model_infrared_motion_sensor model_infrared_motion_sensor_s;
+
+void model_fini_infrared_motion_sensor(void)
+{
+       _I("Infrared Motion Sensor is finishing...");
+
+       if (model_infrared_motion_sensor_s.gpio)
+               peripheral_gpio_close(model_infrared_motion_sensor_s.gpio);
+}
+
+int model_init_infrared_motion_sensor(void)
+{
+       int ret = 0;
+
+       _I("Infrared Motion Sensor is initializing...");
+
+       /* GPIO for Ultrasonic Sensor's Transmit */
+       ret = peripheral_gpio_open(GPIO_NUM, &model_infrared_motion_sensor_s.gpio);
+       retv_if(ret != 0, -1);
+       retv_if(!model_infrared_motion_sensor_s.gpio, -1);
+
+       ret = peripheral_gpio_set_direction(model_infrared_motion_sensor_s.gpio, PERIPHERAL_GPIO_DIRECTION_IN);
+       goto_if(ret != 0, error);
+
+       return 0;
+
+error:
+       model_fini_infrared_motion_sensor();
+       return -1;
+}
+
+int model_read_infrared_motion_sensor(int *out_value)
+{
+       int ret = 0;
+
+       ret = peripheral_gpio_read(model_infrared_motion_sensor_s.gpio, out_value);
+       retv_if(ret < 0, -1);
+
+       _I("Infrared Motion Sensor Value : %d", *out_value);
+
+       return 0;
+}
diff --git a/src/model/model_infrared_obstacle_avoidance_sensor.c b/src/model/model_infrared_obstacle_avoidance_sensor.c
new file mode 100644 (file)
index 0000000..c6dfde1
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+#include "model/model_infrared_obstacle_avoidance_sensor.h"
+
+#define GPIO_NUM 4
+
+struct model_infrared_obstacle_avoidance_sensor {
+       peripheral_gpio_h gpio;
+};
+static struct model_infrared_obstacle_avoidance_sensor model_infrared_obstacle_avoidance_sensor_s;
+
+void model_fini_infrared_obstacle_avoidance_sensor(void)
+{
+       _I("Infrared Motion Sensor is finishing...");
+
+       if (model_infrared_obstacle_avoidance_sensor_s.gpio)
+               peripheral_gpio_close(model_infrared_obstacle_avoidance_sensor_s.gpio);
+}
+
+int model_init_infrared_obstacle_avoidance_sensor(void)
+{
+       int ret = 0;
+
+       _I("Infrared Motion Sensor is initializing...");
+
+       /* GPIO for Ultrasonic Sensor's Transmit */
+       ret = peripheral_gpio_open(GPIO_NUM, &model_infrared_obstacle_avoidance_sensor_s.gpio);
+       retv_if(ret != 0, -1);
+       retv_if(!model_infrared_obstacle_avoidance_sensor_s.gpio, -1);
+
+       ret = peripheral_gpio_set_direction(model_infrared_obstacle_avoidance_sensor_s.gpio, PERIPHERAL_GPIO_DIRECTION_IN);
+       goto_if(ret != 0, error);
+
+       return 0;
+
+error:
+       model_fini_infrared_obstacle_avoidance_sensor();
+       return -1;
+}
+
+int model_read_infrared_obstacle_avoidance_sensor(int *out_value)
+{
+       int ret = 0;
+
+       ret = peripheral_gpio_read(model_infrared_obstacle_avoidance_sensor_s.gpio, out_value);
+       retv_if(ret < 0, -1);
+
+       _I("Infrared Motion Sensor Value : %d", *out_value);
+
+       return 0;
+}
diff --git a/src/model/model_ultrasonic_sensor.c b/src/model/model_ultrasonic_sensor.c
new file mode 100644 (file)
index 0000000..33b3b20
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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.
+ */
+
+#include <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+
+
diff --git a/tizen-manifest.xml b/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..d7b4e80
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.position-finder-server" version="1.0.0">\r
+    <profile name="mobile"/>\r
+    <service-application appid="org.tizen.position-finder-server" auto-restart="false" exec="position-finder-server" multiple="false" nodisplay="true" on-boot="false" taskmanage="false" type="capp">\r
+        <label>Illumination</label>\r
+        <icon>position_finder_server.png</icon>\r
+    </service-application>\r
+</manifest>\r