2b8e8da6ca2f09b86b392c80b92d857dec6cd770
[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 Eina_Bool app_restart_timer_func(void *user_data)
647 {
648         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
649         if (plugin) {
650                 CServiceMain* service_main = plugin->get_service_main();
651                 if (service_main) {
652                         ma_service_state_e service_state = service_main->get_current_service_state();
653                         if (service_state != MA_SERVICE_STATE_UTTERANCE) {
654                                 MAS_LOGE("[SUCCESS] Restarting service");
655                                 service_main->app_restart();
656                         }
657                 }
658         }
659
660         return ECORE_CALLBACK_RENEW;
661 }
662
663 void CServicePlugin::stop_app_restart_timer()
664 {
665         if (mAppRestartTimer) {
666                 ecore_timer_del(mAppRestartTimer);
667                 mAppRestartTimer = nullptr;
668         }
669 }
670
671 void CServicePlugin::start_app_restart_timer()
672 {
673         stop_app_restart_timer();
674         mAppRestartTimer = ecore_timer_add(1.0f, app_restart_timer_func, this);
675 }
676
677 static void __loaded_engine_changed_cb(void* user_data)
678 {
679         MAS_LOGD("[SUCCESS] __loaded_engine_changed_cb is called");
680
681         CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
682         if (nullptr == plugin) return;
683
684         CServiceMain* service_main = plugin->get_service_main();
685         if (service_main) {
686                 /* Make sure the app doesn't restart within a conversation session */
687                 ma_service_state_e service_state = service_main->get_current_service_state();
688                 if (service_state != MA_SERVICE_STATE_UTTERANCE) {
689                         MAS_LOGE("[SUCCESS] Restarting service");
690                         service_main->app_restart();
691                 } else {
692                         MAS_LOGE("Cannot restart service when service_state is %d", service_state);
693                         plugin->start_app_restart_timer();
694                 }
695         }
696 }
697
698 int CServicePlugin::initialize(void)
699 {
700         MAS_LOGD("[Enter]");
701
702         char filepath[512] = {'\0', };
703         const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
704         snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
705
706         char *error;
707         mPluginHandle = nullptr;
708         mPluginHandle = dlopen(filepath, RTLD_LAZY);
709         if (nullptr != (error = dlerror())) {
710                 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
711                 if (mPluginHandle) dlclose(mPluginHandle);
712                 mPluginHandle = nullptr;
713                 return -1; //MAS_ERROR_OPERATION_FAILED;
714         }
715         if (nullptr == mPluginHandle) {
716                 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
717                 return -1; //MAS_ERROR_OPERATION_FAILED;
718         }
719
720         mWakeupManagerInterface.initialize =
721                 (wakeup_manager_initialize)dlsym(mPluginHandle,
722                 MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
723         mWakeupManagerInterface.deinitialize =
724                 (wakeup_manager_deinitialize)dlsym(mPluginHandle,
725                 MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
726         mWakeupManagerInterface.get_settings =
727                 (wakeup_manager_get_settings)dlsym(mPluginHandle,
728                 MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
729         mWakeupManagerInterface.add_assistant_wakeup_word =
730                 (wakeup_manager_add_assistant_wakeup_word)dlsym(mPluginHandle,
731                 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
732         mWakeupManagerInterface.remove_assistant_wakeup_word =
733                 (wakeup_manager_remove_assistant_wakeup_word)dlsym(mPluginHandle,
734                 MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
735         mWakeupManagerInterface.add_assistant_language =
736                 (wakeup_manager_add_assistant_language)dlsym(mPluginHandle,
737                 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
738         mWakeupManagerInterface.add_assistant_wakeup_engine =
739                 (wakeup_manager_add_assistant_wakeup_engine)dlsym(mPluginHandle,
740                 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
741         mWakeupManagerInterface.set_default_assistant =
742                 (wakeup_manager_set_default_assistant)dlsym(mPluginHandle,
743                 MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
744         mWakeupManagerInterface.get_default_assistant =
745                 (wakeup_manager_get_default_assistant)dlsym(mPluginHandle,
746                 MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
747         mWakeupManagerInterface.set_language =
748                 (wakeup_manager_set_language)dlsym(mPluginHandle,
749                 MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
750         mWakeupManagerInterface.activate =
751                 (wakeup_manager_activate)dlsym(mPluginHandle,
752                 MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
753         mWakeupManagerInterface.deactivate =
754                 (wakeup_manager_deactivate)dlsym(mPluginHandle,
755                 MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
756         mWakeupManagerInterface.update_voice_feedback_state =
757                 (wakeup_manager_update_voice_feedback_state)dlsym(mPluginHandle,
758                 MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
759         mWakeupManagerInterface.set_assistant_specific_command =
760                 (wakeup_manager_set_assistant_specific_command)dlsym(mPluginHandle,
761                 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
762         mWakeupManagerInterface.set_background_volume =
763                 (wakeup_manager_set_background_volume)dlsym(mPluginHandle,
764                 MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
765         mWakeupManagerInterface.update_recognition_result =
766                 (wakeup_manager_update_recognition_result)dlsym(mPluginHandle,
767                 MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
768         mWakeupManagerInterface.process_plugin_event =
769                 (wakeup_manager_process_plugin_event)dlsym(mPluginHandle,
770                 MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
771         mWakeupManagerInterface.start_streaming_utterance_data =
772                 (wakeup_manager_start_streaming_utterance_data)dlsym(mPluginHandle,
773                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
774         mWakeupManagerInterface.stop_streaming_utterance_data =
775                 (wakeup_manager_stop_streaming_utterance_data)dlsym(mPluginHandle,
776                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
777         mWakeupManagerInterface.start_streaming_previous_utterance_data =
778                 (wakeup_manager_start_streaming_previous_utterance_data)dlsym(mPluginHandle,
779                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
780         mWakeupManagerInterface.stop_streaming_previous_utterance_data =
781                 (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(mPluginHandle,
782                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
783         mWakeupManagerInterface.start_streaming_follow_up_data =
784                 (wakeup_manager_start_streaming_follow_up_data)dlsym(mPluginHandle,
785                 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
786         mWakeupManagerInterface.stop_streaming_follow_up_data =
787                 (wakeup_manager_stop_streaming_follow_up_data)dlsym(mPluginHandle,
788                 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
789         mWakeupManagerInterface.get_audio_format =
790                 (wakeup_manager_get_audio_format)dlsym(mPluginHandle,
791                 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
792         mWakeupManagerInterface.get_audio_source_type =
793                 (wakeup_manager_get_audio_source_type)dlsym(mPluginHandle,
794                 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
795         mWakeupManagerInterface.set_wake_word_audio_require_flag =
796                 (wakeup_manager_set_wake_word_audio_require_flag)dlsym(mPluginHandle,
797                 MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
798         mWakeupManagerInterface.set_assistant_language =
799                 (wakeup_manager_set_assistant_language)dlsym(mPluginHandle,
800                 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
801         mWakeupManagerInterface.set_voice_key_tap_duration =
802                 (wakeup_manager_set_voice_key_tap_duration)dlsym(mPluginHandle,
803                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
804         mWakeupManagerInterface.unset_voice_key_tap_duration =
805                 (wakeup_manager_unset_voice_key_tap_duration)dlsym(mPluginHandle,
806                 MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
807         mWakeupManagerInterface.set_voice_key_support_mode =
808                 (wakeup_manager_set_voice_key_support_mode)dlsym(mPluginHandle,
809                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
810         mWakeupManagerInterface.set_wakeup_event_callback =
811                 (wakeup_manager_set_wakeup_event_callback)dlsym(mPluginHandle,
812                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
813         mWakeupManagerInterface.set_utterance_streaming_callback =
814                 (wakeup_manager_set_utterance_streaming_callback)dlsym(mPluginHandle,
815                 MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
816         mWakeupManagerInterface.set_previous_utterance_streaming_callback =
817                 (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(mPluginHandle,
818                 MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
819         mWakeupManagerInterface.set_follow_up_streaming_callback =
820                 (wakeup_manager_set_follow_up_streaming_callback)dlsym(mPluginHandle,
821                 MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
822         mWakeupManagerInterface.set_speech_status_callback =
823                 (wakeup_manager_set_speech_status_callback)dlsym(mPluginHandle,
824                 MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
825         mWakeupManagerInterface.set_setting_changed_callback =
826                 (wakeup_manager_set_setting_changed_callback)dlsym(mPluginHandle,
827                 MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
828         mWakeupManagerInterface.set_error_callback =
829                 (wakeup_manager_set_error_callback)dlsym(mPluginHandle,
830                 MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
831         mWakeupManagerInterface.set_streaming_section_changed_callback =
832                 (wakeup_manager_set_streaming_section_changed_callback)dlsym(mPluginHandle,
833                 MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
834         mWakeupManagerInterface.set_wakeup_engine_command_callback =
835                 (wakeup_manager_set_wakeup_engine_command_callback)dlsym(mPluginHandle,
836                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
837         mWakeupManagerInterface.set_wakeup_service_state_changed_callback =
838                 (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(mPluginHandle,
839                 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
840         mWakeupManagerInterface.set_voice_key_status_changed_callback =
841                 (wakeup_manager_set_voice_key_status_changed_callback)dlsym(mPluginHandle,
842                 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
843         mWakeupManagerInterface.set_loaded_engine_changed_callback =
844                 (wakeup_manager_set_loaded_engine_changed_callback)dlsym(mPluginHandle,
845                 MA_WAKEUP_MANAGER_FUNC_SET_LOADED_ENGINE_CHANGED_CALLBACK);
846
847         int ret = -1;
848         if (NULL != mPluginHandle) {
849                 wakeup_manager_initialize func = mWakeupManagerInterface.initialize;
850
851                 if (NULL == func) {
852                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
853                 } else {
854                         ret = func();
855                         if (0 != ret) {
856                                 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
857                         }
858                 }
859
860                 wakeup_manager_get_settings get_settings_func = mWakeupManagerInterface.get_settings;
861
862                 if (NULL == get_settings_func) {
863                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
864                 } else {
865                         size_t struct_size;
866                         ret = get_settings_func(&mPluginSettings, &struct_size);
867                         if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
868                                 MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
869                                 mPluginSettings = NULL;
870                         }
871                 }
872         } else {
873                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
874         }
875         return ret;
876 }
877
878 int CServicePlugin::deinitialize(void)
879 {
880 #ifdef BUF_SAVE_MODE
881         if (mDumpFile) {
882                 fclose(mDumpFile);
883                 mDumpFile = NULL;
884         } else {
885                 MAS_LOGD("[Recorder ERROR] File not found!");
886         }
887 #endif
888
889         if (mAppRestartTimer) {
890                 ecore_timer_del(mAppRestartTimer);
891                 mAppRestartTimer = nullptr;
892         }
893
894         int ret = -1;
895         if (NULL != mPluginHandle) {
896                 wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize;
897                 if (NULL == func) {
898                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
899                 } else {
900                         ret = func();
901                         if (0 != ret) {
902                                 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
903                         }
904                 }
905
906                 dlclose(mPluginHandle);
907                 mPluginHandle = NULL;
908         } else {
909                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
910         }
911
912         return ret;
913 }
914
915 int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size)
916 {
917         int ret = -1;
918         if (NULL != mPluginHandle) {
919                 wakeup_manager_get_settings func = mWakeupManagerInterface.get_settings;
920                 if (NULL == func) {
921                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
922                 } else {
923                         ret = func(settings, struct_size);
924                         if (0 != ret) {
925                                 MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
926                         }
927                 }
928         } else {
929                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
930         }
931         return ret;
932 }
933
934 int CServicePlugin::set_language(const char* language)
935 {
936         int ret = -1;
937         if (NULL != mPluginHandle) {
938                 wakeup_manager_set_language func = mWakeupManagerInterface.set_language;
939                 if (NULL == func) {
940                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
941                 } else {
942                         ret = func(language);
943                         if (0 != ret) {
944                                 MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
945                         }
946                 }
947         } else {
948                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
949         }
950         return ret;
951 }
952
953 int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
954 {
955         int ret = -1;
956         if (NULL != mPluginHandle) {
957                 wakeup_manager_add_assistant_wakeup_word func = mWakeupManagerInterface.add_assistant_wakeup_word;
958                 if (NULL == func) {
959                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
960                 } else {
961                         ret = func(appid, wakeup_word, language);
962                         if (0 != ret) {
963                                 MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
964                         }
965                 }
966         } else {
967                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
968         }
969         return ret;
970 }
971
972 int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
973 {
974         int ret = -1;
975         if (NULL != mPluginHandle) {
976                 wakeup_manager_remove_assistant_wakeup_word func = mWakeupManagerInterface.remove_assistant_wakeup_word;
977                 if (NULL == func) {
978                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
979                 } else {
980                         ret = func(appid, wakeup_word, language);
981                         if (0 != ret) {
982                                 MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
983                         }
984                 }
985         } else {
986                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
987         }
988         return ret;
989 }
990
991 int CServicePlugin::add_assistant_language(const char* appid, const char* language)
992 {
993         int ret = -1;
994         if (NULL != mPluginHandle) {
995                 wakeup_manager_add_assistant_language func = mWakeupManagerInterface.add_assistant_language;
996                 if (NULL == func) {
997                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
998                 } else {
999                         ret = func(appid, language);
1000                         if (0 != ret) {
1001                                 MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
1002                         }
1003                 }
1004         } else {
1005                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1006         }
1007         return ret;
1008 }
1009
1010 int CServicePlugin::add_assistant_wakeup_engine(const char* appid, const char* engine)
1011 {
1012         int ret = -1;
1013         if (NULL != mPluginHandle) {
1014                 wakeup_manager_add_assistant_wakeup_engine func = mWakeupManagerInterface.add_assistant_wakeup_engine;
1015                 if (NULL == func) {
1016                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
1017                 } else {
1018                         ret = func(appid, engine);
1019                         if (0 != ret) {
1020                                 MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
1021                         }
1022                 }
1023         } else {
1024                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1025         }
1026         return ret;
1027 }
1028
1029 int CServicePlugin::set_default_assistant(const char* appid)
1030 {
1031         int ret = -1;
1032         if (NULL != mPluginHandle) {
1033                 wakeup_manager_set_default_assistant func = mWakeupManagerInterface.set_default_assistant;
1034                 if (NULL == func) {
1035                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
1036                 } else {
1037                         ret = func(appid);
1038                         if (0 != ret) {
1039                                 MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
1040                         }
1041                 }
1042         } else {
1043                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1044         }
1045         return ret;
1046 }
1047
1048 int CServicePlugin::get_default_assistant(const char** appid)
1049 {
1050         int ret = -1;
1051         if (NULL == appid) {
1052                 MAS_LOGE("[ERROR] appid is not valid");
1053                 return ret;
1054         }
1055         if (NULL != mPluginHandle) {
1056                 wakeup_manager_get_default_assistant func = mWakeupManagerInterface.get_default_assistant;
1057                 if (NULL == func) {
1058                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
1059                 } else {
1060                         ret = func(appid);
1061                         if (0 != ret) {
1062                                 MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
1063                         }
1064                 }
1065         } else {
1066                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1067         }
1068         return ret;
1069 }
1070
1071 int CServicePlugin::activate(void)
1072 {
1073         int ret = -1;
1074         if (NULL != mPluginHandle) {
1075                 wakeup_manager_activate func = mWakeupManagerInterface.activate;
1076                 if (NULL == func) {
1077                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
1078                 } else {
1079                         ret = func();
1080                         if (0 != ret) {
1081                                 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
1082                         }
1083                 }
1084         } else {
1085                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1086         }
1087         return ret;
1088 }
1089
1090 int CServicePlugin::deactivate(void)
1091 {
1092         int ret = -1;
1093         if (NULL != mPluginHandle) {
1094                 wakeup_manager_deactivate func = mWakeupManagerInterface.deactivate;
1095                 if (NULL == func) {
1096                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
1097                 } else {
1098                         ret = func();
1099                         if (0 != ret) {
1100                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1101                         }
1102                 }
1103         } else {
1104                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1105         }
1106         return ret;
1107 }
1108
1109 int CServicePlugin::update_voice_feedback_state(const char* appid, int state)
1110 {
1111         int ret = -1;
1112         if (NULL != mPluginHandle) {
1113                 wakeup_manager_update_voice_feedback_state func = mWakeupManagerInterface.update_voice_feedback_state;
1114                 if (NULL == func) {
1115                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
1116                 } else {
1117                         ret = func(appid, state);
1118                         if (0 != ret) {
1119                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1120                         }
1121                 }
1122         } else {
1123                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1124         }
1125         return ret;
1126 }
1127
1128 int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command)
1129 {
1130         int ret = -1;
1131         if (NULL != mPluginHandle) {
1132                 wakeup_manager_set_assistant_specific_command func = mWakeupManagerInterface.set_assistant_specific_command;
1133                 if (NULL == func) {
1134                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
1135                 } else {
1136                         ret = func(appid, command);
1137                         if (0 != ret) {
1138                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1139                         }
1140                 }
1141         } else {
1142                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1143         }
1144         return ret;
1145 }
1146
1147 int CServicePlugin::set_background_volume(const char* appid, double ratio)
1148 {
1149         int ret = -1;
1150         if (NULL != mPluginHandle) {
1151                 wakeup_manager_set_background_volume func = mWakeupManagerInterface.set_background_volume;
1152                 if (NULL == func) {
1153                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
1154                 } else {
1155                         ret = func(appid, ratio);
1156                         if (0 != ret) {
1157                                 MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
1158                         }
1159                 }
1160         } else {
1161                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1162         }
1163         return ret;
1164 }
1165
1166 int CServicePlugin::update_recognition_result(const char* appid, int state)
1167 {
1168         int ret = -1;
1169         if (NULL != mPluginHandle) {
1170                 wakeup_manager_update_recognition_result func = mWakeupManagerInterface.update_recognition_result;
1171                 if (NULL == func) {
1172                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
1173                 } else {
1174                         ret = func(appid, state);
1175                         if (0 != ret) {
1176                                 MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
1177                         }
1178                 }
1179         } else {
1180                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1181         }
1182         return ret;
1183 }
1184
1185 int CServicePlugin::process_event(int event, void *data, int len)
1186 {
1187         int ret = -1;
1188         if (NULL != mPluginHandle) {
1189                 wakeup_manager_process_plugin_event func = mWakeupManagerInterface.process_plugin_event;
1190                 if (NULL == func) {
1191                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
1192                 } else {
1193                         ret = func((mas_plugin_event_e)event, data, len);
1194                         if (0 != ret) {
1195                                 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1196                         }
1197                 }
1198         } else {
1199                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1200         }
1201         return ret;
1202 }
1203
1204 int CServicePlugin::start_streaming_utterance_data(void)
1205 {
1206         MAS_LOGI("[ENTER");
1207         int ret = -1;
1208         if (NULL != mPluginHandle) {
1209                 wakeup_manager_start_streaming_utterance_data func = mWakeupManagerInterface.start_streaming_utterance_data;
1210                 if (NULL == func) {
1211                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
1212                 } else {
1213                         ret = func();
1214                         if (0 != ret) {
1215                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1216                         }
1217                 }
1218         } else {
1219                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1220         }
1221         return ret;
1222 }
1223
1224 int CServicePlugin::stop_streaming_utterance_data(void)
1225 {
1226         int ret = -1;
1227         if (NULL != mPluginHandle) {
1228                 wakeup_manager_stop_streaming_utterance_data func = mWakeupManagerInterface.stop_streaming_utterance_data;
1229                 if (NULL == func) {
1230                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
1231                 } else {
1232                         ret = func();
1233                         if (0 != ret) {
1234                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1235                         }
1236                 }
1237         } else {
1238                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1239         }
1240         return ret;
1241 }
1242
1243 int CServicePlugin::start_streaming_previous_utterance_data(void)
1244 {
1245         int ret = -1;
1246         if (NULL != mPluginHandle) {
1247                 wakeup_manager_start_streaming_previous_utterance_data func = mWakeupManagerInterface.start_streaming_previous_utterance_data;
1248                 if (NULL == func) {
1249                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
1250                 } else {
1251                         ret = func();
1252                         if (0 != ret) {
1253                                 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1254                         }
1255                 }
1256         } else {
1257                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1258         }
1259         return ret;
1260 }
1261
1262 int CServicePlugin::stop_streaming_previous_utterance_data(void)
1263 {
1264         int ret = -1;
1265         if (NULL != mPluginHandle) {
1266                 wakeup_manager_stop_streaming_previous_utterance_data func = mWakeupManagerInterface.stop_streaming_previous_utterance_data;
1267                 if (NULL == func) {
1268                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
1269                 } else {
1270                         ret = func();
1271                         if (0 != ret) {
1272                                 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1273                         }
1274                 }
1275         } else {
1276                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1277         }
1278         return ret;
1279 }
1280
1281 int CServicePlugin::start_streaming_follow_up_data(void)
1282 {
1283         int ret = -1;
1284         if (NULL != mPluginHandle) {
1285                 wakeup_manager_start_streaming_follow_up_data func = mWakeupManagerInterface.start_streaming_follow_up_data;
1286                 if (NULL == func) {
1287                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
1288                 } else {
1289                         ret = func();
1290                         if (0 != ret) {
1291                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1292                         }
1293                 }
1294         } else {
1295                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1296         }
1297         return ret;
1298 }
1299
1300 int CServicePlugin::stop_streaming_follow_up_data(void)
1301 {
1302         int ret = -1;
1303         if (NULL != mPluginHandle) {
1304                 wakeup_manager_stop_streaming_follow_up_data func = mWakeupManagerInterface.stop_streaming_follow_up_data;
1305                 if (NULL == func) {
1306                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
1307                 } else {
1308                         ret = func();
1309                         if (0 != ret) {
1310                                 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1311                         }
1312                 }
1313         } else {
1314                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1315         }
1316         return ret;
1317 }
1318
1319 int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type)
1320 {
1321         int ret = -1;
1322         if (NULL != mPluginHandle) {
1323                 wakeup_manager_get_audio_format func = mWakeupManagerInterface.get_audio_format;
1324                 if (NULL == func) {
1325                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
1326                 } else {
1327                         ret = func(rate, channel, audio_type);
1328                         if (0 != ret) {
1329                                 MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
1330                         }
1331                 }
1332         } else {
1333                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1334         }
1335         return ret;
1336 }
1337
1338 int CServicePlugin::get_recording_audio_source_type(char** type)
1339 {
1340         int ret = -1;
1341         if (NULL != mPluginHandle) {
1342                 wakeup_manager_get_audio_source_type func = mWakeupManagerInterface.get_audio_source_type;
1343                 if (NULL == func) {
1344                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
1345                 } else {
1346                         ret = func(type);
1347                         if (0 != ret) {
1348                                 MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
1349                         }
1350                 }
1351         } else {
1352                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1353         }
1354         return ret;
1355 }
1356
1357 int CServicePlugin::set_voice_key_tap_duration(float duration)
1358 {
1359         int ret = -1;
1360         if (NULL != mPluginHandle) {
1361                 wakeup_manager_set_voice_key_tap_duration func = mWakeupManagerInterface.set_voice_key_tap_duration;
1362                 if (NULL == func) {
1363                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
1364                 } else {
1365                         ret = func(duration);
1366                         if (0 != ret) {
1367                                 MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
1368                         }
1369                 }
1370         } else {
1371                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1372         }
1373         return ret;
1374 }
1375
1376 int CServicePlugin::unset_voice_key_tap_duration()
1377 {
1378         int ret = -1;
1379         if (NULL != mPluginHandle) {
1380                 wakeup_manager_unset_voice_key_tap_duration func = mWakeupManagerInterface.unset_voice_key_tap_duration;
1381                 if (NULL == func) {
1382                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
1383                 } else {
1384                         ret = func();
1385                         if (0 != ret) {
1386                                 MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
1387                         }
1388                 }
1389         } else {
1390                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1391         }
1392         return ret;
1393 }
1394
1395 int CServicePlugin::set_voice_key_support_mode(int mode)
1396 {
1397         int ret = -1;
1398         if (NULL != mPluginHandle) {
1399                 wakeup_manager_set_voice_key_support_mode func = mWakeupManagerInterface.set_voice_key_support_mode;
1400                 if (NULL == func) {
1401                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
1402                 } else {
1403                         ret = func(mode);
1404                         if (0 != ret) {
1405                                 MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
1406                         }
1407                 }
1408         } else {
1409                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1410         }
1411         return ret;
1412 }
1413
1414 int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require)
1415 {
1416         int ret = -1;
1417         if (NULL != mPluginHandle) {
1418                 wakeup_manager_set_wake_word_audio_require_flag func = mWakeupManagerInterface.set_wake_word_audio_require_flag;
1419                 if (NULL == func) {
1420                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
1421                 } else {
1422                         ret = func(require);
1423                         if (0 != ret) {
1424                                 MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
1425                         }
1426                 }
1427         } else {
1428                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1429         }
1430         return ret;
1431 }
1432
1433 int CServicePlugin::set_assistant_language(const char* appid, const char* language)
1434 {
1435         int ret = -1;
1436         if (NULL != mPluginHandle) {
1437                 wakeup_manager_set_assistant_language func = mWakeupManagerInterface.set_assistant_language;
1438                 if (NULL == func) {
1439                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
1440                 } else {
1441                         ret = func(appid, language);
1442                         if (0 != ret) {
1443                                 MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
1444                         }
1445                 }
1446         } else {
1447                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1448         }
1449         return ret;
1450 }
1451
1452 int CServicePlugin::set_callbacks(void)
1453 {
1454         int ret = set_wakeup_event_callback(__wakeup_event_cb, this);
1455         if (0 != ret) {
1456                 MAS_LOGE("Fail to set wakeup event cb");
1457                 return ret;
1458         }
1459
1460         ret = set_utterance_streaming_callback(__audio_streaming_cb, this);
1461         if (0 != ret) {
1462                 MAS_LOGE("Fail to set utterance streaming cb");
1463                 return ret;
1464         }
1465
1466         ret = set_previous_utterance_streaming_callback(__audio_streaming_cb, this);
1467         if (0 != ret) {
1468                 MAS_LOGE("Fail to set previous utterance streaming cb");
1469                 return ret;
1470         }
1471
1472         ret = set_follow_up_streaming_callback(__audio_streaming_cb, this);
1473         if (0 != ret) {
1474                 MAS_LOGE("Fail to set follow-up streaming cb");
1475                 return ret;
1476         }
1477
1478         ret = set_speech_status_callback(__speech_status_cb, this);
1479         if (0 != ret) {
1480                 MAS_LOGE("Fail to set speech status changed cb");
1481                 return ret;
1482         }
1483
1484         ret = set_setting_changed_callback(__setting_changed_cb, this);
1485         if (0 != ret) {
1486                 MAS_LOGE("Fail to set setting changed cb");
1487                 return ret;
1488         }
1489
1490         ret = set_error_callback(__error_cb, this);
1491         if (0 != ret) {
1492                 MAS_LOGE("Fail to set error cb");
1493                 return ret;
1494         }
1495
1496         ret = set_streaming_section_changed_callback(__streaming_section_changed_cb, this);
1497         if (0 != ret) {
1498                 MAS_LOGE("Fail to set streaming section changed cb");
1499                 return ret;
1500         }
1501
1502         ret = set_wakeup_engine_command_callback(__wakeup_engine_command_cb, this);
1503         if (0 != ret) {
1504                 MAS_LOGE("Fail to set wakeup engine command cb");
1505                 return ret;
1506         }
1507
1508         ret = set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, this);
1509         if (0 != ret) {
1510                 MAS_LOGE("Fail to set wakeup engine command cb");
1511                 return ret;
1512         }
1513
1514         ret = set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, this);
1515         if (0 != ret) {
1516                 MAS_LOGE("Fail to set wakeup engine command cb");
1517                 return ret;
1518         }
1519
1520         ret = set_loaded_engine_changed_callback(__loaded_engine_changed_cb, this);
1521         if (0 != ret) {
1522                 MAS_LOGE("Fail to set loaded engine changed cb");
1523                 return ret;
1524         }
1525
1526         return 0;
1527 }
1528
1529 int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
1530 {
1531         int ret = -1;
1532         if (NULL != mPluginHandle) {
1533                 wakeup_manager_set_wakeup_event_callback func = mWakeupManagerInterface.set_wakeup_event_callback;
1534                 if (NULL == func) {
1535                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
1536                 } else {
1537                         ret = func(callback, user_data);
1538                         if (0 != ret) {
1539                                 MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
1540                         }
1541                 }
1542         } else {
1543                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1544         }
1545         return ret;
1546 }
1547
1548 int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1549 {
1550         int ret = -1;
1551         if (NULL != mPluginHandle) {
1552                 wakeup_manager_set_utterance_streaming_callback func = mWakeupManagerInterface.set_utterance_streaming_callback;
1553                 if (NULL == func) {
1554                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
1555                 } else {
1556                         ret = func(callback, user_data);
1557                         if (0 != ret) {
1558                                 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1559                         }
1560                 }
1561         } else {
1562                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1563         }
1564         return ret;
1565 }
1566
1567 int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1568 {
1569         int ret = -1;
1570         if (NULL != mPluginHandle) {
1571                 wakeup_manager_set_previous_utterance_streaming_callback func = mWakeupManagerInterface.set_previous_utterance_streaming_callback;
1572                 if (NULL == func) {
1573                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
1574                 } else {
1575                         ret = func(callback, user_data);
1576                         if (0 != ret) {
1577                                 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1578                         }
1579                 }
1580         } else {
1581                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1582         }
1583         return ret;
1584 }
1585
1586 int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1587 {
1588         int ret = -1;
1589         if (NULL != mPluginHandle) {
1590                 wakeup_manager_set_follow_up_streaming_callback func = mWakeupManagerInterface.set_follow_up_streaming_callback;
1591                 if (NULL == func) {
1592                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
1593                 } else {
1594                         ret = func(callback, user_data);
1595                         if (0 != ret) {
1596                                 MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
1597                         }
1598                 }
1599         } else {
1600                 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1601         }
1602         return ret;
1603 }
1604
1605 int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
1606 {
1607         int ret = -1;
1608         if (NULL != mPluginHandle) {
1609                 wakeup_manager_set_speech_status_callback func = mWakeupManagerInterface.set_speech_status_callback;
1610                 if (NULL == func) {
1611                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
1612                 } else {
1613                         ret = func(callback, user_data);
1614                         if (0 != ret) {
1615                                 MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
1616                         }
1617                 }
1618         }
1619         return ret;
1620 }
1621
1622 int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
1623 {
1624         int ret = -1;
1625         if (NULL != mPluginHandle) {
1626                 wakeup_manager_set_setting_changed_callback func = mWakeupManagerInterface.set_setting_changed_callback;
1627                 if (NULL == func) {
1628                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
1629                 } else {
1630                         ret = func(callback, user_data);
1631                         if (0 != ret) {
1632                                 MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
1633                         }
1634                 }
1635         }
1636         return ret;
1637 }
1638
1639 int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data)
1640 {
1641         int ret = -1;
1642         if (NULL != mPluginHandle) {
1643                 wakeup_manager_set_error_callback func = mWakeupManagerInterface.set_error_callback;
1644                 if (NULL == func) {
1645                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
1646                 } else {
1647                         ret = func(callback, user_data);
1648                         if (0 != ret) {
1649                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1650                         }
1651                 }
1652         }
1653         return ret;
1654 }
1655
1656 int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
1657 {
1658         int ret = -1;
1659         if (NULL != mPluginHandle) {
1660                 wakeup_manager_set_streaming_section_changed_callback func = mWakeupManagerInterface.set_streaming_section_changed_callback;
1661                 if (NULL == func) {
1662                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
1663                 } else {
1664                         ret = func(callback, user_data);
1665                         if (0 != ret) {
1666                                 MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
1667                         }
1668                 }
1669         }
1670         return ret;
1671 }
1672
1673 int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
1674 {
1675         int ret = -1;
1676         if (NULL != mPluginHandle) {
1677                 wakeup_manager_set_wakeup_engine_command_callback func = mWakeupManagerInterface.set_wakeup_engine_command_callback;
1678                 if (NULL == func) {
1679                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
1680                 } else {
1681                         ret = func(callback, user_data);
1682                         if (0 != ret) {
1683                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1684                         }
1685                 }
1686         }
1687         return ret;
1688 }
1689
1690 int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
1691 {
1692         int ret = -1;
1693         if (NULL != mPluginHandle) {
1694                 wakeup_manager_set_wakeup_service_state_changed_callback func = mWakeupManagerInterface.set_wakeup_service_state_changed_callback;
1695                 if (NULL == func) {
1696                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
1697                 } else {
1698                         ret = func(callback, user_data);
1699                         if (0 != ret) {
1700                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1701                         }
1702                 }
1703         }
1704         return ret;
1705 }
1706
1707 int CServicePlugin::set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
1708 {
1709         int ret = -1;
1710         if (NULL != mPluginHandle) {
1711                 wakeup_manager_set_voice_key_status_changed_callback func = mWakeupManagerInterface.set_voice_key_status_changed_callback;
1712                 if (NULL == func) {
1713                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
1714                 } else {
1715                         ret = func(callback, user_data);
1716                         if (0 != ret) {
1717                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1718                         }
1719                 }
1720         }
1721         return ret;
1722 }
1723
1724 int CServicePlugin::set_loaded_engine_changed_callback(wakeup_service_loaded_engine_changed_cb callback, void* user_data)
1725 {
1726         int ret = -1;
1727         if (NULL != mPluginHandle) {
1728                 wakeup_manager_set_loaded_engine_changed_callback func = mWakeupManagerInterface.set_loaded_engine_changed_callback;
1729                 if (NULL == func) {
1730                         MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LOADED_ENGINE_CHANGED_CALLBACK);
1731                 } else {
1732                         ret = func(callback, user_data);
1733                         if (0 != ret) {
1734                                 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1735                         }
1736                 }
1737         }
1738         return ret;
1739 }