Update stt for tizen 2.0 beta 2.0alpha master 2.0_alpha accepted/tizen/20130520.103100 submit/master/20120920.151128 submit/tizen/20130517.020037
authorDongyeol Lee <dy3.lee@samsung.com>
Tue, 21 Aug 2012 08:41:15 +0000 (17:41 +0900)
committerDongyeol Lee <dy3.lee@samsung.com>
Tue, 21 Aug 2012 08:41:15 +0000 (17:41 +0900)
29 files changed:
client/stt.c
client/stt.h
client/stt_client.c
client/stt_client.h
client/stt_dbus.c
client/stt_setting.h
client/stt_setting_dbus.c
client/stt_setting_dbus.h
common/stt_defs.h
debian/changelog
debian/copyright [deleted file]
debian/libstt.install.in
packaging/stt.spec
server/CMakeLists.txt
server/sttd.conf [new file with mode: 0644]
server/sttd_client_data.c
server/sttd_client_data.h
server/sttd_config.c
server/sttd_config.h
server/sttd_dbus.c
server/sttd_dbus.h
server/sttd_dbus_server.c
server/sttd_engine_agent.c
server/sttd_engine_agent.h
server/sttd_main.c
server/sttd_main.h
server/sttd_recorder.c
server/sttd_server.c
server/sttd_server.h

index a05ef53518d1dbabe182a7113e0dbc9f70012876..5d8d41806d3c1c4e037230c1dec4d01649e8624a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
 #include <sys/wait.h>
 #include <sys/types.h> 
 #include <unistd.h>
+#include <Ecore.h>
 
 #include "stt.h"
 #include "stt_main.h"
 #include "stt_client.h"
 #include "stt_dbus.h"
 
-#define CONNECTION_RETRY_COUNT 2
+#define CONNECTION_RETRY_COUNT 3
+
+static bool g_is_daemon_started = false;
 
 static int __check_stt_daemon();
+static Eina_Bool __stt_notify_state_changed(void *data);
+static Eina_Bool __stt_notify_error(void *data);
 
 int stt_create(stt_h* stt)
 {
-       int ret = 0; 
-
        SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT");
 
        if (NULL == stt) {
@@ -38,70 +41,186 @@ int stt_create(stt_h* stt)
 
        if (0 == stt_client_get_size()) {
                if (0 != stt_dbus_open_connection()) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection\n ");
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
                        return STT_ERROR_OPERATION_FAILED;
                }
        }
 
-       /* Send hello */
-       if (0 != stt_dbus_request_hello()) {
-               __check_stt_daemon();
-       }
-
        if (0 != stt_client_new(stt)) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!!!!!");
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
                return STT_ERROR_OUT_OF_MEMORY;
        }
 
+       SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+int stt_destroy(stt_h stt)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+       
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = -1;
+
+       /* check state */
+       switch (client->current_state) {
+       case STT_STATE_PROCESSING:
+       case STT_STATE_RECORDING:
+       case STT_STATE_READY:
+               ret = stt_dbus_request_finalize(client->uid);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize");
+               }
+       case STT_STATE_CREATED:
+               /* Free resources */
+               stt_client_destroy(stt);
+               break;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "Success: destroy");
+
+       if (0 == stt_client_get_size()) {
+               if (0 != stt_dbus_close_connection()) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection");
+               }
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+static Eina_Bool __stt_connect_daemon(void *data)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon");
+
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       /* Send hello */
+       if (0 != stt_dbus_request_hello()) {
+               if (false == g_is_daemon_started) {
+                       g_is_daemon_started = true;
+                       __check_stt_daemon();
+               }
+               return EINA_TRUE;
+       }
+
        /* request initialization */
+       int ret = -1;
        int i = 1;
        bool silence_supported = false;
        bool profanity_supported = false;
        bool punctuation_supported = false;
 
        while (1) {
-               ret = stt_dbus_request_initialize((*stt)->handle, &silence_supported, &profanity_supported, &punctuation_supported);
-               
+               ret = stt_dbus_request_initialize(client->uid, &silence_supported, &profanity_supported, &punctuation_supported);
+
                if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
-                       stt_client_destroy(*stt);
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : STT Engine Not founded");
-                       return ret;
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : STT Engine Not found");
+                       
+                       client->reason = STT_ERROR_ENGINE_NOT_FOUND;
+
+                       ecore_timer_add(0, __stt_notify_error, (void*)stt);
+
+                       return EINA_FALSE;
+
                } else if(0 != ret) {
                        usleep(1);
                        if(CONNECTION_RETRY_COUNT == i) {
-                               stt_client_destroy(*stt);
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : TIMED OUT");
-                               return STT_ERROR_TIMED_OUT;                         
+
+                               client->reason = STT_ERROR_TIMED_OUT;
+
+                               ecore_timer_add(0, __stt_notify_error, (void*)stt);
+
+                               return EINA_FALSE;
                        }    
                        i++;
                } else {
                        /* success to connect stt-daemon */
-                       stt_client_set_option_supported(*stt, silence_supported, profanity_supported, punctuation_supported);
+                       stt_client_set_option_supported(client->stt, silence_supported, profanity_supported, punctuation_supported);
                        SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), profanity(%s), punctuation(%s)", 
                                silence_supported ? "true" : "false", profanity_supported ? "true" : "false", punctuation_supported ? "true" : "false");
                        break;
                }
        }
 
-       SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
-       
+       client->before_state = client->current_state;
+       client->current_state = STT_STATE_READY;
+
+       ecore_timer_add(0, __stt_notify_state_changed, (void*)stt);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
+
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
-       SLOG(LOG_DEBUG, TAG_STTC, " ");
+       SLOG(LOG_DEBUG, TAG_STTC, "  ");
 
-       return STT_ERROR_NONE;
+       return EINA_FALSE;
 }
 
-int stt_destroy(stt_h stt)
+
+int stt_prepare(stt_h stt)
 {
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Prepare STT");
 
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
                return STT_ERROR_INVALID_PARAMETER;
        }
-       
+
+       /* check state */
+       if (client->current_state != STT_STATE_CREATED) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'CREATED'"); 
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       ecore_timer_add(0, __stt_connect_daemon, (void*)stt);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+int stt_unprepare(stt_h stt)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
+
        stt_client_s* client = stt_client_get(stt);
 
        /* check handle */
@@ -109,22 +228,24 @@ int stt_destroy(stt_h stt)
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
                return STT_ERROR_INVALID_PARAMETER;
        }
-       
+
+       /* check state */
+       if (client->current_state != STT_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'READY'"); 
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_STATE;
+       }
+
        int ret = stt_dbus_request_finalize(client->uid);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize");
+               SLOG(LOG_WARN, TAG_STTC, "[ERROR] Fail to request finalize");
        }
-       
-       /* Free resources */
-       stt_client_destroy(stt);
 
-       SLOG(LOG_DEBUG, TAG_STTC, "Success: destroy");
+       client->before_state = client->current_state;
+       client->current_state = STT_STATE_CREATED;
 
-       if (0 == stt_client_get_size()) {
-               if (0 != stt_dbus_close_connection()) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection\n ");
-               }
-       }
+       ecore_timer_add(0, __stt_notify_state_changed, (void*)stt);
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
@@ -221,6 +342,7 @@ int stt_get_state(stt_h stt, stt_state_e* state)
        *state = client->current_state;
 
        switch(*state) {
+               case STT_STATE_CREATED:         SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'");        break;
                case STT_STATE_READY:           SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'");          break;
                case STT_STATE_RECORDING:       SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'");      break;
                case STT_STATE_PROCESSING:      SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'");     break;
@@ -384,14 +506,10 @@ int stt_start(stt_h stt, const char* language, const char* type)
        } else {
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
 
-               if (NULL != client->state_changed_cb) {
-                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_RECORDING, client->state_changed_user_data); 
-                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_RECORDING");
-               } else {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
-               }    
-
+               client->before_state = client->current_state;
                client->current_state = STT_STATE_RECORDING;
+
+               ecore_timer_add(0, __stt_notify_state_changed, (void*)stt);
        }
 
        free(temp);
@@ -439,14 +557,10 @@ int stt_stop(stt_h stt)
        } else {
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
 
-               if (NULL != client->state_changed_cb) {
-                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_PROCESSING, client->state_changed_user_data); 
-                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_PROCESSING");
-               } else {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
-               }
-
+               client->before_state = client->current_state;
                client->current_state = STT_STATE_PROCESSING;
+
+               ecore_timer_add(0, __stt_notify_state_changed, (void*)stt);
        }
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
@@ -492,14 +606,11 @@ int stt_cancel(stt_h stt)
                SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to cancel");
        } else {
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
-               if (NULL != client->state_changed_cb) {
-                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_READY, client->state_changed_user_data); 
-                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_READY");
-               } else {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
-               }
 
+               client->before_state = client->current_state;
                client->current_state = STT_STATE_READY;
+
+               ecore_timer_add(0, __stt_notify_state_changed, (void*)stt);
        }
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
@@ -538,6 +649,30 @@ int stt_get_recording_volume(stt_h stt, float* volume)
        return STT_ERROR_NONE;
 }
 
+static Eina_Bool __stt_notify_error(void *data)
+{
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (NULL != client->error_cb) {
+               stt_client_use_callback(client);
+               client->error_cb(client->stt, client->reason, client->error_user_data); 
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "Error callback is called");
+       } else {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
+       }
+
+       return EINA_FALSE;
+}
+
 int __stt_cb_error(int uid, int reason)
 {
        stt_client_s* client = stt_client_get_by_uid(uid);
@@ -546,20 +681,88 @@ int __stt_cb_error(int uid, int reason)
                return -1;
        }
 
-       client->current_state = STT_STATE_READY;
+       client->reason = reason;
 
        if (NULL != client->error_cb) {
-               stt_client_use_callback(client);
-               client->error_cb(client->stt, reason, client->error_user_data); 
-               stt_client_not_use_callback(client);
-               SLOG(LOG_DEBUG, TAG_STTC, "client error callback called");
+               ecore_timer_add(0, __stt_notify_error, client->stt);
        } else {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Error occur but user callback is null");
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
        }    
 
        return 0;
 }
 
+static Eina_Bool __stt_notify_result(void *data)
+{
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (NULL != client->result_cb) {
+               stt_client_use_callback(client);
+               client->result_cb(client->stt, client->type, (const char**)client->data_list, client->data_count, client->msg, client->result_user_data);
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "client result callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
+       } 
+
+       /* Free result */
+       if (NULL != client->type)
+               free(client->type);
+
+       if (NULL != client->data_list) {
+               char **temp = NULL;
+               temp = client->data_list;
+
+               int i = 0;
+               for (i = 0;i < client->data_count;i++) {
+                       if(NULL != temp[i])
+                               free(temp[i]);
+                       else 
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error");
+               }
+               free(client->data_list);
+       }
+       
+       if (NULL != client->msg) 
+               free(client->msg);
+
+       client->data_count = 0;
+
+       return EINA_FALSE;
+}
+
+static Eina_Bool __stt_notify_state_changed(void *data)
+{
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (NULL != client->state_changed_cb) {
+               stt_client_use_callback(client);
+               client->state_changed_cb(client->stt, client->before_state, client->current_state, client->state_changed_user_data); 
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
+       } else {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
+       }
+
+       return EINA_FALSE;
+}
+
 int __stt_cb_result(int uid, const char* type, const char** data, int data_count, const char* msg)
 {
        stt_client_s* client = NULL;
@@ -579,26 +782,68 @@ int __stt_cb_result(int uid, const char* type, const char** data, int data_count
        }       
 
        if (NULL != client->result_cb) {
-               stt_client_use_callback(client);
-               client->result_cb(client->stt, type, data, data_count, msg, client->result_user_data);
-               stt_client_not_use_callback(client);
-               SLOG(LOG_DEBUG, TAG_STTC, "client result callback called");
+               client->type = strdup(type);
+               client->msg = strdup(msg);
+               client->data_count = data_count;
+
+               if (data_count > 0) {
+                       char **temp = NULL;
+                       temp = malloc( sizeof(char*) * data_count);
+
+                       for (i = 0;i < data_count;i++) {
+                               if(NULL != data[i])
+                                       temp[i] = strdup(data[i]);
+                               else 
+                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error");
+                       }
+
+                       client->data_list = temp;
+               }
+
+               ecore_timer_add(0, __stt_notify_result, client->stt);
        } else {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
        }   
 
+       client->before_state = client->current_state;
+       client->current_state = STT_STATE_READY;
+
        if (NULL != client->state_changed_cb) {
-               client->state_changed_cb(client->stt, client->current_state, STT_STATE_READY, client->state_changed_user_data); 
-               SLOG(LOG_DEBUG, TAG_STTC, "client state changed callback called");
+               ecore_timer_add(0, __stt_notify_state_changed, client->stt);
        } else {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register result callback");
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
        }
 
-       client->current_state = STT_STATE_READY;
-
        return 0;
 }
 
