2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "vcd_client_data.h"
22 #include "vcd_config.h"
23 #include "vcd_engine_agent.h"
25 #include "vcd_recorder.h"
29 * Internal data structure
36 char* engine_setting_path;
38 /* engine load info */
41 bool is_command_ready;
45 vce_request_callback_s* callbacks;
48 typedef struct _vcengine_info {
59 /** vc engine agent init */
60 static bool g_agent_init;
62 /** current engine information */
63 static vcengine_s g_dynamic_engine;
65 static char* g_default_lang;
67 bool __supported_language_cb(const char* language, void* user_data);
73 /** get engine info */
74 int __internal_get_engine_info(vce_request_callback_s* callback);
77 * VCS Engine Agent Interfaces
79 int vcd_engine_agent_init()
81 if (true == g_agent_init) {
82 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Already initialized");
83 return VCD_ERROR_NONE;
86 /* init dynamic engine */
87 g_dynamic_engine.engine_uuid = NULL;
88 g_dynamic_engine.engine_name = NULL;
89 g_dynamic_engine.engine_setting_path = NULL;
90 g_dynamic_engine.engine_path = NULL;
92 g_dynamic_engine.is_set = false;
93 g_dynamic_engine.is_loaded = false;
94 g_dynamic_engine.handle = NULL;
95 g_dynamic_engine.is_command_ready = false;
97 g_dynamic_engine.callbacks = (vce_request_callback_s*)calloc(1, sizeof(vce_request_callback_s));
98 if (NULL == g_dynamic_engine.callbacks) {
99 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to allocate memory");
100 return VCD_ERROR_OUT_OF_MEMORY;
105 if (0 != vcd_config_get_default_language(&g_default_lang)) {
106 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] There is No default voice in config");
107 /* Set default voice */
108 g_default_lang = strdup(VC_BASE_LANGUAGE);
109 if (NULL == g_default_lang) {
110 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to allocate memory");
111 return VCD_ERROR_OUT_OF_MEMORY;
115 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent Initialize");
120 int vcd_engine_agent_release()
122 if (false == g_agent_init) {
123 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
124 return VCD_ERROR_OPERATION_FAILED;
127 /* unload current engine */
128 if (0 != vcd_engine_agent_unload_current_engine()) {
129 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize");
130 return VCD_ERROR_OPERATION_FAILED;
133 /* release current engine data */
134 if (NULL != g_dynamic_engine.callbacks) {
135 free(g_dynamic_engine.callbacks);
136 g_dynamic_engine.callbacks = NULL;
138 if (NULL != g_dynamic_engine.engine_uuid) {
139 free(g_dynamic_engine.engine_uuid);
140 g_dynamic_engine.engine_uuid = NULL;
142 if (NULL != g_dynamic_engine.engine_name) {
143 free(g_dynamic_engine.engine_name);
144 g_dynamic_engine.engine_name = NULL;
146 if (NULL != g_dynamic_engine.engine_setting_path) {
147 free(g_dynamic_engine.engine_setting_path);
148 g_dynamic_engine.engine_setting_path = NULL;
151 g_agent_init = false;
153 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent release");
158 bool vcd_engine_is_available_engine()
160 if (true == g_dynamic_engine.is_loaded)
166 int __internal_get_engine_info(vce_request_callback_s* callback)
168 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] inside __internal_get_engine_info");
170 if (NULL == callback) {
171 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine");
172 return VCD_ERROR_ENGINE_NOT_FOUND;
175 if (NULL == callback->get_info) {
176 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine");
177 return VCD_ERROR_ENGINE_NOT_FOUND;
180 if (0 != callback->get_info(&(g_dynamic_engine.engine_uuid), &(g_dynamic_engine.engine_name), &(g_dynamic_engine.engine_setting_path), &(g_dynamic_engine.use_network))) {
181 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info");
182 return VCD_ERROR_ENGINE_NOT_FOUND;
185 if (NULL != g_dynamic_engine.callbacks) {
186 free(g_dynamic_engine.callbacks);
187 g_dynamic_engine.callbacks = NULL;
189 g_dynamic_engine.callbacks = (vce_request_callback_s*)calloc(1, sizeof(vce_request_callback_s));
190 if (NULL == g_dynamic_engine.callbacks) {
191 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to allocate memory");
192 return VCD_ERROR_OUT_OF_MEMORY;
195 g_dynamic_engine.callbacks->get_info = callback->get_info;
196 g_dynamic_engine.callbacks->get_recording_format = callback->get_recording_format;
197 g_dynamic_engine.callbacks->foreach_langs = callback->foreach_langs;
198 g_dynamic_engine.callbacks->is_lang_supported = callback->is_lang_supported;
199 g_dynamic_engine.callbacks->initialize = callback->initialize;
200 g_dynamic_engine.callbacks->deinitialize = callback->deinitialize;
201 g_dynamic_engine.callbacks->set_language = callback->set_language;
202 g_dynamic_engine.callbacks->set_commands = callback->set_commands;
203 g_dynamic_engine.callbacks->unset_commands = callback->unset_commands;
205 g_dynamic_engine.callbacks->start = callback->start;
206 g_dynamic_engine.callbacks->set_recording = callback->set_recording;
207 g_dynamic_engine.callbacks->stop = callback->stop;
208 g_dynamic_engine.callbacks->cancel = callback->cancel;
209 g_dynamic_engine.callbacks->set_domain = callback->set_domain;
210 g_dynamic_engine.callbacks->set_audio_type = callback->set_audio_type;
211 g_dynamic_engine.callbacks->set_server_dialog = callback->set_server_dialog;
212 g_dynamic_engine.callbacks->process_text = callback->process_text;
213 g_dynamic_engine.callbacks->process_list_event = callback->process_list_event;
214 g_dynamic_engine.callbacks->process_haptic_event = callback->process_haptic_event;
216 g_dynamic_engine.callbacks->private_data_set = NULL;
217 g_dynamic_engine.callbacks->private_data_request = NULL;
218 g_dynamic_engine.callbacks->nlu_base_info_request = NULL;
219 g_dynamic_engine.callbacks->specific_engine_request = NULL;
221 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Valid Engine");
222 SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", g_dynamic_engine.engine_uuid);
223 SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", g_dynamic_engine.engine_name);
224 SLOG(LOG_DEBUG, TAG_VCD, "Engine setting : %s", g_dynamic_engine.engine_setting_path);
225 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
230 int vcd_engine_agent_load_current_engine(vce_request_callback_s* callback)
232 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine START");
234 if (false == g_agent_init) {
235 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
236 return VCD_ERROR_OPERATION_FAILED;
239 if (true == g_dynamic_engine.is_loaded) {
240 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Engine has already been loaded");
244 if (NULL == callback) {
245 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine");
246 return VCD_ERROR_ENGINE_NOT_FOUND;
249 /* Get current engine info */
250 int ret = __internal_get_engine_info(callback);
252 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info");
256 /* Check all engine functions */
257 if (NULL == g_dynamic_engine.callbacks->get_info ||
258 NULL == g_dynamic_engine.callbacks->get_recording_format ||
259 NULL == g_dynamic_engine.callbacks->foreach_langs ||
260 NULL == g_dynamic_engine.callbacks->is_lang_supported ||
261 NULL == g_dynamic_engine.callbacks->initialize ||
262 NULL == g_dynamic_engine.callbacks->deinitialize ||
263 NULL == g_dynamic_engine.callbacks->set_language ||
264 NULL == g_dynamic_engine.callbacks->set_commands ||
265 NULL == g_dynamic_engine.callbacks->unset_commands ||
266 NULL == g_dynamic_engine.callbacks->start ||
267 NULL == g_dynamic_engine.callbacks->set_recording ||
268 NULL == g_dynamic_engine.callbacks->stop ||
269 NULL == g_dynamic_engine.callbacks->cancel ||
270 NULL == g_dynamic_engine.callbacks->set_audio_type ||
271 NULL == g_dynamic_engine.callbacks->set_server_dialog ||
272 NULL == g_dynamic_engine.callbacks->set_domain ||
273 NULL == g_dynamic_engine.callbacks->process_text ||
274 NULL == g_dynamic_engine.callbacks->process_list_event ||
275 NULL == g_dynamic_engine.callbacks->process_haptic_event) {
276 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid");
277 return VCD_ERROR_ENGINE_NOT_FOUND;
280 /* initialize engine */
281 ret = g_dynamic_engine.callbacks->initialize();
283 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc engine service");
287 /* set the supported language */
288 if (true == g_dynamic_engine.callbacks->is_lang_supported(g_default_lang)) {
289 ret = g_dynamic_engine.callbacks->set_language(g_default_lang);
291 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set the supported language");
295 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded!!!", g_dynamic_engine.engine_name);
296 g_dynamic_engine.is_loaded = true;
298 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang);
299 g_dynamic_engine.is_loaded = false;
300 return VCD_ERROR_OPERATION_FAILED;
303 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine FINISH");
308 int vcd_engine_agent_unload_current_engine()
310 if (false == g_agent_init) {
311 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
312 return VCD_ERROR_OPERATION_FAILED;
315 if (false == g_dynamic_engine.is_loaded) {
316 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been unloaded");
317 return VCD_ERROR_NONE;
320 /* shut down engine */
322 ret = g_dynamic_engine.callbacks->deinitialize();
324 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize");
327 /* reset current engine data */
328 g_dynamic_engine.is_loaded = false;
335 * VCS Engine Interfaces for client
338 int vcd_engine_set_commands()
340 if (false == g_agent_init) {
341 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
342 return VCD_ERROR_OPERATION_FAILED;
347 if (true == g_dynamic_engine.is_loaded) {
348 /* Set dynamic command */
349 ret = g_dynamic_engine.callbacks->set_commands((vce_cmd_h)0);
351 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent ERROR] Fail to set command of dynamic engine : error(%d)", ret);
352 g_dynamic_engine.is_command_ready = false;
354 g_dynamic_engine.is_command_ready = true;
357 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] set command");
359 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Dynamic engine is not available");
365 int vcd_engine_recognize_start(bool silence)
367 if (false == g_agent_init) {
368 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
369 return VCD_ERROR_OPERATION_FAILED;
373 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] silence is %s", silence ? "true" : "false");
375 if (true == g_dynamic_engine.is_loaded && true == g_dynamic_engine.is_command_ready) {
376 ret = g_dynamic_engine.callbacks->start(silence);
378 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to start engine error(%d)", ret);
379 return VCD_ERROR_OPERATION_FAILED;
382 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine is not available (Cannot start)");
383 return VCD_ERROR_OPERATION_FAILED;
386 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine start");
390 int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech_detect_e* speech_detected)
392 if (false == g_agent_init) {
393 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
394 return VCD_ERROR_OPERATION_FAILED;
398 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
399 return VCD_ERROR_INVALID_PARAMETER;
404 if (true == g_dynamic_engine.is_loaded) {
405 ret = g_dynamic_engine.callbacks->set_recording(data, length, speech_detected);
407 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set recording dynamic engine error(%d)", ret);
408 if (VCE_ERROR_OUT_OF_NETWORK == ret) {
409 return VCD_ERROR_TIMED_OUT;
411 return VCD_ERROR_OPERATION_FAILED;
418 int vcd_engine_recognize_stop()
420 if (false == g_agent_init) {
421 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
422 return VCD_ERROR_OPERATION_FAILED;
425 if (true == g_dynamic_engine.is_loaded) {
427 ret = g_dynamic_engine.callbacks->stop();
429 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to stop dynamic engine error(%d)", ret);
430 return VCD_ERROR_OPERATION_FAILED;
433 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Dynamic engine is not recording state");
434 return VCD_ERROR_OPERATION_FAILED;
440 int vcd_engine_recognize_cancel()
442 if (false == g_agent_init) {
443 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
444 return VCD_ERROR_OPERATION_FAILED;
448 if (true == g_dynamic_engine.is_loaded) {
449 ret = g_dynamic_engine.callbacks->cancel();
451 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to cancel dynamic engine error(%d)", ret);
452 return VCD_ERROR_OPERATION_FAILED;
459 int vcd_engine_set_audio_type(const char* audio)
461 if (false == g_agent_init) {
462 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
463 return VCD_ERROR_OPERATION_FAILED;
467 if (true == g_dynamic_engine.is_loaded) {
468 ret = g_dynamic_engine.callbacks->set_audio_type(audio);
470 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set audio type(%d)", ret);
471 return VCD_ERROR_OPERATION_FAILED;
478 int vcd_engine_set_server_dialog(const char* app_id, const char* credential)
480 if (false == g_agent_init) {
481 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
482 return VCD_ERROR_OPERATION_FAILED;
486 if (true == g_dynamic_engine.is_loaded) {
487 ret = g_dynamic_engine.callbacks->set_server_dialog(app_id, credential);
489 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set server dialog (%d)", ret);
497 int vcd_engine_set_domain(int pid, const char* domain)
499 if (false == g_agent_init) {
500 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
501 return VCD_ERROR_OPERATION_FAILED;
505 if (true == g_dynamic_engine.is_loaded) {
506 ret = g_dynamic_engine.callbacks->set_domain(domain);
508 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set domain (%d)", ret);
509 return VCD_ERROR_OPERATION_FAILED;
516 int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value)
519 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
520 return VCD_ERROR_INVALID_PARAMETER;
523 if (false == g_agent_init) {
524 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
525 return VCD_ERROR_OPERATION_FAILED;
529 if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->nlu_base_info_request) {
530 ret = g_dynamic_engine.callbacks->nlu_base_info_request(key, value);
532 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get nlu base info (%d)", ret);
533 return VCD_ERROR_OPERATION_FAILED;
536 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no nlu_base_info_request callback");
537 return VCD_ERROR_OPERATION_FAILED;
543 int vcd_engine_set_private_data(int pid, const char* key, const char* data)
545 if (false == g_agent_init) {
546 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
547 return VCD_ERROR_OPERATION_FAILED;
551 if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_set) {
552 ret = g_dynamic_engine.callbacks->private_data_set(key, data);
554 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set private data (%d)", ret);
555 return VCD_ERROR_OPERATION_FAILED;
558 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_set callback");
559 return VCD_ERROR_OPERATION_FAILED;
565 int vcd_engine_get_private_data(int pid, const char* key, char** data)
568 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
569 return VCD_ERROR_INVALID_PARAMETER;
572 if (false == g_agent_init) {
573 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
574 return VCD_ERROR_OPERATION_FAILED;
578 if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_request) {
579 ret = g_dynamic_engine.callbacks->private_data_request(key, data);
581 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get private data (%d)", ret);
582 return VCD_ERROR_OPERATION_FAILED;
585 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_request callback");
586 return VCD_ERROR_OPERATION_FAILED;
592 int vcd_engine_send_specific_engine_request(const char* engine_app_id, const char* event, const char* request)
594 if (false == g_agent_init) {
595 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
596 return VCD_ERROR_OPERATION_FAILED;
600 if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->specific_engine_request) {
601 ret = g_dynamic_engine.callbacks->specific_engine_request(engine_app_id, event, request);
603 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set specific engine request (%d)", ret);
604 return VCD_ERROR_OPERATION_FAILED;
607 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no specific_engine_request callback");
608 return VCD_ERROR_OPERATION_FAILED;
614 int vcd_engine_process_text(int pid, const char* text)
616 if (false == g_agent_init) {
617 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
618 return VCD_ERROR_OPERATION_FAILED;
622 if (true == g_dynamic_engine.is_loaded) {
623 ret = g_dynamic_engine.callbacks->process_text(text);
625 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process text (%d)", ret);
626 return VCD_ERROR_OPERATION_FAILED;
633 int vcd_engine_process_list_event(int pid, const char* event)
635 if (false == g_agent_init) {
636 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
637 return VCD_ERROR_OPERATION_FAILED;
641 if (true == g_dynamic_engine.is_loaded) {
642 ret = g_dynamic_engine.callbacks->process_list_event(event);
644 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process list event (%d)", ret);
645 return VCD_ERROR_OPERATION_FAILED;
652 int vcd_engine_process_haptic_event(int pid, const char* event)
654 if (false == g_agent_init) {
655 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
656 return VCD_ERROR_OPERATION_FAILED;
660 if (true == g_dynamic_engine.is_loaded) {
661 ret = g_dynamic_engine.callbacks->process_haptic_event(event);
663 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process haptic event (%d)", ret);
664 return VCD_ERROR_OPERATION_FAILED;
672 * VCS Engine Interfaces for client and setting
675 int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels)
677 if (false == g_agent_init) {
678 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
679 return VCD_ERROR_OPERATION_FAILED;
682 if (true != g_dynamic_engine.is_loaded) {
683 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded");
686 int ret = g_dynamic_engine.callbacks->get_recording_format(audio_id, types, rate, channels);
688 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get recording format(%d)", ret);
689 return VCD_ERROR_OPERATION_FAILED;
695 bool __supported_language_cb(const char* language, void* user_data)
697 GList** lang_list = (GList**)user_data;
699 if (NULL == language || NULL == lang_list) {
700 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL in callback!!!!");
704 SLOG(LOG_DEBUG, TAG_VCD, "-- Language(%s)", language);
706 char* temp_lang = g_strdup(language);
708 *lang_list = g_list_append(*lang_list, temp_lang);
713 int vcd_engine_supported_langs(GList** lang_list)
715 if (false == g_agent_init) {
716 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
717 return VCD_ERROR_OPERATION_FAILED;
720 if (true != g_dynamic_engine.is_loaded) {
721 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded");
724 int ret = g_dynamic_engine.callbacks->foreach_langs(__supported_language_cb, (void*)lang_list);
726 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get language list error(%d)", ret);
727 return VCD_ERROR_OPERATION_FAILED;
734 int vcd_engine_get_current_language(char** lang)
736 if (false == g_agent_init) {
737 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
738 return VCD_ERROR_OPERATION_FAILED;
742 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
743 return VCD_ERROR_INVALID_PARAMETER;
746 /* get default language */
747 *lang = g_strdup(g_default_lang);
752 int vcd_engine_set_current_language(const char* language)
754 if (false == g_agent_init) {
755 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
756 return VCD_ERROR_OPERATION_FAILED;
759 if (NULL == language) {
760 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
761 return VCD_ERROR_INVALID_PARAMETER;
766 if (true == g_dynamic_engine.is_loaded) {
767 g_dynamic_engine.is_command_ready = false;
769 ret = g_dynamic_engine.callbacks->set_language(language);
771 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Fail to set language of dynamic engine error(%d, %s)", ret, language);
774 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Dynamic engine is not available (Cannot start)");
780 int vcd_engine_agent_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
782 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine");
783 return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data);
786 int vcd_engine_agent_get_command_count(vce_cmd_h vce_command, int* count)
788 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine");
790 *count = vcd_client_get_length();
794 int vcd_engine_agent_get_audio_type(char** audio_type)
796 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type");
798 return vcd_recorder_get(audio_type);
801 int vcd_engine_agent_set_private_data(const char* key, const char* data)
803 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data, key(%s), data(%s)", key, data);
804 vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data);
806 return VCD_ERROR_NONE;
809 int vcd_engine_agent_get_private_data(const char* key, char** data)
811 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data, key(%s)", key);
812 vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data);
814 return VCD_ERROR_NONE;
817 int vcd_engine_agent_start_recording()
819 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording");
821 int ret = vcd_recorder_start();
823 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
824 vcd_engine_recognize_cancel();
825 /* Send error cb to manager */
826 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
830 return VCD_ERROR_NONE;
833 int vcd_engine_agent_stop_recording()
835 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording");
837 return vcd_recorder_stop();
840 int vcd_engine_agent_set_private_data_set_cb(vce_private_data_set_cb callback_func)
842 if (false == g_agent_init) {
843 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
844 return VCD_ERROR_OPERATION_FAILED;
847 if (false == g_dynamic_engine.is_loaded) {
848 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine");
849 return VCD_ERROR_OPERATION_FAILED;
852 g_dynamic_engine.callbacks->private_data_set = callback_func;
854 return VCD_ERROR_NONE;
857 int vcd_engine_agent_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
859 if (false == g_agent_init) {
860 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
861 return VCD_ERROR_OPERATION_FAILED;
864 if (false == g_dynamic_engine.is_loaded) {
865 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine");
866 return VCD_ERROR_OPERATION_FAILED;
869 g_dynamic_engine.callbacks->private_data_request = callback_func;
871 return VCD_ERROR_NONE;
874 int vcd_engine_agent_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
876 if (false == g_agent_init) {
877 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
878 return VCD_ERROR_OPERATION_FAILED;
881 if (false == g_dynamic_engine.is_loaded) {
882 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine");
883 return VCD_ERROR_OPERATION_FAILED;
886 g_dynamic_engine.callbacks->nlu_base_info_request = callback_func;
888 return VCD_ERROR_NONE;
891 int vcd_engine_agent_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
893 if (false == g_agent_init) {
894 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
895 return VCD_ERROR_OPERATION_FAILED;
898 if (false == g_dynamic_engine.is_loaded) {
899 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine");
900 return VCD_ERROR_OPERATION_FAILED;
903 g_dynamic_engine.callbacks->specific_engine_request = callback_func;
905 return VCD_ERROR_NONE;