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