+static Eina_Bool __stt_notify_partial_result(void *data)
+{
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (client->partial_result_cb) {
+               stt_client_use_callback(client);
+               client->partial_result_cb(client->stt, client->partial_result, client->partial_result_user_data);
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "Partial result callback is called");
+       } else {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Partial result callback is null");
+       }   
+
+       if (NULL != client->partial_result)
+               free(client->partial_result);
+
+       return EINA_FALSE;
+}
+
 int __stt_cb_partial_result(int uid, const char* data)
 {
        stt_client_s* client = NULL;
@@ -615,41 +860,34 @@ int __stt_cb_partial_result(int uid, const char* data)
        }
 
        if (client->partial_result_cb) {
-               stt_client_use_callback(client);
-               client->partial_result_cb(client->stt, data, client->partial_result_user_data);
-               stt_client_not_use_callback(client);
-               SLOG(LOG_DEBUG, TAG_STTC, "client partial result callback called");
+               client->partial_result = strdup(data);
+               ecore_timer_add(0, __stt_notify_partial_result, client->stt);
        } else {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register partial result callback");
-       }   
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Partial result callback is null");
+       }  
 
        return 0;
 }
 
-int __stt_cb_stop_by_daemon(int uid)
+int __stt_cb_set_state(int uid, int state)
 {
        stt_client_s* client = stt_client_get_by_uid(uid);
        if( NULL == client ) {
-               SLOG(LOG_ERROR, TAG_STTC, "Handle not found\n");
+               SLOG(LOG_ERROR, TAG_STTC, "Handle not found");
                return -1;
        }
 
-       if (client->current_state != STT_STATE_RECORDING) {
-               SLOG(LOG_ERROR, TAG_STTC, "Current state is NOT 'Recording' state");    
-               return 0;
-       }
+       stt_state_e state_from_daemon = (stt_state_e)state;
 
-       if (NULL != client->state_changed_cb) {
-               stt_client_use_callback(client);
-               client->state_changed_cb(client->stt, client->current_state, STT_STATE_PROCESSING, client->state_changed_user_data); 
-               stt_client_not_use_callback(client);
-               SLOG(LOG_DEBUG, TAG_STTC, "client state changed callback called");
-       } else {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Error occur but user callback is null");
+       if (client->current_state == state_from_daemon) {
+               SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
+               return 0;
        }
 
-       client->current_state = STT_STATE_PROCESSING;
+       client->before_state = client->current_state;
+       client->current_state = state_from_daemon;
 
+       ecore_timer_add(0, __stt_notify_state_changed, client->stt);
        return 0;
 }
 
@@ -666,7 +904,7 @@ int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -690,7 +928,7 @@ int stt_unset_result_cb(stt_h stt)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -714,7 +952,7 @@ int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* u
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -738,7 +976,7 @@ int stt_unset_partial_result_cb(stt_h stt)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -762,7 +1000,7 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -786,7 +1024,7 @@ int stt_unset_state_changed_cb(stt_h stt)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -811,7 +1049,7 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -835,7 +1073,7 @@ int stt_unset_error_cb(stt_h stt)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (STT_STATE_READY != client->current_state) {
+       if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
                return STT_ERROR_INVALID_STATE;
        }
@@ -898,7 +1136,7 @@ static void __my_sig_child(int signo, siginfo_t *info, void *data)
 }
 
 
-int __check_stt_daemon()
+static int __check_stt_daemon()
 {
        if( TRUE == __stt_is_alive() )
                return 0;
@@ -933,7 +1171,6 @@ int __check_stt_daemon()
                break;
 
        default:
-               sleep(1);
                break;
        }
 
index 01879ecfd6fdbbabd140d8b195f8fa3c787569d4..3028b701264afcb602f0f1316fd9def92bc2bd89 100644 (file)
@@ -208,7 +208,8 @@ typedef enum {
 * @brief Enumerations of state.
 */
 typedef enum {
-       STT_STATE_READY = 0,                    /**< 'READY' state */
+       STT_STATE_CREATED = 0,                  /**< 'CREATED' state */
+       STT_STATE_READY,                        /**< 'READY' state */
        STT_STATE_RECORDING,                    /**< 'RECORDING' state */
        STT_STATE_PROCESSING                    /**< 'PROCESSING' state*/
 }stt_state_e;
@@ -295,10 +296,6 @@ typedef void (*stt_partial_result_cb)(stt_h stt, const char* data, void *user_da
 *
 * @pre An application registers this callback using stt_set_state_changed_cb() to detect changing state.
 *
-* @see stt_start()
-* @see stt_stop()
-* @see stt_cancel()
-* @see stt_result_cb()
 * @see stt_set_state_changed_cb()
 * @see stt_unset_state_changed_cb()
 */
@@ -323,8 +320,8 @@ typedef void (*stt_error_cb)(stt_h stt, stt_error_e reason, void *user_data);
 *
 * @param[in] stt The handle for STT
 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
-* followed by ISO 639-1 for the two-letter language code. \n
-* For example, "ko_KR" for Korean, "en_US" for American English.
+*              followed by ISO 639-1 for the two-letter language code. \n
+*              For example, "ko_KR" for Korean, "en_US" for American English.
 * @param[in] user_data The user data passed from the foreach function
 *
 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
@@ -336,24 +333,23 @@ typedef bool(*stt_supported_language_cb)(stt_h stt, const char* language, void*
 
 
 /**
-* @brief Creates a handle for STT and connects daemon
+* @brief Creates a handle for STT. 
 *
 * @param[out] stt The handle for STT
 *
 * @return 0 on success, otherwise a negative error value
 * @retval #STT_ERROR_NONE Successful
-* @retval #STT_ERROR_TIMED_OUT The daemon is blocked or do not exist
-* @retval #STT_ERROR_ENGINE_NOT_FOUND No available engine \n Engine should be installed
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
-* @retval #STT_ERROR_OUT_OF_MEMORY Out of memory
 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
 *
+* @post If this function is called, the STT state will be #STT_STATE_CREATED.
+*
 * @see stt_destroy()
 */
 int stt_create(stt_h* stt);
 
 /**
-* @brief Destroys the handle and disconnects the daemon.
+* @brief Destroys the handle.
 *
 * @param[in] stt The handle for STT
 *
@@ -365,6 +361,40 @@ int stt_create(stt_h* stt);
 */
 int stt_destroy(stt_h stt);
 
+/**
+* @brief Connects the daemon. 
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_CREATED.
+* @post If this function is called, the STT state will be #STT_STATE_READY.
+*
+* @see stt_unprepare()
+*/
+int stt_prepare(stt_h stt);
+
+/**
+* @brief Disconnects the daemon.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+* @post If this function is called, the STT state will be #STT_STATE_CREATED.
+*
+* @see stt_prepare()
+*/
+int stt_unprepare(stt_h stt);
+
 /**
 * @brief Retrieves all supported languages of current engine using callback function.
 *
@@ -393,8 +423,8 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac
 *
 * @param[in] stt The handle for STT
 * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
-* followed by ISO 639-1 for the two-letter language code. \n
-* For example, "ko_KR" for Korean, "en_US" for American English.
+*                      followed by ISO 639-1 for the two-letter language code. \n
+*                      For example, "ko_KR" for Korean, "en_US" for American English.
 *
 * @return 0 on success, otherwise a negative error value
 * @retval #STT_ERROR_NONE Successful
@@ -601,7 +631,7 @@ int stt_get_recording_volume(stt_h stt, float* volume);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_result_cb()
 * @see stt_unset_result_cb()
@@ -618,7 +648,7 @@ int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_set_result_cb()
 */
@@ -636,6 +666,8 @@ int stt_unset_result_cb(stt_h stt);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
+* @pre The state should be #STT_STATE_CREATED.
+*
 * @see stt_partial_result_cb()
 * @see stt_unset_partial_result_cb()
 */
@@ -651,7 +683,7 @@ int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* u
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_set_partial_result_cb()
 */
@@ -669,7 +701,7 @@ int stt_unset_partial_result_cb(stt_h stt);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_state_changed_cb()
 * @see stt_unset_state_changed_cb()
@@ -686,7 +718,7 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_set_state_changed_cb()
 */
@@ -704,7 +736,7 @@ int stt_unset_state_changed_cb(stt_h stt);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_error_cb()
 * @see stt_unset_error_cb()
@@ -721,7 +753,7 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data);
 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #STT_ERROR_INVALID_STATE Invalid state
 *
-* @pre The state should be #STT_STATE_READY.
+* @pre The state should be #STT_STATE_CREATED.
 *
 * @see stt_set_error_cb()
 */
index a8b4fb9bcb142fbcb175e7ad075101e4047c6bec..51cf06d3e2d3b01b839fb0be64704fc4b12659c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
@@ -68,7 +68,13 @@ int stt_client_new(stt_h* stt)
        client->punctuation = STT_OPTION_PUNCTUATION_AUTO;
        client->silence = STT_OPTION_SILENCE_DETECTION_AUTO;
 
-       client->current_state = STT_STATE_READY; 
+       client->type = NULL;
+       client->data_list = NULL;
+       client->data_count = 0;
+       client->msg = NULL;
+
+       client->before_state = STT_STATE_CREATED;
+       client->current_state = STT_STATE_CREATED; 
 
        client->cb_ref_count = 0;
 
index e18ef5f6c6c25e55e403a2c109af09e988ee347a..70c4715d39f35b769b735e1326cddd876c678aef 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
@@ -49,10 +49,21 @@ typedef struct {
        stt_option_silence_detection_e  silence;
 
        /* state */
+       stt_state_e     before_state;
        stt_state_e     current_state;
 
        /* mutex */
        int             cb_ref_count;
+
+       /* result data */
+       char*   partial_result;
+       char*   type;
+       char**  data_list;
+       int     data_count;
+       char*   msg;
+
+       /* error data */
+       int     reason;
 }stt_client_s;
 
 int stt_client_new(stt_h* stt);
index 2f752c18fd1ab94a5353e537071566ded9eb0805..d6d7132b65c802f794353d0d8d0cbdd6eda361d3 100644 (file)
@@ -17,6 +17,7 @@
 #include "stt_defs.h"
 
 #include <Ecore.h>
+#include "stt_client.h"
 
 static int g_waiting_time = 1500;
 static int g_waiting_start_time = 2000;
@@ -32,7 +33,7 @@ extern int __stt_cb_result(int uid, const char* type, const char** data, int dat
        
 extern int __stt_cb_partial_result(int uid, const char* data);
 
-extern int __stt_cb_stop_by_daemon(int uid);
+extern int __stt_cb_set_state(int uid, int state);
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
@@ -58,7 +59,127 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        char if_name[64];
        snprintf(if_name, 64, "%s%d", STT_CLIENT_SERVICE_INTERFACE, getpid());
 
-       if (dbus_message_is_method_call(msg, if_name, STT_METHOD_RESULT)) {
+       if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_HELLO)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Hello");
+               int uid = 0;
+               int response = -1;
+
+               dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+               if (uid > 0) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get hello : uid(%d) \n", uid);
+                       
+                       /* check uid */
+                       stt_client_s* client = stt_client_get_by_uid(uid);
+                       if( NULL != client ) 
+                               response = 1;
+                       else 
+                               response = 0;
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get hello : invalid uid \n");
+               }
+
+               reply = dbus_message_new_method_return(msg);
+               
+               if (NULL != reply) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
+
+                       if (!dbus_connection_send(conn, reply, NULL))
+                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to send reply");
+                       else 
+                               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get hello : result(%d)", response);
+
+                       dbus_connection_flush(conn);
+                       dbus_message_unref(reply); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to create reply message");
+               }
+               
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       } /* STTD_METHOD_HELLO */
+
+       else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_SET_STATE)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Set State");
+               int uid = 0;
+               int response = -1;
+               int state = -1;
+
+               dbus_message_get_args(msg, &err, 
+                       DBUS_TYPE_INT32, &uid, 
+                       DBUS_TYPE_INT32, &state,
+                       DBUS_TYPE_INVALID);
+
+               if (uid > 0 && state >= 0) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set state : uid(%d), state(%d)", uid, state);
+
+                       response = __stt_cb_set_state(uid, state);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set state : invalid uid or state");
+               }
+
+               reply = dbus_message_new_method_return(msg);
+
+               if (NULL != reply) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
+
+                       if (!dbus_connection_send(conn, reply, NULL))
+                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set state : fail to send reply");
+                       else 
+                               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set state : result(%d)", response);
+
+                       dbus_connection_flush(conn);
+                       dbus_message_unref(reply); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set state : fail to create reply message");
+               }
+
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       } /* STTD_METHOD_SET_STATE */
+
+       else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_GET_STATE)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get state");
+               int uid = 0;
+               int response = -1;
+
+               dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+               if (uid > 0) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get state : uid(%d) \n", uid);
+
+                       /* check state */
+                       stt_client_s* client = stt_client_get_by_uid(uid);
+                       if( NULL != client ) 
+                               response = client->current_state;
+                       else 
+                               SLOG(LOG_ERROR, TAG_STTC, "invalid uid \n");
+                       
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get state : invalid uid \n");
+               }
+
+               reply = dbus_message_new_method_return(msg);
+
+               if (NULL != reply) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
+
+                       if (!dbus_connection_send(conn, reply, NULL))
+                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get state : fail to send reply");
+                       else 
+                               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get state : result(%d)", response);
+
+                       dbus_connection_flush(conn);
+                       dbus_message_unref(reply); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to create reply message");
+               }
+
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       } /* STTD_METHOD_GET_STATE */
+
+       else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_RESULT)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Get Result");
                int uid = 0;
                DBusMessageIter args;
