Initialized motion sensor using things SDK 88/165288/1
authorEunyoung Lee <ey928.lee@samsung.com>
Thu, 28 Dec 2017 02:15:24 +0000 (11:15 +0900)
committerEunyoung Lee <ey928.lee@samsung.com>
Thu, 28 Dec 2017 02:15:57 +0000 (11:15 +0900)
Change-Id: I899de4bbf77d5d0961e062227d0442d385ce5e0a

51 files changed:
inc/connection_manager.h [new file with mode: 0644]
inc/connectivity.h [deleted file]
inc/controller.h [deleted file]
inc/controller_util.h
inc/log.h
inc/resource.h
inc/resource/resource_co2_sensor.h [new file with mode: 0644]
inc/resource/resource_co2_sensor_internal.h [new file with mode: 0644]
inc/resource/resource_flame_sensor.h
inc/resource/resource_gas_detection_sensor.h
inc/resource/resource_illuminance_sensor.h
inc/resource/resource_infrared_motion_sensor.h
inc/resource/resource_infrared_obstacle_avoidance_sensor.h
inc/resource/resource_rain_sensor.h
inc/resource/resource_sound_detection_sensor.h
inc/resource/resource_tilt_sensor.h
inc/resource/resource_touch_sensor.h
inc/resource/resource_vibration_sensor.h
inc/resource_internal.h
inc/st_things.h [new file with mode: 0644]
inc/st_things_types.h [new file with mode: 0644]
inc/webutil.h
lib/liboicdastack.so [new file with mode: 0644]
lib/libsdkapi.so [new file with mode: 0644]
project_def.prop
res/deviceKey.pem [new file with mode: 0644]
res/device_def.json [new file with mode: 0644]
res/iotcon-test-svr-db-server.dat [deleted file]
res/pi.conf
res/privateKey.der [new file with mode: 0644]
src/connection_manager.c [new file with mode: 0644]
src/connectivity.c [deleted file]
src/controller.c
src/controller_internal.c
src/controller_util.c
src/log.c [new file with mode: 0644]
src/resource.c
src/resource/resource_co2_sensor.c [new file with mode: 0644]
src/resource/resource_flame_sensor.c
src/resource/resource_gas_detection_sensor.c
src/resource/resource_illuminance_sensor.c
src/resource/resource_infrared_motion_sensor.c
src/resource/resource_infrared_obstacle_avoidance_sensor.c
src/resource/resource_rain_sensor.c
src/resource/resource_sound_detection_sensor.c
src/resource/resource_tilt_sensor.c
src/resource/resource_touch_sensor.c
src/resource/resource_ultrasonic_sensor.c
src/resource/resource_vibration_sensor.c
src/webutil.c
tizen-manifest.xml

diff --git a/inc/connection_manager.h b/inc/connection_manager.h
new file mode 100644 (file)
index 0000000..90e5fab
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *          Jeonghoon Park <jh1979.park@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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_CONN_MGR_H__
+#define __POSITION_FINDER_CONN_MGR_H__
+
+int connection_manager_get_ip(const char **ip);
+int connection_manager_init(void);
+int connection_manager_fini(void);
+
+#endif /* __POSITION_FINDER_CONN_MGR_H__ */
+
diff --git a/inc/connectivity.h b/inc/connectivity.h
deleted file mode 100644 (file)
index f35ed6c..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: Jin Yoon <jinny.yoon@samsung.com>
- *          Geunsun Lee <gs86.lee@samsung.com>
- *          Eunyoung Lee <ey928.lee@samsung.com>
- *          Junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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_H__
-#define __POSITION_FINDER_CONNECTIVITY_H__
-
-typedef struct _connectivity_resource connectivity_resource_s;
-
-typedef enum {
-       CONNECTIVITY_PROTOCOL_DEFAULT = 0, /* default protocol */
-       CONNECTIVITY_PROTOCOL_IOTIVITY, /* IoTvity protocol */
-       CONNECTIVITY_PROTOCOL_HTTP, /* HTTP protocol */
-       CONNECTIVITY_PROTOCOL_MAX
-} connectivity_protocol_e;
-
-/**
- * @brief Set connectivity protocol to communicate with other devices.
- * @param[in] protocol_type protocol type to use
- * @return 0 on success, otherwise a negative error value
- * @see You should set protocol before call connectivity_set_resource(),
- * otherwise IoTvitiy protocol will be set as default.
- */
-extern int connectivity_set_protocol(connectivity_protocol_e protocol_type);
-
-/**
- * @brief Create connectivity 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 *path, const char *type, connectivity_resource_s **out_resource_info);
-
-/**
- * @brief Releases all resource about connectivity.
- * @param[in] resource_info A structure containing information about connectivity resource
- */
-extern void connectivity_unset_resource(connectivity_resource_s *resource);
-
-/**
- * @brief Notifies a resource's value to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be sended.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_notify_bool(connectivity_resource_s *resource_info, const char *key, bool value);
-
-/**
- * @brief Notifies a resource's value to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be sended.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_notify_int(connectivity_resource_s *resource_info, const char *key, int value);
-
-/**
- * @brief Notifies a resource's value to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be sended.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_notify_double(connectivity_resource_s *resource_info, const char *key, double value);
-
-/**
- * @brief Notifies a resource's value to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be sended.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_notify_string(connectivity_resource_s *resource_info, const char *key, const char *value);
-
-/* TODO : add comments for these functions */
-/**
- * @brief Add a boolean type value to attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be added.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_attributes_add_bool(connectivity_resource_s *resource_info, const char *key, bool value);
-
-/**
- * @brief Add a integer type value to attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be added.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_attributes_add_int(connectivity_resource_s *resource_info, const char *key, int value);
-
-/**
- * @brief Add a double type value to attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be added.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_attributes_add_double(connectivity_resource_s *resource_info, const char *key, double value);
-
-/**
- * @brief Add a string value to attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @param[in] value A value to be added.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_attributes_add_string(connectivity_resource_s *resource_info, const char *key, const char *value);
-
-/**
- * @brief Notifies values in the attributs to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @return 0 on success, otherwise a negative error value
- */
-extern int connectivity_attributes_notify_all(connectivity_resource_s *resource_info);
-
-/**
- * @brief Remove a value from attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A key to be sended.
- * @return 0 on success, otherwise a negative error value
- * @see If key is already exists, current value will be replaced with new value.
- */
-extern int connectivity_attributes_remove_value_by_key(connectivity_resource_s *resource_info, const char *key);
-
-/**
- * @brief Remove all values from attributes for notifying to observed devices or clouds.
- * @param[in] resource_info A structure containing information about connectivity resource
- * @return 0 on success, otherwise a negative error value
- */
-extern int connectivity_attributes_remove_all(connectivity_resource_s *resource_info);
-
-#endif /* __POSITION_FINDER_CONNECTIVITY_H__ */
diff --git a/inc/controller.h b/inc/controller.h
deleted file mode 100644 (file)
index 890735b..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: Jin Yoon <jinny.yoon@samsung.com>
- *          Geunsun Lee <gs86.lee@samsung.com>
- *          Eunyoung Lee <ey928.lee@samsung.com>
- *          Junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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__
-
-#include "controller_internal.h"
-
-#endif /* __POSITION_FINDER_CONTROLLER_H__ */
index 29b5e462bceec9c8d3370fc635ed15f8260ad678..9b3e0ba24721672a376cc5f9a49da5276cefbe19 100644 (file)
@@ -24,6 +24,7 @@
 
 int controller_util_get_path(const char **path);
 int controller_util_get_address(const char **address);
+int controller_util_get_log_type(int *type);
 void controller_util_free(void);
 
 #endif /* __POSITION_FINDER_CONTROLLER_UTIL_H__ */
index 27579b50da02264d61df109c955e515fce1c1e40..8fa151ccb44aa650cfb539282cd94d0ebd8ce42a 100644 (file)
--- a/inc/log.h
+++ b/inc/log.h
@@ -19,8 +19,8 @@
  * limitations under the License.
  */
 
-#ifndef __POSITION_FINDER_SERVER_H__
-#define __POSITION_FINDER_SERVER_H__
+#ifndef __POSITION_FINDER_SERVER_LOG_H__
+#define __POSITION_FINDER_SERVER_LOG_H__
 
 #include <dlog.h>
 
@@ -46,7 +46,7 @@
 #endif
 
 #define retvm_if(expr, val, fmt, arg...) do { \
