if ((pid = mas_get_client_pid_by_wakeup_word(wakeup_word)) != -1) {
MAS_LOGD("MA Client with wakeup word %s exists, requesting speech data", (wakeup_word ? wakeup_word : "NULL"));
ma_client_set_temp_speech_data_requested(1);
- int (*ws_request_speech_data)(void);
- ws_request_speech_data = (int (*)(void))dlsym(g_handle, "wakeup_service_request_speech_data");
- int ret = ws_request_speech_data();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_request_speech_data)(void);
+ ws_request_speech_data = (int (*)(void))dlsym(g_handle, "wakeup_service_request_speech_data");
+ ret = ws_request_speech_data();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
} else {
// Appropriate MA Client not available, trying to launch new one
char filepath[512] = {'\0',};
snprintf(filepath, 512, "%s/%s", MA_DEFAULT_ENGINE, "libmulti-wakeup-recognizer.so");
+ char *error;
g_handle = NULL;
g_handle = dlopen(filepath, RTLD_LAZY);
- if (NULL != dlerror()) {
- MAS_LOGE("[ERROR] Fail to dlopen");
+ if (NULL != (error = dlerror())) {
+ MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
return -1; //MAS_ERROR_OPERATION_FAILED;
}
- int (*ws_initialize)(void);
- ws_initialize = (int (*)(void))dlsym(g_handle, "wakeup_service_initialize");
- int ret = ws_initialize();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_initialize)(void);
+ ws_initialize = (int (*)(void))dlsym(g_handle, "wakeup_service_initialize");
+ ret = ws_initialize();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
MAS_LOGD("[Recorder ERROR] File not found!");
}
#endif
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_deinitialize)(void);
+ ws_deinitialize = (int (*)(void))dlsym(g_handle, "wakeup_service_deinitialize");
+ ret = ws_deinitialize();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
+ }
- int (*ws_deinitialize)(void);
- ws_deinitialize = (int (*)(void))dlsym(g_handle, "wakeup_service_deinitialize");
- int ret = ws_deinitialize();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
- }
-
- if (g_handle) {
dlclose(g_handle);
g_handle = NULL;
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
int multi_assistant_service_plugin_set_language(const char* language)
{
- int (*ws_set_language)(const char* language);
- ws_set_language = (int (*)(const char* language))dlsym(g_handle, "wakeup_service_set_language");
- int ret = ws_set_language(language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_language)(const char* language);
+ ws_set_language = (int (*)(const char* language))dlsym(g_handle, "wakeup_service_set_language");
+ ret = ws_set_language(language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_set_wakeup_word(const char* language, const char* wakeup_word)
{
- int (*ws_set_wakeup_word)(const char* language, const char* wakeup_word);
- ws_set_wakeup_word = (int (*)(const char* language, const char* wakeup_word))dlsym(g_handle, "wakeup_service_set_wakeup_word");
- int ret = ws_set_wakeup_word(language, wakeup_word);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", language, wakeup_word, ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_wakeup_word)(const char* language, const char* wakeup_word);
+ ws_set_wakeup_word = (int (*)(const char* language, const char* wakeup_word))dlsym(g_handle, "wakeup_service_set_wakeup_word");
+ ret = ws_set_wakeup_word(language, wakeup_word);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", language, wakeup_word, ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_start_recording(void)
{
- int (*ws_start_recording)(void);
- ws_start_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_start_recording");
- int ret = ws_start_recording();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_start_recording)(void);
+ ws_start_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_start_recording");
+ ret = ws_start_recording();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_stop_recording(void)
{
- int (*ws_stop_recording)(void);
- ws_stop_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_stop_recording");
- int ret = ws_stop_recording();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_stop_recording)(void);
+ ws_stop_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_stop_recording");
+ ret = ws_stop_recording();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_cancel_recording(void)
{
- int (*ws_cancel_recording)(void);
- ws_cancel_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_cancel_recording");
- int ret = ws_cancel_recording();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to cancel recording, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_cancel_recording)(void);
+ ws_cancel_recording = (int (*)(void))dlsym(g_handle, "wakeup_service_cancel_recording");
+ ret = ws_cancel_recording();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to cancel recording, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_request_speech_data(void)
{
- int (*ws_request_speech_data)(void);
- ws_request_speech_data = (int (*)(void))dlsym(g_handle, "wakeup_service_request_speech_data");
- int ret = ws_request_speech_data();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_request_speech_data)(void);
+ ws_request_speech_data = (int (*)(void))dlsym(g_handle, "wakeup_service_request_speech_data");
+ ret = ws_request_speech_data();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type)
{
- int (*ws_get_recording_audio_format)(int *rate, int *channel, int *audio_type);
- ws_get_recording_audio_format = (int (*)(int *rate, int *channel, int *audio_type))dlsym(g_handle, "wakeup_service_get_recording_audio_format");
- int ret = ws_get_recording_audio_format(rate, channel, audio_type);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_get_recording_audio_format)(int *rate, int *channel, int *audio_type);
+ ws_get_recording_audio_format = (int (*)(int *rate, int *channel, int *audio_type))dlsym(g_handle, "wakeup_service_get_recording_audio_format");
+ ret = ws_get_recording_audio_format(rate, channel, audio_type);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
{
- int (*ws_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
- ws_set_wakeup_event_callback = (int (*)(wakeup_service_wakeup_event_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_wakeup_event_callback");
- int ret = ws_set_wakeup_event_callback(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
+ ws_set_wakeup_event_callback = (int (*)(wakeup_service_wakeup_event_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_wakeup_event_callback");
+ ret = ws_set_wakeup_event_callback(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_set_speech_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
{
- int (*ws_set_speech_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
- ws_set_speech_streaming_callback = (int (*)(wakeup_service_speech_streaming_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_speech_streaming_callback");
- int ret = ws_set_speech_streaming_callback(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to speech streaming callback, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_speech_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
+ ws_set_speech_streaming_callback = (int (*)(wakeup_service_speech_streaming_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_speech_streaming_callback");
+ ret = ws_set_speech_streaming_callback(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to speech streaming callback, ret(%d)", ret);
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
}
return ret;
}
int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
{
- int (*ws_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
- ws_set_speech_status_callback = (int (*)(wakeup_service_speech_status_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_speech_status_callback");
- int ret = ws_set_speech_status_callback(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
+ ws_set_speech_status_callback = (int (*)(wakeup_service_speech_status_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_speech_status_callback");
+ ret = ws_set_speech_status_callback(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
+ }
}
return ret;
}
int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data)
{
- int (*ws_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
- ws_set_error_callback = (int (*)(wakeup_service_error_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_error_callback");
- int ret = ws_set_error_callback(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ int ret = -1;
+ if (NULL != g_handle) {
+ int (*ws_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
+ ws_set_error_callback = (int (*)(wakeup_service_error_cb callback, void* user_data))dlsym(g_handle, "wakeup_service_set_error_callback");
+ ret = ws_set_error_callback(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
}
return ret;
}