Add function to set/get private data
[platform/core/uifw/tts.git] / server / ttsd_engine_agent.c
old mode 100755 (executable)
new mode 100644 (file)
index e873ba1..c3d794c
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -15,6 +15,7 @@
 #include <dlfcn.h>
 #include <dirent.h>
 
+#include "tts_defs.h"
 #include "ttsd_main.h"
 #include "ttsd_engine_agent.h"
 #include "ttsd_config.h"
 typedef struct {
        /* base info */
        char*   engine_uuid;
-       char*   engine_name; 
+       char*   engine_name;
        char*   engine_path;
 
-       /* info for using engine load*/
+       /* info for using engine load */
        bool    is_set;
-       bool    is_loaded;              
+       bool    is_loaded;
        bool    need_network;
        void    *handle;
 
@@ -40,6 +41,7 @@ typedef struct {
        char*   default_lang;
        int     default_vctype;
        int     default_speed;
+       int     default_pitch;
 
        ttspe_funcs_s*  pefuncs;
        ttspd_funcs_s*  pdfuncs;
@@ -56,48 +58,79 @@ typedef struct {
        bool    use_network;
 } ttsengine_info_s;
 
+typedef struct {
+       bool    is_default;
+       bool    is_loaded;
+       int     client_ref_count;
+
+       char*   lang;
+       int     type;
+} ttsvoice_s;
+
 
 /** Init flag */
 static bool g_agent_init;
 
 /** TTS engine list */
-static GList *g_engine_list;           
+static GList *g_engine_list;
 
 /** Current engine information */
 static ttsengine_s g_cur_engine;
 
+/** Current voice information */
+static GSList* g_cur_voices;
+
 /** Result callback function */
 static synth_result_callback g_result_cb;
 
 
 /** Set current engine */
-int __internal_set_current_engine(const char* engine_uuid);
+static int __internal_set_current_engine(const char* engine_uuid);
 
 /** Check engine id */
-int __internal_check_engine_id(const char* engine_uuid);
+static int __internal_check_engine_id(const char* engine_uuid);
 
 /** Update engine list */
-int __internal_update_engine_list();
+static int __internal_update_engine_list();
 
 /** Get engine info */
-int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info);
+static int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info);
 
 /** Callback function for result */
-bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data);
+bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, 
+                ttsp_audio_type_e audio_type, int rate, void *user_data);
 
 /** Callback function for voice list */
-bool __supported_voice_cb(const char* language, ttsp_voice_type_e type, void* user_data);
+static bool __supported_voice_cb(const char* language, int type, void* user_data);
 
 /** Free voice list */
-void __free_voice_list(GList* voice_list);
+static void __free_voice_list(GList* voice_list);
 
 /** Callback function for engine info */
-void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+static void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
                      bool use_network, void* user_data);
 
-/** Callback fucntion for engine setting */
-bool __engine_setting_cb(const char* key, const char* value, void* user_data);
 
+/** Print list */
+static int ttsd_print_enginelist();
+
+static int ttsd_print_voicelist();
+
+static const char* __ttsd_get_engine_error_code(ttsp_error_e err)
+{
+       switch (err) {
+       case TTSP_ERROR_NONE:                   return "TTSP_ERROR_NONE";
+       case TTSP_ERROR_OUT_OF_MEMORY:          return "TTSP_ERROR_OUT_OF_MEMORY";
+       case TTSP_ERROR_IO_ERROR:               return "TTSP_ERROR_IO_ERROR";
+       case TTSP_ERROR_INVALID_PARAMETER:      return "TTSP_ERROR_INVALID_PARAMETER";
+       case TTSP_ERROR_OUT_OF_NETWORK:         return "TTSP_ERROR_OUT_OF_NETWORK";
+       case TTSP_ERROR_INVALID_STATE:          return "TTSP_ERROR_INVALID_STATE";
+       case TTSP_ERROR_INVALID_VOICE:          return "TTSP_ERROR_INVALID_VOICE";
+       case TTSP_ERROR_OPERATION_FAILED:       return "TTSP_ERROR_OPERATION_FAILED";
+       default:
+               return "Invalid error code";
+       }
+}
 
 int ttsd_engine_agent_init(synth_result_callback result_cb)
 {
@@ -115,22 +148,26 @@ int ttsd_engine_agent_init(synth_result_callback result_cb)
 
        g_cur_engine.is_set = false;
        g_cur_engine.handle = NULL;
-       g_cur_engine.pefuncs = (ttspe_funcs_s*)g_malloc0( sizeof(ttspe_funcs_s) );
-       g_cur_engine.pdfuncs = (ttspd_funcs_s*)g_malloc0( sizeof(ttspd_funcs_s) );
+       g_cur_engine.pefuncs = (ttspe_funcs_s*)calloc(1, sizeof(ttspe_funcs_s));
+       g_cur_engine.pdfuncs = (ttspd_funcs_s*)calloc(1, sizeof(ttspd_funcs_s));
 
        g_agent_init = true;
 
        if (0 != ttsd_config_get_default_voice(&(g_cur_engine.default_lang), &(g_cur_engine.default_vctype))) {
-               SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default voice in config"); 
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default voice in config");
                /* Set default voice */
-               g_cur_engine.default_lang = strdup("en_US");
+               g_cur_engine.default_lang = strdup(TTS_BASE_LANGUAGE);
                g_cur_engine.default_vctype = TTSP_VOICE_TYPE_FEMALE;
        }
 
        if (0 != ttsd_config_get_default_speed(&(g_cur_engine.default_speed))) {
-               SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default speed in config"); 
-               ttsd_config_set_default_speed((int)TTSP_SPEED_NORMAL);
-               g_cur_engine.default_speed = TTSP_SPEED_NORMAL;
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default speed in config");
+               g_cur_engine.default_speed = TTS_SPEED_NORMAL;
+       }
+
+       if (0 != ttsd_config_get_default_pitch(&(g_cur_engine.default_pitch))) {
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default pitch in config");
+               g_cur_engine.default_pitch = TTS_PITCH_NORMAL;
        }
 
        SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Initialize Engine Agent");
@@ -150,7 +187,7 @@ int ttsd_engine_agent_release()
 
        /* release engine list */
        GList *iter = NULL;
-       ttsengine_s *data = NULL;
+       ttsengine_info_s *data = NULL;
 
        if (g_list_length(g_engine_list) > 0) {
                /* Get a first item */
@@ -159,23 +196,29 @@ int ttsd_engine_agent_release()
                        /* Get data from item */
                        data = iter->data;
                        iter = g_list_remove(iter, data);
+
+                       if (NULL != data) {
+                               if (NULL != data->engine_uuid)          free(data->engine_uuid);
+                               if (NULL != data->engine_name)          free(data->engine_name);
+                               if (NULL != data->setting_ug_path)      free(data->setting_ug_path);
+                               if (NULL != data->engine_path)          free(data->engine_path);
+                               free(data);
+                       }
                }
        }
        g_list_free(iter);
+
        /* release current engine data */
-       if (g_cur_engine.pefuncs != NULL)
-               g_free(g_cur_engine.pefuncs);
-       
-       if (g_cur_engine.pdfuncs != NULL)
-               g_free(g_cur_engine.pdfuncs);
+       if (g_cur_engine.engine_uuid != NULL)   free(g_cur_engine.engine_uuid);
+       if (g_cur_engine.engine_name != NULL)   free(g_cur_engine.engine_name);
+       if (g_cur_engine.engine_path != NULL)   free(g_cur_engine.engine_path);
 
+       if (g_cur_engine.pefuncs != NULL)       free(g_cur_engine.pefuncs);
+       if (g_cur_engine.pdfuncs != NULL)       free(g_cur_engine.pdfuncs);
+       if (g_cur_engine.default_lang != NULL)  free(g_cur_engine.default_lang);
        g_result_cb = NULL;
        g_agent_init = false;
 
-       if (g_cur_engine.default_lang != NULL) 
-               g_free(g_cur_engine.default_lang);
-
-
        SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Release Engine Agent");
 
        return 0;