@@ -128,16 +249,11 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                        SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get result : invalid uid \n");
                } 
                
-               reply = dbus_message_new_method_return(msg);
-               dbus_connection_send(conn, reply, NULL);
-               dbus_connection_flush(conn);
-               dbus_message_unref(reply); 
-
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
-       }/* STT_METHOD_RESULT */
+       }/* STTD_METHOD_RESULT */
 
-       else if (dbus_message_is_method_call(msg, if_name, STT_METHOD_PARTIAL_RESULT)) {
+       else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_PARTIAL_RESULT)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Get Partial Result");
                int uid = 0;
                DBusMessageIter args;
@@ -163,40 +279,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                } else {
                        SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get partial result : invalid uid \n");
                }
-               reply = dbus_message_new_method_return(msg);
-               dbus_connection_send(conn, reply, NULL);
-               dbus_connection_flush(conn);
-               dbus_message_unref(reply); 
-
-               SLOG(LOG_DEBUG, TAG_STTC, "=====");
-               SLOG(LOG_DEBUG, TAG_STTC, " ");
-       }/* STT_METHOD_PARTIAL_RESULT */
-
-       else if (dbus_message_is_method_call(msg, if_name, STT_METHOD_STOPED)) {
-               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Silence Detection");
-               int uid;
-               dbus_message_get_args(msg, &err,
-                       DBUS_TYPE_INT32, &uid,
-                       DBUS_TYPE_INVALID);
-
-               if (dbus_error_is_set(&err)) { 
-                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get stop by daemon signal : Get arguments error (%s)\n", err.message);
-                       dbus_error_free(&err); 
-               } else {
-                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< Get stop by daemon signal : uid(%d)\n", uid);
-                       __stt_cb_stop_by_daemon(uid);
-               }
-
-               reply = dbus_message_new_method_return(msg);
-               dbus_connection_send(conn, reply, NULL);
-               dbus_connection_flush(conn);
-               dbus_message_unref(reply); 
 
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
-       }/* STT_METHOD_STOP */
+       }/* STTD_METHOD_PARTIAL_RESULT */
 
-       else if (dbus_message_is_method_call(msg, if_name, STT_METHOD_ERROR)) {
+       else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_ERROR)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Get Error");
                int uid;
                int reason;
@@ -209,21 +297,30 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                        DBUS_TYPE_INVALID);
 
                if (dbus_error_is_set(&err)) { 
-                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get Error signal : Get arguments error (%s)\n", err.message);
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt Get Error message : Get arguments error (%s)\n", err.message);
                        dbus_error_free(&err); 
                } else {
-                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< Get Error signal : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg);
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg);
                        __stt_cb_error(uid, reason);
                }
 
                reply = dbus_message_new_method_return(msg);
-               dbus_connection_send(conn, reply, NULL);
-               dbus_connection_flush(conn);
-               dbus_message_unref(reply); 
+
+               if (NULL != reply) {
+                       if (!dbus_connection_send(conn, reply, NULL))
+                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt Error message : fail to send reply");
+                       else 
+                               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt Error message");
+
+                       dbus_connection_flush(conn);
+                       dbus_message_unref(reply); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt Error message : fail to create reply message");
+               }
 
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
-       }/* STT_METHOD_ERROR */
+       }/* STTD_METHOD_ERROR */
 
        /* free the message */
        dbus_message_unref(msg);
@@ -327,6 +424,9 @@ int stt_dbus_close_connection()
 
        dbus_bus_release_name (g_conn, service_name, &err);
 
+       dbus_connection_close(g_conn);
+
+       g_fd_handler = NULL;
        g_conn = NULL;
 
        return 0;
index 69731f901cb09c154c255de083f883fc047aaab8..171e5d5cca84f33b2da91c0e37d11e84f5cee7e3 100644 (file)
@@ -35,11 +35,13 @@ typedef enum {
        STT_SETTING_ERROR_OUT_OF_MEMORY         = -ENOMEM,      /**< Out of Memory */
        STT_SETTING_ERROR_IO_ERROR              = -EIO,         /**< I/O error */
        STT_SETTING_ERROR_INVALID_PARAMETER     = -EINVAL,      /**< Invalid parameter */
-       STT_SETTING_ERROR_INVALID_STATE         = -0x0100021,   /**< Invalid state */
-       STT_SETTING_ERROR_INVALID_LANGUAGE      = -0x0100022,   /**< Invalid language */
-       STT_SETTING_ERROR_ENGINE_NOT_FOUND      = -0x0100023,   /**< No available STT-engine  */
-       STT_SETTING_ERROR_TIMED_OUT             = -0x0100024,   /**< No answer from STT daemon */
-       STT_SETTING_ERROR_OPERATION_FAILED      = -0x0100025,   /**< STT daemon failed  */
+       STT_SETTING_ERROR_TIMED_OUT             = -ETIMEDOUT,   /**< No answer from the daemon */
+       STT_SETTING_ERROR_OUT_OF_NETWORK        = -ENETDOWN,    /**< Out of network */
+       STT_SETTING_ERROR_INVALID_STATE         = -0x0100031,   /**< Invalid state */
+       STT_SETTING_ERROR_INVALID_LANGUAGE      = -0x0100032,   /**< Invalid language */
+       STT_SETTING_ERROR_ENGINE_NOT_FOUND      = -0x0100033,   /**< No available STT-engine  */
+       STT_SETTING_ERROR_OPERATION_FAILED      = -0x0100034,   /**< STT daemon failed  */
+       STT_SETTING_ERROR_NOT_SUPPORTED_FEATURE = -0x0100035    /**< Not supported feature of current engine */
 }stt_setting_error_e;
 
 /**
index 6f9154c526440f81fc03685974c564b69f0e7ba1..a7f3289ee624f3849b8df70f596ab9abc9502210 100644 (file)
@@ -82,6 +82,8 @@ int stt_setting_dbus_close_connection()
 
        dbus_bus_release_name(g_conn, service_name, &err);
 
+       dbus_connection_close(g_conn);
+
        g_conn = NULL;
 
        return 0;
index 4e5d19f62983d77ab04162675c7b5bc35cf37aab..a9dd602aa9f7ccbb652237fae38039ba5be48df5 100644 (file)
@@ -26,6 +26,8 @@ int stt_setting_dbus_open_connection();
 int stt_setting_dbus_close_connection();
 
 
+int stt_setting_dbus_request_hello();
+
 int stt_setting_dbus_request_initialize();
 
 int stt_setting_dbus_request_finalilze();
index d70ea26d4a6b186bb29429f7e9835bf472b237b9..3f4f4fc0f94ef398985fe801f0e9f1b2c234b0d6 100644 (file)
@@ -37,7 +37,7 @@ extern "C" {
 
 
 /******************************************************************************************
-* Message Definition for APIs
+* Message Definition for Client
 *******************************************************************************************/
 
 #define STT_METHOD_HELLO               "stt_method_hello"
@@ -52,10 +52,12 @@ extern "C" {
 #define STT_METHOD_STOP                        "stt_method_stop"
 #define STT_METHOD_CANCEL              "stt_method_cancel"
 
-#define STT_METHOD_RESULT              "sttd_method_result"
-#define STT_METHOD_PARTIAL_RESULT      "sttd_method_partial_result"
-#define STT_METHOD_STOPED              "sttd_method_stop"
-#define STT_METHOD_ERROR               "sttd_method_error"
+#define STTD_METHOD_RESULT             "sttd_method_result"
+#define STTD_METHOD_PARTIAL_RESULT     "sttd_method_partial_result"
+#define STTD_METHOD_ERROR              "sttd_method_error"
+#define STTD_METHOD_HELLO              "sttd_method_hello"
+#define STTD_METHOD_SET_STATE          "sttd_method_set_state"
+#define STTD_METHOD_GET_STATE          "sttd_method_get_state"
 
 #define STTD_METHOD_STOP_BY_DAEMON     "sttd_method_stop_by_daemon"
 
index e6cb697e5f87eaaf303611bc8e5b758605854268..25b0edc91de1eb059384795c7bf0633c7c3e6356 100644 (file)
@@ -1,7 +1,190 @@
-stt (0.1.1-1) unstable; urgency=low
+stt (0.1.1-24slp2+1) unstable; urgency=low
 
-  * 1.0 release
-  * Git: pkgs/s/stt
-  * Tag: stt_0.1.1-1
+  * update API for asynchronous init 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-24slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 04 Jun 2012 16:39:43 +0900
+
+stt (0.1.1-23slp2+1) unstable; urgency=low
+
+  * update config and time out during processing and recording 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-23slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Wed, 23 May 2012 15:34:39 +0900
+
+stt (0.1.1-22slp2+1) unstable; urgency=low
+
+  * update for identifical state of client and daemon 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-22slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Wed, 04 Apr 2012 20:42:16 +0900
+
+stt (0.1.1-21slp2+1) unstable; urgency=low
+
+  * fix bug about fork daemon 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-21slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 26 Mar 2012 15:57:46 +0900
+
+stt (0.1.1-20slp2+1) unstable; urgency=low
+
+  * update changelog 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-20slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 19 Mar 2012 19:05:18 +0900
+
+stt (0.1.1-19slp2+1) unstable; urgency=low
+
+  * update bug fix of ipc 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-19slp2+1
 
  -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 19 Mar 2012 10:54:03 +0900
+
+stt (0.1.1-18slp2+1) unstable; urgency=low
+
+  * fix bug for not supported feature of engine 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-18slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Wed, 14 Mar 2012 17:19:18 +0900
+
+stt (0.1.1-17slp2+1) unstable; urgency=low
+
+  * API update for recognition message 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-17slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Wed, 07 Mar 2012 16:23:50 +0900
+
+stt (0.1.1-16slp2+1) unstable; urgency=low
+
+  * code cleanup for beta release 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-16slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Fri, 17 Feb 2012 15:46:19 +0900
+
+stt (0.1.1-15slp2+1) unstable; urgency=low
+
+  * bug fix about recording and update api 
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-15slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Thu, 16 Feb 2012 11:28:54 +0900
+
+stt (0.1.1-14slp2+1) unstable; urgency=low
+
+  * update api for setting options
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-14slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Fri, 20 Jan 2012 10:15:22 +0900
+
+stt (0.1.1-13slp2+1) unstable; urgency=low
+
+  * update engine api
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-13slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Thu, 05 Jan 2012 15:58:32 +0900
+
+stt (0.1.1-12slp2+1) unstable; urgency=low
+
+  * update API
+  * Git: slp/pkgs/s/stt
+  * Tag: stt_0.1.1-12slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Thu, 15 Dec 2011 13:54:55 +0900
+
+stt (0.1.1-11slp2+1) unstable; urgency=low
+
+  * change boiler plate
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-11slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Fri, 02 Dec 2011 10:40:19 +0900
+
+stt (0.1.1-10slp2+1) unstable; urgency=low
+
+  * update for connman
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-10slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Tue, 29 Nov 2011 16:16:10 +0900
+
+stt (0.1.1-9slp2+1) unstable; urgency=low
+
+  * update API for voice talk 
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-9slp2+1 
+
+ -- Dongyeol Lee <dy3.lee@samsung.com> Thu, 24 Nov 2011 15:18:02 +0900
+
+stt (0.1.1-8slp2+1) unstable; urgency=low
+
+  * update bug of prevent and remove dependency of gtk
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-8slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Wed, 07 Sep 2011 14:14:07 +0900
+
+stt (0.1.1-7slp2+1) unstable; urgency=low
+
+  * fix control file for build error
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-7slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Thu, 01 Sep 2011 19:27:24 +0900
+
+stt (0.1.1-6slp2+1) unstable; urgency=low
+
+  * update recorder, IPC and network module. add API for bada
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-6slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Thu, 25 Aug 2011 11:26:32 +0900
+
+stt (0.1.1-5slp2+1) unstable; urgency=low
+
+  * fix defect from prevent
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-5slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Tue, 07 Jun 2011 17:02:49 +0900
+
+stt (0.1.1-4slp2+1) unstable; urgency=low
+
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-4slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 23 May 2011 15:11:24 +0900
+
+stt (0.1.1-3slp2+1) unstable; urgency=low
+
+  * Update API - change error code
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-3slp2+1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Mon, 23 May 2011 08:56:57 +0900
+ stt (0.1.1-2slp2+1) unstable; urgency=low
+
+  * Initial Release (change files to unix type)
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-2slp2+1
+
+ -- Jae-Yong Lee <jaeyong911.lee@samsung.com>  Mon, 16 May 2011 10:16:57 +0900
+
+stt (0.1.1-1slp2+1) unstable; urgency=low
+
+  * Initial Release
+  * Git: 165.213.180.234:slp/pkgs/s/stt
+  * Tag: stt_0.1.1-1slp2+1
+
+ -- Jae-Yong Lee <jaeyong911.lee@samsung.com>  Fri, 13 May 2011 16:17:56 +0900
diff --git a/debian/copyright b/debian/copyright
deleted file mode 100644 (file)
index 3fc3df3..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-Copyright (c) 2011 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
-   http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
index 31b3d8063e9a104c4c00a60a3efdbd9b1ba3af32..92b4d36331325040c0efea55243d5f837ae013d9 100644 (file)
@@ -1,3 +1,4 @@
 @PREFIX@/lib/libstt.so*
 @PREFIX@/lib/libstt_setting.so*
 @PREFIX@/bin/stt-daemon
+@PREFIX@/lib/voice/stt/1.0/sttd.conf
\ No newline at end of file
index c4f2e48f10c1199b28bc095816a411cdd0b5ff8f..51e0ebaae5436a5f6b2a424f5240fe1db8afba46 100644 (file)
@@ -60,6 +60,7 @@ rm -rf %{buildroot}
 %defattr(-,root,root,-)
 %{_libdir}/libstt.so
 %{_libdir}/libstt_setting.so
+%{_libdir}/voice/stt/1.0/sttd.conf
 %{_bindir}/stt-daemon
 
 
index 03cbdb5ee9576fd138295296419464192591c5b4..fb5cce7ca305cbb2ca15b8b050ea14746bad662b 100644 (file)
@@ -48,3 +48,4 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
 ## Install
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sttp.h DESTINATION include)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sttd.conf DESTINATION lib/voice/stt/1.0)
diff --git a/server/sttd.conf b/server/sttd.conf
new file mode 100644 (file)
index 0000000..53f382b
--- /dev/null
@@ -0,0 +1,5 @@
+ENGINE_ID A7AB375F-443B-4924-80DB-FF3DA1506580\r
+LANGUAGE en_US\r
+SILENCE 1\r
+PROFANITY 0\r
+PUNCTUATION 0
\ No newline at end of file
index d61931a072d8d2f9f20c817870d4ea4c0f1c454b..bd3793a716f4297c3aec8ddc167ed264337c3595 100644 (file)
@@ -18,6 +18,8 @@
 /* Client list */
 static GList *g_client_list = NULL;
 