-       if(expr) { \
+       if (expr) { \
                _E(fmt, ##arg); \
                _E("(%s) -> %s() return", #expr, __FUNCTION__); \
                return val; \
 } while (0)
 
 #define retv_if(expr, val) do { \
-       if(expr) { \
+       if (expr) { \
                _E("(%s) -> %s() return", #expr, __FUNCTION__); \
                return (val); \
        } \
 } while (0)
 
 #define retm_if(expr, fmt, arg...) do { \
-       if(expr) { \
+       if (expr) { \
                _E(fmt, ##arg); \
                _E("(%s) -> %s() return", #expr, __FUNCTION__); \
                return; \
 } while (0)
 
 #define ret_if(expr) do { \
-       if(expr) { \
+       if (expr) { \
                _E("(%s) -> %s() return", #expr, __FUNCTION__); \
                return; \
        } \
 } while (0)
 
 #define goto_if(expr, val) do { \
-       if(expr) { \
+       if (expr) { \
                _E("(%s) -> goto", #expr); \
                goto val; \
        } \
 } while (0)
 
 #define break_if(expr) { \
-       if(expr) { \
+       if (expr) { \
                _E("(%s) -> break", #expr); \
                break; \
        } \
 }
 
 #define continue_if(expr) { \
-       if(expr) { \
+       if (expr) { \
                _E("(%s) -> continue", #expr); \
                continue; \
        } \
 }
 
+typedef enum {
+       LOG_TYPE_DLOG = 0,
+       LOG_TYPE_FILE,
+       LOG_TYPE_ALL,
+} log_type;
 
+int log_print(log_priority prio, const char *tag, const char *fmt, ...);
+int log_type_set(log_type type);
+void log_file_close(void);
 
-#endif /* __POSITION_FINDER_SERVER_H__ */
+#endif /* __POSITION_FINDER_SERVER_LOG_H__ */
index 783fd8fa1e9d5dd87a0ee8467050e83e8bed0ce1..6a37fb117e5e6cce6db9fa8b29e2ec1ad24a1372 100644 (file)
@@ -38,5 +38,6 @@
 #include "resource/resource_tilt_sensor.h"
 #include "resource/resource_gas_detection_sensor.h"
 #include "resource/resource_sound_level_sensor.h"
+#include "resource/resource_co2_sensor.h"
 
 #endif /* __POSITION_FINDER_RESOURCE_H__ */
diff --git a/inc/resource/resource_co2_sensor.h b/inc/resource/resource_co2_sensor.h
new file mode 100644 (file)
index 0000000..981789b
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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_RESOURCE_CO2_SENSOR_H__
+#define __POSITION_FINDER_RESOURCE_CO2_SENSOR_H__
+
+ /**
+  * @brief Reads the value from co2 sensor through AD converter(MCP3008).
+  * @param[in] ch_num The number of channel connected to the co2 detection sensor with AD converter
+  * @param[out] out_value The vaule of a co2 level
+  * @return 0 on success, otherwise a negative error value
+  *
+  */
+extern int resource_read_co2_sensor(int ch_num, unsigned int *out_value);
+
+#endif /* __POSITION_FINDER_RESOURCE_CO2_SENSOR_H__ */
+
diff --git a/inc/resource/resource_co2_sensor_internal.h b/inc/resource/resource_co2_sensor_internal.h
new file mode 100644 (file)
index 0000000..5b97669
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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_RESOURCE_CO2_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_CO2_SENSOR_INTERNAL_H__
+
+extern void resource_close_co2_sensor(void);
+
+#endif /* __POSITION_FINDER_RESOURCE_CO2_SENSOR_INTERNAL_H__ */
index f7510a5c1a166c13c3722f1878969e2be7218fa8..2729dd8fd9b8914375449f135a6679468a32a0ff 100644 (file)
@@ -30,6 +30,6 @@
  *
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_flame_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_flame_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_FLAME_SENSOR_H__ */
index 8aead54c6e47b14bbc3b2c738ece04c3a551cd8b..729cda839201a3a51d038251f07daebc87ce8063 100644 (file)
@@ -29,6 +29,6 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_gas_detection_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_GAS_DETECTION_SENSOR_H__ */
index b22b1ccf7c0a0aece6fc0688d3d35e0995e703b5..93de8b27877e3b977ae2aeb1e53dccfd3bc98506 100644 (file)
@@ -29,7 +29,7 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the i2c bus is not open, creates i2c handle before reading data from the i2c slave device.
  */
-extern int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value);
+extern int resource_read_illuminance_sensor(int i2c_bus, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */
 
index 65bdda73f268dc67371ef034a860304ce58c78ee..a1b29677649f8b549b8e23058b4cde66863d532f 100644 (file)
@@ -29,6 +29,6 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_infrared_motion_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */
index 549b13505956133564c5153ee21be701a324a7db..1f72e9a773054be27c0f8dbe9a94bd361d08ea58 100644 (file)
@@ -29,6 +29,6 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
index 162b4a228091545cd5d9eec6f1d15a0cff53435e..665a45eb580f67301baff50a962434d884143bfe 100644 (file)
@@ -30,6 +30,6 @@
  *
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_rain_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_rain_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_RAIN_SENSOR_H__ */
index 391ee75f842bb629ae0d23aa9d875ddc55b215eb..094d1cfb48df16961b1c37faa0160ff2430a34d1 100644 (file)
@@ -30,6 +30,6 @@
  *
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_sound_detection_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_sound_detection_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_SOUND_DETECTION_SENSOR_H__ */
index a90d07d6d77406eae2dc0aed72323d9ddcc56565..aa51661704680cd819eb99e7a60e4ec480da643d 100644 (file)
@@ -30,6 +30,6 @@
  *
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_tilt_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_tilt_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_TILT_SENSOR_H__ */
index a28df3f3c42908c317eda1fbde9cd99ff3dfb304..be47b48a519ca3bf75941daff70fb91a73846805 100644 (file)
@@ -29,6 +29,6 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_touch_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_touch_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */
index 042298a2737c15fa5ca35de37fe9a080adbe0910..210a22b2cc3460756fa263a45cf408272d0f931a 100644 (file)
@@ -29,6 +29,6 @@
  * @return 0 on success, otherwise a negative error value
  * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
  */
-extern int resource_read_vibration_sensor(int pin_num, uint32_t *out_value);
+extern int resource_read_vibration_sensor(int pin_num, unsigned int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_VIBRATION_SENSOR_H__ */
index ffc6f6059475c6477cd6f336f3dee4b04dcbed7c..b1dea9cc871794276f1773fa69f4b25a8e3ca12f 100644 (file)
@@ -38,6 +38,7 @@
 #include "resource/resource_tilt_sensor_internal.h"
 #include "resource/resource_gas_detection_sensor_internal.h"
 #include "resource/resource_sound_level_sensor_internal.h"
+#include "resource/resource_co2_sensor_internal.h"
 
 #define PIN_MAX 40
 
diff --git a/inc/st_things.h b/inc/st_things.h
new file mode 100644 (file)
index 0000000..83669e3
--- /dev/null
@@ -0,0 +1,264 @@
+/* ****************************************************************
+ *
+ * Copyright 2017 Samsung Electronics 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.
+ *
+ ******************************************************************/
+
+#ifndef __ST_THINGS_H__
+#define __ST_THINGS_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "st_things_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @brief Initializes things stack and returns whether easy-setup is completed or not.
+ *            Easy-setup enable users to acquire the ownership of things and to connect the things with the cloud.
+ *            After performing easy-setup, users can access things from anywhere through the cloud.
+ *            In things stack, easy-setup is a primary and the first operation to be performed on the thing.
+ *            Application running on the thing can know whether easy-setup is done already or not.
+ *            If easy-setup is done, app can start the things stack by calling st_things_start().
+ *            If easy-setup is not done, app can either wait for the user interaction before starting the things stack or
+ *            start the things stack directly without waiting for any events(This case is for those things which doesn't
+ *            support input capability and for all other unknown cases).
+ * @param[in] json_path Path to Json file which defines a thing. Definition includes the device information,
+ *                                       resources and their properties, configuration info for connectivity and easy-setup, etc.
+ * @param[out] easysetup_complete Indicates whether easysetup is completed already or not.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_initialize(const char* json_path, bool* easysetup_complete);
+
+/**
+ * @brief Deinitializes things stack.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_deinitialize(void);
+
+/**
+ * @brief Callback for handling GET request.
+ * @param[in]  req_msg GET request message.
+ * @param[out] resp_rep Representation that will be set to payload of response.
+ * @return @c true in case of success, otherwise @c false
+ */
+typedef bool (*st_things_get_request_cb) (st_things_get_request_message_s* req_msg,
+                                          st_things_representation_s* resp_rep);
+
+/**
+ * @brief Callback for handling SET(POST) request.
+ * @param[in]  req_msg SET request message.
+ * @param[out] resp_rep Representation that will be set to payload of response.
+ * @return @c true in case of success, otherwise @c false
+ */
+typedef bool (*st_things_set_request_cb) (st_things_set_request_message_s* req_msg,
+                                          st_things_representation_s* resp_rep);
+
+/**
+ * @brief Callback registration function for handling request messages.
+ * @details The callbacks ensure that a request message will be carried with one of the resource uris from json file of st_things_start().
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] get_cb Reference of the callback function to handle GET request.
+ * @param[in] set_cb Reference of the callback function to handle SET(POST) request.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_request_cb(st_things_get_request_cb get_cb,
+                                  st_things_set_request_cb set_cb);
+
+/**
+ * @brief Starts things stack.
+ *            Parses the thing definition(whose path is passed to st_things_initialize(), configures the thing,
+ *            creates the resources and prepares it for easy-setup.
+ *            If easy-setup is not done yet, onboarding will be started using either SoftAP or BLE connection.
+ *                Onboarding creates an ad-hoc network between the thing and the client for performing easy-setup.
+ *            If easy-setup is already done, thing will be connected with the cloud.
+ *            Application can know whether easy-setup is done or not through st_things_initialize API.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_start(void);
+
+/**
+ * @brief Stops things stack.
+ *            Removes all the data being used internally and releases all the memory allocated for the stack.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_stop(void);
+
+/**
+ * @brief Callback for getting user's opinion regarding device reset.
+ * @return @c true to confirm, otherwise @c to deny
+ */
+typedef bool (*st_things_reset_confirm_cb) (void);
+
+/**
+ * @brief Callback for carrying the result of reset.
+ * @param[in] is_success Result of Stack-reset. (true : success, false : failure)
+ */
+typedef void (*st_things_reset_result_cb) (bool is_success);
+
+/**
+ * @brief Callback registration function for Reset-Confirmation and Reset-Result functions.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+            And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] confirm_cb Callback function that will be called to get the user's input when reset is triggered.
+ * @param[in] result_cb Callback function that will be called after the reset process is done.
+ *                      This parameter can be NULL if notification for result of reset is not needed.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_reset_cb(st_things_reset_confirm_cb confirm_cb,
+                                st_things_reset_result_cb  result_cb);
+
+/**
+ * @brief Reset all the data related to security and cloud being used in the stack.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_reset(void);
+
+/**
+ * @brief Callback for carrying the randomly generated PIN info.
+ * @details Device should show the PIN on display.
+ * @param[in] pin_data PIN data in string format.
+ * @param[in] pin_size Length of the PIN String.
+ */
+typedef void (*st_things_pin_generated_cb) (const char* pin_data, const size_t pin_size);
+
+/**
+ * @brief Callback for informing the application to close the PIN display.
+ */
+typedef void (*st_things_pin_display_close_cb) (void);
+
+/**
+ * @brief Callback registration function for getting randomly generated PIN for the PIN-Based Ownership Transfer Request.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] generated_cb Callback function that will be called when device receives a Ownership Transfer request from client.
+ * @param[in] close_cb Callback function that will be called when Ownership Transfer is done so device can stop showing PIN on display.
+ *                     This parameter can be NULL if stop triggering is not needed.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_pin_handling_cb(st_things_pin_generated_cb     generated_cb,
+                                       st_things_pin_display_close_cb close_cb);
+
+/**
+ * @brief Callback for getting user's input regarding mutual verification.
+ * @return @c true true in cse of confirmed, otherwise @c false
+ */
+typedef bool (*st_things_user_confirm_cb) (void);
+
+/**
+ * @brief Callback registration function for getting user confirmation for MUTUAL VERIFICATION BASED JUST WORK Ownership transfer.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] confirm_cb Callback function that will be called when device receives a confirm request from client.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_user_confirm_cb(st_things_user_confirm_cb confirm_cb);
+
+/**
+ * @brief Callback for getting the current state of ST Things.
+ * @param[in]  things_status ST Things State
+ */
+typedef void (*st_things_status_change_cb) (st_things_status_e things_status);
+
+/**
+ * @brief Callback registration function for getting notified when ST Things state changes.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] status_cb Refernce of the callback function to get ST Things status
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_things_status_change_cb(st_things_status_change_cb status_cb);
+
+/**
+ * @brief Notify the observers of a specific resource.
+ * @param[in]  resource_uri Resource URI of the resource which will be notified to observers.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_notify_observers(const char* resource_uri);
+
+/**
+ * @brief Send Representation of a specific resource through push service to Samsung Connect client.
+ * @param[in]  resource_uri Resource uri for which we want to send push message.
+ * @param[in]  rep Representation for resource uri.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_send_push_message(const char* resource_uri, st_things_representation_s* rep);
+
+/**
+ * @brief Create an instance of representation.
+ * @remarks To destroy an instance, st_things_destroy_representation_inst() should be used.
+ * @return a pointer of the created representation, otherwise a null pointer if the memory is insufficient.
+ */
+st_things_representation_s* st_things_create_representation_inst(void);
+
+/**
+ * @brief Destroy an instance of representation.
+ * @param[in]  rep Representation that will be destroyed.
+ */
+void st_things_destroy_representation_inst(st_things_representation_s* rep);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __ST_THINGS_H__ */
diff --git a/inc/st_things_types.h b/inc/st_things_types.h
new file mode 100644 (file)
index 0000000..b5f4671
--- /dev/null
@@ -0,0 +1,317 @@
+/* ****************************************************************
+ *
+ * Copyright 2017 Samsung Electronics 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.
+ *
+ ******************************************************************/
+
+#ifndef __ST_THINGS_TYPES_H__
+#define __ST_THINGS_TYPES_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+/**
+ * @brief Enumeration for ST Things error code.
+ */
+typedef enum {
+    ST_THINGS_ERROR_NONE                =  0, /**< Successful */
+    ST_THINGS_ERROR_INVALID_PARAMETER   = -1, /**< Invalid parameter (If parameter is null or empty)*/
+    ST_THINGS_ERROR_OPERATION_FAILED    = -2, /**< Operation Failed */
+} st_things_error_e;
+
+/**
+ * @brief Enumeration for ST Things status.
+ */
+typedef enum {
+    ST_THINGS_STATUS_INIT = 0,                         /**< Initial state of ST Things */
+    ST_THINGS_STATUS_ES_STARTED,                       /**< Easy-setup is started */
+    ST_THINGS_STATUS_ES_DONE,                          /**< Easy-setup is done */
+    ST_THINGS_STATUS_ES_FAILED_ON_OWNERSHIP_TRANSFER,  /**< Easy-setup failed due to Ownership-Transfer failure */
+    ST_THINGS_STATUS_CONNECTING_TO_AP,                 /**< Connecting to target Wi-Fi access point */
+    ST_THINGS_STATUS_CONNECTED_TO_AP,                  /**< Connected to target Wi-Fi access point */
+    ST_THINGS_STATUS_CONNECTING_TO_AP_FAILED,          /**< Failed to connect to target Wi-Fi access point */
+    ST_THINGS_STATUS_REGISTERING_TO_CLOUD,             /**< Trying to Sign-up/Sign-in/Publish-Resource(s) to Cloud */
+    ST_THINGS_STATUS_REGISTERED_TO_CLOUD,              /**< Publish resource(s) to cloud is complete. Now the Thing is ready to be controlled via Cloud */
+    ST_THINGS_STATUS_REGISTERING_FAILED_ON_SIGN_IN,    /**< Failed to sign-in to Cloud */
+    ST_THINGS_STATUS_REGISTERING_FAILED_ON_PUB_RES     /**< Failed to publish resources to Cloud */
+} st_things_status_e;
+
+/**
+ * @brief Structure for Representation.
+ */
+typedef struct _st_things_representation
+{
+    void*   payload; /**< Payload of representation */
+
+    /**
+     * @brief API for getting the value of string type property with a key.
+     * @remarks This API will return deep-copied string value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value String value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_str_value)            (struct _st_things_representation* rep, const char* key, char** value);
+
+    /**
+     * @brief API for getting the value of boolean type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Bool value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_bool_value)           (struct _st_things_representation* rep, const char* key, bool* value);
+
+    /**
+     * @brief API for getting the value of integer type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Integer value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_int_value)            (struct _st_things_representation* rep, const char* key, int64_t* value);
+
+    /**
+     * @brief API for getting the value of double type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Double value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_double_value)         (struct _st_things_representation* rep, const char* key, double* value);
+
+    /**
+     * @brief API for getting the value of byte array type property with a key.
+     * @remarks This API will return deep-copied byte value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Byte value
+     * @param[out] size Size of Byte value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_byte_value)           (struct _st_things_representation* rep, const char* key, uint8_t** value, size_t* size);
+
+    /**
+     * @brief API for getting the value of object type property with a key.
+     * @remarks This API will return deep-copied object value as out parameter, so application must free it after use.\n
+     *          To free an object, st_things_destroy_representation_inst() in st_things.h should be used.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Object value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_object_value)         (struct _st_things_representation* rep, const char* key, struct _st_things_representation** value);
+
+    /**
+     * @brief API for setting the value of string type property with a key.
+     * @remarks This API will deep-copy the string value inside, so application still has an ownership of memory for the string value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value String value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_str_value)            (struct _st_things_representation* rep, const char* key, const char* value);
+
+    /**
+     * @brief API for setting the value of boolean type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Bool value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_bool_value)           (struct _st_things_representation* rep, const char* key, bool value);
+
+    /**
+     * @brief API for setting the value of integer type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Integer value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_int_value)            (struct _st_things_representation* rep, const char* key, int64_t value);
+
+    /**
+     * @brief API for setting the value of double type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Double value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_double_value)         (struct _st_things_representation* rep, const char* key, double value);
+
+    /**
+     * @brief API for setting the value of byte array type property with a key.
+     * @remarks This API will deep-copy the byte value inside, so application still has an ownership of memory for the byte value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Byte value.
+     * @param[in]  size Size of Byte value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_byte_value)           (struct _st_things_representation* rep, const char* key, const uint8_t* value, size_t size);
+
+    /**
+     * @brief API for setting the value of object type property with a key.
+     * @remarks This API will deep-copy the object value inside, so application still has an ownership of memory for the object value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Object value.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*set_object_value)         (struct _st_things_representation* rep, const char* key, const struct _st_things_representation* value);
+
+    /**
+     * @brief API for getting the value of string array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the string array to where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_str_array_value)      (struct _st_things_representation* rep, const char* key, char*** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of integer array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the integer array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_int_array_value)      (struct _st_things_representation* rep, const char* key, int64_t** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of double array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the double array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_double_array_value)   (struct _st_things_representation* rep, const char* key, double** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of object array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.\n
+     *          To free each object in array, st_things_destroy_representation_inst() in st_things.h should be used.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the array type of value.
+     * @param[out] array Reference of the object array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_object_array_value)   (struct _st_things_representation* rep, const char* key, struct _st_things_representation*** array, size_t* length);
+
+    /**
+     * @brief API for setting the value of string array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array String array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_str_array_value)      (struct _st_things_representation* rep, const char* key, const char** array, size_t length);
+
+    /**
+     * @brief API for setting the value of integer array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Integer array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_int_array_value)      (struct _st_things_representation* rep, const char* key, const int64_t* array, size_t length);
+
+    /**
+     * @brief API for setting the value of double array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Double array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_double_array_value)   (struct _st_things_representation* rep, const char* key, const double* array, size_t length);
+
+    /**
+     * @brief API for setting the value of object array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Object array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_object_array_value)   (struct _st_things_representation* rep, const char* key, const struct _st_things_representation** array, size_t length);
+
+} st_things_representation_s;
+
+/**
+ * @brief Structure for representing the Get Request Message.
+ */
+typedef struct _st_things_get_request_message
+{
+    char*                               resource_uri;   /**< Resource URI */
+    char*                               query;          /**< One or more query parameters of the request message. Ex: key1=value1;key2=value2;... */
+    char*                               property_key;   /**< One or more property key that application needs to set a value for response. Ex: key1;key2;... */
+
+    /**
+     * @brief API for getting the value of a specific query from the query parameters of the request.
+     * @param[in]  req_msg Instance of get request message.
+     * @param[in]  key Name of the query.(ex: key1, key2, etc)
+     * @param[out] value Value of the query.(value1, value2, etc)
+     * @return @c true if query exist, otherwise @c false
+     */
+    bool    (*get_query_value)          (struct _st_things_get_request_message* req_msg, const char* key, char** value);
+
+    /**
+     * @brief API for checking whether the request has a specific property key or not.
+     * @param[in]  req_msg Instance of get request message.
+     * @param[in]  key Name of the property.
+     * @return @c true if the property key exists, otherwise @c false
+     */
+    bool    (*has_property_key)         (struct _st_things_get_request_message* req_msg, const char* key);
+
+} st_things_get_request_message_s;
+
+/**
+ * @brief Structure for representing the Set Request Message.
+ */
+typedef struct _st_things_set_request_message
+{
+    char*                               resource_uri;   /**< Resource URI */
+    char*                               query;          /**< One or more query parameters of the request message. Ex: key1=value1?key2=value2?... */
+    struct _st_things_representation*   rep;            /**< Representation of the set request message */
+
+    /**
+     * @brief API for getting the value of a specific query from the query parameters of the request.
+     * @param[in]  req_msg Instance of request message.
+     * @param[in]  key Name of the query.(ex: key1, key2, etc)
+     * @param[out] value Value of the query.(value1, value2, etc)
+     * @return @c true if query exist, otherwise @c false
+     */
+    bool    (*get_query_value)          (struct _st_things_set_request_message* req_msg, const char* key, char** value);
+
+} st_things_set_request_message_s;
+
+#endif /* __ST_THINGS_TYPES_H__ */
index 0a78fdbdf160a2774b612517be34b0e354459320..3ea47dc6723ba0622a6dbd15cef628652cc340ca 100644 (file)
@@ -61,12 +61,15 @@ struct _web_util_sensor_data_s {
        int touch;
        int gas;
        web_util_sensor_type_e enabled_sensor;
-       char *hash;
+       const char *hash;
+       const char *ip_addr;
 };
 
 int web_util_noti_init(void);
 void web_util_noti_fini(void);
 int web_util_noti_post(const char *resource, const char *json_data);
+
+/* A newly allocated string is assigned to @res, which ought to be freed after use*/
 int web_util_noti_get(const char *resource, char **res);
 
 int web_util_json_init(void);
@@ -80,6 +83,8 @@ int web_util_json_add_double(const char* key, double value);
 int web_util_json_add_boolean(const char* key, bool value);
 int web_util_json_add_string(const char* key, const char *value);
 int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s *sensor_data);
+
+/* The returned string is a newly allocated string which ought to be freed after use*/
 char *web_util_get_json_string(void);
 
 #endif /* __POSITION_FINDER_WEBUTIL_H__ */
diff --git a/lib/liboicdastack.so b/lib/liboicdastack.so
new file mode 100644 (file)
index 0000000..4f2e05e
Binary files /dev/null and b/lib/liboicdastack.so differ
diff --git a/lib/libsdkapi.so b/lib/libsdkapi.so
new file mode 100644 (file)
index 0000000..14838f1
Binary files /dev/null and b/lib/libsdkapi.so differ
index 9826857d64fdb2c40a10f2baf8b509d4160a886c..e3f12db9d8f37c863e5e35f53c4dbd53820f6ff4 100644 (file)
@@ -5,7 +5,7 @@ profile = iot-headless-4.0
 
 USER_SRCS = src/position-finder-server.c
 USER_DEFS =
-USER_INC_DIRS = inc
+USER_INC_DIRS = inc, inc/sdk
 USER_OBJS =
-USER_LIBS =
+USER_LIBS = lib/liboicdastack.so, lib/libsdkapi.so
 USER_EDCS =
diff --git a/res/deviceKey.pem b/res/deviceKey.pem
new file mode 100644 (file)
index 0000000..08cc6a2
--- /dev/null
@@ -0,0 +1,33 @@
+-----BEGIN CERTIFICATE-----\r
+MIICzDCCAnGgAwIBAgIUREVWM1AwMTE1MTM3Njg5NTE1ODMwCgYIKoZIzj0EAwIw\r
+fTE4MDYGA1UEAwwvU2Ftc3VuZyBFbGVjdHJvbmljcyBPQ0YgRGV2ZWxvcGVyIFN1\r
+YkNBIHYzIFRFU1QxFjAUBgNVBAsMDU9DRiBEZXYgU3ViQ0ExHDAaBgNVBAoME1Nh\r
+bXN1bmcgRWxlY3Ryb25pY3MxCzAJBgNVBAYTAktSMB4XDTE3MTIyMDExMjIzMVoX\r
+DTE4MDIxODExMjIzMVowgbQxaDBmBgNVBAMMX0RldmVsb3BlciBEZXZpY2UgVEVT\r
+VDogVGVtcGxhdGVfMDEgKDE5Yzk5ZmFhLTk4NDAtNGVjNy05MTdiLTc0NTkyNzFi\r
+NDNkZCkvbGVlLnR0LnRlc3RAZ21haWwuY29tMR0wGwYDVQQLDBRPQ0YgRGV2IERl\r
+dmljZShmQTYyKTEcMBoGA1UECgwTU2Ftc3VuZyBFbGVjdHJvbmljczELMAkGA1UE\r
+BhMCS1IwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ71EoYetdfyodWyS5EYrh5\r
+7RE1/gE1I8BTnJG8CDFUnatYH/cnWLxApmKQPTz+coGnH7k3E7FV+aJ9yYWgwWcz\r
+o4GWMIGTMAsGA1UdDwQEAwIDyDA8BggrBgEFBQcBAQQwMC4wLAYIKwYBBQUHMAGG\r
+IGh0dHA6Ly9vY3NwLXRlc3Quc2Ftc3VuZ2lvdHMuY29tMDsGA1UdHwQ0MDIwMKAu\r
+oCyGKmh0dHA6Ly9jcmwtdGVzdC5zYW1zdW5naW90cy5jb20vZGV2M2NhLmNybDAJ\r
+BgNVHRMEAjAAMAoGCCqGSM49BAMCA0kAMEYCIQDyIJCN4fsw5SJZr99RRddzLukS\r
+/gTz7siLXJrJ7zR+vwIhAINthOh6GQPw21fM+fcY1v10wsAq3fX4ZXhSxnUJPY/X\r
+-----END CERTIFICATE-----\r
+-----BEGIN CERTIFICATE-----
+MIIClDCCAjmgAwIBAgITCBdmNie8mlu4WgGqOB3KClKsjzAMBggqhkjOPQQDAgUA
+MHAxLTArBgNVBAMTJFNhbXN1bmcgRWxlY3Ryb25pY3MgT0NGIFJvb3QgQ0EgVEVT
+VDEUMBIGA1UECxMLT0NGIFJvb3QgQ0ExHDAaBgNVBAoTE1NhbXN1bmcgRWxlY3Ry
+b25pY3MxCzAJBgNVBAYTAktSMCAXDTE3MTAxMDEwMjY0NloYDzIwNjkxMjMxMTQ1
+OTU5WjB9MTgwNgYDVQQDEy9TYW1zdW5nIEVsZWN0cm9uaWNzIE9DRiBEZXZlbG9w
+ZXIgU3ViQ0EgdjMgVEVTVDEWMBQGA1UECxMNT0NGIERldiBTdWJDQTEcMBoGA1UE
+ChMTU2Ftc3VuZyBFbGVjdHJvbmljczELMAkGA1UEBhMCS1IwWTATBgcqhkjOPQIB
+BggqhkjOPQMBBwNCAASaLdjStXbZ6UcF7TFXDqratJxficMlBt8ec46MYQEocqZw
+cIAh6UP8mpDMlOs1cUxatCoEDrGUNOZyFuNpztqfo4GgMIGdMA4GA1UdDwEB/wQE
+AwIBBjA5BgNVHR8EMjAwMC6gLKAqhihodHRwOi8vY3JsLXRlc3Quc2Ftc3VuZ2lv
+dHMuY29tL3Jvb3QuY3JsMBIGA1UdEwEB/wQIMAYBAf8CAQAwPAYIKwYBBQUHAQEE
+MDAuMCwGCCsGAQUFBzABhiBodHRwOi8vb2NzcC10ZXN0LnNhbXN1bmdpb3RzLmNv
+bTAMBggqhkjOPQQDAgUAA0cAMEQCIDAcuxI2o3RATk1JOGCmNmAqwPNLJxXzq1LA
+GPqAP+fnAiBbrlkNBbmWk3q3nLO+0yJP1jd+uh5a7gd8/WF6t5osGA==
+-----END CERTIFICATE-----
diff --git a/res/device_def.json b/res/device_def.json
new file mode 100644 (file)
index 0000000..1d45388
--- /dev/null
@@ -0,0 +1,76 @@
+{
+  "device": [
+    {
+      "specification": {
+        "device": {
+          "deviceType": "oic.d.motion",
+          "deviceName": "Motion",
+          "specVersion": "core.1.1.0",
+          "dataModelVersion": "res.1.1.0"
+        },
+        "platform": {
+          "manufacturerName": "fA62",
+          "manufacturerUrl": "http://www.samsung.com",
+          "manufacturingDate": "2017-09-20",
+          "modelNumber": "NA-01",
+          "platformVersion": "1.0",
+          "osVersion": "1.0",
+          "hardwareVersion": "1.0",
+          "firmwareVersion": "1.0",
+          "vendorId": "TT_02"
+        }
+      },
+      "resources": {
+        "single": [
+          {
+            "uri": "/capability/motionSensor/main/0",
+            "types": [
+              "oic.r.sensor.motion"
+            ],
+            "interfaces": [
+              "oic.if.r"
+            ],
+            "policy": 3
+          }
+        ]
+      }
+    }
+  ],
+  "resourceTypes": [
+    {
+      "type": "oic.r.sensor.motion",
+      "properties": [
+        {
+          "key": "value",
+          "type": 0,
+          "type_desc": "bool",
+          "mandatory": false,
+          "rw": 1
+        }
+      ]
+    }
+  ],
+  "configuration": {
+    "easySetup": {
+      "connectivity": {
+        "type": 1,
+        "softAP": {
+          "manufacturerId": "fA62",
+          "setupId":"001",
+          "artik":false
+        }
+      },
+      "ownershipTransferMethod": 2
+    },
+    "wifi": {
+      "interfaces": 31,
+      "frequency": 1
+    },
+    "filePath": {
+      "svrdb": "/opt/usr/home/owner/apps_rw/org.tizen.position-finder-server/data/svr_db_server.dat",
+      "provisioning": "/opt/usr/home/owner/apps_rw/org.tizen.position-finder-server/data/provisioning.json",
+      "certificate": "/opt/usr/home/owner/apps_rw/org.tizen.position-finder-server/res/deviceKey.pem",
+      "privateKey": "/opt/usr/home/owner/apps_rw/org.tizen.position-finder-server/res/privateKey.der"
+    }
+  }
+}
diff --git a/res/iotcon-test-svr-db-server.dat b/res/iotcon-test-svr-db-server.dat
deleted file mode 100644 (file)
index d508b68..0000000
Binary files a/res/iotcon-test-svr-db-server.dat and /dev/null differ
index b55530e8a33bc8c9c438b5cfe4c73968b3e42eb2..53850ab3947caa89c71afcdd2cd08a26ed6364a7 100644 (file)
@@ -1,3 +1,4 @@
 [default]
 path=/door/1
 address=http://showiot.xyz/api/tt/data
+log_type=0
diff --git a/res/privateKey.der b/res/privateKey.der
new file mode 100644 (file)
index 0000000..74e6353
Binary files /dev/null and b/res/privateKey.der differ
diff --git a/src/connection_manager.c b/src/connection_manager.c
new file mode 100644 (file)
index 0000000..ef5fd7e
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+ /*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *          Jeonghoon Park <jh1979.park@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <net_connection.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "log.h"
+
+struct conn_mgr_s {
+       connection_h connection;
+       connection_type_e net_state;
+       connection_wifi_state_e wifi_state;
+       char *ip_addr;
+};
+
+struct conn_mgr_s conn_mgr = { 0, };
+
+static const char *__connection_error_to_string(connection_error_e error)
+{
+       switch (error) {
+       case CONNECTION_ERROR_NONE:
+               return "CONNECTION_ERROR_NONE";
+       case CONNECTION_ERROR_INVALID_PARAMETER:
+               return "CONNECTION_ERROR_INVALID_PARAMETER";
+       case CONNECTION_ERROR_OUT_OF_MEMORY:
+               return "CONNECTION_ERROR_OUT_OF_MEMORY";
+       case CONNECTION_ERROR_INVALID_OPERATION:
+               return "CONNECTION_ERROR_INVALID_OPERATION";
+       case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+               return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
+       case CONNECTION_ERROR_OPERATION_FAILED:
+               return "CONNECTION_ERROR_OPERATION_FAILED";
+       case CONNECTION_ERROR_ITERATOR_END:
+               return "CONNECTION_ERROR_ITERATOR_END";
+       case CONNECTION_ERROR_NO_CONNECTION:
+               return "CONNECTION_ERROR_NO_CONNECTION";
+       case CONNECTION_ERROR_NOW_IN_PROGRESS:
+               return "CONNECTION_ERROR_NOW_IN_PROGRESS";
+       case CONNECTION_ERROR_ALREADY_EXISTS:
+               return "CONNECTION_ERROR_ALREADY_EXISTS";
+       case CONNECTION_ERROR_OPERATION_ABORTED:
+               return "CONNECTION_ERROR_OPERATION_ABORTED";
+       case CONNECTION_ERROR_DHCP_FAILED:
+               return "CONNECTION_ERROR_DHCP_FAILED";
+       case CONNECTION_ERROR_INVALID_KEY:
+               return "CONNECTION_ERROR_INVALID_KEY";
+       case CONNECTION_ERROR_NO_REPLY:
+               return "CONNECTION_ERROR_NO_REPLY";
+       case CONNECTION_ERROR_PERMISSION_DENIED:
+               return "CONNECTION_ERROR_PERMISSION_DENIED";
+       case CONNECTION_ERROR_NOT_SUPPORTED:
+               return "CONNECTION_ERROR_NOT_SUPPORTED";
+       default:
+               return "CONNECTION_ERROR_UNKNOWN";
+       }
+}
+
+static void __conn_mgr_ip_changed_cb(const char* ipv4_address,
+               const char* ipv6_address, void* user_data)
+{
+       _D("ip changed from[%s] to[%s]", conn_mgr.ip_addr, ipv4_address);
+
+       if (conn_mgr.ip_addr) {
+               free(conn_mgr.ip_addr);
+               conn_mgr.ip_addr = strdup(ipv4_address);
+       }
+       return;
+}
+
+static void __conn_mgr_connection_changed_cb(connection_type_e type, void* user_data)
+{
+       int ret = CONNECTION_ERROR_NONE;
+       _D("connection changed from[%d] to[%d]", conn_mgr.net_state, type);
+
+       conn_mgr.net_state = type;
+       if (conn_mgr.net_state != CONNECTION_TYPE_WIFI) {
+               ret = connection_get_wifi_state(conn_mgr.connection, &conn_mgr.wifi_state);
+               if (CONNECTION_ERROR_NONE != ret)
+                       _E("fail connection_get_wifi_state - [%s]",
+                               __connection_error_to_string(ret));
+               else
+                       _D("net_state[%d] - wifi_state[%d]",
+                               conn_mgr.net_state, conn_mgr.wifi_state);
+       }
+
+       return;
+}
+
+int connection_manager_get_ip(const char **ip)
+{
+       int ret = CONNECTION_ERROR_NONE;
+
+       retv_if(conn_mgr.connection == NULL, -1);
+       retv_if(ip == NULL, -1);
+
+       if (conn_mgr.ip_addr) {
+               *ip = conn_mgr.ip_addr;
+               return 0;
+       }
+
+       if (conn_mgr.net_state == CONNECTION_TYPE_DISCONNECTED) {
+               _W("disconnected now");
+               if (conn_mgr.ip_addr) {
+                       free(conn_mgr.ip_addr);
+                       conn_mgr.ip_addr = NULL;
+               }
+               return -1;
+       }
+
+       ret = connection_get_ip_address(conn_mgr.connection,
+                       CONNECTION_ADDRESS_FAMILY_IPV4, &conn_mgr.ip_addr);
+       if ((CONNECTION_ERROR_NONE != ret) || (conn_mgr.ip_addr == NULL)) {
+               _E("fail to connection_get_ip_address() - [%s]",
+                       __connection_error_to_string(ret));
+               return -1;
+       }
+
+       return 0;
+}
+
+int connection_manager_init(void)
+{
+       int ret = CONNECTION_ERROR_NONE;
+       if (conn_mgr.connection) {
+               _W("connection manager is already initialized");
+               return 0;
+       }
+
+       ret = connection_create(&conn_mgr.connection);
+       if (CONNECTION_ERROR_NONE != ret) {
+               _E("fail to create connection - [%s]",
+                       __connection_error_to_string(ret));
+               return -1;
+       }
+
+       ret = connection_get_type(conn_mgr.connection, &conn_mgr.net_state);
+       if (CONNECTION_ERROR_NONE != ret)
+               _E("fail connection_get_type - [%s]",
+                       __connection_error_to_string(ret));
+
+       if (conn_mgr.net_state != CONNECTION_TYPE_DISCONNECTED) {
+               ret = connection_get_ip_address(conn_mgr.connection,
+                       CONNECTION_ADDRESS_FAMILY_IPV4, &conn_mgr.ip_addr);
+               if ((CONNECTION_ERROR_NONE != ret) || (conn_mgr.ip_addr == NULL))
+                       _E("fail to connection_get_ip_address() - [%s]",
+                               __connection_error_to_string(ret));
+       }
+
+       ret = connection_set_type_changed_cb(conn_mgr.connection,
+                       __conn_mgr_connection_changed_cb, NULL);
+       if (CONNECTION_ERROR_NONE != ret)
+               _E("fail connection_set_type_changed_cb - [%s]",
+                       __connection_error_to_string(ret));
+
+       ret = connection_get_wifi_state(conn_mgr.connection, &conn_mgr.wifi_state);
+       if (CONNECTION_ERROR_NONE != ret)
+               _E("fail connection_get_wifi_state - [%s]",
+                       __connection_error_to_string(ret));
+
+       ret = connection_set_ip_address_changed_cb(conn_mgr.connection,
+                       __conn_mgr_ip_changed_cb, NULL);
+       if (CONNECTION_ERROR_NONE != ret)
+               _E("fail toconnection_set_ip_address_changed_cb - [%s]",
+                       __connection_error_to_string(ret));
+
+       _D("net_state[%d], wifi_state[%d], ip address[%s]",
+               conn_mgr.net_state, conn_mgr.wifi_state, conn_mgr.ip_addr);
+
+       return 0;
+}
+
+int connection_manager_fini(void)
+{
+       if (conn_mgr.connection) {
+               int ret = 0;
+               ret = connection_destroy(conn_mgr.connection);
+               _D("connection_destroy - [%s]", __connection_error_to_string(ret));
+               conn_mgr.connection = NULL;
+       }
+
+       if (conn_mgr.ip_addr) {
+               free(conn_mgr.ip_addr);
+               conn_mgr.ip_addr = NULL;
+       }
+       return 0;
+}
diff --git a/src/connectivity.c b/src/connectivity.c
deleted file mode 100644 (file)
index d1ef473..0000000
+++ /dev/null
@@ -1,1229 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: Jin Yoon <jinny.yoon@samsung.com>
- *          Geunsun Lee <gs86.lee@samsung.com>
- *          Eunyoung Lee <ey928.lee@samsung.com>
- *          Junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <glib.h>
-#include <app_common.h>
-#include <iotcon.h>
-
-#include "log.h"
-#include "connectivity.h"
-#include "webutil.h"
-#include "controller_util.h"
-
-#define DEFAULT_RESOURCE_TYPE "org.tizen.door"
-#define BUFSIZE 1024
-#define URI_PATH_LEN 64
-#define URI_PATH "/door/1"
-#define PATH "path"
-#define IOTCON_DB_FILENAME "iotcon-test-svr-db-server.dat"
-
-struct _connectivity_resource {
-       char *path;
-       char *type;
-       connectivity_protocol_e protocol_type;
-       GHashTable *value_hash;
-       union {
-               struct {
-                       iotcon_resource_h res;
-                       iotcon_observers_h observers;
-               } iotcon_data;
-               struct {
-                       /* Nothing */
-                       char *reserve;
-               } http_data;
-       } conn_data;
-};
-
-typedef enum {
-       DATA_VAL_TYPE_BOOL = 0,
-       DATA_VAL_TYPE_INT,
-       DATA_VAL_TYPE_DOUBLE,
-       DATA_VAL_TYPE_STRING
-} conn_data_val_type_e;
-
-typedef struct _conn_data_value_s {
-       conn_data_val_type_e type;
-       union {
-               bool b_val;
-               int i_val;
-               double d_val;
-               char *s_val;
-       };
-} conn_data_value_s;
-
-static connectivity_protocol_e ProtocolType = CONNECTIVITY_PROTOCOL_DEFAULT;
-static int connectivity_iotcon_intialized = 0;
-static int connectivity_http_intialized = 0;
-
-static void _print_iotcon_error(int err_no)
-{
-       switch (err_no) {
-       case IOTCON_ERROR_NOT_SUPPORTED:
-               _E("IOTCON_ERROR_NOT_SUPPORTED");
-               break;
-       case IOTCON_ERROR_PERMISSION_DENIED:
-               _E("IOTCON_ERROR_PERMISSION_DENIED");
-               break;
-       case IOTCON_ERROR_INVALID_PARAMETER:
-               _E("IOTCON_ERROR_INVALID_PARAMETER");
-               break;
-       default:
-               _E("Error : [%d]", err_no);
-               break;
-       }
-
-       return;
-}
-
-static void _copy_file(const char *in_filename, const char *out_filename)
-{
-       char buf[BUFSIZE] = { 0, };
-       size_t nread = 0;
-       FILE *in = NULL;
-       FILE *out = NULL;
-
-       ret_if(!in_filename);
-       ret_if(!out_filename);
-
-       in = fopen(in_filename, "r");
-       ret_if(!in);
-
-       out = fopen(out_filename, "w");
-       goto_if(!out, error);
-
-       rewind(in);
-       while ((nread = fread(buf, 1, sizeof(buf), in)) > 0) {
-               if (fwrite(buf, 1, nread, out) < nread) {
-                       _E("critical error to copy a file");
-                       break;
-               }
-       }
-
-       fclose(in);
-       fclose(out);
-
-       return;
-
-error:
-       fclose(out);
-       return;
-}
-
-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 int _handle_query(iotcon_request_h request)
-{
-       iotcon_query_h query = NULL;
-       int ret = -1;
-
-       ret = iotcon_request_get_query(request, &query);
-       retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-       if (query) iotcon_query_foreach(query, _query_cb, NULL);
-
-       return 0;
-}
-
-static int _handle_request_by_crud_type(iotcon_request_h request, connectivity_resource_s *resource_info)
-{
-       iotcon_request_type_e type;
-       int ret = -1;
-
-       ret = iotcon_request_get_request_type(request, &type);
-       retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-       switch (type) {
-       case IOTCON_REQUEST_GET:
-               _I("Do not support 'get' query");
-               break;
-       case IOTCON_REQUEST_PUT:
-               _I("Do not support 'put' query");
-               break;
-       case IOTCON_REQUEST_POST:
-               _I("Do not support 'post' query");
-               break;
-       case IOTCON_REQUEST_DELETE:
-               _I("Do not support 'delete' query");
-               break;
-       default:
-               _E("Cannot reach here");
-               ret = -1;
-               break;
-       }
-       retv_if(0 != ret, -1);
-
-       return 0;
-}
-
-static int _handle_observer(iotcon_request_h request, iotcon_observers_h observers)
-{
-       iotcon_observe_type_e observe_type;
-       int ret = -1;
-       int observe_id = -1;
-
-       ret = iotcon_request_get_observe_type(request, &observe_type);
-       retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-       if (IOTCON_OBSERVE_REGISTER == observe_type) {
-               ret = iotcon_request_get_observe_id(request, &observe_id);
-               retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-               _I("Add an observer : %d", observe_id);
-
-               ret = iotcon_observers_add(observers, observe_id);
-               retv_if(IOTCON_ERROR_NONE != ret, -1);
-       } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
-               ret = iotcon_request_get_observe_id(request, &observe_id);
-               retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-               _I("Remove an observer : %d", observe_id);
-
-               ret = iotcon_observers_remove(observers, observe_id);
-               retv_if(IOTCON_ERROR_NONE != ret, -1);
-       }
-
-       return 0;
-}
-
-static int _send_response(iotcon_request_h request, iotcon_representation_h representation, iotcon_response_result_e result)
-{
-       int ret = -1;
-       iotcon_response_h response;
-
-       ret = iotcon_response_create(request, &response);
-       retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-       ret = iotcon_response_set_result(response, result);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_response_set_representation(response, representation);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_response_send(response);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_response_destroy(response);
-
-       return 0;
-
-error:
-       iotcon_response_destroy(response);
-       return -1;
-}
-
-static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
-       connectivity_resource_s *resource_info = user_data;
-       int ret = -1;
-       char *host_address = NULL;
-
-       ret_if(!request);
-
-       ret = iotcon_request_get_host_address(request, &host_address);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       _D("Host address : %s", host_address);
-
-       ret = _handle_query(request);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = _handle_request_by_crud_type(request, resource_info);
-       goto_if(0 != ret, error);
-
-       ret = _handle_observer(request, resource_info->conn_data.iotcon_data.observers);
-       goto_if(0 != ret, error);
-
-       return;
-
-error:
-       _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
-       return;
-}
-
-static int __init_iotcon(connectivity_resource_s *resource_info)
-{
-       int ret = -1;
-       iotcon_resource_types_h resource_types = NULL;
-       iotcon_resource_interfaces_h ifaces = NULL;
-       uint8_t policies = IOTCON_RESOURCE_NO_POLICY;
-       char res_path[PATH_MAX] = {0,};
-       char data_path[PATH_MAX] = {0,};
-       char *prefix = NULL;
-
-       retv_if(!resource_info, -1);
-       retv_if(resource_info->protocol_type != CONNECTIVITY_PROTOCOL_IOTIVITY, -1);
-
-       prefix = app_get_resource_path();
-       retv_if(!prefix, -1);
-       snprintf(res_path, sizeof(res_path)-1, "%s%s", prefix, IOTCON_DB_FILENAME);
-       free(prefix);
-       prefix = NULL;
-
-       prefix = app_get_data_path();
-       retv_if(!prefix, -1);
-       snprintf(data_path, sizeof(data_path)-1, "%s%s", prefix, IOTCON_DB_FILENAME);
-       free(prefix);
-
-       _copy_file(res_path, data_path);
-
-       ret = iotcon_initialize(data_path);
-       retv_if(IOTCON_ERROR_NONE != ret, -1);
-
-       /* TODO : If we have to set device name, naming it more gorgeous one */
-       ret = iotcon_set_device_name(DEFAULT_RESOURCE_TYPE);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_resource_types_create(&resource_types);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_resource_types_add(resource_types, resource_info->type);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_resource_interfaces_create(&ifaces);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_DEFAULT);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_BATCH);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       policies =
-               IOTCON_RESOURCE_DISCOVERABLE |
-               IOTCON_RESOURCE_OBSERVABLE |
-               IOTCON_RESOURCE_SECURE;
-
-       ret = iotcon_resource_create(URI_PATH,
-                       resource_types,
-                       ifaces,
-                       policies,
-                       _request_resource_handler,
-                       resource_info,
-                       &resource_info->conn_data.iotcon_data.res);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_observers_create(&resource_info->conn_data.iotcon_data.observers);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_resource_types_destroy(resource_types);
-       iotcon_resource_interfaces_destroy(ifaces);
-       connectivity_iotcon_intialized = 1;
-
-       return 0;
-
-error:
-       if (resource_types) iotcon_resource_types_destroy(resource_types);
-       if (ifaces) iotcon_resource_interfaces_destroy(ifaces);
-       if (resource_info->conn_data.iotcon_data.res) iotcon_resource_destroy(resource_info->conn_data.iotcon_data.res);
-       iotcon_deinitialize();
-       return -1;
-}
-
-static int __init_http(connectivity_resource_s *resource_info)
-{
-       int ret = 0;
-       ret = web_util_noti_init();
-       if (!ret)
-               connectivity_http_intialized = 1;
-
-       return ret;
-}
-
-#ifdef PRINT_DEBUG_DETAIL
-static bool __print_attributes_cb(iotcon_attributes_h attributes, const char *key, void *user_data)
-{
-       iotcon_type_e type = IOTCON_TYPE_NONE;
-
-       iotcon_attributes_get_type(attributes, key, &type);
-
-       switch (type) {
-       case IOTCON_TYPE_INT: {
-               int value = 0;
-               iotcon_attributes_get_int(attributes, key, &value);
-               _D("key[%s] - int value [%d]", key, value);
-               }
-               break;
-       case IOTCON_TYPE_BOOL: {
-               bool value = 0;
-               iotcon_attributes_get_bool(attributes, key, &value);
-               _D("key[%s] - bool value [%d]", key, value);
-               }
-               break;
-       case IOTCON_TYPE_DOUBLE: {
-               double value = 0;
-               iotcon_attributes_get_double(attributes, key, &value);
-               _D("key[%s] - double value [%lf]", key, value);
-               }
-       break;
-       case IOTCON_TYPE_STR: {
-               char *value = 0;
-               iotcon_attributes_get_str(attributes, key, &value);
-               _D("key[%s] - string value [%s]", key, value);
-               }
-       break;
-       case IOTCON_TYPE_NONE:
-       case IOTCON_TYPE_BYTE_STR:
-       case IOTCON_TYPE_NULL:
-       case IOTCON_TYPE_LIST:
-       case IOTCON_TYPE_ATTRIBUTES:
-       default:
-               _W("unhandled key[%s] type[%d]", key, type);
-               break;
-       }
-
-       return IOTCON_FUNC_CONTINUE;
-}
-#endif
-
-static void __print_attribute(iotcon_attributes_h attributes)
-{
-#ifdef PRINT_DEBUG_DETAIL
-       ret_if(!attributes);
-
-       iotcon_attributes_foreach(attributes, __print_attributes_cb, NULL);
-#endif
-       return;
-}
-
-static void _destroy_representation(iotcon_representation_h representation)
-{
-       ret_if(!representation);
-       iotcon_representation_destroy(representation);
-       return;
-}
-
-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(resource_info->conn_data.iotcon_data.res, &uri_path);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_representation_create(&representation);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_attributes_create(&attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       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);
-
-       ret = iotcon_representation_set_attributes(representation, attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_attributes_destroy(attributes);
-
-       return representation;
-
-error:
-       if (attributes) iotcon_attributes_destroy(attributes);
-       if (representation) iotcon_representation_destroy(representation);
-
-       return NULL;
-}
-
-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(resource_info->conn_data.iotcon_data.res, &uri_path);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_representation_create(&representation);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_attributes_create(&attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       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_int(attributes, key, value);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_representation_set_attributes(representation, attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_attributes_destroy(attributes);
-
-       return representation;
-
-error:
-       if (attributes) iotcon_attributes_destroy(attributes);
-       if (representation) iotcon_representation_destroy(representation);
-
-       return NULL;
-}
-
-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(resource_info->conn_data.iotcon_data.res, &uri_path);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_representation_create(&representation);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_attributes_create(&attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       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_double(attributes, key, value);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_representation_set_attributes(representation, attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_attributes_destroy(attributes);
-
-       return representation;
-
-error:
-       if (attributes) iotcon_attributes_destroy(attributes);
-       if (representation) iotcon_representation_destroy(representation);
-
-       return NULL;
-}
-
-static iotcon_representation_h _create_representation_with_string(connectivity_resource_s *resource_info, const char *key, const char *value)
-{
-       iotcon_attributes_h attributes = NULL;
-       iotcon_representation_h representation = NULL;
-       char *uri_path = NULL;
-       int ret = -1;
-
-       ret = iotcon_resource_get_uri_path(resource_info->conn_data.iotcon_data.res, &uri_path);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_representation_create(&representation);
-       retv_if(IOTCON_ERROR_NONE != ret, NULL);
-
-       ret = iotcon_attributes_create(&attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       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_str(attributes, key, (char *)value);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       ret = iotcon_representation_set_attributes(representation, attributes);
-       goto_if(IOTCON_ERROR_NONE != ret, error);
-
-       iotcon_attributes_destroy(attributes);
-
-       return representation;
-
-error:
-       if (attributes) iotcon_attributes_destroy(attributes);
-       if (representation) iotcon_representation_destroy(representation);
-
-       return NULL;
-}
-
-static inline void __noti_by_http(void)
-{
-       char *json_data = NULL;
-
-       json_data = web_util_get_json_string();
-       if (json_data) {
-               const char *url = NULL;
-               controller_util_get_address(&url);
-               if (url)
-                       web_util_noti_post(url, json_data);
-               else
-                       _E("fail to get url");
-               free(json_data);
-       } else
-               _E("fail to get json_data");
-
-       return;
-}
-
-int connectivity_notify_bool(connectivity_resource_s *resource_info, const char *key, bool value)
-{
-       int ret = -1;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("Notify key[%s], value[%d]", key, value);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               retv_if(!resource_info->conn_data.iotcon_data.res, -1);
-               retv_if(!resource_info->conn_data.iotcon_data.observers, -1);
-               {
-                       iotcon_representation_h representation;
-                       representation = _create_representation_with_bool(resource_info, key, value);
-                       retv_if(!representation, -1);
-                       ret = iotcon_resource_notify(resource_info->conn_data.iotcon_data.res,
-                                       representation, resource_info->conn_data.iotcon_data.observers, IOTCON_QOS_LOW);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               _W("There are some troubles for notifying value[%d]", ret);
-                               _print_iotcon_error(ret);
-                               return -1;
-                       }
-                       _destroy_representation(representation);
-               }
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = web_util_json_init();
-               retv_if(ret, -1);
-
-               ret = web_util_json_begin();
-               retv_if(ret, -1);
-
-               web_util_json_add_string("SensorPiID", resource_info->path);
-               web_util_json_add_string("SensorPiType", resource_info->type);
-               web_util_json_add_boolean(key, value);
-               web_util_json_end();
-
-               __noti_by_http();
-
-               web_util_json_fini();
-               break;
-       default:
-               _E("Unknown protocol type[%d]", resource_info->protocol_type);
-               return -1;
-               break;
-       }
-
-       return 0;
-}
-
-int connectivity_notify_int(connectivity_resource_s *resource_info, const char *key, int value)
-{
-       int ret = -1;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("Notify key[%s], value[%d]", key, value);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               retv_if(!resource_info->conn_data.iotcon_data.res, -1);
-               retv_if(!resource_info->conn_data.iotcon_data.observers, -1);
-               {
-                       iotcon_representation_h representation;
-                       representation = _create_representation_with_int(resource_info, key, value);
-                       retv_if(!representation, -1);
-                       ret = iotcon_resource_notify(resource_info->conn_data.iotcon_data.res,
-                                       representation, resource_info->conn_data.iotcon_data.observers, IOTCON_QOS_LOW);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               _W("There are some troubles for notifying value[%d]", ret);
-                               _print_iotcon_error(ret);
-                               return -1;
-                       }
-                       _destroy_representation(representation);
-               }
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = web_util_json_init();
-               retv_if(ret, -1);
-
-               ret = web_util_json_begin();
-               retv_if(ret, -1);
-
-               web_util_json_add_string("SensorPiID", resource_info->path);
-               web_util_json_add_string("SensorPiType", resource_info->type);
-               web_util_json_add_int(key, value);
-               web_util_json_end();
-
-               __noti_by_http();
-
-               web_util_json_fini();
-               break;
-       default:
-               _E("Unknown protocol type[%d]", resource_info->protocol_type);
-               return -1;
-               break;
-       }
-       return 0;
-}
-
-int connectivity_notify_double(connectivity_resource_s *resource_info, const char *key, double value)
-{
-       int ret = -1;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("Notify key[%s], value[%lf]", key, value);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               retv_if(!resource_info->conn_data.iotcon_data.res, -1);
-               retv_if(!resource_info->conn_data.iotcon_data.observers, -1);
-               {
-                       iotcon_representation_h representation;
-                       representation = _create_representation_with_double(resource_info, key, value);
-                       retv_if(!representation, -1);
-                       ret = iotcon_resource_notify(resource_info->conn_data.iotcon_data.res,
-                                       representation, resource_info->conn_data.iotcon_data.observers, IOTCON_QOS_LOW);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               _W("There are some troubles for notifying value[%d]", ret);
-                               _print_iotcon_error(ret);
-                               return -1;
-                       }
-                       _destroy_representation(representation);
-               }
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = web_util_json_init();
-               retv_if(ret, -1);
-
-               ret = web_util_json_begin();
-               retv_if(ret, -1);
-
-               web_util_json_add_string("SensorPiID", resource_info->path);
-               web_util_json_add_string("SensorPiType", resource_info->type);
-               web_util_json_add_double(key, value);
-               web_util_json_end();
-
-               __noti_by_http();
-
-               web_util_json_fini();
-               break;
-       default:
-               _E("Unknown protocol type[%d]", resource_info->protocol_type);
-               return -1;
-               break;
-       }
-       return 0;
-}
-
-int connectivity_notify_string(connectivity_resource_s *resource_info, const char *key, const char *value)
-{
-       int ret = -1;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-       retv_if(!value, -1);
-
-       _D("Notify key[%s], value[%s]", key, value);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               retv_if(!resource_info->conn_data.iotcon_data.res, -1);
-               retv_if(!resource_info->conn_data.iotcon_data.observers, -1);
-               {
-                       iotcon_representation_h representation;
-                       representation = _create_representation_with_string(resource_info, key, value);
-                       retv_if(!representation, -1);
-                       ret = iotcon_resource_notify(resource_info->conn_data.iotcon_data.res,
-                                       representation, resource_info->conn_data.iotcon_data.observers, IOTCON_QOS_LOW);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               _W("There are some troubles for notifying value[%d]", ret);
-                               _print_iotcon_error(ret);
-                               return -1;
-                       }
-                       _destroy_representation(representation);
-               }
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = web_util_json_init();
-               retv_if(ret, -1);
-
-               ret = web_util_json_begin();
-               retv_if(ret, -1);
-
-               web_util_json_add_string("SensorPiID", resource_info->path);
-               web_util_json_add_string("SensorPiType", resource_info->type);
-               web_util_json_add_string(key, value);
-               web_util_json_end();
-
-               __noti_by_http();
-
-               web_util_json_fini();
-               break;
-       default:
-               _E("Unknown protocol type[%d]", resource_info->protocol_type);
-               return -1;
-               break;
-       }
-       return 0;
-}
-
-static void __hash_key_free(gpointer data)
-{
-       free(data);
-       return;
-}
-
-static void __hash_value_free(gpointer data)
-{
-       conn_data_value_s *value = data;
-       if (value && (value->type == DATA_VAL_TYPE_STRING))
-               free(value->s_val);
-       free(value);
-
-       return;
-}
-
-static int __add_value_to_hash(connectivity_resource_s *resource_info, const char *key, conn_data_value_s *value)
-{
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-       retv_if(!value, -1);
-
-       if (!resource_info->value_hash) {
-               resource_info->value_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                                                               __hash_key_free, __hash_value_free);
-               retv_if(!resource_info->value_hash, -1);
-       }
-
-       g_hash_table_insert(resource_info->value_hash, strdup(key), value);
-
-       return 0;
-}
-
-int connectivity_attributes_add_bool(connectivity_resource_s *resource_info, const char *key, bool value)
-{
-       conn_data_value_s *data_value = NULL;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("adding key[%s] - value[%d]", key, value);
-
-       data_value = malloc(sizeof(conn_data_value_s));
-       retv_if(!data_value, -1);
-
-       data_value->type = DATA_VAL_TYPE_BOOL;
-       data_value->b_val = value;
-
-       return __add_value_to_hash(resource_info, key, data_value);
-}
-
-int connectivity_attributes_add_int(connectivity_resource_s *resource_info, const char *key, int value)
-{
-       conn_data_value_s *data_value = NULL;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("adding key[%s] - value[%d]", key, value);
-
-       data_value = malloc(sizeof(conn_data_value_s));
-       retv_if(!data_value, -1);
-
-       data_value->type = DATA_VAL_TYPE_INT;
-       data_value->i_val = value;
-
-       return __add_value_to_hash(resource_info, key, data_value);
-}
-
-int connectivity_attributes_add_double(connectivity_resource_s *resource_info, const char *key, double value)
-{
-       conn_data_value_s *data_value = NULL;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       _D("adding key[%s] - value[%lf]", key, value);
-
-       data_value = malloc(sizeof(conn_data_value_s));
-       retv_if(!data_value, -1);
-
-       data_value->type = DATA_VAL_TYPE_DOUBLE;
-       data_value->d_val = value;
-
-       return __add_value_to_hash(resource_info, key, data_value);
-}
-
-int connectivity_attributes_add_string(connectivity_resource_s *resource_info, const char *key, const char *value)
-{
-       conn_data_value_s *data_value = NULL;
-
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-       retv_if(!value, -1);
-
-       _D("adding key[%s] - value[%s]", key, value);
-
-       data_value = malloc(sizeof(conn_data_value_s));
-       retv_if(!data_value, -1);
-
-       data_value->type = DATA_VAL_TYPE_STRING;
-       data_value->s_val = strdup(value);
-
-       return __add_value_to_hash(resource_info, key, data_value);
-}
-
-int connectivity_attributes_remove_value_by_key(connectivity_resource_s *resource_info, const char *key)
-{
-       retv_if(!resource_info, -1);
-       retv_if(!key, -1);
-
-       if (resource_info->value_hash)
-               g_hash_table_remove(resource_info->value_hash, key);
-
-       if (g_hash_table_size(resource_info->value_hash) == 0) {
-               g_hash_table_unref(resource_info->value_hash);
-               resource_info->value_hash = NULL;
-       }
-
-       return 0;
-}
-
-int connectivity_attributes_remove_all(connectivity_resource_s *resource_info)
-{
-       retv_if(!resource_info, -1);
-
-       if (resource_info->value_hash) {
-               g_hash_table_destroy(resource_info->value_hash);
-               resource_info->value_hash = NULL;
-       }
-
-       return 0;
-}
-
-static void __json_add_data_iter_cb(gpointer key, gpointer value, gpointer user_data)
-{
-       char *name = key;
-       conn_data_value_s *data = value;
-       int ret = 0;
-
-       ret_if(name);
-       ret_if(data);
-
-       switch (data->type) {
-       case DATA_VAL_TYPE_BOOL:
-               ret = web_util_json_add_boolean(name, data->b_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%d]", name, data->b_val);
-               break;
-       case DATA_VAL_TYPE_INT:
-               ret = web_util_json_add_int(name, data->i_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%d]", name, data->i_val);
-               break;
-       case DATA_VAL_TYPE_DOUBLE:
-               ret = web_util_json_add_double(name, data->d_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%lf]", name, data->d_val);
-               break;
-       case DATA_VAL_TYPE_STRING:
-               ret = web_util_json_add_string(name, data->s_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%s]", name, data->s_val);
-               break;
-       default:
-               _E("Unknown data type [%d]", data->type);
-               break;
-       }
-
-       return;
-}
-
-static void __attr_add_data_iter_cb(gpointer key, gpointer value, gpointer user_data)
-{
-       char *name = key;
-       conn_data_value_s *data = value;
-       iotcon_attributes_h attr = user_data;
-       int ret = 0;
-
-       ret_if(name);
-       ret_if(data);
-       ret_if(attr);
-
-       switch (data->type) {
-       case DATA_VAL_TYPE_BOOL:
-               ret = iotcon_attributes_add_bool(attr, name, data->b_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%d]", name, data->b_val);
-               break;
-       case DATA_VAL_TYPE_INT:
-               ret = iotcon_attributes_add_int(attr, name, data->i_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%d]", name, data->i_val);
-               break;
-       case DATA_VAL_TYPE_DOUBLE:
-               ret = iotcon_attributes_add_double(attr, name, data->d_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%lf]", name, data->d_val);
-               break;
-       case DATA_VAL_TYPE_STRING:
-               ret = iotcon_attributes_add_str(attr, name, data->s_val);
-               if (IOTCON_ERROR_NONE != ret)
-                       _E("failed to add key[%s], value[%s]", name, data->s_val);
-               break;
-       default:
-               _E("Unknown data type [%d]", data->type);
-               break;
-       }
-
-       return;
-}
-
-static int __create_attributes(connectivity_resource_s *resource_info, iotcon_attributes_h *attributes)
-{
-       int ret = 0;
-       iotcon_attributes_h attr = NULL;
-
-       ret = iotcon_attributes_create(&attr);
-       if (IOTCON_ERROR_NONE != ret) {
-               _print_iotcon_error(ret);
-               return -1;
-       }
-
-       ret = iotcon_attributes_add_str(attr, PATH, resource_info->path);
-       if (IOTCON_ERROR_NONE != ret) {
-               _print_iotcon_error(ret);
-               iotcon_attributes_destroy(attr);
-               return -1;
-       }
-       if (resource_info->value_hash)
-               g_hash_table_foreach(resource_info->value_hash, __attr_add_data_iter_cb, attr);
-
-       *attributes = attr;
-
-       return 0;
-}
-
-int connectivity_attributes_notify_all(connectivity_resource_s *resource_info)
-{
-       int ret = 0;
-
-       retv_if(!resource_info, -1);
-
-       if (resource_info->value_hash == NULL) {
-               _W("You have nothing to notify now");
-               return 0;
-       }
-
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               retv_if(!resource_info->conn_data.iotcon_data.res, -1);
-               retv_if(!resource_info->conn_data.iotcon_data.observers, -1);
-               {
-                       char *uri_path = NULL;
-                       iotcon_representation_h representation = NULL;
-                       iotcon_attributes_h attributes = NULL;
-                       int iotcon_ret = 0;
-
-                       iotcon_ret = iotcon_resource_get_uri_path(resource_info->conn_data.iotcon_data.res, &uri_path);
-                       retv_if(IOTCON_ERROR_NONE != iotcon_ret, -1);
-
-                       iotcon_ret = iotcon_representation_create(&representation);
-                       retv_if(IOTCON_ERROR_NONE != iotcon_ret, -1);
-
-                       iotcon_ret = iotcon_representation_set_uri_path(representation, uri_path);
-                       if (IOTCON_ERROR_NONE != iotcon_ret) {
-                               _print_iotcon_error(iotcon_ret);
-                               ret = -1;
-                       }
-
-                       iotcon_ret = __create_attributes(resource_info, &attributes);
-                       if (iotcon_ret) {
-                               _E("failed to create attributes");
-                               ret = -1;
-                       }
-                       __print_attribute(attributes);
-
-                       iotcon_ret = iotcon_representation_set_attributes(representation, attributes);
-                       if (IOTCON_ERROR_NONE != iotcon_ret) {
-                               _print_iotcon_error(iotcon_ret);
-                               ret = -1;
-                       }
-
-                       iotcon_ret = iotcon_resource_notify(resource_info->conn_data.iotcon_data.res, representation,
-                                       resource_info->conn_data.iotcon_data.observers, IOTCON_QOS_LOW);
-                       if (IOTCON_ERROR_NONE != iotcon_ret) {
-                               _print_iotcon_error(iotcon_ret);
-                               ret = -1;
-                       }
-
-                       iotcon_representation_destroy(representation);
-                       iotcon_attributes_destroy(attributes);
-               }
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = web_util_json_init();
-               retv_if(ret, -1);
-
-               ret = web_util_json_begin();
-               retv_if(ret, -1);
-
-               web_util_json_add_string("SensorPiID", resource_info->path);
-               web_util_json_add_string("SensorPiType", resource_info->type);
-               g_hash_table_foreach(resource_info->value_hash, __json_add_data_iter_cb, NULL);
-               web_util_json_end();
-
-               __noti_by_http();
-
-               web_util_json_fini();
-               break;
-       default:
-               break;
-       }
-
-       g_hash_table_destroy(resource_info->value_hash);
-       resource_info->value_hash = NULL;
-
-       return ret;
-}
-
-void connectivity_unset_resource(connectivity_resource_s *resource_info)
-{
-       ret_if(!resource_info);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               if (resource_info->conn_data.iotcon_data.observers) iotcon_observers_destroy(resource_info->conn_data.iotcon_data.observers);
-               if (resource_info->conn_data.iotcon_data.res) iotcon_resource_destroy(resource_info->conn_data.iotcon_data.res);
-               iotcon_deinitialize();
-               connectivity_iotcon_intialized = 0;
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               web_util_noti_fini();
-               connectivity_http_intialized = 0;
-               break;
-       default:
-               break;
-       }
-
-       if (resource_info->path) free(resource_info->path);
-       if (resource_info->type) free(resource_info->type);
-       free(resource_info);
-
-       return;
-}
-
-int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info)
-{
-       connectivity_resource_s *resource_info = NULL;
-       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);
-
-       resource_info->path = strdup(path);
-       goto_if(!resource_info->path, error);
-
-       resource_info->type = strdup(type);
-       goto_if(!resource_info->type, error);
-
-       resource_info->protocol_type = ProtocolType;
-
-       _D("Path[%s], Type[%s], protocol_type[%d]" , resource_info->path, resource_info->type, resource_info->protocol_type);
-
-       switch (resource_info->protocol_type) {
-       case CONNECTIVITY_PROTOCOL_DEFAULT:
-               _D("default protocol type is iotivity\n \
-                        To set connectivity use connectivity_set_protocol_type() function");
-               resource_info->protocol_type = CONNECTIVITY_PROTOCOL_IOTIVITY;
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               ret = __init_iotcon(resource_info);
-               goto_if(ret, error);
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               ret = __init_http(resource_info);
-               goto_if(ret, error);
-               break;
-       default:
-               goto error;
-               break;
-       }
-
-       *out_resource_info = resource_info;
-
-       return 0;
-
-error:
-       if (resource_info->path) free(resource_info->path);
-       if (resource_info->type) free(resource_info->type);
-       if (resource_info) free(resource_info);
-
-       return -1;
-}
-
-int connectivity_set_protocol(connectivity_protocol_e protocol_type)
-{
-       int ret = 0;
-       retv_if(protocol_type >= CONNECTIVITY_PROTOCOL_MAX, -1);
-
-       switch (protocol_type) {
-       case CONNECTIVITY_PROTOCOL_DEFAULT:
-       case CONNECTIVITY_PROTOCOL_IOTIVITY:
-               if (connectivity_iotcon_intialized) {
-                       _E("protocol type[%d] aleady initialized", protocol_type);
-                       return -1;
-               }
-               ProtocolType = CONNECTIVITY_PROTOCOL_IOTIVITY;
-               break;
-       case CONNECTIVITY_PROTOCOL_HTTP:
-               if (connectivity_http_intialized) {
-                       _E("protocol type[%d] aleady initialized", protocol_type);
-                       return -1;
-               }
-               ProtocolType = CONNECTIVITY_PROTOCOL_HTTP;
-               break;
-       default:
-               _E("unknown protocol type[%d]", protocol_type);
-               return -1;
-               break;
-       }
-
-       return ret;
-}
index 1735ab747346dd6e85419ac3b6926a4e4671d777..b099702e44be0019ffeb5c885ae8d8041e0ae349 100644 (file)
 #include <Ecore.h>
 #include <tizen.h>
 #include <service_app.h>
