#include <unistd.h>
#include <vconf.h>
+#include <stdexcept>
+
#include "multi_assistant_main.h"
#include "dependency_resolver.h"
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_INITIALIZE);
} else {
- ret = func(interface, &dependency_version);
+ try {
+ ret = func(interface, &dependency_version);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_INITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_DEINITIALIZE);
} else {
- ret = func();
+ try {
+ ret = func();
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
} else {
- ret = func(callback, user_data);
+ try {
+ ret = func(callback, user_data);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to set error callback(%p, %p), ret(%d)", callback, user_data, ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_START_RECORDING);
} else {
- ret = func();
+ try {
+ ret = func();
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_STOP_RECORDING);
} else {
- ret = func();
+ try {
+ ret = func();
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
} else {
- ret = func(session);
+ try {
+ ret = func(session);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to set recording session, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
} else {
- ret = func(ratio);
+ try {
+ ret = func(ratio);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to set background volume to %f, ret(%d)", ratio, ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
} else {
- ret = func(rate, channel, audio_type);
+ try {
+ ret = func(rate, channel, audio_type);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to get audio format, ret(%d)", ret);
}
if (NULL == func) {
MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
} else {
- ret = func(type);
+ try {
+ ret = func(type);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+ }
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to get audio source type, ret(%d)", ret);
}
void CWakeupEngineManager::deinitialize()
{
for (auto& info : mEngineInfo) {
- if (info.interface.set_wakeup_event_callback) {
- info.interface.set_wakeup_event_callback(nullptr, nullptr);
- }
- if (info.interface.set_speech_status_callback) {
- info.interface.set_speech_status_callback(nullptr, nullptr);
- }
- if (info.interface.set_error_callback) {
- info.interface.set_error_callback(nullptr, nullptr);
- }
- if (info.interface.set_audio_data_require_status_callback) {
- info.interface.set_audio_data_require_status_callback(nullptr, nullptr);
- }
- if (info.interface.deinitialize) {
- info.interface.deinitialize();
+ try {
+ if (info.interface.set_wakeup_event_callback) {
+ info.interface.set_wakeup_event_callback(nullptr, nullptr);
+ }
+ if (info.interface.set_speech_status_callback) {
+ info.interface.set_speech_status_callback(nullptr, nullptr);
+ }
+ if (info.interface.set_error_callback) {
+ info.interface.set_error_callback(nullptr, nullptr);
+ }
+ if (info.interface.set_audio_data_require_status_callback) {
+ info.interface.set_audio_data_require_status_callback(nullptr, nullptr);
+ }
+ if (info.interface.deinitialize) {
+ info.interface.deinitialize();
+ }
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
}
if (info.engine_handle) {
dlclose(info.engine_handle);
{
for (const auto& info : mEngineInfo) {
if (info.interface.set_language) {
- info.interface.set_language(language.c_str());
+ try {
+ info.interface.set_language(language.c_str());
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
}
return true;
info.activated = (info.activated_assistants.size() > 0);
if (previously_activated != info.activated) {
if (info.activated) {
- info.interface.activate();
+ try {
+ info.interface.activate();
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
} else {
- info.interface.deactivate();
+ try {
+ info.interface.deactivate();
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
/* Activated status changed, need to update audio_data_require_status too */
on_audio_data_require_status(info.engine_name, info.audio_data_require_status);
mWakeWordAudioRequired = require;
for (const auto& info : mEngineInfo) {
if (info.interface.set_wake_word_audio_require_flag) {
- info.interface.set_wake_word_audio_require_flag(require);
+ try {
+ info.interface.set_wake_word_audio_require_flag(require);
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
}
}
{
for (const auto& info : mEngineInfo) {
if (info.interface.update_manager_state) {
- info.interface.update_manager_state(state);
+ try {
+ info.interface.update_manager_state(state);
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
}
}
bool found = contains(info.assistant_list, appid);
if (found) {
if (info.interface.add_wakeup_word) {
- info.interface.add_wakeup_word(appid.c_str(), wakeup_word.c_str(), language.c_str());
+ try {
+ info.interface.add_wakeup_word(appid.c_str(), wakeup_word.c_str(), language.c_str());
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
}
}
bool found = contains(info.assistant_list, appid);
if (found) {
if (info.interface.set_assistant_specific_command) {
- info.interface.set_assistant_specific_command(appid.c_str(), command.c_str());
+ try {
+ info.interface.set_assistant_specific_command(appid.c_str(), command.c_str());
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
+ }
}
}
}
if (info.activated &&
info.audio_data_require_status &&
info.interface.feed_audio_data) {
- int ret = info.interface.feed_audio_data(time, data, len);
- if (0 != ret) {
- LOGE("[ERROR] Fail to feed speech data, ret(%d) : %s", ret, info.engine_name.c_str());
+ try {
+ int ret = info.interface.feed_audio_data(time, data, len);
+ if (0 != ret) {
+ LOGE("[ERROR] Fail to feed speech data, ret(%d) : %s", ret, info.engine_name.c_str());
+ }
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
}
}
}
user_data.engine_name = info.engine_name;
callback_user_data.push_back(user_data);
- if (info.interface.set_wakeup_event_callback) {
- info.interface.set_wakeup_event_callback(
- [](wakeup_event_info info, void* user_data) {
- CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
- if (nullptr == data) return;
- if (nullptr == data->manager) return;
- info.wakeup_engine = data->engine_name.c_str();
- data->manager->on_wakeup_event(data->engine_name, info);
- }, &(callback_user_data.back()));
- }
+ try {
+ if (info.interface.set_wakeup_event_callback) {
+ info.interface.set_wakeup_event_callback(
+ [](wakeup_event_info info, void* user_data) {
+ CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
+ if (nullptr == data) return;
+ if (nullptr == data->manager) return;
+ info.wakeup_engine = data->engine_name.c_str();
+ data->manager->on_wakeup_event(data->engine_name, info);
+ }, &(callback_user_data.back()));
+ }
- if (info.interface.set_audio_data_require_status_callback) {
- info.interface.set_audio_data_require_status_callback(
- [](bool require, void* user_data) {
- CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
- if (nullptr == data) return;
- if (nullptr == data->manager) return;
- data->manager->on_audio_data_require_status(data->engine_name, require);
- }, &(callback_user_data.back()));
- }
+ if (info.interface.set_audio_data_require_status_callback) {
+ info.interface.set_audio_data_require_status_callback(
+ [](bool require, void* user_data) {
+ CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
+ if (nullptr == data) return;
+ if (nullptr == data->manager) return;
+ data->manager->on_audio_data_require_status(data->engine_name, require);
+ }, &(callback_user_data.back()));
+ }
- if (info.interface.initialize) {
- info.interface.initialize();
- }
- if (info.interface.get_version) {
- int version;
- if (0 == info.interface.get_version(&version)) {
- info.version = version;
+ if (info.interface.initialize) {
+ info.interface.initialize();
+ }
+ if (info.interface.get_version) {
+ int version;
+ if (0 == info.interface.get_version(&version)) {
+ info.version = version;
+ }
}
+ } catch (const std::exception& e) {
+ MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
+ info.engine_name.c_str(), e.what());
}
}