+static GList *g_setting_client_list = NULL;
+
 int client_show_list()
 {
        GList *iter = NULL;
@@ -46,10 +48,35 @@ int client_show_list()
 
        SLOG(LOG_DEBUG, TAG_STTD, "-----"); 
 
+       SLOG(LOG_DEBUG, TAG_STTD, "----- setting client list"); 
+
+       setting_client_info_s *setting_data = NULL;
+
+       if (g_list_length(g_setting_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_setting_client_list);
+
+               int i = 1;      
+               while (NULL != iter) {
+                       /*Get handle data from list*/
+                       setting_data = iter->data;
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[%dth] pid(%d)", i, setting_data->pid); 
+
+                       /*Get next item*/
+                       iter = g_list_next(iter);
+                       i++;
+               }
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "No setting client"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "-----"); 
+
        return 0;
 }
 
-GList* sttd_client_get_item(const int uid)
+GList* __client_get_item(const int uid)
 {
        GList *iter = NULL;
        client_info_s *data = NULL;
@@ -75,7 +102,7 @@ int sttd_client_add(const int pid, const int uid)
 {
        /*Check uid is duplicated*/
        GList *tmp = NULL;
-       tmp = sttd_client_get_item(uid);
+       tmp = __client_get_item(uid);
        
        if (NULL != tmp) {
                SLOG(LOG_WARN, TAG_STTD, "[Client Data] Client uid is already registered"); 
@@ -95,13 +122,12 @@ int sttd_client_add(const int pid, const int uid)
                SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client"); 
                return -1;
        } else {
-               SLOG(LOG_ERROR, TAG_STTD, "[Client Data SUCCESS] Add new client"); 
+               SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Add new client"); 
        }
 
 #ifdef CLIENT_DATA_DEBUG
        client_show_list();
 #endif 
-
        return 0;
 }
 
@@ -111,7 +137,7 @@ int sttd_client_delete(const int uid)
        client_info_s* hnd = NULL;
 
        /*Get handle*/
-       tmp = sttd_client_get_item(uid);
+       tmp = __client_get_item(uid);
        if (NULL == tmp) {
                SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
                return STTD_ERROR_INVALID_PARAMETER;
@@ -138,7 +164,7 @@ int sttd_client_get_state(const int uid, app_state_e* state)
        GList *tmp = NULL;
        client_info_s* hnd = NULL;
 
-       tmp = sttd_client_get_item(uid);
+       tmp = __client_get_item(uid);
        if (NULL == tmp) {
                return STTD_ERROR_INVALID_PARAMETER;
        }
@@ -156,7 +182,7 @@ int sttd_client_set_state(const int uid, const app_state_e state)
        GList *tmp = NULL;
        client_info_s* hnd = NULL;
 
-       tmp = sttd_client_get_item(uid);
+       tmp = __client_get_item(uid);
        if (NULL == tmp) {
                SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
                return STTD_ERROR_INVALID_PARAMETER;
@@ -172,7 +198,10 @@ int sttd_client_set_state(const int uid, const app_state_e state)
 
 int sttd_client_get_ref_count()
 {
-       return g_list_length(g_client_list);
+       int count = g_list_length(g_client_list) + g_list_length(g_setting_client_list);
+       SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] client count : %d", count);
+
+       return count;
 }
 
 int sttd_client_get_pid(const int uid)
@@ -180,7 +209,7 @@ int sttd_client_get_pid(const int uid)
        GList *tmp = NULL;
        client_info_s* hnd = NULL;
 
-       tmp = sttd_client_get_item(uid);
+       tmp = __client_get_item(uid);
        if (NULL == tmp) {
                SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%d) is not found", uid); 
                return STTD_ERROR_INVALID_PARAMETER;
@@ -234,3 +263,167 @@ int sttd_client_get_current_thinking()
 
        return -1;
 }
+
+int sttd_cliet_set_timer(int uid, Ecore_Timer* timer)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       tmp = __client_get_item(uid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       hnd = tmp->data;
+       hnd->timer = timer;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Set timer : uid(%d)", uid);
+
+       return 0;
+}
+
+int sttd_cliet_get_timer(int uid, Ecore_Timer** timer)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       tmp = __client_get_item(uid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       hnd = tmp->data;
+       *timer = hnd->timer;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Get timer : uid(%d)", uid);
+
+       return 0;
+}
+
+
+int sttd_client_get_list(int** uids, int* uid_count)
+{
+       if (NULL == uids || NULL == uid_count)
+               return -1;
+       
+       int count = g_list_length(g_client_list);
+
+       if (0 == count)
+               return -1; 
+
+       int *tmp;
+       tmp = (int*)malloc(sizeof(int) * count);
+       
+       GList *iter = NULL;
+       client_info_s *data = NULL;
+       int i = 0;
+
+       iter = g_list_first(g_client_list);
+       for (i = 0;i < count;i++) {
+               data = iter->data;
+               tmp[i] = data->uid;
+               iter = g_list_next(iter);
+       }
+
+       *uids = tmp;
+       *uid_count = count;
+
+       return 0;
+}
+
+/*
+* Functions for setting
+*/
+
+GList* __setting_client_get_item(int pid)
+{
+       GList *iter = NULL;
+       setting_client_info_s *data = NULL;
+
+       if (0 < g_list_length(g_setting_client_list)) {
+               iter = g_list_first(g_setting_client_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       if (pid == data->pid) 
+                               return iter;
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return NULL;
+}
+
+int sttd_setting_client_add(int pid)
+{      
+       /* Check uid is duplicated */
+       GList *tmp = NULL;
+       tmp = __setting_client_get_item(pid);
+
+       if (NULL != tmp) {
+               SLOG(LOG_WARN, TAG_STTD, "[Client Data] Setting client(%d) is already registered", pid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       setting_client_info_s *info = (setting_client_info_s*)g_malloc0(sizeof(setting_client_info_s));
+
+       info->pid = pid;
+
+       /* Add item to global list */
+       g_setting_client_list = g_list_append(g_setting_client_list, info);
+
+       if (NULL == g_setting_client_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client"); 
+               return -1;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Add new client"); 
+       }
+
+#ifdef CLIENT_DATA_DEBUG
+       client_show_list();
+#endif 
+       return 0;
+}
+
+int sttd_setting_client_delete(int pid)
+{
+       GList *tmp = NULL;
+       setting_client_info_s* hnd = NULL;
+
+       /*Get handle*/
+       tmp = __setting_client_get_item(pid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Setting uid(%d) is NOT valid", pid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /*Free client structure*/
+       hnd = tmp->data;
+       if (NULL != hnd) {
+               g_free(hnd);
+       }
+
+       /*Remove handle from list*/
+       g_setting_client_list = g_list_remove_link(g_setting_client_list, tmp);
+
+#ifdef CLIENT_DATA_DEBUG
+       client_show_list();
+#endif 
+
+       return 0;
+}
+
+bool sttd_setting_client_is(int pid)
+{
+       GList *tmp = __setting_client_get_item(pid);
+       if (NULL == tmp) {
+               return false;
+       }
+
+       return true;
+}
\ No newline at end of file
index 5a80c849da86f809e1ea89d353a0c5f3c7536fac..8a640fa482c82385f62446af289aeebe09fa0435 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
 #ifndef __STTD_CLIENT_DATA_H_
 #define __STTD_CLIENT_DATA_H_
 
+#include <glib.h>
+#include <Ecore.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 typedef enum {
-       APP_STATE_READY         = 0,
-       APP_STATE_RECORDING     = 1,
-       APP_STATE_PROCESSING    = 2
+       APP_STATE_CREATED       = 0,
+       APP_STATE_READY         = 1,
+       APP_STATE_RECORDING     = 2,
+       APP_STATE_PROCESSING    = 3
 }app_state_e;
 
 typedef struct {
        int     pid;
        int     uid;
        app_state_e     state;
+       Ecore_Timer*    timer;
 } client_info_s;
 
+typedef struct {
+       int pid;
+} setting_client_info_s;
+
 int sttd_client_add(const int pid, const int uid);
 
 int sttd_client_delete(const int uid);
@@ -48,6 +56,19 @@ int sttd_client_get_current_recording();
 
 int sttd_client_get_current_thinking();
 
+int sttd_cliet_set_timer(int uid, Ecore_Timer* timer);
+
+int sttd_cliet_get_timer(int uid, Ecore_Timer** timer);
+
+int sttd_client_get_list(int** uids, int* uid_count);
+
+
+int sttd_setting_client_add(int pid);
+
+int sttd_setting_client_delete(int pid);
+
+bool sttd_setting_client_is(int pid);
+
 #ifdef __cplusplus
 }
 #endif
index de21d3ca11673687d75c41eacbb3982941ac844a..a30cedfb676ad57a83102dd63556163b8b64c59f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
 *  limitations under the License.
 */
 
-
-#include <vconf.h>
-
 #include "sttd_main.h"
 #include "sttd_config.h"
 
 
-/*
-* stt-daemon config
-*/
+#define CONFIG_FILE_PATH       BASE_DIRECTORY_DOWNLOAD"sttd.conf"
+#define CONFIG_DEFAULT         BASE_DIRECTORY_DEFAULT"sttd.conf"
 
-int sttd_config_get_char_type(const char* key, char** value)
-{
-       if (NULL == key || NULL == value) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
-               return STTD_ERROR_INVALID_PARAMETER;
-       } 
-
-       *value = vconf_get_str(key);
-       if (NULL == *value) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get char type from config : key(%s)", key);
-               return -1;
-       }
+#define ENGINE_ID      "ENGINE_ID"
+#define LANGUAGE       "LANGUAGE"
+#define SILENCE                "SILENCE"
+#define PROFANITY      "PROFANITY"
+#define PUNCTUATION    "PUNCTUATION"
 
-       return 0;
-}
 
-int sttd_config_set_char_type(const char* key, const char* value)
+static char*   g_engine_id;
+static char*   g_language;
+static int     g_silence;
+static int     g_profanity;
+static int     g_punctuation;
+
+int __sttd_config_save()
 {
-       if (NULL == key || NULL == value) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
-               return STTD_ERROR_INVALID_PARAMETER;
-       } 
+       FILE* config_fp;
+       config_fp = fopen(CONFIG_FILE_PATH, "w+");
 
-       if (0 != vconf_set_str(key, value)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set char type"); 
+       if (NULL == config_fp) {
+               // make file and file default
+               SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to load config (engine id)");
                return -1;
        }
 
+       /* Write engine id */
+       fprintf(config_fp, "%s %s\n", ENGINE_ID, g_engine_id);
+
+       /* Write language */
+       fprintf(config_fp, "%s %s\n", LANGUAGE, g_language);
+
+       /* Write silence detection */
+       fprintf(config_fp, "%s %d\n", SILENCE, g_silence);
+
+       /* Write profanity */
+       fprintf(config_fp, "%s %d\n", PROFANITY, g_profanity);
+
+       /* Write punctuation */
+       fprintf(config_fp, "%s %d\n", PUNCTUATION, g_punctuation);
+
+       fclose(config_fp);
+
        return 0;
 }
 
-int sttd_config_get_bool_type(const char* key, bool* value)
+int __sttd_config_load()
 {
-       if (NULL == key || NULL == value) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
-               return STTD_ERROR_INVALID_PARAMETER;
-       } 
-
-       int result ;
-       if (0 != vconf_get_int(key, &result)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
-               return -1;
+       FILE* config_fp;
+       char buf_id[256] = {0};
+       char buf_param[256] = {0};
+       int int_param = 0;
+
+       config_fp = fopen(CONFIG_FILE_PATH, "r");
+
+       if (NULL == config_fp) {
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Not open file(%s)", CONFIG_FILE_PATH);
+
+               config_fp = fopen(CONFIG_DEFAULT, "r");
+               if (NULL == config_fp) {
+                       SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Not open original config file(%s)", CONFIG_FILE_PATH);
+                       __sttd_config_save();
+                       return 0;
+               }
        }
 
-       *value = (bool) result;
+       /* Read engine id */
+       fscanf(config_fp, "%s %s", buf_id, buf_param);
+       if (0 == strncmp(ENGINE_ID, buf_id, strlen(ENGINE_ID))) {
+               g_engine_id = strdup(buf_param);
+       } else {
+               fclose(config_fp);
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Fail to load config (engine id)");
+               __sttd_config_save();
+               return 0;
+       }
 
-       return 0;
-}
+       /* Read language */
+       fscanf(config_fp, "%s %s", buf_id, buf_param);
+       if (0 == strncmp(LANGUAGE, buf_id, strlen(LANGUAGE))) {
+               g_language = strdup(buf_param);
+       } else {
+               fclose(config_fp);
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Fail to load config (language)");
+               __sttd_config_save();
+               return 0;
+       }
 
-int sttd_config_set_bool_type(const char* key, const bool value)
-{
-       if (NULL == key) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
-               return STTD_ERROR_INVALID_PARAMETER;
-       } 
-
-       int result = (int)value;
-       if (0 != vconf_set_int(key, result)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
-               return -1;
+       /* Read silence detection */
+       fscanf(config_fp, "%s %d", buf_id, &int_param);
+       if (0 == strncmp(SILENCE, buf_id, strlen(SILENCE))) {
+               g_silence = int_param;
+       } else {
+               fclose(config_fp);
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Fail to load config (silence)");
+               __sttd_config_save();
+               return 0;
+       }
+
+       /* Read profanity filter */
+       fscanf(config_fp, "%s %d", buf_id, &int_param);
+       if (0 == strncmp(PROFANITY, buf_id, strlen(PROFANITY))) {
+               g_profanity = int_param;
+       } else {
+               fclose(config_fp);
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Fail to load config (profanity filter)");
+               __sttd_config_save();
+               return 0;
+       }
+
+       /* Read punctuation override */
+       fscanf(config_fp, "%s %d", buf_id, &int_param);
+       if (0 == strncmp(PUNCTUATION, buf_id, strlen(PUNCTUATION))) {
+               g_punctuation = int_param;
+       } else {
+               fclose(config_fp);
+               SLOG(LOG_WARN, TAG_STTD, "[Config WARNING] Fail to load config (punctuation override)");
+               __sttd_config_save();
+               return 0;
        }
 
+       SLOG(LOG_DEBUG, TAG_STTD, "[Config] Load config : engine(%s), language(%s), silence(%d), profanity(%d), punctuation(%d)",
+               g_engine_id, g_language, g_silence, g_profanity, g_punctuation);
+
        return 0;
 }
 
-/*
-* plug-in daemon interface
-*/
-
-int __make_key_for_engine(const char* engine_id, const char* key, char** out_key)
+int sttd_config_initialize()
 {
-       int key_size = strlen(STTD_CONFIG_PREFIX) + strlen(engine_id) + strlen(key) + 2; /* 2 means both '/' and '\0'*/
-
-       *out_key = (char*) malloc( sizeof(char) * key_size);
+       g_engine_id = NULL;
+       g_language = NULL;
+       g_silence = 1;
+       g_profanity = 0;
+       g_punctuation = 0;
 
-       snprintf(*out_key, key_size, "%s%s/%s", STTD_CONFIG_PREFIX, engine_id, key );
+       __sttd_config_load();
 
        return 0;
 }
 
-int sttd_config_set_persistent_data(const char* engine_id, const char* key, const char* value)
+int sttd_config_finalize()
 {
-       if (NULL == engine_id || NULL == key || NULL == value) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
-               return STTD_ERROR_INVALID_PARAMETER;
-       }
-
-       char* vconf_key = NULL;
-       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
-               return -1;
-       }
+       __sttd_config_save();
+       return 0;
+}
 
-       if (NULL == vconf_key)          
+int sttd_config_get_default_engine(char** engine_id)
+{
+       if (NULL == engine_id)
                return -1;
 
-       if (0 != vconf_set_str(vconf_key, value)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set key, value");
-
-               if (vconf_key != NULL)  
-                       free(vconf_key);
+       *engine_id = strdup(g_engine_id);
+       return 0;
+}
 
+int sttd_config_set_default_engine(const char* engine_id)
+{
+       if (NULL == engine_id)
                return -1;
-       }
-
-       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_set_persistent_data : key(%s), value(%s)", vconf_key, value);
 
-       if (NULL != vconf_key)  
-               free(vconf_key);
+       if (NULL != g_engine_id)
+               free(g_engine_id);
 
+       g_engine_id = strdup(engine_id);
+       __sttd_config_save();
        return 0;
 }
 
-int sttd_config_get_persistent_data(const char* engine_id, const char* key, char** value)
+int sttd_config_get_default_language(char** language)
 {
-       if (NULL == engine_id) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
-               return STTD_ERROR_INVALID_PARAMETER;
-       }
+       if (NULL == language)
+               return -1;
 
-       char* vconf_key = NULL;
+       *language = strdup(g_language);
 
-       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
-               return -1;
-       }
+       return 0;
+}
 
-       if (NULL == vconf_key)
+int sttd_config_set_default_language(const char* language)
+{
+       if (NULL == language)
                return -1;
 
-       char* temp;
-       temp = vconf_get_str(vconf_key);
-       if (NULL == temp) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get value");
+       if (NULL != g_language)
+               free(g_language);
 
-               if(vconf_key != NULL)   
-                       free(vconf_key);
+       g_language = strdup(language);
 
-               return -1;
-       }
+       __sttd_config_save();
 
-       *value = g_strdup(temp);
+       return 0;
+}
 
-       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_get_persistent_data : key(%s), value(%s)", vconf_key, *value);
+int sttd_config_get_default_silence_detection(int* silence)
+{
+       if (NULL == silence)
+               return -1;
 
-       if (vconf_key != NULL)  free(vconf_key);
-       if (temp != NULL)       free(temp);
+       *silence = g_silence;
 
        return 0;
 }
 
-int sttd_config_remove_persistent_data(const char* engine_id, const char* key)
+int sttd_config_set_default_silence_detection(int silence)
 {
-       if (NULL == engine_id || NULL == key) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
-               return STTD_ERROR_INVALID_PARAMETER;
-       }
+       g_silence = silence;
+       __sttd_config_save();
+       return 0;
+}
 
-       char* vconf_key = NULL;
-       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
+int sttd_config_get_default_profanity_filter(int* profanity)
+{
+       if (NULL == profanity)
                return -1;
-       }
 
-       if (NULL == vconf_key)          
-               return -1;
+       *profanity = g_profanity;
 
-       if (0 != vconf_unset(vconf_key)) {      
-               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to remove key");
+       return 0;
+}
 
-               if(vconf_key != NULL)   
-                       free(vconf_key);
+int sttd_config_set_default_profanity_filter(int profanity)
+{
+       g_profanity = profanity;
+       __sttd_config_save();
+       return 0;
+}
 
+int sttd_config_get_default_punctuation_override(int* punctuation)
+{
+       if (NULL == punctuation)
                return -1;
-       }
 
-       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_remove_persistent_data : key(%s)", vconf_key);
-
-       if( NULL != vconf_key )         
-               free(vconf_key);
+       *punctuation = g_punctuation;
 
        return 0;
 }
 
-
+int sttd_config_set_default_punctuation_override(int punctuation)
+{
+       g_punctuation = punctuation;
+       __sttd_config_save();
+       return 0;
+}
\ No newline at end of file
index d87d290890e5951eae413a917bb5dfbe3305ac16..6e98a4d39dce36b44e5a7bced53f351e6eb47702 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
 #ifndef __STTD_CONFIG_H_
 #define __STTD_CONFIG_H_
 
-#include <stdbool.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define STTD_CONFIG_PREFIX "db/sttd/"
-
-#define CONFIG_KEY_DEFAULT_ENGINE_ID   STTD_CONFIG_PREFIX"engine"
-#define CONFIG_KEY_DEFAULT_LANGUAGE    STTD_CONFIG_PREFIX"language"
-#define CONFIG_KEY_PROFANITY_FILTER    STTD_CONFIG_PREFIX"profanity"
-#define CONFIG_KEY_PUNCTUATION_OVERRIDE        STTD_CONFIG_PREFIX"punctuation"
-#define CONFIG_KEY_SILENCE_DETECTION   STTD_CONFIG_PREFIX"silence"
+int sttd_config_initialize();
 
+int sttd_config_finalize();
 
-/*
-* stt-daemon config
-*/
+int sttd_config_get_default_engine(char** engine_id);
 
-int sttd_config_get_char_type(const char* key, char** value);
+int sttd_config_set_default_engine(const char* engine_id);
 
-int sttd_config_set_char_type(const char* key, const char* value);
+int sttd_config_get_default_language(char** language);
 
-int sttd_config_get_bool_type(const char* key, bool* value);
+int sttd_config_set_default_language(const char* langauge);
 
-int sttd_config_set_bool_type(const char* key, const bool value);
+int sttd_config_get_default_silence_detection(int* silence);
 
+int sttd_config_set_default_silence_detection(int silence);
 
-/*
-* interface for engine plug-in
-*/
+int sttd_config_get_default_profanity_filter(int* profanity);
 
-int sttd_config_set_persistent_data(const char* engine_id, const char* key, const char* value);
+int sttd_config_set_default_profanity_filter(int profanity);
 
-int sttd_config_get_persistent_data(const char* engine_id, const char* key, char** value);
+int sttd_config_get_default_punctuation_override(int* punctuation);
 
-int sttd_config_remove_persistent_data(const char* engine_id, const char* key);
+int sttd_config_set_default_punctuation_override(int punctuation);
 
 
 #ifdef __cplusplus
index 6f4697bbf5992ff116978161aa2614acbeec5cf5..12174d808bc9dfe20f6b664ec164f513e442cb30 100644 (file)
 #include "stt_defs.h"
 
 static DBusConnection* g_conn;
+static int g_waiting_time = 3000;
+
+int sttdc_send_hello(int uid)
+{
+       int pid = sttd_client_get_pid(uid);
+
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+               return -1;
+       }
+
+       char service_name[64];
+       memset(service_name, 0, 64);
+       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+
+       char target_if_name[128];
+       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+
+       DBusMessage* msg;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send hello message : uid(%d)", uid);
+
+       msg = dbus_message_new_method_call(
+               service_name, 
+               STT_CLIENT_SERVICE_OBJECT_PATH, 
+               target_if_name, 
+               STTD_METHOD_HELLO);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
+               return -1;
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = -1;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       dbus_message_unref(msg);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = -1;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
+               result = 0;
+       }
+
+       return result;
+}
+
+int sttdc_send_get_state(int uid, int* state)
+{
+       int pid = sttd_client_get_pid(uid);
+
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+               return -1;
+       }
+
+       char service_name[64];
+       memset(service_name, 0, 64);
+       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+
+       char target_if_name[128];
+       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+
+       DBusMessage* msg;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send get state message : uid(%d)", uid);
+
+       msg = dbus_message_new_method_call(
+               service_name, 
+               STT_CLIENT_SERVICE_OBJECT_PATH, 
+               target_if_name, 
+               STTD_METHOD_GET_STATE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
+               return -1;
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int tmp = -1;
+       int result = 0;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       dbus_message_unref(msg);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &tmp, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = -1;
+               } else {
+                       *state = tmp;
+                       result = 0;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
+               result = -1;
+       }
+       
+       return result;
+}
 
 int sttdc_send_result(int uid, const char* type, const char** data, int data_count, const char* result_msg)
 {
@@ -47,7 +172,7 @@ int sttdc_send_result(int uid, const char* type, const char** data, int data_cou
                service_name, 
                STT_CLIENT_SERVICE_OBJECT_PATH, 
                target_if_name, 
-               STT_METHOD_RESULT);
+               STTD_METHOD_RESULT);
 
        if (NULL == msg) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
@@ -155,7 +280,7 @@ int sttdc_send_partial_result(int uid, const char* data)
                service_name, 
                STT_CLIENT_SERVICE_OBJECT_PATH, 
                target_if_name, 
-               STT_METHOD_PARTIAL_RESULT);
+               STTD_METHOD_PARTIAL_RESULT);
 
        if (NULL == msg) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
@@ -214,7 +339,7 @@ int sttdc_send_error_signal(int uid, int reason, char *err_msg)
                service_name, 
                STT_CLIENT_SERVICE_OBJECT_PATH, 
                target_if_name, 
-               STT_METHOD_PARTIAL_RESULT);
+               STTD_METHOD_ERROR);
 
        if (NULL == msg) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
@@ -227,23 +352,29 @@ int sttdc_send_error_signal(int uid, int reason, char *err_msg)
                DBUS_TYPE_STRING, &err_msg,
                DBUS_TYPE_INVALID);
        
-       if (!dbus_connection_send(g_conn, msg, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !"); 
-               return -1;
-       }
+       DBusError err;
+       dbus_error_init(&err);
 
-       dbus_connection_flush(g_conn);
+       DBusMessage* result_msg;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
 
+       if (NULL != result_msg) {
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL.");
+       }
+
        return 0;
 }
 
-int sttd_send_stop(int uid)
+int sttdc_send_set_state(int uid, int state)
 {
        int pid = sttd_client_get_pid(uid);
 
        if (0 > pid) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
                return -1;
        }
 
@@ -251,38 +382,54 @@ int sttd_send_stop(int uid)
        memset(service_name, 0, 64);
        snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
 
-       char target_if_name[64];
+       char target_if_name[128];
        snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
 
-       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send %s signal : ifname(%s), uid(%d)", signal, target_if_name, uid);
-
        DBusMessage* msg;
 
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send change state message : uid(%d), state(%d)", uid, state);
+
        msg = dbus_message_new_method_call(
                service_name, 
                STT_CLIENT_SERVICE_OBJECT_PATH, 
                target_if_name, 
-               STT_METHOD_STOPED);
+               STTD_METHOD_SET_STATE);
 
        if (NULL == msg) { 
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create stop message"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
                return -1;
        }
 
-       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+       dbus_message_append_args(msg, 
+               DBUS_TYPE_INT32, &uid, 
+               DBUS_TYPE_INT32, &state, 
+               DBUS_TYPE_INVALID);
 
-       /* send the message and flush the connection */
-       if (!dbus_connection_send(g_conn, msg, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Out Of Memory!"); 
-               return -1;
-       }
+       DBusError err;
+       dbus_error_init(&err);
 
-       dbus_connection_flush(g_conn);
+       DBusMessage* result_msg;
+       int result = -1;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
 
-       return 0;
-}
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
 
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = -1;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
+       }
+
+       return result;
+}
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
@@ -392,8 +539,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_ENGINE_SETTING))
                sttd_dbus_server_setting_set_engine_setting(conn, msg);
 
-       else 
-               return ECORE_CALLBACK_RENEW; 
+
+       /* free the message */
+       dbus_message_unref(msg);
 
        return ECORE_CALLBACK_RENEW;
 }
index 37dbb13c868a37226b86fecc6b678fc7b34ab1b6..fa0e7fe56d93c8f16d5b1535a48692f0f447c64a 100644 (file)
@@ -24,13 +24,17 @@ int sttd_dbus_open_connection();
 int sttd_dbus_close_connection();
 
 
+int sttdc_send_hello(int uid);
+
+int sttdc_send_get_state(int uid, int* state);
+
 int sttdc_send_result(int uid, const char* type, const char** data, int data_count, const char* result_msg);
 
 int sttdc_send_partial_result(int uid, const char* data);
 
 int sttdc_send_error_signal(int uid, int reason, char *err_msg);
 
-int sttd_send_stop(int uid);
+int sttdc_send_set_state(int uid, int state);
 
 int sttd_send_stop_recognition_by_daemon(int uid);
 
index 159231a2143b89fe3b1f75b4c13e44913c0e279b..96725c2d4e4e5d917d8455d1e65ae63530b6772f 100644 (file)
@@ -1546,11 +1546,13 @@ int sttd_dbus_server_stop_by_daemon(DBusMessage* msg)
                sttd_server_stop(uid);
 
                /* check silence detection option from config */
-               int ret = sttd_send_stop(uid); 
+               int ret = sttdc_send_set_state(uid, (int)APP_STATE_PROCESSING);
                if (0 == ret) {
                        SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
                } else {
                        SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+                       /* Remove client */
+                       sttd_server_finalize(uid);
                }
        }
        
index 2d7195a97c9e277140ae9bb1f426cec46373a050..054de52c098a0db74f34e4d8ea003939be35f5f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
@@ -150,35 +150,32 @@ int sttd_engine_agent_init(result_callback result_cb, partial_result_callback pa
 
        g_agent_init = true;
 
-       if (0 != sttd_config_get_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, &(g_cur_engine.default_lang)) ) {
-               /* Default Voice is NULL */
-               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No default language in config"); 
-               g_cur_engine.default_lang = NULL;
+       if (0 != sttd_config_get_default_language(&(g_cur_engine.default_lang))) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No default voice in config"); 
+               /* Set default voice */
+               g_cur_engine.default_lang = strdup("en_US");
        }
 
-       bool temp;
-       if (0 != sttd_config_get_bool_type(CONFIG_KEY_PROFANITY_FILTER, &temp)) {
-               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No profanity filter value in config"); 
-               sttd_config_set_bool_type(CONFIG_KEY_PROFANITY_FILTER, false);
-               g_default_profanity_filter = false;
+       int temp;
+       if (0 != sttd_config_get_default_silence_detection(&temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config"); 
+               g_default_silence_detected = true;
        } else {
-               g_default_profanity_filter = temp;
+               g_default_silence_detected = (bool)temp;
        }
 
-       if (0 != sttd_config_get_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, &temp)) {
-               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No punctuation override value in config"); 
-               sttd_config_set_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, false);
-               g_default_punctuation_override = false;
+       if (0 != sttd_config_get_default_profanity_filter(&temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no profanity filter in config"); 
+               g_default_profanity_filter = false;
        } else {
-               g_default_punctuation_override = temp;
+               g_default_profanity_filter = (bool)temp;
        }
 
-       if (0 != sttd_config_get_bool_type(CONFIG_KEY_SILENCE_DETECTION, &temp)) {
-               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config"); 
-               sttd_config_set_bool_type(CONFIG_KEY_SILENCE_DETECTION, true);
-               g_default_silence_detected = true;
+       if (0 != sttd_config_get_default_punctuation_override(&temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no punctuation override in config"); 
+               g_default_punctuation_override = false;
        } else {
-               g_default_silence_detected = temp;
+               g_default_punctuation_override = (bool)temp;
        }
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Engine Agent Initialize"); 
@@ -190,7 +187,7 @@ int sttd_engine_agent_release()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        /* unload current engine */
@@ -237,7 +234,7 @@ int sttd_engine_agent_initialize_current_engine()
        /* check agent init */
        if (false == g_agent_init ) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        /* update engine list */
@@ -250,7 +247,7 @@ int sttd_engine_agent_initialize_current_engine()
        char* cur_engine_uuid = NULL;
        bool is_get_engineid_from_config = false;
 
-       if (0 != sttd_config_get_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, &cur_engine_uuid)) {
+       if (0 != sttd_config_get_default_engine(&cur_engine_uuid)) {
 
                SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] There is not current engine from config"); 
 
@@ -312,7 +309,7 @@ int sttd_engine_agent_initialize_current_engine()
        }
 
        if (false == is_get_engineid_from_config) {
-               if (0 != sttd_config_set_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, cur_engine_uuid))
+               if (0 != sttd_config_set_default_engine(cur_engine_uuid))
                        SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine "); 
        }
 
@@ -622,7 +619,7 @@ int sttd_engine_agent_load_current_engine()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_set) {
@@ -767,8 +764,8 @@ int sttd_engine_agent_load_current_engine()
                                        return STTD_ERROR_OPERATION_FAILED;
                                }
 
-                               sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, temp_lang);
-                               
+                               sttd_config_set_default_language(temp_lang);
+
                                g_cur_engine.default_lang = g_strdup(temp_lang);
                                
                                SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Select default voice : lang(%s)", temp_lang);
@@ -796,7 +793,7 @@ int sttd_engine_agent_unload_current_engine()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized "); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_set) {
@@ -834,7 +831,7 @@ bool sttd_engine_agent_need_network()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -849,7 +846,7 @@ int sttd_engine_get_option_supported(bool* silence, bool* profanity, bool* punct
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -958,7 +955,7 @@ int __set_option(int profanity, int punctuation, int silence)
                }
        } else {
                /* Client selection */
-               if (g_cur_engine.silence_detection != punctuation) {
+               if (g_cur_engine.silence_detection != silence) {
                        if (NULL != g_cur_engine.pefuncs->set_silence_detection) {
                                if (0 != g_cur_engine.pefuncs->set_silence_detection((bool)silence)) {
                                        SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection");
@@ -982,7 +979,7 @@ int sttd_engine_recognize_start(const char* lang, const char* recognition_type,
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1029,7 +1026,7 @@ int sttd_engine_recognize_audio(const void* data, unsigned int length)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1049,7 +1046,7 @@ int sttd_engine_recognize_audio(const void* data, unsigned int length)
 
        int ret = g_cur_engine.pefuncs->set_recording(data, length);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set recording error(%d)", ret); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret); 
                return ret;
        }
 
@@ -1060,7 +1057,7 @@ int sttd_engine_recognize_stop()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1086,7 +1083,7 @@ int sttd_engine_recognize_cancel()
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1112,7 +1109,7 @@ int sttd_engine_get_audio_format(sttp_audio_type_e* types, int* rate, int* chann
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1160,7 +1157,7 @@ int sttd_engine_supported_langs(GList** lang_list)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1187,7 +1184,7 @@ int sttd_engine_get_default_lang(char** lang)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1210,7 +1207,7 @@ int sttd_engine_is_partial_result_supported(bool* partial_result)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1242,7 +1239,7 @@ int sttd_engine_setting_get_engine_list(GList** engine_list)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1308,7 +1305,7 @@ int sttd_engine_setting_set_engine(const char* engine_id)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == engine_id) {
@@ -1319,7 +1316,7 @@ int sttd_engine_setting_set_engine(const char* engine_id)
        /* compare current engine and new engine. */
        if (NULL != g_cur_engine.engine_uuid) {
                if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(g_cur_engine.engine_uuid))) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent] New engine is the same as current engine"); 
+                       SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] New engine is the same as current engine"); 
                        return 0;
                }
        }
@@ -1343,6 +1340,7 @@ int sttd_engine_setting_set_engine(const char* engine_id)
                
                /* roll back to old current engine. */
                __internal_set_current_engine(tmp_uuid);
+               sttd_engine_agent_load_current_engine();
 
                if (NULL != tmp_uuid)   
                        free(tmp_uuid);
@@ -1365,7 +1363,7 @@ int sttd_engine_setting_set_engine(const char* engine_id)
                free(tmp_uuid);
 
        /* set engine id to config */
-       if (0 != sttd_config_set_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, engine_id)) {
+       if (0 != sttd_config_set_default_engine(engine_id)) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set engine id"); 
        }
 
@@ -1376,7 +1374,7 @@ int sttd_engine_setting_get_lang_list(char** engine_id, GList** lang_list)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1405,7 +1403,7 @@ int sttd_engine_setting_get_default_lang(char** language)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1446,7 +1444,7 @@ int sttd_engine_setting_get_default_lang(char** language)
                                        return STTD_ERROR_OPERATION_FAILED;
                                }
 
-                               sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, temp_lang);
+                               sttd_config_set_default_language(temp_lang);
 
                                g_cur_engine.default_lang = g_strdup(temp_lang);
 
@@ -1472,7 +1470,7 @@ int sttd_engine_setting_set_default_lang(const char* language)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1496,7 +1494,7 @@ int sttd_engine_setting_set_default_lang(const char* language)
 
        g_cur_engine.default_lang = strdup(language);
 
-       ret = sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, language);
+       ret = sttd_config_set_default_language(language);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret); 
        }
@@ -1508,7 +1506,7 @@ int sttd_engine_setting_get_profanity_filter(bool* value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1530,7 +1528,7 @@ int sttd_engine_setting_set_profanity_filter(bool value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1551,7 +1549,7 @@ int sttd_engine_setting_set_profanity_filter(bool value)
 
        g_default_profanity_filter = value;
 
-       ret = sttd_config_set_bool_type(CONFIG_KEY_PROFANITY_FILTER, value);
+       ret = sttd_config_set_default_profanity_filter((int)value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret); 
        }
@@ -1563,7 +1561,7 @@ int sttd_engine_setting_get_punctuation_override(bool* value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1585,7 +1583,7 @@ int sttd_engine_setting_set_punctuation_override(bool value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1605,7 +1603,7 @@ int sttd_engine_setting_set_punctuation_override(bool value)
        }
        g_default_punctuation_override = value;
 
-       ret = sttd_config_set_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, value);
+       ret = sttd_config_set_default_punctuation_override((int)value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override (%d)", ret); 
        }
@@ -1617,7 +1615,7 @@ int sttd_engine_setting_get_silence_detection(bool* value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1639,7 +1637,7 @@ int sttd_engine_setting_set_silence_detection(bool value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1655,7 +1653,7 @@ int sttd_engine_setting_set_silence_detection(bool value)
        
        g_default_silence_detected = value;
 
-       ret = sttd_config_set_bool_type(CONFIG_KEY_SILENCE_DETECTION, value);
+       ret = sttd_config_set_default_silence_detection((int)value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection (%d)", ret); 
        }
@@ -1685,7 +1683,7 @@ int sttd_engine_setting_get_engine_setting_info(char** engine_id, GList** settin
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
@@ -1722,7 +1720,7 @@ int sttd_engine_setting_set_engine_setting(const char* key, const char* value)
 {
        if (false == g_agent_init) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
-               return STTD_ERROR_INVALID_STATE;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (false == g_cur_engine.is_loaded) {
index d9c4a7d4dfc18d3401c97b91bc94364bf598782a..eb097104113f38e3b863c10f3f5bab323edda767 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
index dc2b3074813098b6002e60888bf6eaad4141a526..c3f2e0848c493e133476d658be435d3e725d2bbb 100644 (file)
@@ -18,6 +18,9 @@
 #include "sttd_dbus.h"
 
 #include <Ecore.h>
+#include "sttd_server.h"
+
+#define CLIENT_CLEAN_UP_TIME 500
 
 int main(int argc, char** argv)
 {
@@ -37,6 +40,8 @@ int main(int argc, char** argv)
 
        sttd_network_initialize();
 
+       ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL);
+
        printf("stt-daemon start...\n");
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-daemon start..."); 
index 57fc5f997865d55c48d7d6290e18e655ec2cd05b..8dad6c6cda5e0411dabcb64fbaed65a26c00ff63 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
@@ -34,14 +34,17 @@ extern "C" {
 
 #define TAG_STTD "sttd"
 
+#define BASE_DIRECTORY_DEFAULT                 "/usr/lib/voice/stt/1.0/"
 #define ENGINE_DIRECTORY_DEFAULT               "/usr/lib/voice/stt/1.0/engine"
 #define ENGINE_DIRECTORY_DEFAULT_SETTING       "/usr/lib/voice/stt/1.0/setting"
 
+#define BASE_DIRECTORY_DOWNLOAD                        "/opt/apps/voice/stt/1.0/"
 #define ENGINE_DIRECTORY_DOWNLOAD              "/opt/apps/voice/stt/1.0/engine"
 #define ENGINE_DIRECTORY_DOWNLOAD_SETTING      "/opt/apps/voice/stt/1.0/setting"
 
 /* for debug message */
 #define RECORDER_DEBUG
+#define CLIENT_DATA_DEBUG
 
 typedef enum {
        STTD_ERROR_NONE                 = 0,            /**< Successful */
index ee831166ea5534c86ce8e06987e96e607e4db4a1..4f9f7f009ebe2138f106abbde003b116a5334a09 100644 (file)
@@ -61,6 +61,10 @@ static bool g_init = false;
 
 static char g_temp_file_name[128] = {'\0',};
 
+#ifdef BUF_SAVE_MODE
+static FILE* g_pFile;
+#endif 
+
 /* Recorder obj */
 sttd_recorder_s *__recorder_getinstance();
 void __recorder_state_set(sttd_recorder_state state);
index 8fba549120dcb11a84e6a9324dbd90f695bc4aa0..dc9121f9ce4ca364ec3e208baaa1a045a3a055df 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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
 */
 static bool g_is_engine;
 
+static double g_state_check_time = 15.5;
+
 /*
 * STT Server Callback Functions                                                                                        `                                 *
 */
 
+Eina_Bool __stop_by_silence(void *data)
+{
+       SLOG(LOG_DEBUG, TAG_STTD, "===== Stop by silence detection");
+
+       int uid = 0;
+
+       uid = sttd_client_get_current_recording();
+
+       if (uid > 0) {
+               if (0 != sttd_server_stop(uid))
+                       return EINA_FALSE;
+
+               int ret = sttdc_send_set_state(uid, (int)APP_STATE_PROCESSING);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send state : result(%d)", ret); 
+
+                       /* Remove client */
+                       sttd_server_finalize(uid);
+               }       
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return EINA_FALSE;
+}
+
 int audio_recorder_callback(const void* data, const unsigned int length)
 {
        if (0 != sttd_engine_recognize_audio(data, length)) {
-               
-               /* send message for stop */
-               SLOG(LOG_DEBUG, TAG_STTD, "===== Fail to set recording data ");
-                       
                int uid = sttd_client_get_current_recording();
 
                app_state_e state;
@@ -51,19 +76,16 @@ int audio_recorder_callback(const void* data, const unsigned int length)
                        return -1;
                }
 
-               if (0 != sttd_send_stop_recognition_by_daemon(uid)) {
+               ecore_timer_add(0, __stop_by_silence, NULL);
+
+               /*if (0 != sttd_send_stop_recognition_by_daemon(uid)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail "); 
                } else {
                        SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] <<<< stop message : uid(%d)", uid); 
-               }
-
-               SLOG(LOG_DEBUG, TAG_STTD, "=====");
-               SLOG(LOG_DEBUG, TAG_STTD, "  ");
+               }*/
                
                return -1;
        }
-       
-       
 
        return 0;
 }
@@ -76,7 +98,7 @@ void sttd_server_recognition_result_callback(sttp_result_event_e event, const ch
        /* check uid */
        int *uid = (int*)user_data;
 
-       SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event); 
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", *uid, event); 
 
        app_state_e state;
        if (0 != sttd_client_get_state(*uid, &state)) {
@@ -86,6 +108,13 @@ void sttd_server_recognition_result_callback(sttp_result_event_e event, const ch
                return;
        }
 
+       /* Delete timer for processing time out */
+       Ecore_Timer* timer;
+       sttd_cliet_get_timer(*uid, &timer);
+
+       if (NULL != timer)
+               ecore_timer_del(timer);
+
        /* send result to client */
        if (STTP_RESULT_EVENT_SUCCESS == event && 0 < data_count && NULL != data) {
 
@@ -98,54 +127,26 @@ void sttd_server_recognition_result_callback(sttp_result_event_e event, const ch
 
                                if (0 != sttdc_send_error_signal(*uid, reason, "Fail to send recognition result")) {
                                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info . Remove client data"); 
-
-                                       /* clean client data */
-                                       sttd_client_delete(*uid);
                                }
                        }
                } else {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is NOT thinking"); 
-
-                       int reason = (int)STTD_ERROR_INVALID_STATE;             
-                       if (0 != sttdc_send_error_signal(*uid, reason, "Client state is NOT thinking. Client don't receive recognition result in current state.")) {
-                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info. Remove client data "); 
-
-                               /* clean client data */
-                               sttd_client_delete(*uid);               
-                       }
+                       SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is NOT thinking."); 
                }
-       } else if (STTP_RESULT_EVENT_NO_RESULT == event) {
+       } else if (STTP_RESULT_EVENT_NO_RESULT == event || STTP_RESULT_EVENT_ERROR == event) {
 
                if (APP_STATE_PROCESSING == state ) {
-                       if (0 != sttdc_send_result(*uid, NULL, NULL, 0, NULL)) {
+                       if (0 != sttdc_send_result(*uid, type, NULL, 0, msg)) {
                                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result "); 
 
                                /* send error msg */
                                int reason = (int)STTD_ERROR_INVALID_STATE;     
                                if (0 != sttdc_send_error_signal(*uid, reason, "[ERROR] Fail to send recognition result")) {
                                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info "); 
-                                       sttd_client_delete(*uid);
                                }
                        }
                } else {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is NOT thinking "); 
-
-                       int reason = (int)STTD_ERROR_INVALID_STATE;             
-
-                       if (0 != sttdc_send_error_signal(*uid, reason, "Client state is NOT thinking. Client don't receive recognition result in current state.")) {
-                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info. Remove client data"); 
-
-                               /* clean client data */
-                               sttd_client_delete(*uid);               
-                       }
+                       SLOG(LOG_WARN, TAG_STTD, "[Server ERROR] Current state is NOT thinking."); 
                }
-       } else if (STTP_RESULT_EVENT_ERROR == event) {
-               int reason = (int)STTD_ERROR_OPERATION_FAILED;
-
-               if (0 != sttdc_send_error_signal(*uid, reason, "STT Engine ERROR : Recognition fail")) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info"); 
-                       sttd_client_delete(*uid);
-               }       
        } else {
                /* nothing */
        }
@@ -207,11 +208,7 @@ void sttd_server_silence_dectection_callback(void *user_param)
                return;
        }
 
-       if (0 != sttd_send_stop_recognition_by_daemon(uid)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail "); 
-       } else {
-               SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] <<<< stop message : uid(%d)", uid); 
-       }
+       ecore_timer_add(0, __stop_by_silence, NULL);
 
        SLOG(LOG_DEBUG, TAG_STTD, "=====");
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
@@ -220,13 +217,17 @@ void sttd_server_silence_dectection_callback(void *user_param)
 }
 
 /*
-* Daemon initialize
+* Daemon function
 */
 
 int sttd_initialize()
 {
        int ret = 0;
 
+       if (sttd_config_initialize()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server WARNING] Fail to initialize config.");
+       }
+
        /* recoder init */
        ret = sttd_recorder_init();
        if (0 != ret) {
@@ -254,6 +255,41 @@ int sttd_initialize()
        return 0;
 }
 
+Eina_Bool sttd_cleanup_client(void *data)
+{
+       int* client_list = NULL;
+       int client_count = 0;
+
+       if (0 != sttd_client_get_list(&client_list, &client_count)) 
+               return EINA_TRUE;
+       
+       if (NULL == client_list)
+               return EINA_TRUE;
+
+       int result;
+       int i = 0;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "===== Clean up client ");
+
+       for (i = 0;i < client_count;i++) {
+               result = sttdc_send_hello(client_list[i]);
+
+               if (0 == result) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%d) should be removed.", client_list[i]); 
+                       sttd_server_finalize(client_list[i]);
+               } else if (-1 == result) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Hello result has error"); 
+               }
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       free(client_list);
+
+       return EINA_TRUE;
+}
+
 /*
 * STT Server Functions for Client
 */
@@ -477,6 +513,39 @@ int sttd_server_get_audio_volume( const int uid, float* current_volume)
        return STTD_ERROR_NONE;
 }
 
+Eina_Bool __check_recording_state(void *data)
+{      
+       /* current uid */
+       int uid = sttd_client_get_current_recording();
+       if (-1 == uid)
+               return EINA_FALSE;
+
+       app_state_e state;
+       if (0 != sttdc_send_get_state(uid, (int*)&state)) {
+               /* client is removed */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%d) should be removed.", uid); 
+               sttd_server_finalize(uid);
+               return EINA_FALSE;
+       }
+
+       if (APP_STATE_READY == state) {
+               /* Cancel stt */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Ready'. The daemon should cancel recording", uid); 
+               sttd_server_cancel(uid);
+       } else if (APP_STATE_PROCESSING == state) {
+               /* Cancel stt and send change state */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Processing'. The daemon should cancel recording", uid); 
+               sttd_server_cancel(uid);
+               sttdc_send_set_state(uid, (int)APP_STATE_READY);
+       } else {
+               /* Normal state */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server] The states of daemon and client are identical"); 
+               return EINA_TRUE;
+       }
+
+       return EINA_FALSE;
+}
+
 int sttd_server_start(const int uid, const char* lang, const char* recognition_type, 
                      int profanity, int punctuation, int silence)
 {
@@ -539,9 +608,42 @@ int sttd_server_start(const int uid, const char* lang, const char* recognition_t
        /* change uid state */
        sttd_client_set_state(uid, APP_STATE_RECORDING);
 
+       Ecore_Timer* timer = ecore_timer_add(g_state_check_time, __check_recording_state, NULL);
+       sttd_cliet_set_timer(uid, timer);
+
        return STTD_ERROR_NONE;
 }
 
+Eina_Bool __time_out_for_processing(void *data)
+{      
+       /* current uid */
+       int uid = sttd_client_get_current_thinking();
+       if (-1 == uid)
+               return EINA_FALSE;
+
+       /* Cancel engine */
+       int ret = sttd_engine_recognize_cancel();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); 
+       }
+
+       if (0 != sttdc_send_result(uid, STTP_RECOGNITION_TYPE_FREE, NULL, 0, "Time out not to receive recognition result.")) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result "); 
+
+               /* send error msg */
+               int reason = (int)STTD_ERROR_TIMED_OUT; 
+               if (0 != sttdc_send_error_signal(uid, reason, "[ERROR] Fail to send recognition result")) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info "); 
+               }
+       }
+
+       /* Change uid state */
+       sttd_client_set_state(uid, APP_STATE_READY);
+
+       return EINA_FALSE;
+}
+
+
 int sttd_server_stop(const int uid)
 {
        /* check if uid is valid */
@@ -568,10 +670,19 @@ int sttd_server_stop(const int uid)
        
                return STTD_ERROR_OPERATION_FAILED;
        }
+       
+       Ecore_Timer* timer;
+       sttd_cliet_get_timer(uid, &timer);
+
+       if (NULL != timer)
+               ecore_timer_del(timer);
 
        /* change uid state */
        sttd_client_set_state(uid, APP_STATE_PROCESSING);
 
+       timer = ecore_timer_add(g_state_check_time, __time_out_for_processing, NULL);
+       sttd_cliet_set_timer(uid, timer);
+
        return STTD_ERROR_NONE;
 }
 
@@ -601,6 +712,10 @@ int sttd_server_cancel(const int uid)
                return STTD_ERROR_OPERATION_FAILED;
        }
 
+       Ecore_Timer* timer;
+       sttd_cliet_get_timer(uid, &timer);
+       ecore_timer_del(timer);
+
        /* change uid state */
        sttd_client_set_state(uid, APP_STATE_READY);
 
@@ -612,7 +727,7 @@ int sttd_server_cancel(const int uid)
 * STT Server Functions for setting
 *******************************************************************************************/
 
-int sttd_server_setting_initialize(int uid)
+int sttd_server_setting_initialize(int pid)
 {
        if (false == g_is_engine) {
                if (0 != sttd_engine_agent_initialize_current_engine()) {
@@ -624,10 +739,9 @@ int sttd_server_setting_initialize(int uid)
                }
        }
 
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 == sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid has already been registered"); 
+       /* check whether pid is valid */
+       if (true == sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -639,26 +753,19 @@ int sttd_server_setting_initialize(int uid)
                }
        }
 
-       /* Add client information to client manager (For internal use) */
-       if (0 != sttd_client_add(uid, uid)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info"); 
+       /* Add setting client information to client manager (For internal use) */
+       if (0 != sttd_setting_client_add(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add setting client"); 
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_finalize(int uid)
+int sttd_server_setting_finalize(int pid)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
-               return STTD_ERROR_INVALID_PARAMETER;
-       }
-
        /* Remove client information */
-       if (0 != sttd_client_delete(uid)) {
+       if (0 != sttd_setting_client_delete(pid)) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete setting client"); 
        }
 
@@ -674,12 +781,11 @@ int sttd_server_setting_finalize(int uid)
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_engine_list(int uid, GList** engine_list)
+int sttd_server_setting_get_engine_list(int pid, GList** engine_list)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -691,17 +797,17 @@ int sttd_server_setting_get_engine_list(int uid, GList** engine_list)
        int ret = sttd_engine_setting_get_engine_list(engine_list); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine list : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_engine(int uid, char** engine_id)
+int sttd_server_setting_get_engine(int pid, char** engine_id)
 {
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -714,18 +820,17 @@ int sttd_server_setting_get_engine(int uid, char** engine_id)
        int ret = sttd_engine_setting_get_engine(engine_id); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_engine(const int uid, const char* engine_id)
+int sttd_server_setting_set_engine(int pid, const char* engine_id)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -738,18 +843,17 @@ int sttd_server_setting_set_engine(const int uid, const char* engine_id)
        int ret = sttd_engine_setting_set_engine(engine_id); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_lang_list(int uid, char** engine_id, GList** lang_list)
+int sttd_server_setting_get_lang_list(int pid, char** engine_id, GList** lang_list)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
        
@@ -761,18 +865,17 @@ int sttd_server_setting_get_lang_list(int uid, char** engine_id, GList** lang_li
        int ret = sttd_engine_setting_get_lang_list(engine_id, lang_list); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get language list : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_default_language(int uid, char** language)
+int sttd_server_setting_get_default_language(int pid, char** language)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -784,18 +887,17 @@ int sttd_server_setting_get_default_language(int uid, char** language)
        int ret = sttd_engine_setting_get_default_lang(language); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_default_language(int uid, const char* language)
+int sttd_server_setting_set_default_language(int pid, const char* language)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -807,18 +909,17 @@ int sttd_server_setting_set_default_language(int uid, const char* language)
        int ret = sttd_engine_setting_set_default_lang((char*)language); 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set default lang : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_profanity_filter(int uid, bool* value)
+int sttd_server_setting_get_profanity_filter(int pid, bool* value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -831,18 +932,17 @@ int sttd_server_setting_get_profanity_filter(int uid, bool* value)
        ret = sttd_engine_setting_get_profanity_filter(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get profanity filter : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_profanity_filter(int uid, bool value)
+int sttd_server_setting_set_profanity_filter(int pid, bool value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -850,18 +950,17 @@ int sttd_server_setting_set_profanity_filter(int uid, bool value)
        ret = sttd_engine_setting_set_profanity_filter(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set profanity filter: result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_punctuation_override(int uid, bool* value)
+int sttd_server_setting_get_punctuation_override(int pid, bool* value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -874,18 +973,17 @@ int sttd_server_setting_get_punctuation_override(int uid, bool* value)
        ret = sttd_engine_setting_get_punctuation_override(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get punctuation override : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_punctuation_override(int uid, bool value)
+int sttd_server_setting_set_punctuation_override(int pid, bool value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -893,18 +991,17 @@ int sttd_server_setting_set_punctuation_override(int uid, bool value)
        ret = sttd_engine_setting_set_punctuation_override(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set punctuation override : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_silence_detection(int uid, bool* value)
+int sttd_server_setting_get_silence_detection(int pid, bool* value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -917,18 +1014,17 @@ int sttd_server_setting_get_silence_detection(int uid, bool* value)
        ret = sttd_engine_setting_get_silence_detection(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get silence detection : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_silence_detection(int uid, bool value)
+int sttd_server_setting_set_silence_detection(int pid, bool value)
 {
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -936,18 +1032,17 @@ int sttd_server_setting_set_silence_detection(int uid, bool value)
        ret = sttd_engine_setting_set_silence_detection(value);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }       
 
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_get_engine_setting(int uid, char** engine_id, GList** lang_list)
+int sttd_server_setting_get_engine_setting(int pid, char** engine_id, GList** lang_list)
 {      
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -959,12 +1054,11 @@ int sttd_server_setting_get_engine_setting(int uid, char** engine_id, GList** la
        return STTD_ERROR_NONE;
 }
 
-int sttd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
+int sttd_server_setting_set_engine_setting(int pid, const char* key, const char* value)
 {      
-       /* check if uid is valid */
-       app_state_e state;
-       if (0 != sttd_client_get_state(uid, &state)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+       /* check whether pid is valid */
+       if (true != sttd_setting_client_is(pid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid "); 
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -975,5 +1069,3 @@ int sttd_server_setting_set_engine_setting(int uid, const char* key, const char*
 
        return STTD_ERROR_NONE;
 }
-
-
index 634f424e3232cd2ae858bd22b6e197a85f9e4634..377f04b1de9ba6d6db22941587ce9776051bd699 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011 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 @@
 #ifndef __STTD_SERVER_H_
 #define __STTD_SERVER_H_
 
+#include <Ecore.h>
 #include "sttd_main.h"
 
 #ifdef __cplusplus
@@ -22,9 +23,13 @@ extern "C" {
 #endif
 
 
-/** Daemon initialize */
+/*
+* Daemon functions
+*/
 int sttd_initialize();
 
+Eina_Bool sttd_cleanup_client(void *data);
+
 /*
 * API for client
 */
@@ -54,37 +59,37 @@ int sttd_server_cancel(const int uid);
 * API for setting
 */
 
-int sttd_server_setting_initialize(int uid);
+int sttd_server_setting_initialize(int pid);
 
-int sttd_server_setting_finalize(int uid);
+int sttd_server_setting_finalize(int pid);
 
-int sttd_server_setting_get_engine_list(int uid, GList** engine_list);
+int sttd_server_setting_get_engine_list(int pid, GList** engine_list);
 
-int sttd_server_setting_get_engine(int uid, char** engine_id);
+int sttd_server_setting_get_engine(int pid, char** engine_id);
 
-int sttd_server_setting_set_engine(const int uid, const char* engine_id);
+int sttd_server_setting_set_engine(int pid, const char* engine_id);
 
-int sttd_server_setting_get_lang_list(int uid, char** engine_id, GList** lang_list);
+int sttd_server_setting_get_lang_list(int pid, char** engine_id, GList** lang_list);
 
-int sttd_server_setting_get_default_language(int uid, char** language);
+int sttd_server_setting_get_default_language(int pid, char** language);
 
-int sttd_server_setting_set_default_language(int uid, const char* language);
+int sttd_server_setting_set_default_language(int pid, const char* language);
 
-int sttd_server_setting_get_profanity_filter(int uid, bool* value);
+int sttd_server_setting_get_profanity_filter(int pid, bool* value);
 
-int sttd_server_setting_set_profanity_filter(int uid, bool value);
+int sttd_server_setting_set_profanity_filter(int pid, bool value);
 
-int sttd_server_setting_get_punctuation_override(int uid, bool* value);
+int sttd_server_setting_get_punctuation_override(int pid, bool* value);
 
-int sttd_server_setting_set_punctuation_override(int uid, bool value);
+int sttd_server_setting_set_punctuation_override(int pid, bool value);
 
-int sttd_server_setting_get_silence_detection(int uid, bool* value);
+int sttd_server_setting_get_silence_detection(int pid, bool* value);
 
-int sttd_server_setting_set_silence_detection(int uid, bool value);
+int sttd_server_setting_set_silence_detection(int pid, bool value);
 
-int sttd_server_setting_get_engine_setting(int uid, char** engine_id, GList** lang_list);
+int sttd_server_setting_get_engine_setting(int pid, char** engine_id, GList** lang_list);
 
-int sttd_server_setting_set_engine_setting(int uid, const char* key, const char* value);
+int sttd_server_setting_set_engine_setting(int pid, const char* key, const char* value);
 
 
 #ifdef __cplusplus