+#include <st_things.h>
+#include <pthread.h>
 
 #include "log.h"
 #include "resource.h"
-#include "connectivity.h"
-#include "controller.h"
+#include "controller_internal.h"
+#include "controller_util.h"
+#include "webutil.h"
+#include "connection_manager.h"
+
+#define WILL_BE_COMMENTED_OUT
+
+#define SENSORING_TIME_INTERVAL_MOTION 2.0f
+#define SENSOR_GPIO_MOTION 21
+
+#ifdef WILL_BE_COMMENTED_OUT
+#define SENSOR_URI_MOTION "/capability/motionSensor/main/0"
+#define SENSOR_KEY_MOTION "value"
+#endif /* WILL_BE_COMMENTED_OUT */
+
+#define JSON_PATH "device_def.json"
 
 typedef struct app_data_s {
-       Ecore_Timer *getter_timer;
-       connectivity_resource_s *resource_info;
+       Ecore_Timer *getter;
+       bool motion;
+       st_things_status_e things_status;
 } app_data;
 
+static app_data *ghandle = NULL;
+pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-static Eina_Bool _control_sensors_cb(void *data)
+static Eina_Bool __get_motion(void *data)
 {
+       int ret = 0;
+       unsigned int value = 0;
+       st_things_status_e things_status;
        app_data *ad = data;
-       uint32_t value = -1;
-       int ret = -1;
-
-#if 0
-       ret = resource_read_infrared_motion_sensor(PIN_NUMBER, &value);
-       if (ret != 0) _E("Cannot read sensor value");
 
-       _D("Detected value : %d", value);
+#ifdef WILL_BE_COMMENTED_OUT
+       ret = resource_read_infrared_motion_sensor(SENSOR_GPIO_MOTION, &value);
 #endif
+       retv_if(ret != 0, ECORE_CALLBACK_RENEW);
+
+       pthread_mutex_lock(&g_mutex);
+       ad->motion = (bool)value;
+       things_status = ad->things_status;
+       pthread_mutex_unlock(&g_mutex);
 
-#if 0
-       ret = connectivity_notify_int(ad->resource_info, KEY, value);
-       if (ret != 0) _E("Cannot notify value");
+#ifdef WILL_BE_COMMENTED_OUT
+       if (things_status == ST_THINGS_STATUS_REGISTERED_TO_CLOUD)
+               st_things_notify_observers(SENSOR_URI_MOTION);
 #endif
 
        return ECORE_CALLBACK_RENEW;
 }
 