@@ -184,7 +227,7 @@ int ttsd_engine_agent_release()
 int ttsd_engine_agent_initialize_current_engine()
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -206,84 +249,81 @@ int ttsd_engine_agent_initialize_current_engine()
 
                if (g_list_length(g_engine_list) > 0) {
                        iter = g_list_first(g_engine_list);
-                       char* default_engine = "27F277E9-BBC4-4dca-B553-D9884A3CDAA0";
-
-                       while (NULL != iter) {
-                               data = iter->data;
+                       data = iter->data;
 
-                               if (0 == strncmp(data->engine_uuid, default_engine, strlen(default_engine))) {
-                                       /* current data is default engine */
-                                       break;
+                       if (NULL != data) {
+                               if (NULL != data->engine_uuid) {
+                                       cur_engine_uuid = strdup(data->engine_uuid);
+                                       ttsd_config_set_default_engine(cur_engine_uuid);
+                               } else {
+                                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Data of current engine is corrupt");
+                                       return TTSD_ERROR_OPERATION_FAILED;
                                }
-
-                               iter = g_list_next(iter);
                        }
                } else {
-                       SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to set a engine of engine list\n");
-                       return TTSD_ERROR_OPERATION_FAILED;     
-               }
-
-               if (NULL != data->engine_uuid) {
-                       cur_engine_uuid = strdup(data->engine_uuid); 
-               } else {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Data of current engine is corrupt\n");
+                       SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to set a engine of engine list");
                        return TTSD_ERROR_OPERATION_FAILED;
                }
-               
+
                is_get_engineid_from_config = false;
        } else {
                is_get_engineid_from_config = true;
        }
 
+       if (NULL == cur_engine_uuid) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Current engine id is NULL");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
        /* check whether cur engine uuid is valid or not. */
        if (0 != __internal_check_engine_id(cur_engine_uuid)) {
                SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] It is not valid engine id from config");
 
                GList *iter = NULL;
-               
-               if (g_list_length(g_engine_list) > 0) 
+
+               if (g_list_length(g_engine_list) > 0)
                        iter = g_list_first(g_engine_list);
                else {
                        SLOG(LOG_WARN, get_tag(), "[Engine Agent ERROR] NO TTS Engine !!");
-                       return TTSD_ERROR_OPERATION_FAILED;     
+                       if (NULL != cur_engine_uuid)    free(cur_engine_uuid);
+                       return TTSD_ERROR_OPERATION_FAILED;
                }
 
-               if (cur_engine_uuid != NULL)    
-                       g_free(cur_engine_uuid);
-
+               if (cur_engine_uuid != NULL)    free(cur_engine_uuid);
                ttsengine_info_s *data = NULL;
                data = iter->data;
 
-               cur_engine_uuid = g_strdup(data->engine_uuid);
+               cur_engine_uuid = strdup(data->engine_uuid);
 
                is_get_engineid_from_config = false;
        }
 
-       if (NULL != cur_engine_uuid) 
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
-       else 
+       if (NULL != cur_engine_uuid)
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
+       else
                return TTSD_ERROR_OPERATION_FAILED;
 
        /* set current engine */
        if (0 != __internal_set_current_engine(cur_engine_uuid)) {
                SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set current engine ");
+               if (NULL != cur_engine_uuid)    free(cur_engine_uuid);
                return TTSD_ERROR_OPERATION_FAILED;
-       } 
+       }
 
        if (false == is_get_engineid_from_config) {
-               if (0 != ttsd_config_set_default_engine(cur_engine_uuid))
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set id to config"); 
+               if (0 != ttsd_config_set_default_engine(cur_engine_uuid)) {
+                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set id to config");
+               }
        }
 
-       if (NULL != cur_engine_uuid)    
-               g_free(cur_engine_uuid);
+       if (NULL != cur_engine_uuid)    free(cur_engine_uuid);
 
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set current engine"); 
+       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set current engine");
 
        return 0;
 }
 
-int __internal_check_engine_id(const char* engine_uuid)
+static int __internal_check_engine_id(const char* engine_uuid)
 {
        GList *iter = NULL;
        ttsengine_s *data = NULL;
@@ -294,9 +334,9 @@ int __internal_check_engine_id(const char* engine_uuid)
                while (NULL != iter) {
                        data = iter->data;
 
-                       if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) 
+                       if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid)))
                                return 0;
-       
+
                        iter = g_list_next(iter);
                }
        }
@@ -307,37 +347,44 @@ int __internal_check_engine_id(const char* engine_uuid)
 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
                             bool use_network, void* user_data)
 {
-       ttsengine_info_s* temp = (ttsengine_info_s*)user_data; 
+       ttsengine_info_s* temp = (ttsengine_info_s*)user_data;
+
+       if (NULL != engine_uuid)
+               temp->engine_uuid = strdup(engine_uuid);
+
+       if (NULL != engine_name)
+               temp->engine_name = strdup(engine_name);
+
+       if (NULL != setting_ug_name)
+               temp->setting_ug_path = strdup(setting_ug_name);
 
-       temp->engine_uuid = g_strdup(engine_uuid);
-       temp->engine_name = g_strdup(engine_name);
-       temp->setting_ug_path = g_strdup(setting_ug_name);
        temp->use_network = use_network;
+       return;
 }
 
-int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
+static int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
 {
        char *error;
        void* handle;
 
-       handle = dlopen (filepath, RTLD_LAZY );
+       handle = dlopen(filepath, RTLD_LAZY);
 
        if (!handle) {
-               SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine : %s", filepath); 
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine : %s", filepath);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* link engine to daemon */
        dlsym(handle, "ttsp_load_engine");
        if ((error = dlerror()) != NULL) {
-               SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine. Fail to open ttsp_load_engine : %s", filepath);
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Engine Agent] Fail to open ttsp_load_engine : path(%s) message(%s)", filepath, error);
                dlclose(handle);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        dlsym(handle, "ttsp_unload_engine");
        if ((error = dlerror()) != NULL) {
-               SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine. Fail to open ttsp_unload_engine : %s", filepath);
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Engine Agent] Fail to open ttsp_unload_engine : path(%s) message(%s)", filepath, error);
                dlclose(handle);
                return TTSD_ERROR_OPERATION_FAILED;
        }
@@ -346,41 +393,47 @@ int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
 
        get_engine_info = (int (*)(ttsp_engine_info_cb, void*))dlsym(handle, "ttsp_get_engine_info");
        if (NULL != (error = dlerror()) || NULL == get_engine_info) {
-               SLOG(LOG_WARN, get_tag(), "[Engine Agent] ttsp_get_engine_info() link error");
+               SLOG(LOG_WARN, get_tag(), "[Engine Agent] Fail to open ttsp_get_engine_info() :path(%s) message(%s)", filepath, error);
                dlclose(handle);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        ttsengine_info_s* temp;
-       temp = (ttsengine_info_s*)g_malloc0(sizeof(ttsengine_info_s));
+       temp = (ttsengine_info_s*)calloc(1, sizeof(ttsengine_info_s));
+       if (NULL == temp) {
+               SLOG(LOG_WARN, get_tag(), "[Engine Agent] Fail to alloc memory");
+               dlclose(handle);
+               return TTSD_ERROR_OUT_OF_MEMORY;
+       }
 
        /* get engine info */
        if (0 != get_engine_info(&__engine_info_cb, (void*)temp)) {
                SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get engine info");
                dlclose(handle);
-               g_free(temp);
+               free(temp);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* close engine */
        dlclose(handle);
 
-       if (TTSD_MODE_NOTIFICATION == ttsd_get_mode() || TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
-               if (true == temp->use_network) {
-                       free(temp);
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent WARNING] %s is invalid because of network based engine.", temp->engine_name);
-                       return TTSD_ERROR_OPERATION_FAILED;
-               }
+       if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && true == temp->use_network) {
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent WARNING] %s is invalid because of network based", temp->engine_name);
+               if (NULL != temp->engine_uuid)          free(temp->engine_uuid);
+               if (NULL != temp->engine_name)          free(temp->engine_name);
+               if (NULL != temp->setting_ug_path)      free(temp->setting_ug_path);
+               free(temp);
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       temp->engine_path = g_strdup(filepath);
-       
+       temp->engine_path = strdup(filepath);
+
        SLOG(LOG_DEBUG, get_tag(), "----- Valid engine");
-       SLOG(LOG_DEBUG, get_tag(), "Engine uuid : %s", temp->engine_uuid);
-       SLOG(LOG_DEBUG, get_tag(), "Engine name : %s", temp->engine_name);
-       SLOG(LOG_DEBUG, get_tag(), "Setting ug path : %s", temp->setting_ug_path);
-       SLOG(LOG_DEBUG, get_tag(), "Engine path : %s", temp->engine_path);
-       SLOG(LOG_DEBUG, get_tag(), "Use network : %s", temp->use_network ? "true":"false");
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Engine uuid : %s", temp->engine_uuid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Engine name : %s", temp->engine_name);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Setting path : %s", temp->setting_ug_path);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Engine path : %s", temp->engine_path);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Use network : %s", temp->use_network ? "true" : "false");
        SLOG(LOG_DEBUG, get_tag(), "-----");
        SLOG(LOG_DEBUG, get_tag(), "  ");
 
@@ -389,7 +442,7 @@ int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
        return 0;
 }
 
-int __internal_update_engine_list()
+static int __internal_update_engine_list()
 {
        /* relsease engine list */
        GList *iter = NULL;
@@ -401,96 +454,68 @@ int __internal_update_engine_list()
                while (NULL != iter) {
                        data = iter->data;
 
-                       if (data != NULL)
-                               g_free(data);
-
+                       if (data != NULL)       free(data);
                        g_engine_list = g_list_remove_link(g_engine_list, iter);
+                       g_list_free(iter);
                        iter = g_list_first(g_engine_list);
                }
        }
 
        /* get file name from engine directory and get engine information from each filename */
