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