-static bool service_app_create(void *data)
+static void __register_timer(void *data)
 {
        app_data *ad = data;
-       int ret = -1;
 
-       /**
-        * DO NOT EDIT: please don't edit the function below.
-        * Access only when modifying internal functions.
-        */
-       controller_init_internal_functions();
+#ifdef WILL_BE_COMMENTED_OUT
+       ad->getter = ecore_timer_add(SENSORING_TIME_INTERVAL_MOTION, __get_motion, ad);
+       if (!ad->getter)
+               _E("Failed to add getter");
+#endif
 
-#if 0
-       ret = connectivity_set_protocol(CONNECTIVITY_PROTOCOL);
-       if (ret != 0) _E("Cannot set connectivity type");
+       return;
+}
+
+/* handle : reset request*/
+static bool handle_reset_request()
+{
+       bool confirmed = true;
+       return confirmed;
+}
+
+/* handle : reset result */
+static void handle_reset_result(bool result)
+{
+       return;
+}
+
+/* handle : ownership transfer request */
+static bool handle_ownership_transfer_request()
+{
+       bool confirmed = true;
+       return confirmed;
+}
+
+/* handle : for things status change */
+static void handle_things_status_change(st_things_status_e things_status)
+{
+       _D("thing status : %d", things_status);
+#ifdef WILL_BE_COMMENTED_OUT
+       pthread_mutex_lock(&g_mutex);
+       ghandle->things_status = things_status;
+       pthread_mutex_unlock(&g_mutex);
 #endif
 
-#if 0
-       ret = connectivity_set_resource("/door/0", "org.tizen.door", &ad->resource_info);
-       if (ret != 0) _E("Cannot set connectivity resource");
+       return;
+}
+
+/* handle : for getting request on resources */
+static bool handle_get_request(st_things_get_request_message_s *req_msg, st_things_representation_s *resp_rep)
+{
+       bool value = false;
+
+       _D("resource_uri [%s]", req_msg->resource_uri);
+       _D("query [%s]", req_msg->query);
+       _D("property_key [%s]", req_msg->property_key);
+
+       if (strncmp(SENSOR_URI_MOTION, req_msg->resource_uri, strlen(SENSOR_URI_MOTION)) == 0) {
+               pthread_mutex_lock(&g_mutex);
+               value = ghandle->motion;
+               pthread_mutex_unlock(&g_mutex);
+#ifdef WILL_BE_COMMENTED_OUT
+               resp_rep->set_bool_value(resp_rep, SENSOR_KEY_MOTION, value);
 #endif
+               _D("Requested key [%s] - value [%d]", SENSOR_KEY_MOTION, value);
+       }
 
-       /**
-        * 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.
-        */
-#if 0
-       ad->getter_timer = ecore_timer_add(Duration , _control_sensors_cb, ad);
-       if (!ad->getter_timer) {
-               _E("Failed to add getter timer");
+       return true;
+}
+
+/* handle : for setting request on resources */
+static bool handle_set_request(st_things_set_request_message_s *req_msg, st_things_representation_s *resp_rep)
+{
+       _D("resource_uri [%s]", req_msg->resource_uri);
+       _D("query [%s]", req_msg->query);
+
+       return true;
+}
+
+static bool service_app_create(void *data)
+{
+       app_data *ad = data;
+       bool easysetup_complete = false;
+       char app_json_path[128] = {0,};
+       char *app_res_path = NULL;
+       int ret = 0;
+
+       app_res_path = app_get_resource_path();
+       if (app_res_path == NULL) {
+               _E("cannot get resource path");
                return false;
        }
+
+       snprintf(app_json_path, sizeof(app_json_path),
+               "%s/%s", app_res_path, JSON_PATH);
+       free(app_res_path);
+       app_res_path = NULL;
+
+       controller_init_internal_functions();
+
+       st_things_initialize(app_json_path, &easysetup_complete);
+
+#ifdef WILL_BE_COMMENTED_OUT
+       st_things_register_request_cb(handle_get_request, handle_set_request);
+#endif
+       st_things_register_reset_cb(handle_reset_request, handle_reset_result);
+       st_things_register_user_confirm_cb(handle_ownership_transfer_request);
+#ifdef WILL_BE_COMMENTED_OUT
+       st_things_register_things_status_change_cb(handle_things_status_change);
 #endif
 
-    return true;
+       ret = st_things_start();
+       if (ret != ST_THINGS_ERROR_NONE)
+               _E("cannot start st things");
+
+       __register_timer(ad);
+
+       ghandle = ad;
+
+       return true;
 }
 
 static void service_app_terminate(void *data)
 {
        app_data *ad = (app_data *)data;
 
-       if (ad->getter_timer) {
-               ecore_timer_del(ad->getter_timer);
-       }
+       if (ad->getter)
+               ecore_timer_del(ad->getter);
 
-       connectivity_unset_resource(ad->resource_info);
+       st_things_stop();
+       st_things_deinitialize();
 
        /**
-        * DO NOT EDIT: please don't edit the function below.
+        * No modification required!!!
         * Access only when modifying internal functions.
         */
        controller_fini_internal_functions();
index 97e8499bc59c0576921272f50e930fb0fe3a62cf..8c3ba41f284bd8b92f6e705aa47d7462ec66dabe 100644 (file)
 #include <iotcon.h>
 
 #include "log.h"
-#include "connectivity.h"
 #include "resource.h"
 #include "controller_util.h"
+#include "webutil.h"
+#include "connection_manager.h"
 
 void controller_init_internal_functions(void)
 {
-       return;
+       int log_type = LOG_TYPE_DLOG;
+
+       controller_util_get_log_type(&log_type);
+       log_type_set(log_type);
+       connection_manager_init();
+       web_util_noti_init();
 }
 
 void controller_fini_internal_functions(void)
 {
        _I("Terminating...");
        resource_close_all();
+       web_util_noti_fini();
+       connection_manager_fini();
        controller_util_free();
-
-       return;
+       log_file_close();
 }
+
index 3bba0d5cf3e34e5ae94d18af83027d0cedbc0152..9f289927026c556e2471f202e3e5c3c3394a41e9 100644 (file)
 #define CONF_GROUP_DEFAULT_NAME "default"
 #define CONF_KEY_PATH_NAME "path"
 #define CONF_KEY_ADDRESS_NAME "address"
+#define CONF_KEY_LOG_TYPE_NAME "log_type"
 #define CONF_FILE_NAME "pi.conf"
 
 struct controller_util_s {
        char *path;
        char *address;
+       int log_type;
 };
 
-struct controller_util_s controller_util = { 0, };
+struct controller_util_s controller_util = { NULL, NULL, -1 };
 
 static int _read_conf_file(void)
 {
@@ -71,6 +73,11 @@ static int _read_conf_file(void)
        if (!controller_util.address)
                _E("could not get the key string");
 
+       controller_util.log_type = g_key_file_get_integer(gkf,
+                       CONF_GROUP_DEFAULT_NAME,
+                       CONF_KEY_LOG_TYPE_NAME,
+                       NULL);
+
        g_key_file_free(gkf);
 
        return 0;
@@ -106,6 +113,21 @@ int controller_util_get_address(const char **address)
        return 0;
 }
 
+int controller_util_get_log_type(int *type)
+{
+       retv_if(!type, -1);
+
+       if (controller_util.log_type < 0) {
+               int ret = -1;
+               ret = _read_conf_file();
+               retv_if(-1 == ret, -1);
+       }
+
+       *type = controller_util.log_type;
+
+       return 0;
+}
+
 void controller_util_free(void)
 {
        if (controller_util.path) {
diff --git a/src/log.c b/src/log.c
new file mode 100644 (file)
index 0000000..b86e188
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,136 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <app_common.h>
+#include "log.h"
+
+#define MAX_LOG_SIZE 4096
+#define PATH_MAX 4096
+
+static FILE *log_fp = NULL;
+static log_type ltype = LOG_TYPE_DLOG;
+
+static const char log_prio_name[][DLOG_PRIO_MAX-1] = {
+       "UNKNOWN",
+       "DEFAULT", /**< Default */
+       "VERBOSE", /**< Verbose */
+       "DEBUG", /**< Debug */
+       "INFO", /**< Info */
+       "WARN", /**< Warning */
+       "ERROR", /**< Error */
+       "FATAL", /**< Fatal */
+       "SILENT" /**< Silent */
+};
+
+static inline char* getFormattedTime(void)
+{
+       struct timeval val;
+       struct tm *ptm;
+       static char res_time[40] = {0, };
+
+       gettimeofday(&val, NULL);
+       ptm = localtime(&val.tv_sec);
+
+       // format : YYMMDDhhmmssuuuuuu
+       snprintf(res_time, sizeof(res_time), "%04d-%02d-%02d %02d:%02d:%02d:%06ld"
+               , ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday
+               , ptm->tm_hour, ptm->tm_min, ptm->tm_sec
+               , val.tv_usec);
+
+       return res_time;
+}
+
+static int __open_log_file(void)
+{
+       char buf[PATH_MAX] = {0,};
+       char *prefix = NULL;
+
+       prefix = app_get_data_path();
+
+       if (!prefix)
+               goto error;
+
+       snprintf(buf, sizeof(buf)-1, "%s%s", prefix, "log.txt");
+       free(prefix);
+
+       log_fp = fopen(buf, "a"); /* append or create new ??? */
+       if (log_fp == NULL) {
+               dlog_print(DLOG_WARN, LOG_TAG, "%s\n", strerror(errno));
+               goto error;
+       }
+
+       return 0;
+
+error:
+       dlog_print(DLOG_WARN, LOG_TAG, "error to use log file, so use dlog as log system\n");
+       ltype = LOG_TYPE_DLOG;
+       return -1;
+}
+
+int log_type_set(log_type type)
+{
+       ltype = type;
+       dlog_print(DLOG_DEBUG, LOG_TAG, "setting log type : [%d]\n", type);
+       switch (type) {
+       case LOG_TYPE_FILE:
+       case LOG_TYPE_ALL:
+               __open_log_file();
+               break;
+       case LOG_TYPE_DLOG: /* nothing to do */
+       default:
+               ltype = LOG_TYPE_DLOG;
+               break;
+       }
+       return 0;
+}
+
+void log_file_close(void)
+{
+       if (log_fp) {
+               fclose(log_fp);
+               log_fp = NULL;
+               dlog_print(DLOG_DEBUG, LOG_TAG, "close log file\n");
+       }
+
+       return;
+}
+
+int log_print(log_priority prio, const char *tag, const char *fmt, ...)
+{
+       va_list ap;
+
+       switch (ltype) {
+       case LOG_TYPE_FILE:
+               if (log_fp) {
+                       va_start(ap, fmt);
+                       fprintf(log_fp, "[%s] [%s]", getFormattedTime(), log_prio_name[prio]);
+                       vfprintf(log_fp, fmt, ap);
+                       va_end(ap);
+                       fflush(log_fp);
+               }
+               break;
+       case LOG_TYPE_ALL:
+               va_start(ap, fmt);
+               if (log_fp) {
+                       fprintf(log_fp, "[%s] [%s]", getFormattedTime(), log_prio_name[prio]);
+                       vfprintf(log_fp, fmt, ap);
+               }
+               dlog_vprint(prio, tag, fmt, ap);
+               va_end(ap);
+
+               if (log_fp)
+                       fflush(log_fp);
+               break;
+       case LOG_TYPE_DLOG:
+       default:
+               va_start(ap, fmt);
+               dlog_vprint(prio, tag, fmt, ap);
+               va_end(ap);
+               break;
+       }
+       return 0;
+}
index 2354522ef182832d42eca980f86be99cff99e798..777c14e97b5bb39ed8fa13bdf2d42e6f34dace28 100644 (file)
@@ -43,4 +43,5 @@ void resource_close_all(void)
        }
        resource_close_illuminance_sensor();
        resource_close_sound_level_sensor();
+       resource_close_co2_sensor();
 }
diff --git a/src/resource/resource_co2_sensor.c b/src/resource/resource_co2_sensor.c
new file mode 100644 (file)
index 0000000..946023e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+#include "resource/resource_adc_mcp3008.h"
+
+static bool initialized = false;
+
+void resource_close_co2_sensor(void)
+{
+       resource_adc_mcp3008_fini();
+       initialized = false;
+}
+
+int resource_read_co2_sensor(int ch_num, unsigned int *out_value)
+{
+       unsigned int read_value = 0;
+       int ret = 0;
+
+       if (!initialized) {
+               ret = resource_adc_mcp3008_init();
+               retv_if(ret != 0, -1);
+               initialized = true;
+       }
+       ret = resource_read_adc_mcp3008(ch_num, &read_value);
+       retv_if(ret != 0, -1);
+
+       *out_value = read_value;
+
+       return 0;
+}
+
index ec30f784345ac1fee32b33f004fe814a9f17138f..1eb21697ff7dfb81b4bbad40c0856bfc9bbf61b2 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_flame_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_flame_sensor(int pin_num, uint32_t *out_value)
+int resource_read_flame_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index 0f7d0c734b39eef13cb0aa95f89f6689cba97b5e..49e5ab5ce5b7e6db29f293fc28c94982318f32cb 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_gas_detection_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value)
+int resource_read_gas_detection_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
@@ -51,7 +51,6 @@ int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value)
                resource_get_info(pin_num)->close = resource_close_gas_detection_sensor;
        }
 