-       DIR *dp;
-       struct dirent *dirp;
-       dp = opendir(ENGINE_DIRECTORY_DEFAULT);
+       DIR *dp = NULL;
+       int ret = -1;
+       struct dirent entry;
+       struct dirent *dirp = NULL;
+       dp = opendir(TTS_DEFAULT_ENGINE);
 
        if (dp != NULL) {
-               while ((dirp = readdir(dp)) != NULL) {
-                       ttsengine_info_s* info;
-                       char* filepath = NULL;
-                       int file_size;
-
-                       file_size = strlen(ENGINE_DIRECTORY_DEFAULT) + strlen(dirp->d_name) + 5;
-                       filepath = (char*)g_malloc0( sizeof(char) * file_size);
-
-                       if (NULL != filepath) { 
-                               strncpy(filepath, ENGINE_DIRECTORY_DEFAULT, strlen(ENGINE_DIRECTORY_DEFAULT) );
-                               strncat(filepath, "/", strlen("/") );
-                               strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
-                       } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
-                               continue;       
-                       }
-
-                       /* get its info and update engine list */
-                       if (0 == __internal_get_engine_info(filepath, &info)) {
-                               /* add engine info to g_engine_list */
-                               g_engine_list = g_list_append(g_engine_list, info);
+               do {
+                       ret = readdir_r(dp, &entry, &dirp);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to read directory");
+                               break;
                        }
 
-                       if (NULL != filepath)
-                               g_free(filepath);
-               }
+                       if (NULL != dirp) {
+                               ttsengine_info_s* info;
+                               char* filepath = NULL;
+                               int file_size;
 
-               closedir(dp);
-       }
+                               file_size = strlen(TTS_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
+                               filepath = (char*)calloc(file_size, sizeof(char));
 
-       dp = opendir(ENGINE_DIRECTORY_DOWNLOAD);
+                               if (NULL != filepath) {
+                                       snprintf(filepath, file_size, "%s/%s", TTS_DEFAULT_ENGINE, dirp->d_name);
+                               } else {
+                                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!");
+                                       continue;
+                               }
 
-       if (dp != NULL) {
-               while ((dirp = readdir(dp)) != NULL) {
-                       ttsengine_info_s* info;
-                       char* filepath = NULL;
-                       int file_size;
-
-                       file_size = strlen(ENGINE_DIRECTORY_DOWNLOAD) + strlen(dirp->d_name) + 5;
-                       filepath = (char*)g_malloc0( sizeof(char) * file_size);
-
-                       if (NULL != filepath) { 
-                               strcpy(filepath, ENGINE_DIRECTORY_DOWNLOAD);
-                               strcat(filepath, "/");
-                               strcat(filepath, dirp->d_name);
-                       } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
-                               continue;       
-                       }
+                               /* get its info and update engine list */
+                               if (0 == __internal_get_engine_info(filepath, &info)) {
+                                       /* add engine info to g_engine_list */
+                                       g_engine_list = g_list_append(g_engine_list, info);
+                               }
 
-                       /* get its info and update engine list */
-                       if (0 == __internal_get_engine_info(filepath, &info)) {
-                               /* add engine info to g_engine_list */
-                               g_engine_list = g_list_append(g_engine_list, info);
+                               if (NULL != filepath)   free(filepath);
                        }
-
-                       if (NULL != filepath)
-                               g_free(filepath);
-               }
+               } while (NULL != dirp);
 
                closedir(dp);
        }
 
        if (g_list_length(g_engine_list) <= 0) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No Engine\n");
-               return TTSD_ERROR_OPERATION_FAILED;     
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No Engine");
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
-#ifdef ENGINE_AGENT_DEBUG      
+#ifdef ENGINE_AGENT_DEBUG
        ttsd_print_enginelist();
 #endif
-
        return 0;
 }
 
-int __internal_set_current_engine(const char* engine_uuid)
+static int __internal_set_current_engine(const char* engine_uuid)
 {
        /* check whether engine id is valid or not. */
        GList *iter = NULL;
@@ -515,7 +540,7 @@ int __internal_set_current_engine(const char* engine_uuid)
 
        /* If current engine does not exist, return error */
        if (false == flag) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] __internal_set_current_engine : Cannot find engine id");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Cannot find engine id");
                return TTSD_ERROR_OPERATION_FAILED;
        } else {
                if (g_cur_engine.engine_uuid != NULL) {
@@ -528,18 +553,18 @@ int __internal_set_current_engine(const char* engine_uuid)
        }
 
        /* set data from g_engine_list */
-       if (g_cur_engine.engine_uuid != NULL)   g_free(g_cur_engine.engine_uuid);
-       if (g_cur_engine.engine_name != NULL)   g_free(g_cur_engine.engine_name);
-       if (g_cur_engine.engine_path != NULL)   g_free(g_cur_engine.engine_path);
+       if (g_cur_engine.engine_uuid != NULL)   free(g_cur_engine.engine_uuid);
+       if (g_cur_engine.engine_name != NULL)   free(g_cur_engine.engine_name);
+       if (g_cur_engine.engine_path != NULL)   free(g_cur_engine.engine_path);
 
        if (NULL == data->engine_uuid || NULL == data->engine_name || NULL == data->engine_path) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] __internal_set_current_engine : Engine data is NULL");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Engine data is NULL");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       g_cur_engine.engine_uuid = g_strdup(data->engine_uuid);
-       g_cur_engine.engine_name = g_strdup(data->engine_name);
-       g_cur_engine.engine_path = g_strdup(data->engine_path);
+       g_cur_engine.engine_uuid = strdup(data->engine_uuid);
+       g_cur_engine.engine_name = strdup(data->engine_name);
+       g_cur_engine.engine_path = strdup(data->engine_path);
 
        g_cur_engine.handle = NULL;
        g_cur_engine.is_loaded = false;
@@ -547,111 +572,230 @@ int __internal_set_current_engine(const char* engine_uuid)
        g_cur_engine.need_network = data->use_network;
 
        SLOG(LOG_DEBUG, get_tag(), "-----");
-       SLOG(LOG_DEBUG, get_tag(), "Current engine uuid : %s", g_cur_engine.engine_uuid);
-       SLOG(LOG_DEBUG, get_tag(), "Current engine name : %s", g_cur_engine.engine_name);
-       SLOG(LOG_DEBUG, get_tag(), "Current engine path : %s", g_cur_engine.engine_path);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Current engine uuid : %s", g_cur_engine.engine_uuid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Current engine name : %s", g_cur_engine.engine_name);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Current engine path : %s", g_cur_engine.engine_path);
        SLOG(LOG_DEBUG, get_tag(), "-----");
 
        return 0;
 }
 
+int __ttsd_get_mode(ttsp_mode_e* mode)
+{
+       if (NULL == mode) {
+               SLOG(LOG_ERROR, get_tag(), "[ERROR] Input parameter is null");
+               return TTSP_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (ttsd_get_mode()) {
+       case TTSD_MODE_DEFAULT:         *mode = TTSP_MODE_DEFAULT;      break;
+       case TTSD_MODE_NOTIFICATION:    *mode = TTSP_MODE_NOTIFICATION; break;
+       case TTSD_MODE_SCREEN_READER:   *mode = TTSP_MODE_SCREEN_READER;        break;
+       default:
+               SLOG(LOG_ERROR, get_tag(), "[ERROR] tts mode is NOT valid");
+       }
+
+       return 0;
+}
+
+int __ttsd_engine_agent_get_speed_range(int* min, int* normal, int* max)
+{
+       if (NULL == min || NULL == normal || NULL == max) {
+               SLOG(LOG_ERROR, get_tag(), "[ERROR] Input parameter is null");
+               return TTSP_ERROR_INVALID_PARAMETER;
+       }
+
+       *min = TTS_SPEED_MIN;
+       *normal = TTS_SPEED_NORMAL;
+       *max = TTS_SPEED_MAX;
+
+       return 0;
+}
+
+int __ttsd_engine_agent_get_pitch_range(int* min, int* normal, int* max)
+{
+       if (NULL == min || NULL == normal || NULL == max) {
+               SLOG(LOG_ERROR, get_tag(), "[ERROR] Input parameter is null");
+               return TTSP_ERROR_INVALID_PARAMETER;
+       }
+
+       *min = TTS_PITCH_MIN;
+       *normal = TTS_PITCH_NORMAL;
+       *max = TTS_PITCH_MAX;
+
+       return 0;
+}
+
+static bool __set_voice_info_cb(const char* language, int type, void* user_data)
+{
+       if (NULL == language) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in voice list callback!!!!");
+               return false;
+       }
+
+       ttsvoice_s* voice = calloc(1, sizeof(ttsvoice_s));
+       if (NULL == voice) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to allocate memory");
+               return false;
+       }
+       voice->lang = strdup(language);
+       voice->type = type;
+
+       voice->client_ref_count = 0;
+       voice->is_loaded = false;
+
+       if (0 == strcmp(g_cur_engine.default_lang, language) && g_cur_engine.default_vctype == type) {
+               voice->is_default = true;
+               voice->is_loaded = true;
+       } else {
+               voice->is_default = false;
+       }
+
+       g_cur_voices = g_slist_append(g_cur_voices, voice);
+
+       return true;
+}
+
+static int __update_voice_list()
+{
+       /* Get voice list */
+       g_cur_voices = NULL;
+       int ret = 0;
+
+       ret = g_cur_engine.pefuncs->foreach_voices(__set_voice_info_cb, NULL);
+       if (0 != ret || 0 >= g_slist_length(g_cur_voices)) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get voice list : result(%d)", ret);
+               return -1;
+       }
+
+#ifdef ENGINE_AGENT_DEBUG
+       ttsd_print_voicelist();
+#endif
+       return 0;
+}
+
 int ttsd_engine_agent_load_current_engine()
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_set) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : No Current Engine ");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No Current Engine ");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* check whether current engine is loaded or not */
-       if (true == g_cur_engine.is_loaded ) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent] ttsd_engine_agent_load_current_engine : Engine has already been loaded " );
+       if (true == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent] Engine has already been loaded ");
                return 0;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] current engine path : %s\n", g_cur_engine.engine_path);
-
        /* open engine */
        char *error = NULL;
        g_cur_engine.handle = dlopen(g_cur_engine.engine_path, RTLD_LAZY); /* RTLD_LAZY RTLD_NOW*/
 
        if (NULL != (error = dlerror()) || NULL == g_cur_engine.handle) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get current engine handle : dlopen error ($s)", error);
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to get current engine handle : %s", error);
                return -2;
        }
 
        g_cur_engine.ttsp_unload_engine = (int (*)())dlsym(g_cur_engine.handle, "ttsp_unload_engine");
        if (NULL != (error = dlerror()) || NULL == g_cur_engine.ttsp_unload_engine) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to link daemon to ttsp_unload_engine() of current engine : (%s)", error);
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to link daemon to ttsp_unload_engine() : %s", error);
                return -3;
        }
 
-       g_cur_engine.ttsp_load_engine = (int (*)(const ttspd_funcs_s* , ttspe_funcs_s*) )dlsym(g_cur_engine.handle, "ttsp_load_engine");
+       g_cur_engine.ttsp_load_engine = (int (*)(const ttspd_funcs_s* , ttspe_funcs_s*))dlsym(g_cur_engine.handle, "ttsp_load_engine");
        if (NULL != (error = dlerror()) || NULL == g_cur_engine.ttsp_load_engine) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to link daemon to ttsp_load_engine() of current engine : %s", error);
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to link daemon to ttsp_load_engine() : %s", error);
                return -3;
        }
 
        /* load engine */
        g_cur_engine.pdfuncs->version = 1;
        g_cur_engine.pdfuncs->size = sizeof(ttspd_funcs_s);
+       g_cur_engine.pdfuncs->get_mode = __ttsd_get_mode;
+       g_cur_engine.pdfuncs->get_speed_range = __ttsd_engine_agent_get_speed_range;
+       g_cur_engine.pdfuncs->get_pitch_range = __ttsd_engine_agent_get_pitch_range;
 
        int ret = 0;
-       ret = g_cur_engine.ttsp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs); 
+       ret = g_cur_engine.ttsp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs);
        if (0 != ret) {
-               printf("Fail load '%s' engine\n", g_cur_engine.engine_path);
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to load engine : result(%d)");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to load engine - %s : result(%s)",
+                        g_cur_engine.engine_path, __ttsd_get_engine_error_code(ret));
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] engine info : version(%d), size(%d)\n",g_cur_engine.pefuncs->version, g_cur_engine.pefuncs->size );
-
        /* engine error check */
        if (g_cur_engine.pefuncs->size != sizeof(ttspe_funcs_s)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : current engine is not valid");
-               return TTSD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] The size of engine function is not valid");
        }
 
-       /* initalize engine */
-       if (NULL == g_cur_engine.pefuncs->initialize) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] init function of engine is NULL!!");
+       if (NULL == g_cur_engine.pefuncs->initialize ||
+               NULL == g_cur_engine.pefuncs->deinitialize ||
+               NULL == g_cur_engine.pefuncs->foreach_voices ||
+               NULL == g_cur_engine.pefuncs->is_valid_voice ||
+               NULL == g_cur_engine.pefuncs->start_synth ||
+               NULL == g_cur_engine.pefuncs->cancel_synth) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] The engine functions are NOT valid");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        ret = g_cur_engine.pefuncs->initialize(__result_cb);
        if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to initialize current engine : result(%d)\n", ret);
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to initialize current engine : %s", __ttsd_get_engine_error_code(ret));
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       /* Get voice info of current engine */
+       ret = __update_voice_list();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to set voice info : result(%d)", ret);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       /* select default voice */
-       bool set_voice = false;
+       /* Select default voice */
        if (NULL != g_cur_engine.default_lang) {
-               if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] is_valid_voice() of engine is NULL!!");
+               if (true == g_cur_engine.pefuncs->is_valid_voice(g_cur_engine.default_lang, g_cur_engine.default_vctype)) {
+                       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s), type(%d)",
+                                g_cur_engine.default_lang,  g_cur_engine.default_vctype);
+               } else {
+                       SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail set origin default voice : lang(%s), type(%d)",
+                                g_cur_engine.default_lang, g_cur_engine.default_vctype);
+
                        return TTSD_ERROR_OPERATION_FAILED;
                }
+       }
 
-               if (true == g_cur_engine.pefuncs->is_valid_voice(g_cur_engine.default_lang, g_cur_engine.default_vctype)) {
-                       set_voice = true;
-                       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s), type(%d)", 
-                               g_cur_engine.default_lang,  g_cur_engine.default_vctype);
+       /* load default voice */
+       if (NULL != g_cur_engine.pefuncs->load_voice) {
+               ret = g_cur_engine.pefuncs->load_voice(g_cur_engine.default_lang, g_cur_engine.default_vctype);
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Load default voice : lang(%s), type(%d)",
+                                g_cur_engine.default_lang,  g_cur_engine.default_vctype);
                } else {
-                       SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail set origin default voice : lang(%s), type(%d)\n",
-                               g_cur_engine.default_lang, g_cur_engine.default_vctype);
+                       SLOG(LOG_WARN, get_tag(), "[Engine Agent ERROR] Fail to load default voice : lang(%s), type(%d) result(%s)",
+                               g_cur_engine.default_lang, g_cur_engine.default_vctype, __ttsd_get_engine_error_code(ret));
+
+                       return TTSD_ERROR_OPERATION_FAILED;
                }
        }
 
-       if (false == set_voice) {
-               if (NULL == g_cur_engine.pefuncs->foreach_voices) {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
+       /* set default pitch */
+       if (NULL != g_cur_engine.pefuncs->set_pitch) {
+               ret = g_cur_engine.pefuncs->set_pitch(g_cur_engine.default_pitch);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to set pitch : pitch(%d), result(%s)", 
+                               g_cur_engine.default_pitch, __ttsd_get_engine_error_code(ret));
                        return TTSD_ERROR_OPERATION_FAILED;
                }
+               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default pitch : pitch(%d)", g_cur_engine.default_pitch);
+       }
 
+#if 0
+       if (false == set_voice) {
                /* get language list */
                int ret;
                GList* voice_list = NULL;
@@ -660,39 +804,47 @@ int ttsd_engine_agent_load_current_engine()
 
                if (0 == ret && 0 < g_list_length(voice_list)) {
                        GList *iter = NULL;
-                       voice_s* voice;
-                       
+                       voice_s* voice = NULL;
+
                        iter = g_list_first(voice_list);
 
-                       if (NULL != iter) {
+                       /* check english */
+                       while (NULL != iter) {
                                voice = iter->data;
 
-                               if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
-                                       SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail voice is NOT valid");
-                                       return TTSD_ERROR_OPERATION_FAILED;
+                               if (NULL != voice) {
+                                       if (0 == strcmp("en_US", voice->language))
+                                               break;
                                }
 
-                               ttsd_config_set_default_voice(voice->language, (int)voice->type);
-                               
-                               g_cur_engine.default_lang = g_strdup(voice->language);
-                               g_cur_engine.default_vctype = voice->type;
-
-                               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Select default voice : lang(%s), type(%d)", 
-                                       voice->language,  voice->type);
+                               iter = g_list_next(iter);
+                       }
+                       if (NULL == voice) {
+                               SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to find voice in list");
+                               return TTSD_ERROR_OPERATION_FAILED;
+                       }
 
-                               
-                       } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                       /* Set selected language and type */
+                       if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
+                               SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail voice is NOT valid");
                                return TTSD_ERROR_OPERATION_FAILED;
                        }
 
