6f820c65ab1d26cf3b57a8a8acef0654f6e54b30
[platform/core/uifw/multi-assistant-service.git] / src / service_plugin.cpp
1 /*
2  * Copyright 2020 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <tizen.h>
18 #include <service_app.h>
19 #include <app_manager.h>
20 #include <app.h>
21 #include <malloc.h>
22 #include <Ecore.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <glib.h>
28 #include <dlfcn.h>
29 #include <new>
30
31 #include "service_main.h"
32 #include "service_plugin.h"
33 #include "service_ipc_dbus.h"
34
35 /* Sound buf save for test */
36 #if 0
37 #define BUF_SAVE_MODE
38 #endif
39
40 static int g_last_wakeup_event_id = 0;
41
42 typedef struct {
43         int id;
44         void* data;
45         CServicePlugin* plugin;
46 } AsyncParam;
47
48 bool CServicePlugin::is_ui_panel_enabled()
49 {
50         /* By default we assume the ui panel is always enabled unless explicitly turned off */
51         bool ret = false;
52         if (mPluginSettings) {
53                 ret = mPluginSettings->ui_panel_enabled;
54         }
55         MAS_LOGD("UI Panel Enabled : %d", ret);
56         return ret;
57 }
58
59 #if 0 /* + TEST_CODE */
60 Eina_Bool __send_asr_result(void *data)
61 {
62         MAS_LOGD("[ENTER]");
63
64         if (!strcmp((char*)data, "Today's")) {
65                 masc_ui_dbus_send_asr_result(-1, 1, "Today's");
66         }
67         if (!strcmp((char*)data, "weather.")) {
68                 masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
69         }
70
71         MAS_LOGD("END");
72         return EINA_FALSE;
73 }
74
75 Eina_Bool __send_result(void *data)
76 {
77         MAS_LOGD("[ENTER]");
78
79         int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
80         if (0 != ret) {
81                 MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
82                 return EINA_TRUE;
83         }
84
85         MAS_LOGD("END");
86         return EINA_FALSE;
87 }
88 #endif /* -TEST_CODE */
89
90 static void process_wakeup_event_by_appid_timer(void* data)
91 {
92         if (nullptr == data) return;
93
94         AsyncParam* param = static_cast<AsyncParam*>(data);
95
96         char* appid = static_cast<char*>(param->data);
97         MAS_LOGI("[ENTER] appid(%s), id(%d), g_last_wakeup_event_id(%d)",
98                 appid, param->id, g_last_wakeup_event_id);
99
100         if (!appid) {
101                 delete param;
102                 return;
103         }
104
105         if (param->id < g_last_wakeup_event_id) {
106                 free(param->data);
107                 delete param;
108                 return;
109         }
110
111         pid_t pid = -1;
112
113         CServicePlugin* plugin = param->plugin;
114         CServiceIpcDbus* service_ipc = nullptr;
115         CServiceMain* service_main = nullptr;
116         if (plugin) {
117                 service_ipc = plugin->get_service_ipc();
118                 service_main = plugin->get_service_main();
119         }
120
121         if (service_ipc && service_main) {
122                 bool use_custom_ui = service_main->get_client_custom_ui_option_by_appid(appid);
123                 bool ui_panel_enabled = false;
124                 if (param->plugin) ui_panel_enabled = param->plugin->is_ui_panel_enabled();
125                 if (ui_panel_enabled) {
126                         service_ipc->masc_ui_dbus_enable_common_ui(!use_custom_ui);
127                         service_ipc->masc_ui_dbus_change_assistant(appid);
128                 }
129
130                 service_main->set_current_client_by_appid(appid);
131                 if ((pid = service_main->get_client_pid_by_appid(appid)) != -1) {
132                         service_main->client_send_preprocessing_information(pid);
133                         service_ipc->change_active_state(pid, MA_ACTIVE_STATE_ACTIVE);
134                         service_main->process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
135                 } else {
136                         // Appropriate MA Client not available, trying to launch new one
137                         MAS_LOGI("MA Client with appid %s does not exist, launching client", appid);
138                         service_main->launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
139                 }
140         }
141
142         if (param->data) free(param->data);
143         delete param;
144 }
145
146 static void process_wakeup_event_by_word_timer(void* data)
147 {
148         if (nullptr == data) return;
149
150         AsyncParam* param = static_cast<AsyncParam*>(data);
151         MAS_LOGI("[ENTER] wakeword(%s), id(%d)", (const char*)(param->data), param->id);
152
153         if (!param->data) {
154                 delete param;
155                 return;
156         }
157
158         char* wakeup_word = static_cast<char*>(param->data);
159         const char* appid = nullptr;
160         int id = param->id;
161         CServicePlugin* plugin = param->plugin;
162         CServiceMain* service_main = nullptr;
163
164         if (plugin) {
165                 service_main = plugin->get_service_main();
166                 if (service_main) {
167                         appid = service_main->get_client_appid_by_wakeup_word(wakeup_word);
168                 }
169         }
170
171         free(param->data);
172         delete param;
173         param = nullptr;
174
175         if (service_main && appid) {
176                 param = new(std::nothrow) AsyncParam;
177                 if (param) {
178                         param->id = id;
179                         param->data = static_cast<void*>(strdup(appid));
180                         param->plugin = plugin;
181                         process_wakeup_event_by_appid_timer(static_cast<void*>(param));
182                 }
183         }
184
185         MAS_LOGI("END");
186         return;
187 }
188
189 static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data)
190 {
191         MAS_LOGI("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
192         int ret = -1;
193
194         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
195         if (plugin) {
196                 CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
197                 if (plugin->is_ui_panel_enabled() && service_ipc) {
198                         int retry_cnt = 0;
199                         while (0 != ret) {
200                                 ret = service_ipc->masc_ui_dbus_send_hello();
201                                 retry_cnt++;
202                                 if (5 < retry_cnt) {
203                                         MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
204                                         break;
205                                 }
206                         }
207                 }
208         }
209
210 #ifdef BUF_SAVE_MODE
211         if (mDumpFile) {
212                 fclose(mDumpFile);
213                 mDumpFile = NULL;
214         } else {
215                 MAS_LOGD("[Recorder Info] File not found!");
216         }
217
218         while (1) {
219                 snprintf(mDumpFilename, sizeof(mDumpFilename), "/tmp/ma_service_%d_%d", getpid(), mDumpCount);
220                 int ret = access(mDumpFilename, 0);
221
222                 if (0 == ret) {
223                         MAS_LOGD("[Recorder ERROR] File is already exist");
224                         if (0 == remove(mDumpFilename)) {
225                                 MAS_LOGD("[Recorder] Remove file");
226                                 break;
227                         } else {
228                                 mDumpCount++;
229                         }
230                 } else {
231                         break;
232                 }
233         }
234
235         MAS_LOGD("[Recorder] Temp file name=[%s]", mDumpFilename);
236
237         /* open test file */
238         mDumpFile = fopen(mDumpFilename, "wb+x");
239         if (!mDumpFile) {
240                 MAS_LOGD("[Recorder ERROR] File not found!");
241                 return;
242         }
243         mDumpCount++;
244 #endif
245
246 #if 0 /* + TEST_CODE */
247         if (WAKEUP_EVENT_SUCCESS == event) {
248                 ecore_thread_main_loop_begin();
249                 ecore_timer_add(1.0, __send_asr_result, "Today's");
250                 ecore_thread_main_loop_end();
251
252                 ecore_thread_main_loop_begin();
253                 ecore_timer_add(2.0, __send_asr_result, "weather.");
254                 ecore_thread_main_loop_end();
255
256                 ecore_thread_main_loop_begin();
257                 ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
258                 ecore_thread_main_loop_end();
259         }
260 #endif /* - TEST_CODE */
261         if (wakeup_info.wakeup_appid) {
262                 AsyncParam* param = new(std::nothrow) AsyncParam;
263                 if (param) {
264                         param->id = ++g_last_wakeup_event_id;
265                         param->data = static_cast<void*>(strdup(wakeup_info.wakeup_appid));
266                         param->plugin = static_cast<CServicePlugin*>(user_data);
267                         ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_appid_timer,
268                                 static_cast<void*>(param));
269                 }
270         } else if (wakeup_info.wakeup_word) {
271                 AsyncParam* param = new(std::nothrow) AsyncParam;
272                 if (param) {
273                         param->id = ++g_last_wakeup_event_id;
274                         param->data = static_cast<void*>(strdup(wakeup_info.wakeup_word));
275                         param->plugin = static_cast<CServicePlugin*>(user_data);
276                         ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_word_timer,
277                                 static_cast<void*>(param));
278                 }
279         }
280 }
281
282 static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_event_e *event)
283 {
284         bool ret = false;
285
286         static int previous_pid = -1;
287         static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
288
289         if (NULL == event) return false;
290
291         mas_speech_streaming_event_e expected_sequence[][2] = {
292                 {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
293                 {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_FINISH},
294                 {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
295                 {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_FINISH},
296                 {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_START},
297                 /* If there is no audio data even after the start streaming request */
298                 {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
299         };
300
301         if (pid != previous_pid) {
302                 /* When sending streaming event to a new client, it always sends START message first */
303                 previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
304         }
305
306         for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
307                 if (previous_event == expected_sequence[loop][0] &&
308                         *event == expected_sequence[loop][1]) {
309                         ret = true;
310                 }
311         }
312         if (!ret) {
313                 /* In case of FINISH -> CONTINUE without START, simply modify current event value */
314                 if (MAS_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
315                         MAS_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
316                         *event = MAS_SPEECH_STREAMING_EVENT_START;
317                         ret = true;
318
319                         MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
320                                 previous_event, *event, previous_pid, pid);
321                 }
322         }
323
324         if (ret) {
325                 previous_pid = pid;
326                 previous_event = *event;
327         } else {
328                 MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
329                         previous_event, *event, previous_pid, pid);
330         }
331         return ret;
332 }
333
334 void handle_speech_streaming_event_failure(void* data)
335 {
336         AsyncParam* param = static_cast<AsyncParam*>(data);
337         if (NULL == param) return;
338
339         CServicePlugin* plugin = param->plugin;
340         CServiceMain* service_main = nullptr;
341         if (plugin) service_main = plugin->get_service_main();
342
343         if (service_main) {
344                 pid_t pid = service_main->get_current_client_pid();
345                 service_main->client_send_recognition_result(pid, MA_RECOGNITION_RESULT_EVENT_ERROR);
346         }
347
348         delete param;
349 }
350
351 static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data)
352 {
353         CServicePlugin* plugin = static_cast<CServicePlugin*>(user_data);
354
355         if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
356                 AsyncParam* param = new(std::nothrow) AsyncParam;
357                 if (param) {
358                         param->plugin = plugin;
359                         ecore_main_loop_thread_safe_call_async(
360                                 handle_speech_streaming_event_failure, static_cast<void*>(param));
361                 }
362                 return;
363         }
364         static int count = 0;
365         if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
366                 MAS_LOGD("[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
367                         event, buffer, len);
368         }
369         ++count;
370
371         CServiceIpcDbus* service_ipc = nullptr;
372         CServiceMain* service_main = nullptr;
373         if (plugin) {
374                 service_ipc = plugin->get_service_ipc();
375                 service_main = plugin->get_service_main();
376         }
377
378         if (service_ipc && service_main) {
379                 /* First check if we have dedicated audio processing app for current client */
380                 pid_t pid = service_main->get_current_audio_processing_pid();
381                 /* If not, send audio data to the main client */
382                 if (-1 == pid) pid = service_main->get_current_client_pid();
383
384                 int preprocessing_pid = service_main->get_current_preprocessing_client_pid();
385                 if (pid == -1) {
386                         MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
387                 } else {
388                         if (__validate_streaming_event_order(pid, &event)) {
389                                 int ret = service_ipc->send_streaming_audio_data(pid,
390                                         event, buffer, len);
391                                 if (0 != ret) {
392                                         MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
393                                 }
394                                 if (pid != preprocessing_pid && -1 != preprocessing_pid) {
395                                         int ret = service_ipc->send_streaming_audio_data(preprocessing_pid,
396                                                 event, buffer, len);
397                                         if (0 != ret) {
398                                                 MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
399                                         }
400                                 }
401                         }
402                 }
403         }
404 #ifdef BUF_SAVE_MODE
405         if (mDumpFile)
406                 fwrite(speech_data->buffer, 1, speech_data->len, mDumpFile);
407
408         if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
409                 if (mDumpFile) {
410                         MAS_LOGE("[Recorder SUCCESS] File Close");
411                         fclose(mDumpFile);
412                         mDumpFile = NULL;
413                 } else {
414                         MAS_LOGE("[Recorder ERROR] File not found!");
415                 }
416         }
417 #endif
418 }
419
420 static void __speech_status_cb(mas_speech_status_e status, void *user_data)
421 {
422         MAS_LOGD("[SUCCESS] __speech_status_cb is called, status(%d)", status);
423 }
424
425 static void __error_cb(int error, const char* err_msg, void* user_data)
426 {
427         MAS_LOGE("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
428
429         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
430         if (nullptr == plugin) return;
431
432         CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
433         if (plugin->is_ui_panel_enabled() && service_ipc) {
434                 int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg);
435                 if (0 != ret) {
436                         MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
437                 }
438         }
439 }
440
441 static void __setting_changed_cb(void *user_data)
442 {
443         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
444         if (nullptr == plugin) return;
445
446         CServiceMain* service_main = plugin->get_service_main();
447         if (service_main) {
448                 service_main->prelaunch_default_assistant();
449                 service_main->update_voice_key_support_mode();
450         }
451         MAS_LOGD("[SUCCESS] __setting_changed_cb is called");
452 }
453
454 static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
455 {
456         MAS_LOGI("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
457
458         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
459         if (nullptr == plugin) return;
460
461         CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
462         CServiceMain* service_main = plugin->get_service_main();
463         if (service_ipc && service_main) {
464                 pid_t pid = service_main->get_current_client_pid();
465                 int ret = service_ipc->send_streaming_section_changed(pid, (int)section);
466                 if (0 != ret) {
467                         MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
468                 }
469         }
470 }
471
472 static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
473 {
474         MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);
475
476         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
477         if (nullptr == plugin) return;
478
479         CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
480         CServiceMain* service_main = plugin->get_service_main();
481         if (service_ipc && service_main) {
482                 pid_t pid = service_main->get_client_pid_by_appid(assistant_name);
483                 if (-1 != pid) {
484                         int ret = service_ipc->send_wakeup_engine_command(pid, command);
485                         if (0 != ret) {
486                                 MAS_LOGE("[ERROR] Fail to send wakeup engine command, ret(%d)", ret);
487                         }
488                 }
489         }
490 }
491
492 static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
493 {
494         MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
495
496         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
497         if (nullptr == plugin) return;
498
499         CServiceMain* service_main = plugin->get_service_main();
500         if (service_main) {
501                 service_main->set_current_service_state(state);
502         }
503 }
504
505 static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e status, void* user_data)
506 {
507         MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status);
508
509         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
510         if (nullptr == plugin) return;
511
512         CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
513         CServiceMain* service_main = plugin->get_service_main();
514         if (service_ipc && service_main) {
515                 pid_t pid = service_main->get_current_client_pid();
516                 int ret = service_ipc->change_voice_key_status(pid, status);
517                 if (0 != ret) {
518                         MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
519                 }
520         }
521 }
522
523 int CServicePlugin::initialize(void)
524 {
525         MAS_LOGD("[Enter]");
526
527         char filepath[512] = {'\0', };
528         const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
529         snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
530
531         char *error;
532         mPluginHandle = nullptr;
533         mPluginHandle = dlopen(filepath, RTLD_LAZY);
534         if (nullptr != (error = dlerror())) {
535                 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
536                 if (mPluginHandle) dlclose(mPluginHandle);
537                 mPluginHandle = nullptr;
538                 return -1; //MAS_ERROR_OPERATION_FAILED;
539         }
540         if (nullptr == mPluginHandle) {
541                 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
542                 return -1; //MAS_ERROR_OPERATION_FAILED;
543         }
544
545         mWakeupManagerInterface.initialize =
546                 (wakeup_manager_initialize)dlsym(mPluginHandle,
547                 MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
548         mWakeupManagerInterface.deinitialize =
549                 (wakeup_manager_deinitialize)dlsym(mPluginHandle,
550                 MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
551         mWakeupManagerInterface.get_settings =
552                 (wakeup_manager_get_settings)dlsym(mPluginHandle,
553                 MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
554         mWakeupManagerInterface.add_assistant_wakeup_word =
555                 (wakeup_manager_add_assistant_wakeup_word)dlsym(mPluginHandle,
556                 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
557         mWakeupManagerInterface.remove_assistant_wakeup_word =
558                 (wakeup_manager_remove_assistant_wakeup_word)dlsym(mPluginHandle,
559                 MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
560         mWakeupManagerInterface.add_assistant_language =
561                 (wakeup_manager_add_assistant_language)dlsym(mPluginHandle,
562                 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
563         mWakeupManagerInterface.set_assistant_wakeup_engine =
564                 (wakeup_manager_set_assistant_wakeup_engine)dlsym(mPluginHandle,
565                 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
566         mWakeupManagerInterface.set_default_assistant =
567                 (wakeup_manager_set_default_assistant)dlsym(mPluginHandle,
568                 MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
569         mWakeupManagerInterface.get_default_assistant =
570                 (wakeup_manager_get_default_assistant)dlsym(mPluginHandle,
571                 MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
572         mWakeupManagerInterface.set_language =
573                 (wakeup_manager_set_language)dlsym(mPluginHandle,
574                 MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
575         mWakeupManagerInterface.activate =
576                 (wakeup_manager_activate)dlsym(mPluginHandle,
577                 MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
578         mWakeupManagerInterface.deactivate =
579                 (wakeup_manager_deactivate)dlsym(mPluginHandle,
580                 MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
581         mWakeupManagerInterface.update_voice_feedback_state =
582                 (wakeup_manager_update_voice_feedback_state)dlsym(mPluginHandle,
583                 MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
584         mWakeupManagerInterface.set_assistant_specific_command =
585                 (wakeup_manager_set_assistant_specific_command)dlsym(mPluginHandle,
586                 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
587         mWakeupManagerInterface.set_background_volume =
588                 (wakeup_manager_set_background_volume)dlsym(mPluginHandle,
589                 MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
590         mWakeupManagerInterface.update_recognition_result =
591                 (wakeup_manager_update_recognition_result)dlsym(mPluginHandle,
592                 MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
593         mWakeupManagerInterface.process_plugin_event =
594                 (wakeup_manager_process_plugin_event)dlsym(mPluginHandle,
595                 MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
596         mWakeupManagerInterface.start_streaming_utterance_data =
597                 (wakeup_manager_start_streaming_utterance_data)dlsym(mPluginHandle,
598                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
599         mWakeupManagerInterface.stop_streaming_utterance_data =
600                 (wakeup_manager_stop_streaming_utterance_data)dlsym(mPluginHandle,
601                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
602         mWakeupManagerInterface.start_streaming_previous_utterance_data =
603                 (wakeup_manager_start_streaming_previous_utterance_data)dlsym(mPluginHandle,
604                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
605         mWakeupManagerInterface.stop_streaming_previous_utterance_data =
606                 (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(mPluginHandle,
607                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
608         mWakeupManagerInterface.start_streaming_follow_up_data =
609                 (wakeup_manager_start_streaming_follow_up_data)dlsym(mPluginHandle,
610                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
611         mWakeupManagerInterface.stop_streaming_follow_up_data =
612                 (wakeup_manager_stop_streaming_follow_up_data)dlsym(mPluginHandle,
613                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
614         mWakeupManagerInterface.get_audio_format =
615                 (wakeup_manager_get_audio_format)dlsym(mPluginHandle,
616                 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
617         mWakeupManagerInterface.get_audio_source_type =
618                 (wakeup_manager_get_audio_source_type)dlsym(mPluginHandle,
619                 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
620         mWakeupManagerInterface.set_wake_word_audio_require_flag =
621                 (wakeup_manager_set_wake_word_audio_require_flag)dlsym(mPluginHandle,
622                 MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
623         mWakeupManagerInterface.set_assistant_language =
624                 (wakeup_manager_set_assistant_language)dlsym(mPluginHandle,
625                 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
626         mWakeupManagerInterface.set_voice_key_tap_duration =
627                 (wakeup_manager_set_voice_key_tap_duration)dlsym(mPluginHandle,
628                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
629         mWakeupManagerInterface.unset_voice_key_tap_duration =
630                 (wakeup_manager_unset_voice_key_tap_duration)dlsym(mPluginHandle,
631                 MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
632         mWakeupManagerInterface.set_voice_key_support_mode =
633                 (wakeup_manager_set_voice_key_support_mode)dlsym(mPluginHandle,
634                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
635         mWakeupManagerInterface.set_wakeup_event_callback =
636                 (wakeup_manager_set_wakeup_event_callback)dlsym(mPluginHandle,
637                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
638         mWakeupManagerInterface.set_utterance_streaming_callback =
639                 (wakeup_manager_set_utterance_streaming_callback)dlsym(mPluginHandle,
640                 MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
641         mWakeupManagerInterface.set_previous_utterance_streaming_callback =
642                 (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(mPluginHandle,
643                 MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
644         mWakeupManagerInterface.set_follow_up_streaming_callback =
645                 (wakeup_manager_set_follow_up_streaming_callback)dlsym(mPluginHandle,
646                 MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
647         mWakeupManagerInterface.set_speech_status_callback =
648                 (wakeup_manager_set_speech_status_callback)dlsym(mPluginHandle,
649                 MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
650         mWakeupManagerInterface.set_setting_changed_callback =
651                 (wakeup_manager_set_setting_changed_callback)dlsym(mPluginHandle,
652                 MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
653         mWakeupManagerInterface.set_error_callback =
654                 (wakeup_manager_set_error_callback)dlsym(mPluginHandle,
655                 MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
656         mWakeupManagerInterface.set_streaming_section_changed_callback =
657                 (wakeup_manager_set_streaming_section_changed_callback)dlsym(mPluginHandle,
658                 MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
659         mWakeupManagerInterface.set_wakeup_engine_command_callback =
660                 (wakeup_manager_set_wakeup_engine_command_callback)dlsym(mPluginHandle,
661                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
662         mWakeupManagerInterface.set_wakeup_service_state_changed_callback =
663                 (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(mPluginHandle,
664                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
665         mWakeupManagerInterface.set_voice_key_status_changed_callback =
666                 (wakeup_manager_set_voice_key_status_changed_callback)dlsym(mPluginHandle,
667                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
668
669         int ret = -1;
670         if (NULL != mPluginHandle) {
671                 wakeup_manager_initialize func = mWakeupManagerInterface.initialize;
672
673                 if (NULL == func) {
674                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
675                 } else {
676                         ret = func();
677                         if (0 != ret) {
678                                 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
679                         }
680                 }
681
682                 wakeup_manager_get_settings get_settings_func = mWakeupManagerInterface.get_settings;
683
684                 if (NULL == get_settings_func) {
685                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
686                 } else {
687                         size_t struct_size;
688                         ret = get_settings_func(&mPluginSettings, &struct_size);
689                         if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
690                                 MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
691                                 mPluginSettings = NULL;
692                         }
693                 }
694         } else {
695                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
696         }
697         return ret;
698 }
699
700 int CServicePlugin::deinitialize(void)
701 {
702 #ifdef BUF_SAVE_MODE
703         if (mDumpFile) {
704                 fclose(mDumpFile);
705                 mDumpFile = NULL;
706         } else {
707                 MAS_LOGD("[Recorder ERROR] File not found!");
708         }
709 #endif
710
711         int ret = -1;
712         if (NULL != mPluginHandle) {
713                 wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize;
714                 if (NULL == func) {
715                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
716                 } else {
717                         ret = func();
718                         if (0 != ret) {
719                                 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
720                         }
721                 }
722
723                 dlclose(mPluginHandle);
724                 mPluginHandle = NULL;
725         } else {
726                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
727         }
728
729         return ret;
730 }
731
732 int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size)
733 {
734         int ret = -1;
735         if (NULL != mPluginHandle) {
736                 wakeup_manager_get_settings func = mWakeupManagerInterface.get_settings;
737                 if (NULL == func) {
738                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
739                 } else {
740                         ret = func(settings, struct_size);
741                         if (0 != ret) {
742                                 MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
743                         }
744                 }
745         } else {
746                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
747         }
748         return ret;
749 }
750
751 int CServicePlugin::set_language(const char* language)
752 {
753         int ret = -1;
754         if (NULL != mPluginHandle) {
755                 wakeup_manager_set_language func = mWakeupManagerInterface.set_language;
756                 if (NULL == func) {
757                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
758                 } else {
759                         ret = func(language);
760                         if (0 != ret) {
761                                 MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
762                         }
763                 }
764         } else {
765                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
766         }
767         return ret;
768 }
769
770 int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
771 {
772         int ret = -1;
773         if (NULL != mPluginHandle) {
774                 wakeup_manager_add_assistant_wakeup_word func = mWakeupManagerInterface.add_assistant_wakeup_word;
775                 if (NULL == func) {
776                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
777                 } else {
778                         ret = func(appid, wakeup_word, language);
779                         if (0 != ret) {
780                                 MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
781                         }
782                 }
783         } else {
784                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
785         }
786         return ret;
787 }
788
789 int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
790 {
791         int ret = -1;
792         if (NULL != mPluginHandle) {
793                 wakeup_manager_remove_assistant_wakeup_word func = mWakeupManagerInterface.remove_assistant_wakeup_word;
794                 if (NULL == func) {
795                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
796                 } else {
797                         ret = func(appid, wakeup_word, language);
798                         if (0 != ret) {
799                                 MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
800                         }
801                 }
802         } else {
803                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
804         }
805         return ret;
806 }
807
808 int CServicePlugin::add_assistant_language(const char* appid, const char* language)
809 {
810         int ret = -1;
811         if (NULL != mPluginHandle) {
812                 wakeup_manager_add_assistant_language func = mWakeupManagerInterface.add_assistant_language;
813                 if (NULL == func) {
814                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
815                 } else {
816                         ret = func(appid, language);
817                         if (0 != ret) {
818                                 MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
819                         }
820                 }
821         } else {
822                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
823         }
824         return ret;
825 }
826
827 int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* engine)
828 {
829         int ret = -1;
830         if (NULL != mPluginHandle) {
831                 wakeup_manager_set_assistant_wakeup_engine func = mWakeupManagerInterface.set_assistant_wakeup_engine;
832                 if (NULL == func) {
833                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
834                 } else {
835                         ret = func(appid, engine);
836                         if (0 != ret) {
837                                 MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
838                         }
839                 }
840         } else {
841                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
842         }
843         return ret;
844 }
845
846 int CServicePlugin::set_default_assistant(const char* appid)
847 {
848         int ret = -1;
849         if (NULL != mPluginHandle) {
850                 wakeup_manager_set_default_assistant func = mWakeupManagerInterface.set_default_assistant;
851                 if (NULL == func) {
852                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
853                 } else {
854                         ret = func(appid);
855                         if (0 != ret) {
856                                 MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
857                         }
858                 }
859         } else {
860                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
861         }
862         return ret;
863 }
864
865 int CServicePlugin::get_default_assistant(const char** appid)
866 {
867         int ret = -1;
868         if (NULL == appid) {
869                 MAS_LOGE("[ERROR] appid is not valid");
870                 return ret;
871         }
872         if (NULL != mPluginHandle) {
873                 wakeup_manager_get_default_assistant func = mWakeupManagerInterface.get_default_assistant;
874                 if (NULL == func) {
875                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
876                 } else {
877                         ret = func(appid);
878                         if (0 != ret) {
879                                 MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
880                         }
881                 }
882         } else {
883                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
884         }
885         return ret;
886 }
887
888 int CServicePlugin::activate(void)
889 {
890         int ret = -1;
891         if (NULL != mPluginHandle) {
892                 wakeup_manager_activate func = mWakeupManagerInterface.activate;
893                 if (NULL == func) {
894                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
895                 } else {
896                         ret = func();
897                         if (0 != ret) {
898                                 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
899                         }
900                 }
901         } else {
902                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
903         }
904         return ret;
905 }
906
907 int CServicePlugin::deactivate(void)
908 {
909         int ret = -1;
910         if (NULL != mPluginHandle) {
911                 wakeup_manager_deactivate func = mWakeupManagerInterface.deactivate;
912                 if (NULL == func) {
913                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
914                 } else {
915                         ret = func();
916                         if (0 != ret) {
917                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
918                         }
919                 }
920         } else {
921                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
922         }
923         return ret;
924 }
925
926 int CServicePlugin::update_voice_feedback_state(const char* appid, int state)
927 {
928         int ret = -1;
929         if (NULL != mPluginHandle) {
930                 wakeup_manager_update_voice_feedback_state func = mWakeupManagerInterface.update_voice_feedback_state;
931                 if (NULL == func) {
932                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
933                 } else {
934                         ret = func(appid, state);
935                         if (0 != ret) {
936                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
937                         }
938                 }
939         } else {
940                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
941         }
942         return ret;
943 }
944
945 int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command)
946 {
947         int ret = -1;
948         if (NULL != mPluginHandle) {
949                 wakeup_manager_set_assistant_specific_command func = mWakeupManagerInterface.set_assistant_specific_command;
950                 if (NULL == func) {
951                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
952                 } else {
953                         ret = func(appid, command);
954                         if (0 != ret) {
955                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
956                         }
957                 }
958         } else {
959                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
960         }
961         return ret;
962 }
963
964 int CServicePlugin::set_background_volume(const char* appid, double ratio)
965 {
966         int ret = -1;
967         if (NULL != mPluginHandle) {
968                 wakeup_manager_set_background_volume func = mWakeupManagerInterface.set_background_volume;
969                 if (NULL == func) {
970                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
971                 } else {
972                         ret = func(appid, ratio);
973                         if (0 != ret) {
974                                 MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
975                         }
976                 }
977         } else {
978                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
979         }
980         return ret;
981 }
982
983 int CServicePlugin::update_recognition_result(const char* appid, int state)
984 {
985         int ret = -1;
986         if (NULL != mPluginHandle) {
987                 wakeup_manager_update_recognition_result func = mWakeupManagerInterface.update_recognition_result;
988                 if (NULL == func) {
989                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
990                 } else {
991                         ret = func(appid, state);
992                         if (0 != ret) {
993                                 MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
994                         }
995                 }
996         } else {
997                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
998         }
999         return ret;
1000 }
1001
1002 int CServicePlugin::process_event(int event, void *data, int len)
1003 {
1004         int ret = -1;
1005         if (NULL != mPluginHandle) {
1006                 wakeup_manager_process_plugin_event func = mWakeupManagerInterface.process_plugin_event;
1007                 if (NULL == func) {
1008                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
1009                 } else {
1010                         ret = func((mas_plugin_event_e)event, data, len);
1011                         if (0 != ret) {
1012                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1013                         }
1014                 }
1015         } else {
1016                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1017         }
1018         return ret;
1019 }
1020
1021 int CServicePlugin::start_streaming_utterance_data(void)
1022 {
1023         MAS_LOGI("[ENTER");
1024         int ret = -1;
1025         if (NULL != mPluginHandle) {
1026                 wakeup_manager_start_streaming_utterance_data func = mWakeupManagerInterface.start_streaming_utterance_data;
1027                 if (NULL == func) {
1028                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
1029                 } else {
1030                         ret = func();
1031                         if (0 != ret) {
1032                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1033                         }
1034                 }
1035         } else {
1036                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1037         }
1038         return ret;
1039 }
1040
1041 int CServicePlugin::stop_streaming_utterance_data(void)
1042 {
1043         int ret = -1;
1044         if (NULL != mPluginHandle) {
1045                 wakeup_manager_stop_streaming_utterance_data func = mWakeupManagerInterface.stop_streaming_utterance_data;
1046                 if (NULL == func) {
1047                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
1048                 } else {
1049                         ret = func();
1050                         if (0 != ret) {
1051                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1052                         }
1053                 }
1054         } else {
1055                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1056         }
1057         return ret;
1058 }
1059
1060 int CServicePlugin::start_streaming_previous_utterance_data(void)
1061 {
1062         int ret = -1;
1063         if (NULL != mPluginHandle) {
1064                 wakeup_manager_start_streaming_previous_utterance_data func = mWakeupManagerInterface.start_streaming_previous_utterance_data;
1065                 if (NULL == func) {
1066                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
1067                 } else {
1068                         ret = func();
1069                         if (0 != ret) {
1070                                 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1071                         }
1072                 }
1073         } else {
1074                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1075         }
1076         return ret;
1077 }
1078
1079 int CServicePlugin::stop_streaming_previous_utterance_data(void)
1080 {
1081         int ret = -1;
1082         if (NULL != mPluginHandle) {
1083                 wakeup_manager_stop_streaming_previous_utterance_data func = mWakeupManagerInterface.stop_streaming_previous_utterance_data;
1084                 if (NULL == func) {
1085                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
1086                 } else {
1087                         ret = func();
1088                         if (0 != ret) {
1089                                 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1090                         }
1091                 }
1092         } else {
1093                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1094         }
1095         return ret;
1096 }
1097
1098 int CServicePlugin::start_streaming_follow_up_data(void)
1099 {
1100         int ret = -1;
1101         if (NULL != mPluginHandle) {
1102                 wakeup_manager_start_streaming_follow_up_data func = mWakeupManagerInterface.start_streaming_follow_up_data;
1103                 if (NULL == func) {
1104                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
1105                 } else {
1106                         ret = func();
1107                         if (0 != ret) {
1108                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1109                         }
1110                 }
1111         } else {
1112                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1113         }
1114         return ret;
1115 }
1116
1117 int CServicePlugin::stop_streaming_follow_up_data(void)
1118 {
1119         int ret = -1;
1120         if (NULL != mPluginHandle) {
1121                 wakeup_manager_stop_streaming_follow_up_data func = mWakeupManagerInterface.stop_streaming_follow_up_data;
1122                 if (NULL == func) {
1123                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
1124                 } else {
1125                         ret = func();
1126                         if (0 != ret) {
1127                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1128                         }
1129                 }
1130         } else {
1131                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1132         }
1133         return ret;
1134 }
1135
1136 int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type)
1137 {
1138         int ret = -1;
1139         if (NULL != mPluginHandle) {
1140                 wakeup_manager_get_audio_format func = mWakeupManagerInterface.get_audio_format;
1141                 if (NULL == func) {
1142                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
1143                 } else {
1144                         ret = func(rate, channel, audio_type);
1145                         if (0 != ret) {
1146                                 MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
1147                         }
1148                 }
1149         } else {
1150                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1151         }
1152         return ret;
1153 }
1154
1155 int CServicePlugin::get_recording_audio_source_type(char** type)
1156 {
1157         int ret = -1;
1158         if (NULL != mPluginHandle) {
1159                 wakeup_manager_get_audio_source_type func = mWakeupManagerInterface.get_audio_source_type;
1160                 if (NULL == func) {
1161                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
1162                 } else {
1163                         ret = func(type);
1164                         if (0 != ret) {
1165                                 MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
1166                         }
1167                 }
1168         } else {
1169                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1170         }
1171         return ret;
1172 }
1173
1174 int CServicePlugin::set_voice_key_tap_duration(float duration)
1175 {
1176         int ret = -1;
1177         if (NULL != mPluginHandle) {
1178                 wakeup_manager_set_voice_key_tap_duration func = mWakeupManagerInterface.set_voice_key_tap_duration;
1179                 if (NULL == func) {
1180                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
1181                 } else {
1182                         ret = func(duration);
1183                         if (0 != ret) {
1184                                 MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
1185                         }
1186                 }
1187         } else {
1188                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1189         }
1190         return ret;
1191 }
1192
1193 int CServicePlugin::unset_voice_key_tap_duration()
1194 {
1195         int ret = -1;
1196         if (NULL != mPluginHandle) {
1197                 wakeup_manager_unset_voice_key_tap_duration func = mWakeupManagerInterface.unset_voice_key_tap_duration;
1198                 if (NULL == func) {
1199                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
1200                 } else {
1201                         ret = func();
1202                         if (0 != ret) {
1203                                 MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
1204                         }
1205                 }
1206         } else {
1207                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1208         }
1209         return ret;
1210 }
1211
1212 int CServicePlugin::set_voice_key_support_mode(int mode)
1213 {
1214         int ret = -1;
1215         if (NULL != mPluginHandle) {
1216                 wakeup_manager_set_voice_key_support_mode func = mWakeupManagerInterface.set_voice_key_support_mode;
1217                 if (NULL == func) {
1218                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
1219                 } else {
1220                         ret = func(mode);
1221                         if (0 != ret) {
1222                                 MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
1223                         }
1224                 }
1225         } else {
1226                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1227         }
1228         return ret;
1229 }
1230
1231 int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require)
1232 {
1233         int ret = -1;
1234         if (NULL != mPluginHandle) {
1235                 wakeup_manager_set_wake_word_audio_require_flag func = mWakeupManagerInterface.set_wake_word_audio_require_flag;
1236                 if (NULL == func) {
1237                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
1238                 } else {
1239                         ret = func(require);
1240                         if (0 != ret) {
1241                                 MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
1242                         }
1243                 }
1244         } else {
1245                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1246         }
1247         return ret;
1248 }
1249
1250 int CServicePlugin::set_assistant_language(const char* appid, const char* language)
1251 {
1252         int ret = -1;
1253         if (NULL != mPluginHandle) {
1254                 wakeup_manager_set_assistant_language func = mWakeupManagerInterface.set_assistant_language;
1255                 if (NULL == func) {
1256                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
1257                 } else {
1258                         ret = func(appid, language);
1259                         if (0 != ret) {
1260                                 MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
1261                         }
1262                 }
1263         } else {
1264                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1265         }
1266         return ret;
1267 }
1268
1269 int CServicePlugin::set_callbacks(void)
1270 {
1271         int ret = set_wakeup_event_callback(__wakeup_event_cb, this);
1272         if (0 != ret) {
1273                 MAS_LOGE("Fail to set wakeup event cb");
1274                 return ret;
1275         }
1276
1277         ret = set_utterance_streaming_callback(__audio_streaming_cb, this);
1278         if (0 != ret) {
1279                 MAS_LOGE("Fail to set utterance streaming cb");
1280                 return ret;
1281         }
1282
1283         ret = set_previous_utterance_streaming_callback(__audio_streaming_cb, this);
1284         if (0 != ret) {
1285                 MAS_LOGE("Fail to set previous utterance streaming cb");
1286                 return ret;
1287         }
1288
1289         ret = set_follow_up_streaming_callback(__audio_streaming_cb, this);
1290         if (0 != ret) {
1291                 MAS_LOGE("Fail to set follow-up streaming cb");
1292                 return ret;
1293         }
1294
1295         ret = set_speech_status_callback(__speech_status_cb, this);
1296         if (0 != ret) {
1297                 MAS_LOGE("Fail to set speech status changed cb");
1298                 return ret;
1299         }
1300
1301         ret = set_setting_changed_callback(__setting_changed_cb, this);
1302         if (0 != ret) {
1303                 MAS_LOGE("Fail to set setting changed cb");
1304                 return ret;
1305         }
1306
1307         ret = set_error_callback(__error_cb, this);
1308         if (0 != ret) {
1309                 MAS_LOGE("Fail to set error cb");
1310                 return ret;
1311         }
1312
1313         ret = set_streaming_section_changed_callback(__streaming_section_changed_cb, this);
1314         if (0 != ret) {
1315                 MAS_LOGE("Fail to set streaming section changed cb");
1316                 return ret;
1317         }
1318
1319         ret = set_wakeup_engine_command_callback(__wakeup_engine_command_cb, this);
1320         if (0 != ret) {
1321                 MAS_LOGE("Fail to set wakeup engine command cb");
1322                 return ret;
1323         }
1324
1325         ret = set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, this);
1326         if (0 != ret) {
1327                 MAS_LOGE("Fail to set wakeup engine command cb");
1328                 return ret;
1329         }
1330
1331         ret = set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, this);
1332         if (0 != ret) {
1333                 MAS_LOGE("Fail to set wakeup engine command cb");
1334                 return ret;
1335         }
1336
1337         return 0;
1338 }
1339
1340 int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
1341 {
1342         int ret = -1;
1343         if (NULL != mPluginHandle) {
1344                 wakeup_manager_set_wakeup_event_callback func = mWakeupManagerInterface.set_wakeup_event_callback;
1345                 if (NULL == func) {
1346                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
1347                 } else {
1348                         ret = func(callback, user_data);
1349                         if (0 != ret) {
1350                                 MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
1351                         }
1352                 }
1353         } else {
1354                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1355         }
1356         return ret;
1357 }
1358
1359 int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1360 {
1361         int ret = -1;
1362         if (NULL != mPluginHandle) {
1363                 wakeup_manager_set_utterance_streaming_callback func = mWakeupManagerInterface.set_utterance_streaming_callback;
1364                 if (NULL == func) {
1365                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
1366                 } else {
1367                         ret = func(callback, user_data);
1368                         if (0 != ret) {
1369                                 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1370                         }
1371                 }
1372         } else {
1373                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1374         }
1375         return ret;
1376 }
1377
1378 int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1379 {
1380         int ret = -1;
1381         if (NULL != mPluginHandle) {
1382                 wakeup_manager_set_previous_utterance_streaming_callback func = mWakeupManagerInterface.set_previous_utterance_streaming_callback;
1383                 if (NULL == func) {
1384                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
1385                 } else {
1386                         ret = func(callback, user_data);
1387                         if (0 != ret) {
1388                                 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1389                         }
1390                 }
1391         } else {
1392                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1393         }
1394         return ret;
1395 }
1396
1397 int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1398 {
1399         int ret = -1;
1400         if (NULL != mPluginHandle) {
1401                 wakeup_manager_set_follow_up_streaming_callback func = mWakeupManagerInterface.set_follow_up_streaming_callback;
1402                 if (NULL == func) {
1403                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
1404                 } else {
1405                         ret = func(callback, user_data);
1406                         if (0 != ret) {
1407                                 MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
1408                         }
1409                 }
1410         } else {
1411                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1412         }
1413         return ret;
1414 }
1415
1416 int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
1417 {
1418         int ret = -1;
1419         if (NULL != mPluginHandle) {
1420                 wakeup_manager_set_speech_status_callback func = mWakeupManagerInterface.set_speech_status_callback;
1421                 if (NULL == func) {
1422                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
1423                 } else {
1424                         ret = func(callback, user_data);
1425                         if (0 != ret) {
1426                                 MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
1427                         }
1428                 }
1429         }
1430         return ret;
1431 }
1432
1433 int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
1434 {
1435         int ret = -1;
1436         if (NULL != mPluginHandle) {
1437                 wakeup_manager_set_setting_changed_callback func = mWakeupManagerInterface.set_setting_changed_callback;
1438                 if (NULL == func) {
1439                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
1440                 } else {
1441                         ret = func(callback, user_data);
1442                         if (0 != ret) {
1443                                 MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
1444                         }
1445                 }
1446         }
1447         return ret;
1448 }
1449
1450 int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data)
1451 {
1452         int ret = -1;
1453         if (NULL != mPluginHandle) {
1454                 wakeup_manager_set_error_callback func = mWakeupManagerInterface.set_error_callback;
1455                 if (NULL == func) {
1456                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
1457                 } else {
1458                         ret = func(callback, user_data);
1459                         if (0 != ret) {
1460                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1461                         }
1462                 }
1463         }
1464         return ret;
1465 }
1466
1467 int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
1468 {
1469         int ret = -1;
1470         if (NULL != mPluginHandle) {
1471                 wakeup_manager_set_streaming_section_changed_callback func = mWakeupManagerInterface.set_streaming_section_changed_callback;
1472                 if (NULL == func) {
1473                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
1474                 } else {
1475                         ret = func(callback, user_data);
1476                         if (0 != ret) {
1477                                 MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
1478                         }
1479                 }
1480         }
1481         return ret;
1482 }
1483
1484 int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
1485 {
1486         int ret = -1;
1487         if (NULL != mPluginHandle) {
1488                 wakeup_manager_set_wakeup_engine_command_callback func = mWakeupManagerInterface.set_wakeup_engine_command_callback;
1489                 if (NULL == func) {
1490                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
1491                 } else {
1492                         ret = func(callback, user_data);
1493                         if (0 != ret) {
1494                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1495                         }
1496                 }
1497         }
1498         return ret;
1499 }
1500
1501 int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
1502 {
1503         int ret = -1;
1504         if (NULL != mPluginHandle) {
1505                 wakeup_manager_set_wakeup_service_state_changed_callback func = mWakeupManagerInterface.set_wakeup_service_state_changed_callback;
1506                 if (NULL == func) {
1507                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
1508                 } else {
1509                         ret = func(callback, user_data);
1510                         if (0 != ret) {
1511                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1512                         }
1513                 }
1514         }
1515         return ret;
1516 }
1517
1518 int CServicePlugin::set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
1519 {
1520         int ret = -1;
1521         if (NULL != mPluginHandle) {
1522                 wakeup_manager_set_voice_key_status_changed_callback func = mWakeupManagerInterface.set_voice_key_status_changed_callback;
1523                 if (NULL == func) {
1524                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
1525                 } else {
1526                         ret = func(callback, user_data);
1527                         if (0 != ret) {
1528                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1529                         }
1530                 }
1531         }
1532         return ret;
1533 }
1534