-
        /**
         * This model(FC-22) normally outputs 1, and outputs 0 as out_value when a flame is detected.
         */
index 1bbf6620827f2b21f7c6e6529d8db23a3dfb4dd4..e02d642027693e8b50afddd9bd6e469e74e3e48a 100644 (file)
@@ -47,7 +47,7 @@ void resource_close_illuminance_sensor(void)
        resource_sensor_s.opened = 0;
 }
 
-int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value)
+int resource_read_illuminance_sensor(int i2c_bus, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
        unsigned char buf[10] = { 0, };
index 460fa45135881da0d7c3e1d9339176dfadeabee5..82940584d7176213c272e22f96988ae9c08ea8f3 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_infrared_motion_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
+int resource_read_infrared_motion_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index bb2c3420922f564c2b625fad1b8553960078f8dd..8bcfc0a1593ce307d753cca4b2882b8c76ed561c 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_infrared_obstacle_avoidance_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value)
+int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
@@ -56,5 +56,7 @@ int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_
 
        _I("Infrared Obstacle Avoidance Sensor Value : %d", *out_value);
 
+       *out_value = !*out_value;
+
        return 0;
 }
index 93ba5445a4d7d268d4b28c93a96c61fbcf305e2b..5e2ee598a3c99960806b77acb06f6faaba99f894 100644 (file)
  * limitations under the License.
  */
 
