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