Delete ecore timer when quit ecore main loop
[platform/core/uifw/tts.git] / server / ttse.c
index 358d38a..0f40802 100755 (executable)
 #include <Ecore.h>
 
 #include "ttse.h"
-
-#define CLIENT_CLEAN_UP_TIME 500
-
-static Ecore_Timer* g_check_client_timer = NULL;
+#include "ttse_internal.h"
 
 static ttsd_mode_e g_tts_mode = TTSD_MODE_DEFAULT;
 
@@ -36,6 +33,8 @@ const char* tts_tag()
                return "ttsdnoti";
        } else if (TTSD_MODE_SCREEN_READER == g_tts_mode) {
                return "ttsdsr";
+       } else if (TTSD_MODE_INTERRUPT == g_tts_mode) {
+               return "ttsdinterrupt";
        } else {
                return "ttsd";
        }
@@ -56,6 +55,7 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
 {
        bundle *b = NULL;
        ttsd_mode_e mode = TTSD_MODE_DEFAULT;
+       int ret = TTSE_ERROR_NONE;
 
        b = bundle_import_from_argv(argc, argv);
        if (NULL != b) {
@@ -66,6 +66,8 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
                                        mode = TTSD_MODE_NOTIFICATION;
                                } else if (!strcmp("sr", val)) {
                                        mode = TTSD_MODE_SCREEN_READER;
+                               } else if (!strcmp("interrupt", val)) {
+                                       mode = TTSD_MODE_INTERRUPT;
                                } else {
                                        SLOG(LOG_WARN, tts_tag(), "[WARNING] mode (%s)", val);
                                }
@@ -76,6 +78,7 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
                        SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get data from bundle");
                }
                bundle_free(b);
+               val = NULL;
        } else {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get bundle");
        }
@@ -86,32 +89,37 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
 
        if (!ecore_init()) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize Ecore");
-               return -1;
+               return TTSE_ERROR_OPERATION_FAILED;
        }
 
        if (0 != ttsd_dbus_open_connection()) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open dbus connection");
-               return -1;
+               ecore_shutdown();
+               return TTSE_ERROR_OPERATION_FAILED;
        }
 
-       if (0 != ttsd_initialize(callback)) {
+       ret = ttsd_initialize(callback);
+       if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize");
-               return -1;
+               ttsd_dbus_close_connection();
+               ecore_shutdown();
+               return ret;
        }
 
        if (0 != ttsd_network_initialize()) {
                SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to initialize network");
        }
 
-       g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
-       if (NULL == g_check_client_timer) {
-               SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
-       }
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
-       SLOG(LOG_DEBUG, tts_tag(), "====");
-       SLOG(LOG_DEBUG, tts_tag(), "");
+       return TTSE_ERROR_NONE;
+}
 
-       return 0;
+int ttse_terminate()
+{
+       ttsd_terminate();
+
+       return TTSE_ERROR_NONE;
 }
 
 int ttse_get_speed_range(int* min, int* normal, int* max)
@@ -148,7 +156,6 @@ int ttse_send_result(ttse_result_event_e event, const void* data, unsigned int d
 
        if (NULL == data) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
-               return TTSE_ERROR_INVALID_PARAMETER;
        }
 
        ret = ttsd_send_result(event, data, data_size, audio_type, rate, user_data);
@@ -164,11 +171,6 @@ int ttse_send_error(ttse_error_e error, const char* msg)
 {
        int ret;
 
-       if (NULL == msg) {
-               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
-               return TTSE_ERROR_INVALID_PARAMETER;
-       }
-
        ret = ttsd_send_error(error, msg);
 
        if (0 != ret) {