- #include <stdlib.h>
- #include <unistd.h>
+#include <stdlib.h>
+#include <unistd.h>
 
- #include "log.h"
- #include "resource_internal.h"
+#include "log.h"
+#include "resource_internal.h"
 
- void resource_close_rain_sensor(int pin_num)
- {
-        if (!resource_get_info(pin_num)->opened) return;
+void resource_close_rain_sensor(int pin_num)
+{
+       if (!resource_get_info(pin_num)->opened) return;
 
-        _I("Rain Sensor is finishing...");
-        peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
-        resource_get_info(pin_num)->opened = 0;
- }
+       _I("Rain Sensor is finishing...");
+       peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
+       resource_get_info(pin_num)->opened = 0;
+}
 
- int resource_read_rain_sensor(int pin_num, uint32_t *out_value)
- {
-        int ret = PERIPHERAL_ERROR_NONE;
+int resource_read_rain_sensor(int pin_num, unsigned int *out_value)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
 
-        if (!resource_get_info(pin_num)->opened) {
-                ret = peripheral_gpio_open(pin_num, &resource_get_info(pin_num)->sensor_h);
-                retv_if(!resource_get_info(pin_num)->sensor_h, -1);
+       if (!resource_get_info(pin_num)->opened) {
+               ret = peripheral_gpio_open(pin_num, &resource_get_info(pin_num)->sensor_h);
+               retv_if(!resource_get_info(pin_num)->sensor_h, -1);
 
-                ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
-                retv_if(ret != 0, -1);
+               ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+               retv_if(ret != 0, -1);
 
-                resource_get_info(pin_num)->opened = 1;
-                resource_get_info(pin_num)->close = resource_close_flame_sensor;
-        }
+               resource_get_info(pin_num)->opened = 1;
+               resource_get_info(pin_num)->close = resource_close_flame_sensor;
+       }
 
-        /**
-         * This model(FC-37 + YL-38) normally outputs 1, and outputs 0 as out_value when a rain is detected.
-         */
-        ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
-        retv_if(ret < 0, -1);
+       /**
+        * This model(FC-37 + YL-38) normally outputs 1, and outputs 0 as out_value when a rain is detected.
+        */
+       ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
+       retv_if(ret < 0, -1);
 
-        *out_value = !*out_value;
+       *out_value = !*out_value;
 
-        return 0;
- }
+       return 0;
+}
index c03c7b88ef3f0ab444e32056ac09ecf32f76b22d..5225891c457d29fc72d6d1ce72cf942a4605bf40 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_sound_detection_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_sound_detection_sensor(int pin_num, uint32_t *out_value)
+int resource_read_sound_detection_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index f47c3c735908ce590fd053fe30df478ed3a379b3..66516964d6503cf4a1bf039bfef7e477292660b3 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_tilt_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_tilt_sensor(int pin_num, uint32_t *out_value)
+int resource_read_tilt_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index fc946e43803b4bf879b252f6c6a0f78c16722d1b..3d122310b8bbeb187cc46655a834b4fc2eedd0d2 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_touch_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_touch_sensor(int pin_num, uint32_t *out_value)
+int resource_read_touch_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index 4a9b035a68e83d97fe40ddb0d4ba8f100ec30d55..550caf69e7e7553a28415d549f7ca22f6f4fab73 100644 (file)
@@ -28,9 +28,6 @@
 #include "log.h"
 #include "resource_internal.h"
 
-static resource_read_s *resource_read_info = NULL;
-static unsigned long long triggered_time = 0;
-
 void resource_close_ultrasonic_sensor_trig(int trig_pin_num)
 {
        if (!resource_get_info(trig_pin_num)->opened) return;
@@ -49,8 +46,6 @@ void resource_close_ultrasonic_sensor_echo(int echo_pin_num)
 
        peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
        resource_get_info(echo_pin_num)->opened = 0;
-       free(resource_read_info);
-       resource_read_info = NULL;
 }
 
 static unsigned long long _get_timestamp(void)
@@ -64,7 +59,8 @@ static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripher
 {
        float dist = 0;
        uint32_t value;
-       unsigned long long returned_time = 0;
+       static unsigned long long prev = 0;
+       unsigned long long now = _get_timestamp();
        resource_read_s *resource_read_info = user_data;
 
        ret_if(!resource_read_info);
@@ -72,36 +68,26 @@ static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripher
 
        peripheral_gpio_read(gpio, &value);
 
-       if (value == 1) {
-               triggered_time = _get_timestamp();
-       } else if (value == 0) {
-               returned_time = _get_timestamp();
-       }
-
-       if (triggered_time > 0 && value == 0) {
-               dist = returned_time - triggered_time;
-               if (dist < 150 || dist > 25000) {
-                       dist = -1;
-               } else {
-                       dist = (dist * 34300) / 2000000;
-               }
+       if (prev > 0 && value == 0) {
+               dist = now - prev;
+               dist = (dist * 34300) / 2000000;
+               _I("Measured Distance : %0.2fcm\n", dist);
 
                resource_read_info->cb(dist, resource_read_info->data);
+               peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
+               free(resource_read_info);
        }
+
+       prev = now;
 }
 
 int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data)
 {
        int ret = 0;
+       resource_read_s *resource_read_info = NULL;
 
-       triggered_time = 0;
-
-       if (resource_read_info == NULL) {
-               resource_read_info = calloc(1, sizeof(resource_read_s));
-               retv_if(!resource_read_info, -1);
-       } else {
-               peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
-       }
+       resource_read_info = calloc(1, sizeof(resource_read_s));
+       retv_if(!resource_read_info, -1);
        resource_read_info->cb = cb;
        resource_read_info->data = data;
        resource_read_info->pin_num = echo_pin_num;
@@ -143,13 +129,9 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource
        ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0);
        retv_if(ret < 0, -1);
 
