#include <sys/wait.h>
#include <system_info.h>
#include <vconf.h>
+#include <package-manager.h>
#include "tts.h"
#include "tts_client.h"
static int g_speed = -1;
+/* for checking engine update */
+static pkgmgr_client* g_pkgmgr = NULL;
+static char* g_engine_name = NULL;
+static int g_engine_update_status = 0;
/* Function definition */
static Eina_Bool __tts_notify_state_changed(void *data);
static Eina_Bool __tts_notify_error(void *data);
+int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg);
+
const char* tts_tag()
{
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
}
+static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
+{
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] pkgmgr status cb is invoked. pkgname(%s), type(%s), key(%s), val(%s)", pkgname, type, key, val);
+
+ if (0 != strncmp(g_engine_name, pkgname, strlen(g_engine_name))) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[WARN] this is not tts engine");
+ return 0;
+ } else {
+ if (key && 0 == strncmp(key, "start", strlen(key))) {
+ if (val && (0 == strncmp(val, "update", strlen(val) || 0 == strncmp(val, "uninstall", strlen(val))))) {
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] start to install.");
+ g_engine_update_status = 1;
+ }
+ } else if (key && 0 == strncmp(key, "end", strlen(key))) {
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish to install");
+ g_engine_update_status = 0;
+ }
+ }
+
+ return 0;
+}
+
+static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
+{
+ while (!g_pkgmgr) {
+ g_pkgmgr = pkgmgr_client_new(PC_LISTENING);
+ if (NULL == g_pkgmgr) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create pkgmgr handle");
+ } else {
+ if (pkgmgr_client_listen_status(g_pkgmgr, __pkgmgr_status_cb, NULL) < 0) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to listen pkgmgr status. remove and recreate client");
+ pkgmgr_client_free(g_pkgmgr);
+ g_pkgmgr = NULL;
+ continue;
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Succeed to register pkgmgr cb");
+ }
+ }
+ usleep(10000);
+ }
+
+ return ;
+}
+
+static void __finish_pkgmgr_thread(void* data, Ecore_Thread* thread)
+{
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Finish pkgmgr thread");
+}
+
int tts_create(tts_h* tts)
{
if (0 != __tts_get_feature_enabled()) {
return __tts_convert_config_error_code(ret);
}
+ ecore_thread_main_loop_begin();
+ ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, NULL, NULL);
+ ecore_thread_main_loop_end();
+
+ g_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+ if (NULL == g_engine_name) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name");
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Engine name(%s)", g_engine_name);
+ }
+
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_OPERATION_FAILED;
}
+ if (g_pkgmgr) {
+ pkgmgr_client_remove_listen_status(g_pkgmgr);
+ pkgmgr_client_free(g_pkgmgr);
+ g_pkgmgr = NULL;
+ }
+
tts_config_mgr_finalize(client->uid);
int ret = -1;
return EINA_FALSE;
}
+ /* check whether engine is updating or not */
+ if (g_engine_update_status) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update");
+ __tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+
+ return EINA_FALSE;
+ }
+
/* Send hello */
if (0 != tts_dbus_request_hello(client->uid)) {
return EINA_TRUE;
return EINA_FALSE;
}
+static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
+{
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] start reprepare thread. engine update status(%d)", g_engine_update_status);
+
+ tts_client_s* temp = (tts_client_s*)data;
+ if (NULL == temp) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] data is null");
+ return ;
+ }
+
+ int cnt = 0;
+ while (!g_engine_update_status && (cnt < 10)) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for starting update");
+ usleep(50000);
+ cnt++;
+ }
+
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] update status(%d)", g_engine_update_status);
+
+ while (g_engine_update_status && (NULL != g_pkgmgr)) {
+// SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for finishing update");
+ usleep(200000);
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish updating. request to prepare");
+
+ if (0 != tts_prepare(temp->tts)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+ }
+
+ return ;
+}
+
+static void __end_reprepare_thread(void* data, Ecore_Thread* thread)
+{
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] end reprepare thread");
+}
+
int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
{
if (-1 == uid) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
data->current_state = TTS_STATE_CREATED;
- if (0 != tts_prepare(data->tts)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
- }
+ ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, data);
}
/* Next item */
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
client->current_state = TTS_STATE_CREATED;
- if (0 != tts_prepare(client->tts)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
- }
+
+ ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, client);
}
}