1 #include "wakeup_settings.h"
2 #include "wakeup_manager_main.h"
7 namespace multiassistant
12 CWakeupSettings::CWakeupSettings()
16 CWakeupSettings::~CWakeupSettings()
20 static void wakeup_setting_input_language_changed_cb(keynode_t *node, void* data)
22 if (nullptr == node) return;
24 CWakeupSettings* settings = static_cast<CWakeupSettings*>(data);
25 if (nullptr == settings) return;
27 if (VCONF_TYPE_STRING == node->type) {
28 const char* value = static_cast<const char*>(node->value.s);
29 vector<ISettingsEventObserver*> observers = settings->get_observers();
30 for (const auto& observer : observers) {
32 if (!observer->on_voice_input_language_changed(value)) {
33 LOGW("[Settings WARNING] One of the observer returned false");
38 LOGE("[Settings ERROR] the value type is not string : %d", node->type);
42 void CWakeupSettings::initialize()
49 vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID);
51 mDefaultAssistantAppid = vconf_str;
52 MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
56 vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool);
58 mUiPanelEnabled = vconf_bool;
59 MWR_LOGD("ui_panel_enabled : %s", (mUiPanelEnabled ? "true" : "false"));
61 vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &vconf_double);
63 mConversationTimeout = vconf_double;
64 MWR_LOGD("conversation_timeout : %f", mConversationTimeout);
66 vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &vconf_bool);
68 mMultipleMode = vconf_bool;
69 MWR_LOGD("multiple_mode : %s", (mMultipleMode ? "true" : "false"));
71 vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS);
74 istringstream iss(vconf_str);
75 mEnabledAssistants.clear();
76 while (getline(iss, token, ';')) {
77 mEnabledAssistants.push_back(token);
78 MWR_LOGD("enabled_assistants : %s", token.c_str());
83 vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double);
85 mWakeupPolicyDelay = vconf_double;
86 MWR_LOGD("conversation_timeout : %f", mWakeupPolicyDelay);
88 vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY);
91 istringstream iss(vconf_str);
92 mWakeupPolicyPriority.clear();
93 while (getline(iss, token, ';')) {
94 mWakeupPolicyPriority.push_back(token);
95 MWR_LOGD("wakeup_policy_priority : %s", token.c_str());
100 vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &vconf_double);
101 if (0 == vconf_ret) {
102 mStreamingDurationMax = vconf_double;
103 MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax);
106 vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE,
107 wakeup_setting_input_language_changed_cb, this);
110 void CWakeupSettings::deinitialize()
112 vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE, NULL);
115 void CWakeupSettings::subscribe(ISettingsEventObserver *observer)
117 mObservers.push_back(observer);
120 void CWakeupSettings::unsubscribe(ISettingsEventObserver *observer)
122 auto iter = find(mObservers.begin(), mObservers.end(), observer);
123 if (iter != mObservers.end()) {
124 mObservers.erase(iter);
128 vector<ISettingsEventObserver*> CWakeupSettings::get_observers()
133 string CWakeupSettings::get_default_assistant_appid()
136 vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID);
137 MWR_LOGD("default_assistant_appid : %s", vconf_str);
139 mDefaultAssistantAppid = vconf_str;
140 MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
145 return mDefaultAssistantAppid;
148 bool CWakeupSettings::get_ui_panel_enabled()
150 return mUiPanelEnabled;
153 float CWakeupSettings::get_conversation_timeout()
155 return mConversationTimeout;
158 bool CWakeupSettings::get_multiple_mode()
160 return mMultipleMode;
163 vector<string> CWakeupSettings::get_enabled_assistants()
165 return mEnabledAssistants;
168 float CWakeupSettings::get_wakeup_policy_delay()
170 return mWakeupPolicyDelay;
173 vector<string> CWakeupSettings::get_wakeup_policy_priority()
175 return mWakeupPolicyPriority;
178 float CWakeupSettings::get_streaming_duration_max()
180 return mStreamingDurationMax;
183 std::string CWakeupSettings::get_current_language(void)
185 std::string result{"en_US"};
186 char* language = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE);