Add Timer to stop the service when it's not needed. 25/188825/8
authorXie Ligang <ligang0.xie@samsung.com>
Tue, 11 Sep 2018 01:43:10 +0000 (09:43 +0800)
committerXie Ligang <ligang0.xie@samsung.com>
Tue, 11 Sep 2018 03:23:00 +0000 (11:23 +0800)
Change-Id: I3a6d80ee03ad959efaeca0bb3053ba1ff36c4ba4
Signed-off-by: Xie Ligang <ligang0.xie@samsung.com>
packaging/nlp.spec
service/CMakeLists.txt
service/src/service.c

index feabce3..e41163f 100755 (executable)
@@ -14,6 +14,7 @@ BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(python)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(rpc-port)
+BuildRequires: pkgconfig(ecore)
 Requires: python-numpy
 Requires: python-xml
 Requires: python-six
index b60de17..0aae714 100755 (executable)
@@ -29,6 +29,7 @@ pkg_check_modules(pkgs REQUIRED
         python
         glib-2.0
         rpc-port
+        ecore
     )
 FOREACH(flag ${pkgs_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -fpie")
index 39303a4..3eb2068 100755 (executable)
@@ -2,10 +2,14 @@
 #include <dlfcn.h>
 #include <service_app.h>
 #include <glib.h>
+#include <Ecore.h>
 #include "service.h"
 #include "nlp_log.h"
 #include "message.h"
 
+int sec = 60.0;
+static Ecore_Timer *service_close_timer = NULL;
+
 struct client_s {
     char *id;
     rpc_port_message_notify_cb_h cb;
@@ -41,6 +45,30 @@ static struct client_s *__create_client(const char *id,
     return handle;
 }
 
+static Eina_Bool timer_cb(void *data)
+{
+    PLOG("time runs out");
+    service_close_timer = NULL;
+    service_app_exit();
+    return ECORE_CALLBACK_CANCEL;
+}
+
+void start_timer()
+{
+    stop_timer();
+    service_close_timer = ecore_timer_add(sec,timer_cb,NULL);
+    if (service_close_timer == NULL)
+        PLOG("failed to create timer");
+}
+
+void stop_timer()
+{
+    if (service_close_timer != NULL) {
+        ecore_timer_del(service_close_timer);
+        service_close_timer = NULL;
+    }
+}
+
 static void __destroy_client(gpointer data)
 {
     PENTER();
@@ -102,6 +130,7 @@ static int __message_register(rpc_port_stub_message_context_h context,
 static int __message_send(rpc_port_stub_message_context_h context,
         const bundle *msg, void *user_data)
 {
+    stop_timer();
     struct client_s *sender_client = NULL;
 
     char *message = NULL;
@@ -354,6 +383,7 @@ static int __message_send(rpc_port_stub_message_context_h context,
     bundle_add_str(reply, "request_id", request_id);
     rpc_port_message_notify_cb_invoke(sender_client->cb, sender_client->id, reply);
     bundle_free(reply);
+    start_timer();
     return 0;
 }
 
@@ -380,6 +410,7 @@ bool service_app_create(void *data)
     PINFO("nltk stem library loaded success: ");
     globe_lang = nltk_get_module("langdetect");
     PINFO("langdetect library loaded success: ");
+    start_timer();
 
     int ret;
     rpc_port_stub_message_callback_s callback = {
@@ -409,6 +440,7 @@ void service_app_terminate(void *data)
 void service_app_control(app_control_h app_control, void *data)
 {
     // Todo: add your code here.
+    PINFO("service_app_control");
     return;
 }