Add bux2ctl_get for getting buxton key and setting an engine by users
[platform/core/uifw/stt.git] / common / stt_config_mgr.c
index f5ba157..b8162e8 100644 (file)
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <sys/inotify.h>
 #include <vconf.h>
+#include <buxton2.h>
 
 #include "stt_config_mgr.h"
 #include "stt_defs.h"
@@ -1060,6 +1061,62 @@ int stt_config_mgr_get_engine(char** engine)
        return STT_CONFIG_ERROR_NONE;
 }
 
+int __stt_config_set_buxtonkey(const char* engine)
+{
+       /* Set vconfkey */
+       struct buxton_client * bux_cli;
+       struct buxton_layer * bux_layer;
+       struct buxton_value * bux_val;
+
+       int ret = buxton_open(&bux_cli, NULL, NULL);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client, ret(%d)", ret);
+               return STT_CONFIG_ERROR_OPERATION_FAILED;
+       }
+       bux_layer = buxton_create_layer("user");
+       if (NULL == bux_layer) {
+               SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
+               buxton_close(bux_cli);
+               bux_cli = NULL;
+               return STT_CONFIG_ERROR_OPERATION_FAILED;
+       }
+       bux_val = buxton_value_create_string(engine);
+       if (NULL == bux_val) {
+               SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
+               buxton_free_layer(bux_layer);
+               buxton_close(bux_cli);
+               bux_layer = NULL;
+               bux_cli = NULL;
+               return STT_CONFIG_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] layer: %s", buxton_layer_get_name(bux_layer));
+       }
+
+       ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_DEFAULT, bux_val);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync, ret(%d)", ret);
+               buxton_value_free(bux_val);
+               buxton_free_layer(bux_layer);
+               buxton_close(bux_cli);
+
+               bux_cli = NULL;
+               bux_layer = NULL;
+               bux_val = NULL;
+               return STT_CONFIG_ERROR_OPERATION_FAILED;
+       }
+       SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %s", STT_ENGINE_DB_DEFAULT);
+
+       buxton_value_free(bux_val);
+       buxton_free_layer(bux_layer);
+       buxton_close(bux_cli);
+
+       bux_cli = NULL;
+       bux_layer = NULL;
+       bux_val = NULL;
+
+       return STT_CONFIG_ERROR_NONE;
+}
+
 int stt_config_mgr_set_engine(const char* engine)
 {
        if (0 >= g_slist_length(g_config_client_list)) {
@@ -1082,6 +1139,12 @@ int stt_config_mgr_set_engine(const char* engine)
 
        SLOG(LOG_DEBUG, stt_tag(), "New engine id : %s", engine);
 
+       int ret = __stt_config_set_buxtonkey(engine);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] set buxtonkey Failed!!!");
+               return ret;
+       }
+
        GSList *iter = NULL;
        stt_engine_info_s *engine_info = NULL;
        bool is_valid_engine = false;