+                       ttsd_config_set_default_voice(voice->language, (int)voice->type);
+
+                       g_cur_engine.default_lang = strdup(voice->language);
+                       g_cur_engine.default_vctype = voice->type;
+
+                       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Select default voice : lang(%s), type(%d)",
+                                voice->language,  voice->type);
+
                        __free_voice_list(voice_list);
                } else {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                       SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)", ret);
                        return TTSD_ERROR_OPERATION_FAILED;
                }
-       } 
+       }
+#endif
        g_cur_engine.is_loaded = true;
 
        return 0;
@@ -701,7 +853,7 @@ int ttsd_engine_agent_load_current_engine()
 int ttsd_engine_agent_unload_current_engine()
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -711,37 +863,50 @@ int ttsd_engine_agent_unload_current_engine()
        }
 
        if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Engine has already been unloaded " );
+               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Engine has already been unloaded ");
                return 0;
        }
 
        /* shutdown engine */
-       if (NULL == g_cur_engine.pefuncs->deinitialize) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The deinitialize() of engine is NULL!!");
-       } else {
-               int ret = 0;
-               ret = g_cur_engine.pefuncs->deinitialize();
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent] Fail deinitialize() : result(%d)\n", ret);
-               }
+       int ret = 0;
+       ret = g_cur_engine.pefuncs->deinitialize();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent] Fail deinitialize() : %s", __ttsd_get_engine_error_code(ret));
        }
 
        /* unload engine */
        g_cur_engine.ttsp_unload_engine();
-       
+
        dlclose(g_cur_engine.handle);
 
        /* reset current engine data */
        g_cur_engine.handle = NULL;
        g_cur_engine.is_loaded = false;
 
+       GSList *iter = NULL;
+       ttsvoice_s* data = NULL;
+
+       iter = g_slist_nth(g_cur_voices, 0);
+       while (NULL != iter) {
+               data = iter->data;
+
+               if (NULL != data) {
+                       if (NULL != data->lang)         free(data->lang);
+                       g_cur_voices = g_slist_remove(g_cur_voices, data);
+                       free(data);
+                       data = NULL;
+               }
+
+               iter = g_slist_nth(g_cur_voices, 0);
+       }
+
        return 0;
 }
 
 bool ttsd_engine_agent_need_network()
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -753,29 +918,28 @@ bool ttsd_engine_agent_need_network()
        return g_cur_engine.need_network;
 }
 
-bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang, ttsp_voice_type_e* out_type)
+bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang, int* out_type)
 {
        if (NULL == lang || NULL == out_lang || NULL == out_type) {
                return false;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Select voice : input lang(%s) , input type(%d), default lang(%s), default type(%d)", 
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Not loaded engine");
+               return false;
+       }
+
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Select voice : input lang(%s), input type(%d), default lang(%s), default type(%d)", 
                lang, type, g_cur_engine.default_lang, g_cur_engine.default_vctype);
 
-       
        /* case 1 : Both are default */
        if (0 == strncmp(lang, "default", strlen("default")) && 0 == type) {
                *out_lang = strdup(g_cur_engine.default_lang);
                *out_type = g_cur_engine.default_vctype;
                return true;
-       } 
-       
-       /* Get voice list */
-       if (NULL == g_cur_engine.pefuncs->foreach_voices) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] foreach_voices of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       /* Get voice list */
        GList* voice_list = NULL;
        int ret = 0;
 
@@ -851,7 +1015,7 @@ bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang,
                                /* Get handle data from list */
                                voice = iter->data;
 
-                               if (0 == strncmp(voice->language, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang)) ) {
+                               if (0 == strncmp(voice->language, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang))) {
                                        voice_selected = voice;
                                        if (voice->type == type) {
                                                voice_selected = voice;
@@ -870,7 +1034,7 @@ bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang,
        }
 
        if (true == result) {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Selected voice : lang(%s), type(%d)", *out_lang, *out_type);
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Selected voice : lang(%s), type(%d)", *out_lang, *out_type);
        }
 
        __free_voice_list(voice_list);
@@ -881,7 +1045,7 @@ bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang,
 bool ttsd_engine_agent_is_same_engine(const char* engine_id)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return false;
        }
 
@@ -898,54 +1062,76 @@ bool ttsd_engine_agent_is_same_engine(const char* engine_id)
        return false;
 }
 
-int ttsd_engine_agent_set_default_voice(const char* language, ttsp_voice_type_e vctype)
+int ttsd_engine_agent_set_default_engine(const char* engine_id)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
+       /* compare current engine and new engine.*/
+       if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] new engine(%s) is the same as current engine", engine_id);
+               return 0;
        }
 
-       if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
+       bool is_engine_loaded = false;
+       char* tmp_uuid = NULL;
+       tmp_uuid = strdup(g_cur_engine.engine_uuid);
+       if (NULL == tmp_uuid) {
+                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Current engine id is NULL");
+                       return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       int ret = -1;
-       if(false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice is NOT valid !!");
-               return TTSD_ERROR_INVALID_VOICE;
+       is_engine_loaded = g_cur_engine.is_loaded;
+
+       if (true == is_engine_loaded) {
+               /* unload engine */
+               if (0 != ttsd_engine_agent_unload_current_engine()) {
+                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] fail to unload current engine");
+               }
        }
 
-       if (NULL != g_cur_engine.default_lang)
-               free(g_cur_engine.default_lang);
+       /* change current engine */
+       if (0 != __internal_set_current_engine(engine_id)) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to set current engine. Recovery origin engine");
 
-       g_cur_engine.default_lang = strdup(language);
-       g_cur_engine.default_vctype = vctype;
+               /* roll back to old current engine. */
+               __internal_set_current_engine(tmp_uuid);
+               if (true == is_engine_loaded) {
+                       ttsd_engine_agent_load_current_engine();
+               }
 
-       ret = ttsd_config_set_default_voice(language, (int)vctype);
-       if (0 == ret) {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d)",
-                       g_cur_engine.default_lang, g_cur_engine.default_vctype); 
-       } else {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret); 
+               if (tmp_uuid != NULL)   free(tmp_uuid);
+               return TTSD_ERROR_OPERATION_FAILED;
        }
-}
 
-/******************************************************************************************
-* TTS Engine Interfaces for client
-*******************************************************************************************/
+       if (true == is_engine_loaded) {
+               /* load engine */
+               if (0 != ttsd_engine_agent_load_current_engine()) {
+                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] Fail to load new engine. Recovery origin engine");
 
-int ttsd_engine_start_synthesis(const char* lang, const ttsp_voice_type_e vctype, const char* text, const int speed, void* user_param)
-{
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] start ttsd_engine_start_synthesis()");
+                       /* roll back to old current engine. */
+                       __internal_set_current_engine(tmp_uuid);
+                       if (true == is_engine_loaded) {
+                               ttsd_engine_agent_load_current_engine();
+                       }
+
+                       if (tmp_uuid != NULL)   free(tmp_uuid);
+                       return TTSD_ERROR_OPERATION_FAILED;
+               } else {
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] load new engine : %s", engine_id);
+               }
+       }
+
+       if (tmp_uuid != NULL)   free(tmp_uuid);
+       return 0;
+}
 
+int ttsd_engine_agent_set_default_voice(const char* language, int vctype)
+{
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -954,129 +1140,122 @@ int ttsd_engine_start_synthesis(const char* lang, const ttsp_voice_type_e vctype
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       /* select voice for default */
-       char* temp_lang = NULL;
-       ttsp_voice_type_e temp_type;
-       if (true != ttsd_engine_select_valid_voice(lang, vctype, &temp_lang, &temp_type)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to select default voice");
+       if (false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice is NOT valid !!");
                return TTSD_ERROR_INVALID_VOICE;
-       } else {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s)", 
-                       temp_lang, temp_type, speed, text);
        }
 
-       if (NULL == g_cur_engine.pefuncs->start_synth) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] start_synth() of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+       int ret = -1;
+       GSList *iter = NULL;
+       ttsvoice_s* data = NULL;
 
-       ttsp_speed_e temp_speed;
+       /* Update new default voice info */
+       iter = g_slist_nth(g_cur_voices, 0);
+       while (NULL != iter) {
+               /* Get handle data from list */
+               data = iter->data;
 
-       if (0 == speed) {
-               temp_speed = g_cur_engine.default_speed;
-       } else {
-               temp_speed = speed;
-       }
+               if (NULL == data) {
+                       SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice data is NULL");
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
 
-       /* synthesize text */
-       int ret = 0;
-       ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, user_param);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************", ret);
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] * synthesize error : result(%6d) *", ret);
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************", ret);
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+               if (0 == strcmp(data->lang, language) && data->type == vctype) {
+                       data->is_default = true;
+                       if (0 == data->client_ref_count) {
+                               /* load voice */
+                               if (NULL != g_cur_engine.pefuncs->load_voice) {
+                                       ret = g_cur_engine.pefuncs->load_voice(data->lang, data->type);
+                                       if (0 == ret) {
+                                               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] load voice : lang(%s), type(%d)", 
+                                                       data->lang, data->type);
+                                               data->is_loaded = true;
+                                       } else {
+                                               SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to load voice : lang(%s), type(%d), result(%s)",
+                                                       data->lang, data->type, __ttsd_get_engine_error_code(ret));
+                                       }
+                               } else {
+                                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent ERROR] Load voice of engine function is NULL");
+                               }
+                       }
+                       break;
+               }
 
-       if (NULL == temp_lang)
-               free(temp_lang);
+               /*Get next item*/
+               iter = g_slist_next(iter);
+       }
 
-       return 0;
-}
+#ifdef ENGINE_AGENT_DEBUG
+       ttsd_print_voicelist();
+#endif
 
+       /* Update old default voice info */
+       iter = g_slist_nth(g_cur_voices, 0);
+       while (NULL != iter) {
+               /*Get handle data from list*/
+               data = iter->data;
 
-int ttsd_engine_cancel_synthesis()
-{
-       SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] start ttsd_engine_cancel_synthesis()");
-       
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+               if (NULL == data) {
+                       SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice data is NULL");
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
 
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-       
-       if (NULL == g_cur_engine.pefuncs->cancel_synth) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] cancel_synth() of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+               if (0 == strcmp(data->lang, g_cur_engine.default_lang) && data->type == g_cur_engine.default_vctype) {
+                       data->is_default = false;
+                       if (0 == data->client_ref_count) {
+                               /* Unload voice */
+                               if (NULL != g_cur_engine.pefuncs->unload_voice) {
+                                       ret = g_cur_engine.pefuncs->unload_voice(data->lang, data->type);
+                                       if (0 == ret) {
+                                               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Unload voice : lang(%s), type(%d)", 
+                                                       data->lang, data->type);
+                                               data->is_loaded = false;
+                                       } else {
+                                               SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to unload voice : lang(%s), type(%d), result(%s)",
+                                                       data->lang, data->type, __ttsd_get_engine_error_code(ret));
+                                       }
+                               } else {
+                                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent ERROR] Unload voice of engine function is NULL");
+                               }
+                       }
+                       break;
+               }
 
-       /* stop synthesis */
-       int ret = 0;
-       ret = g_cur_engine.pefuncs->cancel_synth();
-       if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail cancel synthesis : result(%d)", ret);
-               return TTSD_ERROR_OPERATION_FAILED;
+               /*Get next item*/
+               iter = g_slist_next(iter);
        }
 
-       return 0;
-}
+       if (NULL != g_cur_engine.default_lang)  free(g_cur_engine.default_lang);
 
-int ttsd_engine_get_audio_format( ttsp_audio_type_e* type, int* rate, int* channels)
-{
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+       g_cur_engine.default_lang = strdup(language);
+       g_cur_engine.default_vctype = vctype;
 
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+#ifdef ENGINE_AGENT_DEBUG
+       ttsd_print_voicelist();
+#endif
 
-       if (NULL == g_cur_engine.pefuncs->get_audio_format) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_audio_format() of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d)",
+               g_cur_engine.default_lang, g_cur_engine.default_vctype);
 
-       int ret = 0;
-       ret = g_cur_engine.pefuncs->get_audio_format(type, rate, channels);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get audio format : result(%d)", ret);
-               return TTSD_ERROR_OPERATION_FAILED;
-       } else
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] get audio format : type(%d), rate(%d), channel(%d)", *type, *rate, *channels);
-       
        return 0;
 }
 
-bool __supported_voice_cb(const char* language, ttsp_voice_type_e type, void* user_data)
+int ttsd_engine_agent_set_default_speed(int speed)
 {
-       GList** voice_list = (GList**)user_data;
-
-       if (NULL == language || NULL == voice_list) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in voice list callback!!!!");
-               return false;
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "-- Language(%s), Type(%d)", language, type);
-
-       voice_s* voice = g_malloc0(sizeof(voice_s));
-       voice->language = strdup(language);
-       voice->type = type;
-
-       *voice_list = g_list_append(*voice_list, voice);
+       g_cur_engine.default_speed = speed;
 
-       return true;
+       return 0;
 }
 
-int ttsd_engine_get_voice_list(GList** voice_list)
+int ttsd_engine_agent_set_default_pitch(int pitch)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -1085,230 +1264,209 @@ int ttsd_engine_get_voice_list(GList** voice_list)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (NULL == g_cur_engine.pefuncs->foreach_voices) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
+       if (NULL == g_cur_engine.pefuncs->set_pitch) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not support pitch");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       int ret = 0;
-       ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, (void*)voice_list);
+       int ret = g_cur_engine.pefuncs->set_pitch(pitch);
        if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to get voice list : result(%d)", ret);
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to set pitch : pitch(%d), result(%s)",
+                        pitch, __ttsd_get_engine_error_code(ret));
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       g_cur_engine.default_pitch = pitch;
+
        return 0;
 }
 
-int ttsd_engine_get_default_voice( char** lang, ttsp_voice_type_e* vctype )
-{
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+/******************************************************************************************
+* TTS Engine Interfaces for client
+*******************************************************************************************/
 
-       if (NULL == lang || NULL == vctype) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] BAD Parameter"); 
-               return TTSD_ERROR_INVALID_PARAMETER;
-       }
+int ttsd_engine_load_voice(const char* lang, const int vctype)
+{
+       /* 1. Find voice info */
+       int ret = -1;
+       GSList *iter = NULL;
+       ttsvoice_s* data = NULL;
 
-       if (NULL != g_cur_engine.default_lang) {
-               *lang = g_strdup(g_cur_engine.default_lang);
-               *vctype = g_cur_engine.default_vctype;
+       iter = g_slist_nth(g_cur_voices, 0);
+       while (NULL != iter) {
+               /*Get handle data from list*/
+               data = iter->data;
 
-               SLOG(LOG_DEBUG, get_tag(), "[Engine] Get default voice : language(%s), type(%d)\n", *lang, *vctype);
-       } else {
-               if (NULL == g_cur_engine.pefuncs->foreach_voices) {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
-                       return TTSD_ERROR_OPERATION_FAILED;
+               if (NULL != data) {
+                       if (0 == strcmp(data->lang, lang) && data->type == vctype) {
+                               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Find voice : default(%d) loaded(%d) ref(%d) lang(%s) type(%d)",
+                                        data->is_default, data->is_loaded,  data->client_ref_count, data->lang, data->type);
+                               break;
+                       }
                }
 
-               /* get language list */
-               int ret;
-               GList* voice_list = NULL;
-
-               ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
-
-               if (0 == ret && 0 < g_list_length(voice_list)) {
-                       GList *iter = NULL;
-                       voice_s* voice;
-
-                       iter = g_list_first(voice_list);
-
-                       if (NULL != iter) {
-                               voice = iter->data;
-                               
-                               if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
-                                       SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail voice is NOT valid ");
-                                       return TTSD_ERROR_OPERATION_FAILED;
-                               }
-                               
-                               ttsd_config_set_default_voice(voice->language, (int)voice->type);
-                               
-                               if (NULL != g_cur_engine.default_lang)
-                                       g_free(g_cur_engine.default_lang);
+               /*Get next item*/
+               iter = g_slist_next(iter);
+               data = NULL;
+       }
 
-                               g_cur_engine.default_lang = g_strdup(voice->language);
-                               g_cur_engine.default_vctype = voice->type;
+       if (NULL == data) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] This voice is not supported voice : lang(%s) type(%d)", lang, vctype);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
 
-                               *lang = g_strdup(g_cur_engine.default_lang);
-                               *vctype = g_cur_engine.default_vctype = voice->type;
+       /* 2. increse ref count */
+       data->client_ref_count++;
 
-                               SLOG(LOG_DEBUG, get_tag(), "[Engine] Get default voice (New selected) : language(%s), type(%d)\n", *lang, *vctype);
+       /* 3. if ref count change 0 to 1 and not default, load voice */
+       if (1 == data->client_ref_count && false == data->is_default) {
+               /* load voice */
+               if (NULL != g_cur_engine.pefuncs->load_voice) {
+                       ret = g_cur_engine.pefuncs->load_voice(data->lang, data->type);
+                       if (0 == ret) {
+                               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Load voice : lang(%s), type(%d)", 
+                                       data->lang, data->type);
+                               data->is_loaded = true;
                        } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                               SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to load voice : lang(%s), type(%d), result(%s)",
+                                       data->lang, data->type, __ttsd_get_engine_error_code(ret));
+
                                return TTSD_ERROR_OPERATION_FAILED;
                        }
-
-                       __free_voice_list(voice_list);
                } else {
-                       SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
-                       return TTSD_ERROR_OPERATION_FAILED;
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent ERROR] Load voice of engine function is NULL");
                }