-       usleep(20000);
-
        ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 1);
        retv_if(ret < 0, -1);
 
-       usleep(20000);
-
        ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0);
        retv_if(ret < 0, -1);
 
index 686e8f7df6c9a3c5a8b6d76e3f0fc40e357760b8..0e3ad1b4badd7e3de5fe84d8e67f595d95599113 100644 (file)
@@ -36,7 +36,7 @@ void resource_close_vibration_sensor(int pin_num)
        resource_get_info(pin_num)->opened = 0;
 }
 
-int resource_read_vibration_sensor(int pin_num, uint32_t *out_value)
+int resource_read_vibration_sensor(int pin_num, unsigned int *out_value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
index f498071936093e310e221a4b287ee7678cf13cf4..1054d06bc5d1b3be3005ae829d10499175051cf2 100644 (file)
@@ -367,6 +367,7 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_
        const char n_gas[] = "Gas";
        const char n_e_sensor[] = "SensorEnabled";
        const char n_hash[] = "Hash";
+       const char n_ip[] = "SensorPiIP";
 
        retv_if(!sensorpi_id, -1);
        retv_if(Json_h.builder == NULL, -1);
@@ -377,6 +378,7 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_
        /* JSON structure :
        {
                SensorPiID: string,
+               SensorPiIP: string,
                Motion: boolean,
                Flame: boolean,
                Humidity: double,
@@ -403,6 +405,11 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_
        json_builder_set_member_name(Json_h.builder, n_id);
        json_builder_add_string_value(Json_h.builder, sensorpi_id);
 
+       if (sensor_data->ip_addr) {
+               json_builder_set_member_name(Json_h.builder, n_ip);
+               json_builder_add_string_value(Json_h.builder, sensor_data->ip_addr);
+       }
+
        if (sensor_data->enabled_sensor & WEB_UTIL_SENSOR_MOTION) {
                json_builder_set_member_name(Json_h.builder, n_motion);
                json_builder_add_int_value(Json_h.builder, sensor_data->motion);
index 4238b66df80db42c43845c6a996faae84e132d60..b543222f2c41a0e55ef82265a8831cfc38929ab7 100644 (file)
@@ -6,9 +6,11 @@
         <icon>position-finder-server.png</icon>
     </service-application>
     <privileges>
-        <privilege>http://tizen.org/privilege/appdir.shareddata</privilege>
         <privilege>http://tizen.org/privilege/network.get</privilege>
+        <privilege>http://tizen.org/privilege/network.set</privilege>
         <privilege>http://tizen.org/privilege/internet</privilege>
+        <privilege>http://tizen.org/privilege/alarm.set</privilege>
+        <privilege>http://tizen.org/privilege/network.profile</privilege>
         <privilege>http://tizen.org/privilege/peripheralio</privilege>
     </privileges>
 </manifest>