add web notification feature, but not enabled yet 54/142154/6
authorJeonghoon Park <jh1979.park@samsung.com>
Thu, 3 Aug 2017 01:52:45 +0000 (10:52 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Fri, 4 Aug 2017 01:14:48 +0000 (10:14 +0900)
Change-Id: Ib45f7e66df520fd822848c0c64c5bbe4b0131a33
Signed-off-by: Jeonghoon Park <jh1979.park@samsung.com>
CMakeLists.txt [changed mode: 0644->0755]
inc/webnotify.h [new file with mode: 0755]
packaging/org.tizen.position-finder-server.spec [changed mode: 0644->0755]
src/controller.c [changed mode: 0644->0755]
src/controller_internal.c [changed mode: 0644->0755]
src/webnotify.c [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index 91e1717..86f207f
@@ -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 (executable)
index 0000000..7f415d0
--- /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>
+ *          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_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__ */
+
old mode 100644 (file)
new mode 100755 (executable)
index 12e6acd..0477e94
@@ -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
old mode 100644 (file)
new mode 100755 (executable)
index 20388a7..da4b439
@@ -5,6 +5,7 @@
  *          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.
 #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;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index cd24bad..8c8e2d8
@@ -5,6 +5,7 @@
  *          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.
 #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 (executable)
index 0000000..c469a9c
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * 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 <stdbool.h>
+#include <glib.h>
+#include <curl/curl.h>
+#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;
+}