From fa2d9fba5b708dc3bfc966973c7d699ee062467e Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Thu, 3 Aug 2017 10:52:45 +0900 Subject: [PATCH] add web notification feature, but not enabled yet Change-Id: Ib45f7e66df520fd822848c0c64c5bbe4b0131a33 Signed-off-by: Jeonghoon Park --- CMakeLists.txt | 33 +++++-- inc/webnotify.h | 35 +++++++ packaging/org.tizen.position-finder-server.spec | 5 +- src/controller.c | 13 +++ src/controller_internal.c | 11 +++ src/webnotify.c | 120 ++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 10 deletions(-) mode change 100644 => 100755 CMakeLists.txt create mode 100755 inc/webnotify.h mode change 100644 => 100755 packaging/org.tizen.position-finder-server.spec mode change 100644 => 100755 src/controller.c mode change 100644 => 100755 src/controller_internal.c create mode 100755 src/webnotify.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 91e1717..86f207f --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,19 +9,33 @@ SET(CMAKE_VERBOSE_MAKEFILE 0) SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}") SET(PROJECT_RESOURCES_DIR "${PROJECT_ROOT_DIR}/res") -INCLUDE(FindPkgConfig) -pkg_check_modules(APP_PKGS REQUIRED +#disable web notify +#SET(PF_TYPE "Zarie-web") + +MESSAGE("position-finder-server type: ${PF_TYPE}") + +SET(CHECK_MODULES 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}) + FOREACH (flag ${APP_PKGS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -32,7 +46,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc) -ADD_EXECUTABLE(${PROJECT_NAME} +SET(SRCS ${PROJECT_ROOT_DIR}/src/controller.c ${PROJECT_ROOT_DIR}/src/controller_internal.c ${PROJECT_ROOT_DIR}/src/connectivity.c @@ -43,7 +57,12 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_ROOT_DIR}/src/resource/resource_touch_sensor.c ${PROJECT_ROOT_DIR}/src/resource/resource_ultrasonic_sensor.c ) -#${PROJECT_ROOT_DIR}/src/connectivity.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}) diff --git a/inc/webnotify.h b/inc/webnotify.h new file mode 100755 index 0000000..7f415d0 --- /dev/null +++ b/inc/webnotify.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + + +#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__ */ + diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec old mode 100644 new mode 100755 index 12e6acd..0477e94 --- a/packaging/org.tizen.position-finder-server.spec +++ b/packaging/org.tizen.position-finder-server.spec @@ -12,13 +12,12 @@ 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(gio-2.0) +BuildRequires: pkgconfig(libcurl) +BuildRequires: pkgconfig(glib-2.0) %description Server for Position Finder diff --git a/src/controller.c b/src/controller.c old mode 100644 new mode 100755 index 20388a7..da4b439 --- a/src/controller.c +++ b/src/controller.c @@ -5,6 +5,7 @@ * 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. @@ -32,6 +33,13 @@ #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 @@ -62,6 +70,11 @@ static Eina_Bool control_read_sensors_cb(void *data) 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; } diff --git a/src/controller_internal.c b/src/controller_internal.c old mode 100644 new mode 100755 index cd24bad..8c8e2d8 --- a/src/controller_internal.c +++ b/src/controller_internal.c @@ -5,6 +5,7 @@ * 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. @@ -24,10 +25,17 @@ #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) @@ -35,4 +43,7 @@ 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/webnotify.c b/src/webnotify.c new file mode 100755 index 0000000..c469a9c --- /dev/null +++ b/src/webnotify.c @@ -0,0 +1,120 @@ +/* + * 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; +} -- 2.7.4