+       } else {
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Not load voice : default voice(%d) or ref count(%d)",
+                       data->is_default, data->client_ref_count);
        }
-       
+
+#ifdef ENGINE_AGENT_DEBUG
+       ttsd_print_voicelist();
+#endif
+
        return 0;
 }
 
-/*
-* TTS Engine Interfaces for setting
-*/
-int ttsd_engine_setting_get_engine_list(GList** engine_list)
+int ttsd_engine_unload_voice(const char* lang, const int vctype)
 {
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+       /* 1. Find voice info */
+       int ret = -1;
+       GSList *iter = NULL;
+       ttsvoice_s* data = NULL;
 
-       if (NULL == engine_list) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL" );
-               return TTSD_ERROR_INVALID_PARAMETER;
+       iter = g_slist_nth(g_cur_voices, 0);
+       while (NULL != iter) {
+               /*Get handle data from list*/
+               data = iter->data;
+
+               if (NULL != data) {
+                       if (0 == strcmp(data->lang, lang) && data->type == vctype) {
+                               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Find voice : default(%d) loaded(%d) ref(%d) lang(%s) type(%d)",
+                                        data->is_default, data->is_loaded,  data->client_ref_count, data->lang, data->type);
+                               break;
+                       }
+               }
+
+               /*Get next item*/
+               iter = g_slist_next(iter);
+               data = NULL;
        }
 
-       /* update engine list */
-       if (0 != __internal_update_engine_list()) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail __internal_update_engine_list()");
+       if (NULL == data) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] This voice is not supported voice : lang(%s) type(%d)", lang, vctype);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       GList *iter = NULL;
-       ttsengine_info_s *data = NULL;
-
-       iter = g_list_first(g_engine_list);
-
-       SLOG(LOG_DEBUG, get_tag(), "----- [Engine Agent] engine list -----");
-       
-       while (NULL != iter) {
-               engine_s* temp_engine;
-       
-               temp_engine = (engine_s*)g_malloc0(sizeof(engine_s));
-
-               data = iter->data;
-
-               temp_engine->engine_id = strdup(data->engine_uuid);
-               temp_engine->engine_name = strdup(data->engine_name);
-               temp_engine->ug_name = strdup(data->setting_ug_path);
-
-               *engine_list = g_list_append(*engine_list, temp_engine);
+       /* 2. Decrese ref count */
+       data->client_ref_count--;
 
-               iter = g_list_next(iter);
+       /* 3. if ref count change 0 and not default, load voice */
+       if (0 == data->client_ref_count && false == data->is_default) {
+               /* load voice */
+               if (NULL != g_cur_engine.pefuncs->unload_voice) {
+                       ret = g_cur_engine.pefuncs->unload_voice(data->lang, data->type);
+                       if (0 == ret) {
+                               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Unload voice : lang(%s), type(%d)", 
+                                       data->lang, data->type);
+                               data->is_loaded = false;
+                       } else {
+                               SECURE_SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to unload voice : lang(%s), type(%d), result(%s)",
+                                       data->lang, data->type, __ttsd_get_engine_error_code(ret));
 
-               SLOG(LOG_DEBUG, get_tag(), " -- engine id(%s) engine name(%s) ug name(%s)", 
-                       temp_engine->engine_id, temp_engine->engine_name, temp_engine->ug_name);
-               
+                               return TTSD_ERROR_OPERATION_FAILED;
+                       }
+               } else {
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent ERROR] Unload voice of engine function is NULL");
+               }
+       } else {
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Not unload voice : default voice(%d) or ref count(%d)",
+                       data->is_default, data->client_ref_count);
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "--------------------------------------");
-       
+#ifdef ENGINE_AGENT_DEBUG
+       ttsd_print_voicelist();
+#endif
        return 0;
 }
 
-int ttsd_engine_setting_get_engine(char** engine_id)
+int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int speed, void* user_param)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
                SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_ENGINE_NOT_FOUND;
-       }
-
-       *engine_id = strdup(g_cur_engine.engine_uuid);
-
-       return 0;
-}
-
-int ttsd_engine_setting_set_engine(const char* engine_id)
-{
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       /* compare current engine and new engine.*/
-       if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] new engine(%s) is the same as current engine(%s)", engine_id, g_cur_engine.engine_uuid);
-               return 0;
-       }
-
-       char* tmp_uuid = NULL;
-       tmp_uuid = strdup(g_cur_engine.engine_uuid);
-
-       /* unload engine */
-       if (0 != ttsd_engine_agent_unload_current_engine()) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] fail to unload current engine");
+       /* select voice for default */
+       char* temp_lang = NULL;
+       int temp_type;
+       if (true != ttsd_engine_select_valid_voice(lang, vctype, &temp_lang, &temp_type)) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to select default voice");
+               if (NULL != temp_lang)  free(temp_lang);
+               return TTSD_ERROR_INVALID_VOICE;
        } else {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] unload current engine");
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s)", 
+                       temp_lang, temp_type, speed, text);
        }
 
-       /* change current engine */
-       if (0 != __internal_set_current_engine(engine_id)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail __internal_set_current_engine()");
-
-               /* roll back to old current engine. */
-               __internal_set_current_engine(tmp_uuid);
-               ttsd_engine_agent_load_current_engine();
-               
-               if (tmp_uuid != NULL)   
-                       free(tmp_uuid);
-
+       if (NULL == g_cur_engine.pefuncs->start_synth) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] start_synth() of engine is NULL!!");
+               if (NULL != temp_lang)  free(temp_lang);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       /* load engine */
-       if (0 != ttsd_engine_agent_load_current_engine()) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] fail to load new engine");
-               
-               if( tmp_uuid != NULL )  
-                       free(tmp_uuid);
+       int temp_speed;
 
-               return TTSD_ERROR_OPERATION_FAILED;
+       if (0 == speed) {
+               temp_speed = g_cur_engine.default_speed;
        } else {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] load new engine");
+               temp_speed = speed;
        }
 
-       /* save engine id to config */
-       if (0 != ttsd_config_set_default_engine(engine_id)) {
-               SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to save engine id to config"); 
+       /* synthesize text */
+       int ret = 0;
+       ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, user_param);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] * synthesize error : %s *", __ttsd_get_engine_error_code(ret));
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************");
+               if (NULL != temp_lang)  free(temp_lang);
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (tmp_uuid != NULL)   
-               free(tmp_uuid);
-
+       if (NULL != temp_lang)  free(temp_lang);
        return 0;
 }
 
-int ttsd_engine_setting_get_voice_list(char** engine_id, GList** voice_list)
+int ttsd_engine_cancel_synthesis()
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -1317,99 +1475,48 @@ int ttsd_engine_setting_get_voice_list(char** engine_id, GList** voice_list)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       int ret = 0;
-
-       /* get language list from engine*/
-       ret = ttsd_engine_get_voice_list(voice_list);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Server Error] fail ttsd_engine_get_voice_list() ");
-               return ret;
-       }
-
-       *engine_id = strdup(g_cur_engine.engine_uuid);
-       
-       return 0;
-}
-
-int ttsd_engine_setting_get_default_voice(char** language, ttsp_voice_type_e* vctype)
-{
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
+       if (NULL == g_cur_engine.pefuncs->cancel_synth) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] cancel_synth() of engine is NULL!!");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       /* get current language from engine*/
+       /* stop synthesis */
        int ret = 0;
-       char* temp_lang;
-       ttsp_voice_type_e temp_int;
-
-       ret = ttsd_engine_get_default_voice(&temp_lang, &temp_int);
+       ret = g_cur_engine.pefuncs->cancel_synth();
        if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Server Error] fail ttsd_engine_get_default_voice()");
-               return ret;
-       } 
-
-       if (NULL != temp_lang) {
-               *language = strdup(temp_lang);
-               *vctype = temp_int;
-               free(temp_lang);
-       } else {
-               SLOG(LOG_ERROR, get_tag(), "[Server Error] fail to get default language");
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail cancel synthesis : %s", __ttsd_get_engine_error_code(ret));
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        return 0;
 }
 
-int ttsd_engine_setting_set_default_voice(const char* language, ttsp_voice_type_e vctype)
+bool __supported_voice_cb(const char* language, int type, void* user_data)
 {
-       if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-
-       if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
+       GList** voice_list = (GList**)user_data;
 
-       if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
+       if (NULL == language || NULL == voice_list) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in voice list callback!!!!");
+               return false;
        }
 
