From 2b84281cf78986fe838c03fd39d72a9830c51486 Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Tue, 26 Sep 2017 15:23:27 +0900 Subject: [PATCH] Change peripheral io APIs Change-Id: I1910aeda0d15153e7eaebe34ded79cb534fbd63c --- CMakeLists.txt | 51 ++++----- inc/connectivity.h | 42 +++++++- inc/resource.h | 1 + inc/resource/resource_illuminance_sensor.h | 8 +- .../resource_illuminance_sensor_internal.h | 3 + inc/resource/resource_infrared_motion_sensor.h | 9 +- .../resource_infrared_motion_sensor_internal.h | 6 +- .../resource_infrared_obstacle_avoidance_sensor.h | 9 +- ...e_infrared_obstacle_avoidance_sensor_internal.h | 4 + inc/{webnotify.h => resource/resource_led.h} | 16 +-- inc/resource/resource_led_internal.h | 27 +++++ inc/resource/resource_touch_sensor.h | 7 ++ inc/resource/resource_touch_sensor_internal.h | 4 + inc/resource/resource_ultrasonic_sensor.h | 9 ++ inc/resource/resource_ultrasonic_sensor_internal.h | 8 +- inc/resource_internal.h | 1 + packaging/org.tizen.position-finder-server.spec | 55 +++++++--- src/connectivity.c | 84 ++++++++++++++- src/controller.c | 59 ++++++---- src/controller_internal.c | 10 -- src/resource/resource_illuminance_sensor.c | 7 +- src/resource/resource_infrared_motion_sensor.c | 2 +- .../resource_infrared_obstacle_avoidance_sensor.c | 2 +- src/resource/resource_led.c | 58 ++++++++++ src/resource/resource_touch_sensor.c | 2 +- src/resource/resource_ultrasonic_sensor.c | 45 +++++--- src/webnotify.c | 120 --------------------- tizen-manifest.xml => tizen-manifest.xml.in | 8 +- 28 files changed, 415 insertions(+), 242 deletions(-) rename inc/{webnotify.h => resource/resource_led.h} (63%) mode change 100755 => 100644 create mode 100644 inc/resource/resource_led_internal.h create mode 100644 src/resource/resource_led.c delete mode 100755 src/webnotify.c rename tizen-manifest.xml => tizen-manifest.xml.in (66%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86f207f..a2cfc40 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(position-finder-server C) +PROJECT(${P_NAME} C) SET(INSTALL_EXEC_PREFIX "${INSTALL_PREFIX}/bin") -SET(INSTALL_RESDIR "${INSTALL_PREFIX}/res") -SET(INSTALL_DATADIR "/home/owner/apps_rw/org.tizen.position-finder-server/data") SET(CMAKE_VERBOSE_MAKEFILE 0) SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}") SET(PROJECT_RESOURCES_DIR "${PROJECT_ROOT_DIR}/res") -#disable web notify -#SET(PF_TYPE "Zarie-web") - -MESSAGE("position-finder-server type: ${PF_TYPE}") - -SET(CHECK_MODULES +INCLUDE(FindPkgConfig) +pkg_check_modules(APP_PKGS REQUIRED dlog + aul capi-appfw-application capi-appfw-service-application capi-system-peripheral-io ecore + eina iotcon + gio-2.0 ) -IF("${PF_TYPE}" STREQUAL "Zarie-web") - SET(CHECK_MODULES ${CHECK_MODULES} - libcurl - glib-2.0 - ) -ADD_DEFINITIONS (-DENABLE_WEBNOTIFY - -DTEST_RES_URI=\"http://10.113.63.43:8080\" -) -ENDIF("${PF_TYPE}" STREQUAL "Zarie-web") - -INCLUDE(FindPkgConfig) -pkg_check_modules(APP_PKGS REQUIRED ${CHECK_MODULES}) +ADD_DEFINITIONS(-DCBOR_FILE_IN_RES="${INSTALL_RESDIR}/${CBOR_FILE}") +ADD_DEFINITIONS(-DCBOR_FILE_IN_DATA="${INSTALL_OWNER_DATADIR}/${CBOR_FILE}") +ADD_DEFINITIONS(-DCONF_FILE="${INSTALL_OWNER_DATADIR}/${CONF_FILE}") FOREACH (flag ${APP_PKGS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -46,7 +34,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc) -SET(SRCS +ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_ROOT_DIR}/src/controller.c ${PROJECT_ROOT_DIR}/src/controller_internal.c ${PROJECT_ROOT_DIR}/src/connectivity.c @@ -56,23 +44,20 @@ SET(SRCS ${PROJECT_ROOT_DIR}/src/resource/resource_infrared_obstacle_avoidance_sensor.c ${PROJECT_ROOT_DIR}/src/resource/resource_touch_sensor.c ${PROJECT_ROOT_DIR}/src/resource/resource_ultrasonic_sensor.c + ${PROJECT_ROOT_DIR}/src/resource/resource_led.c ) -IF("${PF_TYPE}" STREQUAL "Zarie-web") - SET(SRCS ${SRCS} ${PROJECT_ROOT_DIR}/src/webnotify.c) -ENDIF("${PF_TYPE}" STREQUAL "Zarie-web") - -ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} ) - TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS}) +Message("APP_LABEL : ${APP_LABEL}") + +CONFIGURE_FILE(${PROJECT_ROOT_DIR}/tizen-manifest.xml.in ${ORG_PREFIX}.${PROJECT_NAME}.xml @ONLY) # Install INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX}) - -INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.position-finder-server.xml) -INSTALL(DIRECTORY DESTINATION ${PREFIX}/data) -INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/position_finder_server.png DESTINATION ${SYS_ICONS_DIR}) -INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-server.dat DESTINATION ${INSTALL_DATADIR}) +INSTALL(DIRECTORY DESTINATION ${INSTALL_OWNER_DATADIR}) +INSTALL(FILES ${ORG_PREFIX}.${PROJECT_NAME}.xml DESTINATION ${SYS_PACKAGES_DIR}) +INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/default_icon.png DESTINATION ${SYS_ICONS_DIR} RENAME ${PROJECT_NAME}.png) +INSTALL(FILES ${PROJECT_ROOT_DIR}/res/${CBOR_FILE} DESTINATION ${INSTALL_RESDIR}) # End of a file diff --git a/inc/connectivity.h b/inc/connectivity.h index 7b21043..daa1784 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -31,11 +31,51 @@ struct connectivity_resource { typedef struct connectivity_resource connectivity_resource_s; -extern int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info); +/** + * @brief Create connectivity resource and registers the resource in server. + * @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 specific clients that resource's attributes have changed with boolean value. + * @param[in] resource_info A structure containing information about connectivity resource + * @param[in] key A new key to be added into attributes + * @param[in] value A boolean value to be added into attributes + * @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 specific clients that resource's attributes have changed with int value. + * @param[in] resource_info A structure containing information about connectivity resource + * @param[in] key A new key to be added into attributes + * @param[in] value A int value to be added into attributes + * @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 specific clients that resource's attributes have changed with double value. + * @param[in] resource_info A structure containing information about connectivity resource + * @param[in] key A new key to be added into attributes + * @param[in] value A double value to be added into attributes + * @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); #endif /* __POSITION_FINDER_CONNECTIVITY_H__ */ diff --git a/inc/resource.h b/inc/resource.h index 512b896..b2d22ef 100644 --- a/inc/resource.h +++ b/inc/resource.h @@ -30,5 +30,6 @@ #include "resource/resource_infrared_obstacle_avoidance_sensor.h" #include "resource/resource_touch_sensor.h" #include "resource/resource_ultrasonic_sensor.h" +#include "resource/resource_led.h" #endif /* __POSITION_FINDER_RESOURCE_H__ */ diff --git a/inc/resource/resource_illuminance_sensor.h b/inc/resource/resource_illuminance_sensor.h index 4203ebe..f3329a5 100644 --- a/inc/resource/resource_illuminance_sensor.h +++ b/inc/resource/resource_illuminance_sensor.h @@ -22,7 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ -/* You have to use this illuminance sensor ONLY ONE in the pi board */ +/** + * @brief Reads the value of i2c bus connected illuminance sensor. + * @param[in] i2c_bus The i2c bus number that the slave device is connected + * @param[out] out_value The value read by the illuminance sensor + * @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, int *out_value); #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_illuminance_sensor_internal.h b/inc/resource/resource_illuminance_sensor_internal.h index bdcf255..3193a5b 100644 --- a/inc/resource/resource_illuminance_sensor_internal.h +++ b/inc/resource/resource_illuminance_sensor_internal.h @@ -22,6 +22,9 @@ #ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ +/** + * @brief Destory the i2c handle and changes the gpio pin state to the close(0). + */ extern void resource_close_illuminance_sensor(void); #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_infrared_motion_sensor.h b/inc/resource/resource_infrared_motion_sensor.h index 7914678..65bdda7 100644 --- a/inc/resource/resource_infrared_motion_sensor.h +++ b/inc/resource/resource_infrared_motion_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ -extern int resource_read_infrared_motion_sensor(int pin_num, int *out_value); +/** + * @brief Reads the value of gpio connected infrared motion sensor(HC-SR501). + * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor + * @param[out] out_value The value of the gpio (zero or non-zero) + * @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); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_motion_sensor_internal.h b/inc/resource/resource_infrared_motion_sensor_internal.h index 773ada5..3737e15 100644 --- a/inc/resource/resource_infrared_motion_sensor_internal.h +++ b/inc/resource/resource_infrared_motion_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ -extern void resource_close_infrared_motion_sensor(int sensor_index); +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor + */ +extern void resource_close_infrared_motion_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h index 640bc40..549b135 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ -extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value); +/** + * @brief Reads the value of gpio connected infrared obstacle avoidance sensor. + * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor + * @param[out] out_value The value of the gpio (zero or non-zero) + * @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); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h index 0e6e44e..f52cdf1 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor + */ extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ */ diff --git a/inc/webnotify.h b/inc/resource/resource_led.h old mode 100755 new mode 100644 similarity index 63% rename from inc/webnotify.h rename to inc/resource/resource_led.h index 7f415d0..aef79ae --- a/inc/webnotify.h +++ b/inc/resource/resource_led.h @@ -5,7 +5,6 @@ * Geunsun Lee * Eunyoung Lee * Junkyu Han - * Jeonghoon Park * * Licensed under the Flora License, Version 1.1 (the License); * you may not use this file except in compliance with the License. @@ -20,16 +19,9 @@ * limitations under the License. */ +#ifndef __POSITION_FINDER_RESOURCE_LED_H__ +#define __POSITION_FINDER_RESOURCE_LED_H__ -#ifndef __POSITION_FINDER_WEBNOTIFY_H__ -#define __POSITION_FINDER_WEBNOTIFY_H__ - -int web_notify_init(void); -void web_notify_fini(void); -int web_notify_data(const char *resource, const char *data); -int web_notify_bool(const char *resource, bool value); -int web_notify_int(const char *resource, int value); -int web_notify_double(const char *resource, double value); - -#endif /* __POSITION_FINDER_WEBNOTIFY_H__ */ +extern int resource_write_led(int pin_num, int write_value); +#endif /* __POSITION_FINDER_RESOURCE_LED_H__ */ diff --git a/inc/resource/resource_led_internal.h b/inc/resource/resource_led_internal.h new file mode 100644 index 0000000..7073f17 --- /dev/null +++ b/inc/resource/resource_led_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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_LED_INTERNAL_H__ +#define __POSITION_FINDER_RESOURCE_LED_INTERNAL_H__ + +extern void resource_close_led(int pin_num); + +#endif /* __POSITION_FINDER_RESOURCE_LED_INTERNAL_H__ */ diff --git a/inc/resource/resource_touch_sensor.h b/inc/resource/resource_touch_sensor.h index f6f31db..2cd76d2 100644 --- a/inc/resource/resource_touch_sensor.h +++ b/inc/resource/resource_touch_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ +/** + * @brief Reads the value of gpio connected touch sensor. + * @param[in] pin_num The number of the gpio pin connected to the touch sensor + * @param[out] out_value The value of the gpio (zero or non-zero) + * @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, int *out_value); #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */ diff --git a/inc/resource/resource_touch_sensor_internal.h b/inc/resource/resource_touch_sensor_internal.h index dcd0e09..3bde69b 100644 --- a/inc/resource/resource_touch_sensor_internal.h +++ b/inc/resource/resource_touch_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the touch sensor + */ extern void resource_close_touch_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_ultrasonic_sensor.h b/inc/resource/resource_ultrasonic_sensor.h index e2956b4..cfcfe64 100644 --- a/inc/resource/resource_ultrasonic_sensor.h +++ b/inc/resource/resource_ultrasonic_sensor.h @@ -22,6 +22,15 @@ #ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ +/** + * @brief Reads the value of gpio connected ultrasonic sensor(HC-SR04). + * @param[in] trig_pin_num The number of the gpio pin connected to the trig of the ultrasonic sensor + * @param[in] echo_pin_num The number of the gpio pin connected to the echo of the ultrasonic sensor + * @param[in] cb A callback function to be invoked when the gpio interrupt is triggered + * @param[in] data The data to be passed to the callback function + * @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_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data); #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ */ diff --git a/inc/resource/resource_ultrasonic_sensor_internal.h b/inc/resource/resource_ultrasonic_sensor_internal.h index bf86d73..efd5436 100644 --- a/inc/resource/resource_ultrasonic_sensor_internal.h +++ b/inc/resource/resource_ultrasonic_sensor_internal.h @@ -22,6 +22,12 @@ #ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ -extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num); +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] trig_pin_num The number of the gpio pin connected to the trig of the ultrasonic sensor + * @param[in] echo_pin_num The number of the gpio pin connected to the echo of the ultrasonic sensor + */ +extern void resource_close_ultrasonic_sensor_trig(int trig_pin_num); +extern void resource_close_ultrasonic_sensor_echo(int echo_pin_num); #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource_internal.h b/inc/resource_internal.h index 48cd1a3..5ef6cce 100644 --- a/inc/resource_internal.h +++ b/inc/resource_internal.h @@ -29,6 +29,7 @@ #include "resource/resource_infrared_obstacle_avoidance_sensor_internal.h" #include "resource/resource_touch_sensor_internal.h" #include "resource/resource_ultrasonic_sensor_internal.h" +#include "resource/resource_led_internal.h" #define PIN_MAX 40 diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec index 0477e94..1487fb0 100755 --- a/packaging/org.tizen.position-finder-server.spec +++ b/packaging/org.tizen.position-finder-server.spec @@ -1,23 +1,28 @@ -Name: org.tizen.position-finder-server -%define alias org.tizen.position-finder-server +%define P_NAME position-finder-server +%define APP_LABEL "Position Finder Server" +%define ORG_PREFIX org.tizen + +Name: %{ORG_PREFIX}.%{P_NAME} +%define alias %{name} Summary: IoTivity Application Group: Applications/Core Applications Version: 0.0.1 Release: 1 License: Flora-1.1 -Provides: org.tizen.position-finder-server = %{version}-%{release} +Provides: %{name} = %{version}-%{release} Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: hash-signer BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-appfw-service-application) BuildRequires: pkgconfig(capi-system-peripheral-io) BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(eina) BuildRequires: pkgconfig(iotcon) -BuildRequires: pkgconfig(libcurl) -BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) %description Server for Position Finder @@ -30,10 +35,13 @@ Server for Position Finder %define _pkg_dir %{TZ_SYS_RO_APP}/%{alias} %define _pkg_shared_dir %{_pkg_dir}/shared %define _pkg_data_dir %{_pkg_dir}/data -%define _pkg_rw_data_dir /home/owner/apps_rw/org.tizen.position-finder-server/data +%define _pkg_rw_data_dir /home/owner/apps_rw/%{alias}/data +%define _pkg_res_dir %{_pkg_dir}/res %define _sys_icons_dir %{_pkg_shared_dir}/res %define _sys_packages_dir %{TZ_SYS_RO_PACKAGES} %define _sys_license_dir %{TZ_SYS_SHARE}/license +%define _cbor_file iotcon-test-svr-db-server.dat +%define _conf_file .dev_id %ifarch %{arm} export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET" @@ -45,9 +53,16 @@ export CXXFLAGS="$CXXFLAGS -DTIZEN_BUILD_EMULATOR" export FFLAGS="$FFLAGS -DTIZEN_BUILD_EMULATOR" %endif -cmake . -DINSTALL_PREFIX=%{_pkg_dir} \ +cmake . -DP_NAME=%{P_NAME} \ + -DORG_PREFIX=%{ORG_PREFIX} \ + -DAPP_LABEL=%{APP_LABEL} \ + -DINSTALL_PREFIX=%{_pkg_dir} \ + -DINSTALL_OWNER_DATADIR=%{_pkg_rw_data_dir} \ + -DINSTALL_RESDIR=%{_pkg_res_dir} \ -DSYS_ICONS_DIR=%{_sys_icons_dir} \ - -DSYS_PACKAGES_DIR=%{_sys_packages_dir} + -DSYS_PACKAGES_DIR=%{_sys_packages_dir} \ + -DCBOR_FILE=%{_cbor_file} \ + -DCONF_FILE=%{_conf_file} make %{?jobs:-j%jobs} %install @@ -62,18 +77,28 @@ make %{?jobs:-j%jobs} %post /sbin/ldconfig -chsmack -a "User::Pkg::org.tizen.position-finder-server" %{_pkg_rw_data_dir}/*.dat +chsmack -a "User::Pkg::%{alias}" %{_pkg_res_dir}/*.dat +chmod 444 %{_pkg_res_dir}/*.dat + +touch %{_pkg_rw_data_dir}/%{_cbor_file} +chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/*.dat chmod 666 %{_pkg_rw_data_dir}/*.dat +# This routine will be used in the file of .dev_id. +#touch %{_pkg_rw_data_dir}/%{_conf_file} +#echo "/door/777" > %{_pkg_rw_data_dir}/%{_conf_file} +#chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/%{_conf_file} +#chmod 444 %{_pkg_rw_data_dir}/%{_conf_file} + %postun -p /sbin/ldconfig %files -%manifest org.tizen.position-finder-server.manifest -%{_pkg_rw_data_dir}/*.dat -/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat +%{_pkg_res_dir}/*.dat +%manifest %{alias}.manifest %defattr(-,root,root,-) -%{_pkg_dir}/bin/position-finder-server -%{_sys_packages_dir}/org.tizen.position-finder-server.xml -%{_sys_icons_dir}/position_finder_server.png +%{_pkg_rw_data_dir} +%{_pkg_dir}/bin/%{P_NAME} +%{_sys_packages_dir}/%{alias}.xml +%{_sys_icons_dir}/*.png %{_pkg_dir}/author-signature.xml %{_pkg_dir}/signature1.xml diff --git a/src/connectivity.c b/src/connectivity.c index eb281f1..5065735 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -19,6 +19,7 @@ * limitations under the License. */ +#include #include #include #include @@ -29,9 +30,9 @@ #include "log.h" #include "connectivity.h" -#define ULTRASONIC_RESOURCE_1_URI "/door/1" -#define ULTRASONIC_RESOURCE_2_URI "/door/2" #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" +#define BUFSIZE 1024 +#define URI_PATH_LEN 64 static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data); @@ -86,7 +87,7 @@ static iotcon_representation_h _create_representation_with_bool(iotcon_resource_ ret = iotcon_representation_set_uri_path(representation, uri_path); goto_if(IOTCON_ERROR_NONE != ret, error); - ret = iotcon_attributes_add_bool(attributes, "opened", value); + ret = iotcon_attributes_add_bool(attributes, key, value); goto_if(IOTCON_ERROR_NONE != ret, error); ret = iotcon_representation_set_attributes(representation, attributes); @@ -302,12 +303,16 @@ static int _handle_observer(iotcon_request_h request, iotcon_observers_h observe 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); } @@ -343,11 +348,46 @@ error: _send_response(request, NULL, IOTCON_RESPONSE_ERROR); } +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); +} + int connectivity_init(void) { int ret = -1; - ret = iotcon_initialize("/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat"); + _copy_file(CBOR_FILE_IN_RES, CBOR_FILE_IN_DATA); + + ret = iotcon_initialize(CBOR_FILE_IN_DATA); retv_if(IOTCON_ERROR_NONE != ret, -1); ret = iotcon_set_device_name(ULTRASONIC_RESOURCE_TYPE); @@ -374,6 +414,28 @@ void connectivity_unset_resource(connectivity_resource_s *resource_info) free(resource_info); } +static int _get_default_uri_path_in_conf(char *buf, int size) +{ + FILE *in = NULL; + size_t nread = 0; + + in = fopen(CONF_FILE, "r"); + retv_if(!in, -1); + + nread = fread(buf, 1, size, in); + if (nread <= 0) { + _I("No contents in the conf."); + return -1; + } + + if (buf[nread - 1] == '\n') + buf[nread - 1] = '\0'; + + fclose(in); + + return 0; +} + int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info) { iotcon_resource_types_h resource_types = NULL; @@ -381,6 +443,18 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi connectivity_resource_s *resource_info = NULL; uint8_t policies; int ret = -1; + const char *final_uri_path = NULL; + char default_uri_path[URI_PATH_LEN] = { 0, }; + + if (uri_path) { + final_uri_path = uri_path; + } else { + ret = _get_default_uri_path_in_conf(default_uri_path, URI_PATH_LEN); + retv_if(ret < 0, -1); + final_uri_path = default_uri_path; + } + + _D("uri path : [%s]", final_uri_path); resource_info = calloc(1, sizeof(connectivity_resource_s)); retv_if(!resource_info, -1); @@ -406,7 +480,7 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi IOTCON_RESOURCE_OBSERVABLE | IOTCON_RESOURCE_SECURE; - ret = iotcon_resource_create(uri_path, + ret = iotcon_resource_create(final_uri_path, resource_types, ifaces, policies, diff --git a/src/controller.c b/src/controller.c index da4b439..ab34528 100755 --- a/src/controller.c +++ b/src/controller.c @@ -20,11 +20,11 @@ * limitations under the License. */ -#include -#include -#include #include #include +#include +#include +#include #include // Please remove this after test @@ -33,13 +33,6 @@ #include "connectivity.h" #include "controller.h" -#ifdef ENABLE_WEBNOTIFY -#include "webnotify.h" -#ifndef RESOURCE_URI -#define RESOURCE_URI TEST_RES_URI -#endif /* RESOURCE_URI */ -#endif /* ENABLE_WEBNOTIFY */ - #define GPIO_ULTRASONIC_TRIG_NUM_1 20 #define GPIO_ULTRASONIC_ECHO_NUM_1 21 #define MULTIPLE_SENSOR_NUMBER 5 @@ -50,31 +43,40 @@ typedef struct app_data_s { connectivity_resource_s *resource_info; } app_data; -static Eina_Bool control_read_sensors_cb(void *data) +static Eina_Bool control_sensors_cb(void *data) { - int value[MULTIPLE_SENSOR_NUMBER] = { 0, }; + uint32_t value[MULTIPLE_SENSOR_NUMBER] = { 0, }; int total = 0; int gpio_num[MULTIPLE_SENSOR_NUMBER] = { 5, 6, 13, 19, 26 }; int i = 0; app_data *ad = data; + /** + * This is the case when a number of the same sensors are installed. + * Each of the five infrared motion sensors will receive the value. + */ for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) { + /** + * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is not detected. + */ if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) { _E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]); continue; } + /** + * If at least one of the five infrared motion sensors detects motion (1), + * it is judged that there is a person (total == 1). + */ total |= value[i]; } _I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total); + /** + * Notifies specific clients that resource's attributes have changed. + */ if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, total) == -1) _E("Cannot notify message"); -#ifdef ENABLE_WEBNOTIFY - if (web_notify_bool(RESOURCE_URI, total) == -1) - _E("Cannot notify web message"); -#endif /* ENABLE_WEBNOTIFY */ - return ECORE_CALLBACK_RENEW; } @@ -83,11 +85,23 @@ static bool service_app_create(void *data) app_data *ad = data; int ret = -1; + /** + * No modification required!!! + * Access only when modifying internal functions. + */ controller_init_internal_functions(); + + /** + * Create a connectivity resource and registers the resource in server. + */ ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info); if (ret == -1) _E("Cannot broadcast resource"); - ad->getter_timer = ecore_timer_add(0.5f, control_read_sensors_cb, ad); + /** + * Creates a timer to call the given function in the given period of time. + * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor. + */ + ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad); if (!ad->getter_timer) { _E("Failed to add infrared motion getter timer"); return false; @@ -106,7 +120,15 @@ static void service_app_terminate(void *data) } } + /** + * Releases the resource about connectivity. + */ connectivity_unset_resource(ad->resource_info); + + /** + * No modification required!!! + * Access only when modifying internal functions. + */ controller_fini_internal_functions(); free(ad); @@ -145,6 +167,7 @@ int main(int argc, char* argv[]) app_event_handler_h handlers[5] = {NULL, }; ad = calloc(1, sizeof(app_data)); + retv_if(!ad, -1); event_callback.create = service_app_create; event_callback.terminate = service_app_terminate; diff --git a/src/controller_internal.c b/src/controller_internal.c index 8c8e2d8..835066f 100755 --- a/src/controller_internal.c +++ b/src/controller_internal.c @@ -25,17 +25,10 @@ #include "log.h" #include "connectivity.h" #include "resource.h" -#ifdef ENABLE_WEBNOTIFY -#include "webnotify.h" -#endif /* ENABLE_WEBNOTIFY */ - void controller_init_internal_functions(void) { connectivity_init(); -#ifdef ENABLE_WEBNOTIFY - web_notify_init(); -#endif /* ENABLE_WEBNOTIFY */ } void controller_fini_internal_functions(void) @@ -43,7 +36,4 @@ void controller_fini_internal_functions(void) _I("Terminating..."); resource_close_all(); connectivity_fini(); -#ifdef ENABLE_WEBNOTIFY - web_notify_fini(); -#endif /* ENABLE_WEBNOTIFY */ } diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c index d5e2367..62e52be 100644 --- a/src/resource/resource_illuminance_sensor.c +++ b/src/resource/resource_illuminance_sensor.c @@ -42,7 +42,7 @@ void resource_close_illuminance_sensor(void) { if (!resource_sensor_s.opened) return; - _I("Infrared Motion Sensor is finishing..."); + _I("Illuminance Sensor is finishing..."); peripheral_i2c_close(resource_sensor_s.sensor_h); resource_sensor_s.opened = 0; } @@ -59,7 +59,8 @@ int resource_read_illuminance_sensor(int i2c_bus, int *out_value) resource_sensor_s.opened = 1; } - ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE); + buf[0] = GY30_CONT_HIGH_RES_MODE; + ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1); retv_if(ret < 0, -1); ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2); @@ -67,7 +68,7 @@ int resource_read_illuminance_sensor(int i2c_bus, int *out_value) *out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit - _I("Infrared Motion Sensor Value : %d", *out_value); + _I("Illuminance Sensor Value : %d", *out_value); return 0; } diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c index d20664f..d03c915 100644 --- a/src/resource/resource_infrared_motion_sensor.c +++ b/src/resource/resource_infrared_motion_sensor.c @@ -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, int *out_value) +int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c index bb57940..f802506 100644 --- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c +++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c @@ -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, int *out_value) +int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c new file mode 100644 index 0000000..19361f5 --- /dev/null +++ b/src/resource/resource_led.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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 +#include +#include + +#include "log.h" +#include "resource_internal.h" + +void resource_close_led(int pin_num) +{ + if (!resource_get_info(pin_num)->opened) return; + + _I("LED is finishing..."); + peripheral_gpio_close(resource_get_info(pin_num)->sensor_h); + resource_get_info(pin_num)->opened = 0; +} + +int resource_write_led(int pin_num, int write_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); + + ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); + retv_if(ret != 0, -1); + + resource_get_info(pin_num)->opened = 1; + } + + ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value); + retv_if(ret < 0, -1); + + _I("LED Value : %s", write_value ? "ON":"OFF"); + + return 0; +} diff --git a/src/resource/resource_touch_sensor.c b/src/resource/resource_touch_sensor.c index 2b75e62..3b54fd5 100644 --- a/src/resource/resource_touch_sensor.c +++ b/src/resource/resource_touch_sensor.c @@ -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, int *out_value) +int resource_read_touch_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c index 97e952f..550caf6 100644 --- a/src/resource/resource_ultrasonic_sensor.c +++ b/src/resource/resource_ultrasonic_sensor.c @@ -28,40 +28,57 @@ #include "log.h" #include "resource_internal.h" -void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num) +void resource_close_ultrasonic_sensor_trig(int trig_pin_num) { - if (!resource_get_info(echo_pin_num)->opened) return; if (!resource_get_info(trig_pin_num)->opened) return; - _I("Ultrasonic sensor is finishing..."); + _I("Ultrasonic sensor's trig is finishing..."); - peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h); peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h); + resource_get_info(trig_pin_num)->opened = 0; +} + +void resource_close_ultrasonic_sensor_echo(int echo_pin_num) +{ + if (!resource_get_info(echo_pin_num)->opened) return; + _I("Ultrasonic sensor's echo is finishing..."); + + peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h); resource_get_info(echo_pin_num)->opened = 0; - resource_get_info(trig_pin_num)->opened = 0; } -static void _resource_read_ultrasonic_sensor_cb(gpio_isr_cb_s *data, void *user_data) +static unsigned long long _get_timestamp(void) +{ + struct timespec t; + clock_gettime(CLOCK_REALTIME, &t); + return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000; +} + +static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data) { float dist = 0; - static unsigned long long timestamp = 0; + uint32_t value; + 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); ret_if(!resource_read_info->cb); - if (timestamp > 0 && data->value == 0) { - dist = data->timestamp - timestamp; + peripheral_gpio_read(gpio, &value); + + 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_unregister_cb(resource_get_info(resource_read_info->pin_num)->sensor_h); + peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h); free(resource_read_info); } - timestamp = data->timestamp; + prev = now; } int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data) @@ -81,10 +98,11 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h); retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1); - ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT); + ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); retv_if(ret != 0, -1); resource_get_info(trig_pin_num)->opened = 1; + resource_get_info(trig_pin_num)->close = resource_close_ultrasonic_sensor_trig; } if (!resource_get_info(echo_pin_num)->opened) { @@ -100,10 +118,11 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource retv_if(ret != 0, -1); resource_get_info(echo_pin_num)->opened = 1; + resource_get_info(echo_pin_num)->close = resource_close_ultrasonic_sensor_echo; } if (resource_get_info(echo_pin_num)->sensor_h) { - ret = peripheral_gpio_register_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info); + ret = peripheral_gpio_set_interrupted_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info); retv_if(ret != 0, -1); } diff --git a/src/webnotify.c b/src/webnotify.c deleted file mode 100755 index c469a9c..0000000 --- a/src/webnotify.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Jin Yoon - * Geunsun Lee - * Eunyoung Lee - * Junkyu Han - * Jeonghoon Park - * - * 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 -#include -#include -#include "log.h" - -static int _web_notify(const char *resource, const char *data) -{ - CURL *curl; - CURLcode response; - curl = curl_easy_init(); - int ret = 0; - - if(!curl) { - _E("fail to init curl"); - return -1; - } - - curl_easy_setopt(curl, CURLOPT_URL, resource); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); - - response = curl_easy_perform(curl); - - if(response != CURLE_OK) { - _E("curl_easy_perform() failed: %s", - curl_easy_strerror(response)); - ret = -1; - } - - curl_easy_cleanup(curl); - - return ret; -} - -int web_notify_init(void) -{ - int ret = 0; - CURLcode result; - result = curl_global_init(CURL_GLOBAL_DEFAULT); - if(result != CURLE_OK) { - _E("curl_global_init() failed: %s", - curl_easy_strerror(result)); - ret = -1; - } - return ret; -} - -void web_notify_fini(void) -{ - curl_global_cleanup(); - return; -} - -int web_notify_data(const char *resource, const char *data) -{ - return _web_notify(resource, data); -} - -int web_notify_bool(const char *resource, bool value) -{ - int ret = 0; - - _D("Notify to %s - value[%d]", resource, value); - - if(value) - ret = _web_notify(resource, "TRUE"); - else - ret = _web_notify(resource, "FALSE"); - - return ret; -} - -int web_notify_int(const char *resource, int value) -{ - int ret = 0; - char *data = NULL; - - data = g_strdup_printf("%d", value); - retv_if(NULL == data, -1); - - ret = _web_notify(resource, data); - g_free(data); - - return ret; -} - -int web_notify_double(const char *resource, double value) -{ - int ret = 0; - char *data = NULL; - - data = g_strdup_printf("%lf", value); - retv_if(NULL == data, -1); - - ret = _web_notify(resource, data); - g_free(data); - - return ret; -} diff --git a/tizen-manifest.xml b/tizen-manifest.xml.in similarity index 66% rename from tizen-manifest.xml rename to tizen-manifest.xml.in index 2cd9c25..677801e 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml.in @@ -1,13 +1,13 @@ - + Jin Yoon Geunsun Lee Eunyoung Lee Junkyu Han - - - position_finder_server.png + + + @PROJECT_NAME@.png http://tizen.org/privilege/network.get -- 2.7.4