-       int ret = -1;
-       if(false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice is NOT valid !!");
-               return TTSD_ERROR_INVALID_VOICE;
+       voice_s* voice = calloc(1, sizeof(voice_s));
+       if (NULL == voice) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to allocate memory");
+               return false;
        }
+       voice->language = strdup(language);
+       voice->type = type;
 
-       if (NULL != g_cur_engine.default_lang)
-               free(g_cur_engine.default_lang);
-
-       g_cur_engine.default_lang = strdup(language);
-       g_cur_engine.default_vctype = vctype;
-
-       ret = ttsd_config_set_default_voice(language, (int)vctype);
-       if (0 == ret) {
-               SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d)",
-                               g_cur_engine.default_lang, g_cur_engine.default_vctype); 
-       } else {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret); 
-       }
+       *voice_list = g_list_append(*voice_list, voice);
 
-       return 0;
+       return true;
 }
 
-int ttsd_engine_setting_get_default_speed(ttsp_speed_e* speed)
+int ttsd_engine_get_voice_list(GList** voice_list)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -1417,17 +1524,21 @@ int ttsd_engine_setting_get_default_speed(ttsp_speed_e* speed)
                SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
                return TTSD_ERROR_OPERATION_FAILED;
        }
-       
-       /* get current language */
-       *speed = g_cur_engine.default_speed;
+
+       int ret = 0;
+       ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, (void*)voice_list);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to get voice list : %s", __ttsd_get_engine_error_code(ret));
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
 
        return 0;
 }
 
-int ttsd_engine_setting_set_default_speed(const ttsp_speed_e speed)
+int ttsd_engine_get_default_voice(char** lang, int* vctype)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -1436,100 +1547,87 @@ int ttsd_engine_setting_set_default_speed(const ttsp_speed_e speed)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       g_cur_engine.default_speed = speed;
-
-       if (0 != ttsd_config_set_default_speed(speed)) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set default speed to config");
+       if (NULL == lang || NULL == vctype) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] BAD Parameter");
+               return TTSD_ERROR_INVALID_PARAMETER;
        }
 
-       return 0;
-}
-
-bool __engine_setting_cb(const char* key, const char* value, void* user_data)
-{
-       GList** engine_setting_list = (GList**)user_data;
+       if (NULL != g_cur_engine.default_lang) {
+               *lang = strdup(g_cur_engine.default_lang);
+               *vctype = g_cur_engine.default_vctype;
 
-       if (NULL == engine_setting_list || NULL == key || NULL == value) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in engine setting callback!!!!");
-               return false;
+               SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine] Get default voice : language(%s), type(%d)", *lang, *vctype);
+       } else {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Default voice is NULL");
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       engine_setting_s* temp = g_malloc0(sizeof(engine_setting_s));
-       temp->key = g_strdup(key);
-       temp->value = g_strdup(value);
-
-       *engine_setting_list = g_list_append(*engine_setting_list, temp);
-
-       return true;
+       return 0;
 }
 
-
-int ttsd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list)
+int ttsd_engine_set_private_data(const char* key, const char* data)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No loaded engine");
+               return TTSD_ERROR_ENGINE_NOT_FOUND;
        }
 
-       if (NULL == setting_list) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL");
+       if (NULL == key) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Invalid parameter");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
-       if (NULL == g_cur_engine.pefuncs->foreach_engine_setting) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] foreach_engine_setting() of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
+       if (NULL == g_cur_engine.pefuncs->set_private_data) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not supported feature");
+               return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
        }
 
-       /* get setting info and move setting info to input parameter */
-       int result = 0;
-
-       result = g_cur_engine.pefuncs->foreach_engine_setting(__engine_setting_cb, setting_list);
-
-       if (0 == result && 0 < g_list_length(*setting_list)) {
-               *engine_id = strdup(g_cur_engine.engine_uuid);
-       } else {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get setting info : result(%d)\n", result);
-               result = TTSD_ERROR_OPERATION_FAILED;
+       int ret = 0;
+       ret = g_cur_engine.pefuncs->set_private_data(key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to set private data(%d)", ret);
        }
 
-       return result;
+       return ret;
 }
 
-int ttsd_engine_setting_set_engine_setting(const char* key, const char* value)
+int ttsd_engine_get_private_data(const char* key, char** data)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
-               return TTSD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No loaded engine");
+               return TTSD_ERROR_ENGINE_NOT_FOUND;
        }
 
-       if (NULL == g_cur_engine.pefuncs->set_engine_setting) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] set_setting_info of engine is NULL!!");
-               return TTSD_ERROR_OPERATION_FAILED;
+       if (NULL == key || NULL == data) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Invalid parameter");
+               return TTSD_ERROR_INVALID_PARAMETER;
        }
 
-       /* get setting info and move setting info to input parameter */
-       int ret = 0;
-       ret = g_cur_engine.pefuncs->set_engine_setting(key, value);
+       if (NULL == g_cur_engine.pefuncs->get_private_data) {
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not supported feature");
+               return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
+       }
 
+       int ret = 0;
+       ret = g_cur_engine.pefuncs->get_private_data(key, data);
        if (0 != ret) {
-               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set engine setting : result(%d)\n", ret); 
-               return TTSD_ERROR_OPERATION_FAILED;
-       } 
+               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to get private data(%d)", ret);
+       }
 
-       return 0;
+       return ret;
 }
 
+
 void __free_voice_list(GList* voice_list)
 {
        GList *iter = NULL;
@@ -1542,16 +1640,14 @@ void __free_voice_list(GList* voice_list)
 
                while (NULL != iter) {
                        data = iter->data;
-                       
-                       if (NULL != data) {
-                               if (NULL != data->language)
-                                       g_free(data->language);
 
-                               g_free(data);
+                       if (NULL != data) {
+                               if (NULL != data->language)     free(data->language);
+                               free(data);
                        }
-                       
+
                        voice_list = g_list_remove_link(voice_list, iter);
-                       
+                       g_list_free(iter);
                        iter = g_list_first(voice_list);
                }
        }
@@ -1560,10 +1656,9 @@ void __free_voice_list(GList* voice_list)
 /*
 * TTS Engine Callback Functions                                                                                        `                                 *
 */
-bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
+bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, ttsp_audio_type_e audio_type, int rate, void *user_data)
 {
-       g_result_cb(event, data, data_size, user_data);
-
+       g_result_cb(event, data, data_size, audio_type, rate, user_data);
        return true;
 }
 
@@ -1578,15 +1673,15 @@ int ttsd_print_enginelist()
 
                SLOG(LOG_DEBUG, get_tag(), "----- engine list -----");
 
-               int i = 1;      
+               int i = 1;
                while (NULL != iter) {
                        data = iter->data;
 
-                       SLOG(LOG_DEBUG, get_tag(), "[%dth]\n", i);
-                       SLOG(LOG_DEBUG, get_tag(), "engine uuid : %s\n", data->engine_uuid);
-                       SLOG(LOG_DEBUG, get_tag(), "engine name : %s\n", data->engine_name);
-                       SLOG(LOG_DEBUG, get_tag(), "engine path : %s\n", data->engine_path);
-                       SLOG(LOG_DEBUG, get_tag(), "setting ug path : %s\n", data->setting_ug_path);
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[%dth]", i);
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "engine uuid : %s", data->engine_uuid);
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "engine name : %s", data->engine_name);
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "engine path : %s", data->engine_path);
+                       SECURE_SLOG(LOG_DEBUG, get_tag(), "setting ug path : %s", data->setting_ug_path);
 
                        iter = g_list_next(iter);
                        i++;
@@ -1602,9 +1697,38 @@ int ttsd_print_enginelist()
        return 0;
 }
 
+int ttsd_print_voicelist()
+{
+       /* Test log */
+       GSList *iter = NULL;
+       ttsvoice_s* data = NULL;
 
+       SLOG(LOG_DEBUG, get_tag(), "=== Voice list ===");
 
+       if (g_slist_length(g_cur_voices) > 0) {
+               /* Get a first item */
+               iter = g_slist_nth(g_cur_voices, 0);
 
+               int i = 1;
+               while (NULL != iter) {
+                       /*Get handle data from list*/
+                       data = iter->data;
 
+                       if (NULL == data || NULL == data->lang) {
+                               SLOG(LOG_ERROR, get_tag(), "[ERROR] Data is invalid");
+                               return 0;
+                       }
 
+                       SLOG(LOG_DEBUG, get_tag(), "[%dth] default(%d) loaded(%d) ref(%d) lang(%s) type(%d)",
+                                i, data->is_default, data->is_loaded,  data->client_ref_count, data->lang, data->type);
 
+                       /*Get next item*/
+                       iter = g_slist_next(iter);
+                       i++;
+               }
+       }
+
+       SLOG(LOG_DEBUG, get_tag(), "==================");
+
+       return 0;
+}
\ No newline at end of file