Merge "Add new property in command handle" into tizen
[platform/core/uifw/voice-control.git] / server / vcd_engine_agent.c
1 /*
2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
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
18 #include <dlfcn.h>
19 #include <dirent.h>
20
21 #include "vcd_client_data.h"
22 #include "vcd_config.h"
23 #include "vcd_engine_agent.h"
24 #include "vcd_main.h"
25 #include "vcd_recorder.h"
26 #include "vcd_dbus.h"
27
28 /*
29 * Internal data structure
30 */
31 typedef struct {
32         /* engine info */
33         char*   engine_uuid;
34         char*   engine_name;
35         char*   engine_path;
36
37         /* engine load info */
38         bool    is_set;
39         bool    is_loaded;
40         bool    is_command_ready;
41         void    *handle;
42
43         vcpe_funcs_s*   pefuncs;
44         vcpd_funcs_s*   pdfuncs;
45
46         int (*vcp_load_engine)(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs);
47         int (*vcp_unload_engine)();
48 } vcengine_s;
49
50 typedef struct _vcengine_info {
51         char*   engine_uuid;
52         char*   engine_path;
53         char*   engine_name;
54 } vcengine_info_s;
55
56
57 /*
58 * static data
59 */
60
61 /** vc engine agent init */
62 static bool g_agent_init;
63
64 /** vc engine list */
65 static GList *g_engine_list;
66
67 /** current engine information */
68 static vcengine_s g_dynamic_engine;
69
70 static char* g_default_lang;
71
72 /** callback functions */
73 static result_callback g_result_cb = NULL;
74
75 static asr_result_callback g_asr_result_cb = NULL;
76 static nlg_result_callback g_nlg_result_cb = NULL;
77
78 #if 0
79 static pre_result_callback g_pre_result_cb = NULL;
80
81 static nlu_result_callback g_nlu_result_cb = NULL;
82 #endif
83
84 static error_callback g_error_cb = NULL;
85
86 bool __supported_language_cb(const char* language, void* user_data);
87
88 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data);
89
90 bool __engine_setting_cb(const char* key, const char* value, void* user_data);
91
92 /** Free voice list */
93 void __free_language_list(GList* lang_list);
94
95
96 /*
97 * Internal Interfaces
98 */
99
100 /** check engine id */
101 int __internal_check_engine_id(const char* engine_uuid);
102
103 /** update engine list */
104 int __internal_update_engine_list();
105
106 /** get engine info */
107 int __internal_get_engine_info(const char* filepath, vcengine_info_s** info);
108
109 int __log_enginelist();
110
111 /*
112 * VCS Engine Agent Interfaces
113 */
114 //int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb)
115 int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb)
116 {
117         if (/*NULL == pre_result_cb*/ NULL == asr_result_cb || NULL == result_cb /*|| NULL == nlu_result_cb*/ || NULL == error_cb) {
118                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL");
119                 return VCD_ERROR_OPERATION_FAILED;
120         }
121
122         /* init dynamic engine */
123         g_dynamic_engine.engine_uuid = NULL;
124         g_dynamic_engine.engine_name = NULL;
125         g_dynamic_engine.engine_path = NULL;
126
127         g_dynamic_engine.is_set = false;
128         g_dynamic_engine.is_loaded = false;
129         g_dynamic_engine.handle = NULL;
130         g_dynamic_engine.is_command_ready = false;
131         g_dynamic_engine.pefuncs = (vcpe_funcs_s*)calloc(1, sizeof(vcpe_funcs_s));
132         g_dynamic_engine.pdfuncs = (vcpd_funcs_s*)calloc(1, sizeof(vcpd_funcs_s));
133
134         g_agent_init = true;
135
136         //g_pre_result_cb = pre_result_cb;
137         g_asr_result_cb = asr_result_cb;
138         g_nlg_result_cb = nlg_result_cb;
139         g_result_cb = result_cb;
140         //g_nlu_result_cb = nlu_result_cb;
141         g_error_cb = error_cb;
142
143         if (0 != vcd_config_get_default_language(&g_default_lang)) {
144                 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] There is No default voice in config");
145                 /* Set default voice */
146                 g_default_lang = strdup(VC_BASE_LANGUAGE);
147         }
148
149         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent Initialize");
150
151         return 0;
152 }
153
154 int vcd_engine_agent_release()
155 {
156         if (false == g_agent_init) {
157                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
158                 return VCD_ERROR_OPERATION_FAILED;
159         }
160
161         /* unload current engine */
162         vcd_engine_agent_unload_current_engine();
163
164         /* release engine list */
165         GList *iter = NULL;
166         vcengine_s *data = NULL;
167
168         if (g_list_length(g_engine_list) > 0) {
169                 /* Get a first item */
170                 iter = g_list_first(g_engine_list);
171
172                 while (NULL != iter) {
173                         /* Get handle data from list */
174                         data = iter->data;
175                         iter = g_list_remove(iter, data);
176
177                         if (NULL != data) {
178                                 if (NULL != data->engine_uuid) {
179                                         g_free(data->engine_uuid);
180                                         data->engine_uuid = NULL;
181                                 }
182                                 if (NULL != data->engine_name) {
183                                         g_free(data->engine_name);
184                                         data->engine_name = NULL;
185                                 }
186                                 if (NULL != data->engine_path) {
187                                         g_free(data->engine_path);
188                                         data->engine_path = NULL;
189                                 }
190
191                                 free(data);
192                                 data = NULL;
193                         }
194                 }
195         }
196
197         g_list_free(iter);
198         g_engine_list = NULL;
199
200         /* release current engine data */
201         if (NULL != g_dynamic_engine.pefuncs) {
202                 free(g_dynamic_engine.pefuncs);
203                 g_dynamic_engine.pefuncs = NULL;
204         }
205         if (NULL != g_dynamic_engine.pdfuncs) {
206                 free(g_dynamic_engine.pdfuncs);
207                 g_dynamic_engine.pdfuncs = NULL;
208         }
209
210         g_agent_init = false;
211
212         //g_pre_result_cb = NULL;
213         g_asr_result_cb = NULL;
214         g_nlg_result_cb = NULL;
215         g_result_cb = NULL;
216         //g_nlu_result_cb = NULL;
217         g_error_cb = NULL;
218
219         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent release");
220
221         return 0;
222 }
223
224 bool vcd_engine_is_available_engine()
225 {
226         if (true == g_dynamic_engine.is_loaded)
227                 return true;
228
229         return false;
230 }
231
232 int vcd_engine_agent_initialize_current_engine()
233 {
234         /* check agent init */
235         if (false == g_agent_init) {
236                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
237                 return VCD_ERROR_OPERATION_FAILED;
238         }
239
240         /* update engine list */
241         if (0 != __internal_update_engine_list()) {
242                 SLOG(LOG_ERROR, TAG_VCD, "[engine agent] vcd_engine_agent_init : __internal_update_engine_list : no engine error");
243                 return VCD_ERROR_ENGINE_NOT_FOUND;
244         }
245
246         /* check whether engine id is valid or not.*/
247         GList *iter = NULL;
248         vcengine_info_s *dynamic_engine = NULL;
249
250         if (g_list_length(g_engine_list) > 0) {
251                 /*Get a first item*/
252                 iter = g_list_first(g_engine_list);
253
254                 while (NULL != iter) {
255                         /*Get handle data from list*/
256                         dynamic_engine = iter->data;
257                         if (NULL != dynamic_engine) {
258                                 break;
259                         }
260
261                         /*Get next item*/
262                         iter = g_list_next(iter);
263                 }
264         } else {
265                 return VCD_ERROR_ENGINE_NOT_FOUND;
266         }
267
268         if (NULL == dynamic_engine) {
269                 return VCD_ERROR_ENGINE_NOT_FOUND;
270         } else {
271                 if (NULL != g_dynamic_engine.engine_uuid) {
272                         /* set data from g_engine_list */
273                         if (g_dynamic_engine.engine_uuid != NULL)       g_free(g_dynamic_engine.engine_uuid);
274                         if (g_dynamic_engine.engine_name != NULL)       g_free(g_dynamic_engine.engine_name);
275                         if (g_dynamic_engine.engine_path != NULL)       g_free(g_dynamic_engine.engine_path);
276                 }
277
278                 g_dynamic_engine.engine_uuid = g_strdup(dynamic_engine->engine_uuid);
279                 g_dynamic_engine.engine_name = g_strdup(dynamic_engine->engine_name);
280                 g_dynamic_engine.engine_path = g_strdup(dynamic_engine->engine_path);
281
282                 g_dynamic_engine.handle = NULL;
283                 g_dynamic_engine.is_loaded = false;
284                 g_dynamic_engine.is_set = true;
285
286                 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
287                 SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine uuid : %s", g_dynamic_engine.engine_uuid);
288                 SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine name : %s", g_dynamic_engine.engine_name);
289                 SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine path : %s", g_dynamic_engine.engine_path);
290                 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
291
292         }
293
294         return 0;
295 }
296
297 int __internal_check_engine_id(const char* engine_uuid)
298 {
299         if (NULL == engine_uuid) {
300                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
301                 return VCD_ERROR_INVALID_PARAMETER;
302         }
303
304         GList *iter = NULL;
305         vcengine_s *data = NULL;
306
307         if (0 < g_list_length(g_engine_list)) {
308                 /*Get a first item*/
309                 iter = g_list_first(g_engine_list);
310
311                 while (NULL != iter) {
312                         data = iter->data;
313
314                         if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) {
315                                 return 0;
316                         }
317
318                         iter = g_list_next(iter);
319                 }
320         }
321
322         return -1;
323 }
324
325 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data)
326 {
327         vcengine_info_s* temp = (vcengine_info_s*)user_data;
328
329         temp->engine_uuid = g_strdup(engine_uuid);
330         temp->engine_name = g_strdup(engine_name);
331 }
332
333
334 int __internal_get_engine_info(const char* filepath, vcengine_info_s** info)
335 {
336         if (NULL == filepath || NULL == info) {
337                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
338                 return VCD_ERROR_INVALID_PARAMETER;
339         }
340
341         /* load engine */
342         char *error;
343         void* handle;
344
345         handle = dlopen(filepath, RTLD_LAZY);
346         if (!handle) {
347                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine : %s", filepath);
348                 if ((error = dlerror()) != NULL) {
349                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] %s", error);
350                 }
351                 return -1;
352         }
353
354         /* link engine to daemon */
355         dlsym(handle, "vcp_load_engine");
356         if ((error = dlerror()) != NULL) {
357                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_load_engine : %s", filepath);
358                 dlclose(handle);
359                 return -1;
360         }
361
362         dlsym(handle, "vcp_unload_engine");
363         if ((error = dlerror()) != NULL) {
364                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_unload_engine : %s", filepath);
365                 dlclose(handle);
366                 return -1;
367         }
368
369         int (*get_engine_info)(vcpe_engine_info_cb callback, void* user_data);
370
371         get_engine_info = (int (*)(vcpe_engine_info_cb, void*))dlsym(handle, "vcp_get_engine_info");
372         if (NULL != (error = dlerror()) || NULL == get_engine_info) {
373                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Invalid engine. Fail to open vcp_get_engine_info : %s", filepath);
374                 dlclose(handle);
375                 return -1;
376         }
377
378         vcengine_info_s* temp;
379         temp = (vcengine_info_s*)calloc(1, sizeof(vcengine_info_s));
380         if (NULL == temp) {
381                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
382                 dlclose(handle);
383                 return VCD_ERROR_OUT_OF_MEMORY;
384         }
385
386         /* get engine info */
387         if (0 != get_engine_info(__engine_info_cb, (void*)temp)) {
388                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info from engine");
389                 dlclose(handle);
390                 free(temp);
391                 return -1;
392         }
393
394         /* close engine */
395         dlclose(handle);
396
397         temp->engine_path = g_strdup(filepath);
398
399         SLOG(LOG_DEBUG, TAG_VCD, "@@@ Valid Engine");
400         SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", temp->engine_uuid);
401         SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", temp->engine_name);
402         SLOG(LOG_DEBUG, TAG_VCD, "Engine path : %s", temp->engine_path);
403         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
404
405         *info = temp;
406
407         return 0;
408 }
409
410 int __internal_update_engine_list()
411 {
412         /* relsease engine list */
413         GList *iter = NULL;
414         vcengine_info_s *data = NULL;
415
416         if (0 < g_list_length(g_engine_list)) {
417                 /* Get a first item */
418                 iter = g_list_first(g_engine_list);
419
420                 while (NULL != iter) {
421                         /* Get handle data from list */
422                         data = iter->data;
423
424                         if (NULL != data) {
425                                 if (NULL != data->engine_uuid)          g_free(data->engine_uuid);
426                                 if (NULL != data->engine_path)          g_free(data->engine_path);
427                                 if (NULL != data->engine_name)          g_free(data->engine_name);
428
429                                 data->engine_uuid = NULL;
430                                 data->engine_path = NULL;
431                                 data->engine_name = NULL;
432
433                                 free(data);
434                         }
435
436                         g_engine_list = g_list_remove_link(g_engine_list, iter);
437                         iter = g_list_first(g_engine_list);
438                 }
439         }
440
441         /* Get file name from default engine directory */
442         DIR *dp = NULL;
443         struct dirent *dirp = NULL;
444
445         dp  = opendir(VC_DEFAULT_ENGINE);
446         if (NULL != dp) {
447                 do {
448                         dirp = readdir(dp);
449
450                         if (NULL != dirp) {
451                                 if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
452                                         continue;
453
454                                 vcengine_info_s* info = NULL;
455                                 char* filepath = NULL;
456                                 int filesize = 0;
457
458                                 filesize = strlen(VC_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
459                                 filepath = (char*)calloc(filesize, sizeof(char));
460
461                                 if (NULL != filepath) {
462                                         snprintf(filepath, filesize, "%s/%s", VC_DEFAULT_ENGINE, dirp->d_name);
463                                 } else {
464                                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Memory not enough!!");
465                                         continue;
466                                 }
467
468                                 /* get its info and update engine list */
469                                 if (0 == __internal_get_engine_info(filepath, &info)) {
470                                         /* add engine info to g_engine_list */
471                                         g_engine_list = g_list_append(g_engine_list, info);
472                                 }
473
474                                 if (NULL != filepath) {
475                                         free(filepath);
476                                         filepath = NULL;
477                                 }
478                         }
479                 } while (NULL != dirp);
480
481                 closedir(dp);
482         } else {
483                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Fail to open default directory");
484         }
485
486         if (0 >= g_list_length(g_engine_list)) {
487                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] No Engine");
488                 return VCD_ERROR_ENGINE_NOT_FOUND;
489         }
490
491         __log_enginelist();
492
493         return 0;
494 }
495
496
497 int __foreach_command(vcp_cmd_h vc_command, vcpd_foreach_command_cb callback, void* user_data)
498 {
499         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine");
500         return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data);
501 }
502
503 int __command_get_length(vcp_cmd_h vc_command)
504 {
505         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine");
506         return vcd_client_get_length();
507 }
508
509 int __get_audio_type(char** audio_type)
510 {
511         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type");
512
513         return vcd_recorder_get(audio_type);
514 }
515
516 int __set_private_data(const char* key, const char* data)
517 {
518         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data");
519         vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data);
520
521         return 0;
522 }
523
524 int __get_private_data(const char* key, char** data)
525 {
526         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data");
527         vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data);
528
529         return 0;
530 }
531
532 int __start_recording()
533 {
534         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording");
535
536         int ret = vcd_recorder_start();
537         if (0 != ret) {
538                 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
539                 vcd_engine_recognize_cancel();
540                 /* Send error cb to manager */
541                 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
542                 return ret;
543         }
544
545         return 0;
546 }
547
548 int __stop_recording()
549 {
550         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording");
551
552         return vcd_recorder_stop();
553 }
554
555 void __result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed, const char* nlu_result, const char* msg, void *user_data)
556 {
557         SLOG(LOG_DEBUG, TAG_VCD, "[Engine agent] Event(%d), Count(%d) Text(%s) Nonfixed(%s) NLU result(%s) Msg(%s)", event, count, all_result, non_fixed, nlu_result, msg);
558
559         if (NULL != g_result_cb) {
560                 g_result_cb(event, result_id, count, all_result, non_fixed, nlu_result, msg, user_data);
561         } else {
562                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Result callback function is NOT valid");
563         }
564
565         return;
566 }
567
568 void __asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void *user_data)
569 {
570         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] ASR result -  Event(%d), Result(%s)", event, asr_result);
571
572         if (NULL != g_asr_result_cb) {
573                 g_asr_result_cb(event, asr_result, user_data);
574         } else {
575                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] ASR result callback function is NOT valid");
576         }
577
578         return;
579 }
580
581 void __nlg_result_cb(const char* nlg_result, void *user_data)
582 {
583         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] NLG result -  Result(%s)", nlg_result);
584
585         if (NULL != g_nlg_result_cb) {
586                 g_nlg_result_cb(nlg_result, user_data);
587         } else {
588                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] NLG result callback function is NOT valid");
589         }
590
591         return;
592 }
593
594 void __error_cb(vcp_error_e error, const char* msg, void *user_data)
595 {
596         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] ERROR(%d)", error);
597
598         if (NULL != g_error_cb) {
599                 g_error_cb(error, msg, user_data);
600         } else {
601                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Error callback function is NOT vaild");
602         }
603
604         return;
605 }
606
607 int __load_engine(vcengine_s* engine)
608 {
609         /* check whether current engine is loaded or not */
610         if (true == engine->is_loaded) {
611                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been loaded ");
612                 return 0;
613         }
614
615         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Current engine path : %s", engine->engine_path);
616
617         /* open engine */
618         char *error;
619         engine->handle = dlopen(engine->engine_path, RTLD_LAZY);
620
621         if ((error = dlerror()) != NULL || !engine->handle) {
622                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine handle");
623                 return VCD_ERROR_OPERATION_FAILED;
624         }
625
626         engine->vcp_unload_engine = (int (*)())dlsym(engine->handle, "vcp_unload_engine");
627         if ((error = dlerror()) != NULL) {
628                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_unload_engine()");
629                 dlclose(engine->handle);
630                 return VCD_ERROR_OPERATION_FAILED;
631         }
632
633         engine->vcp_load_engine = (int (*)(vcpd_funcs_s*, vcpe_funcs_s*))dlsym(engine->handle, "vcp_load_engine");
634         if (NULL != (error = dlerror()) || NULL == engine->vcp_load_engine) {
635                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_load_engine()");
636                 dlclose(engine->handle);
637                 return VCD_ERROR_OPERATION_FAILED;
638         }
639
640         /* load engine */
641         engine->pdfuncs->version = 1;
642         engine->pdfuncs->size = sizeof(vcpd_funcs_s);
643
644         engine->pdfuncs->foreach_command = __foreach_command;
645         engine->pdfuncs->get_command_count = __command_get_length;
646         engine->pdfuncs->get_audio_type = __get_audio_type;
647
648         engine->pdfuncs->set_private_data = __set_private_data;
649         engine->pdfuncs->get_private_data = __get_private_data;
650
651         engine->pdfuncs->start_recording = __start_recording;
652         engine->pdfuncs->stop_recording = __stop_recording;
653
654         if (0 != engine->vcp_load_engine(engine->pdfuncs, engine->pefuncs)) {
655                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail vcp_load_engine()");
656                 dlclose(engine->handle);
657                 return VCD_ERROR_OPERATION_FAILED;
658         }
659
660         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] engine info : version(%d), size(%d)(%d)", engine->pefuncs->version, engine->pefuncs->size, sizeof(vcpe_funcs_s));
661
662         /* engine error check */
663         if (engine->pefuncs->size != sizeof(vcpe_funcs_s)) {
664                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not valid");
665                 return VCD_ERROR_OPERATION_FAILED;
666         }
667
668         /* Check all engine functions */
669         if (NULL == engine->pefuncs->initialize ||
670                 NULL == engine->pefuncs->deinitialize ||
671                 NULL == engine->pefuncs->get_recording_format ||
672                 NULL == engine->pefuncs->foreach_langs ||
673                 NULL == engine->pefuncs->is_lang_supported ||
674                 NULL == engine->pefuncs->set_result_cb ||
675                 NULL == engine->pefuncs->set_language ||
676                 NULL == engine->pefuncs->set_commands ||
677                 NULL == engine->pefuncs->unset_commands ||
678                 NULL == engine->pefuncs->start ||
679                 NULL == engine->pefuncs->set_recording ||
680                 NULL == engine->pefuncs->stop ||
681                 NULL == engine->pefuncs->cancel ||
682                 NULL == engine->pefuncs->set_audio_type ||
683                 NULL == engine->pefuncs->set_asr_result_cb ||
684                 NULL == engine->pefuncs->set_nlg_result_cb ||
685                 //NULL == engine->pefuncs->set_pre_result_cb ||
686                 NULL == engine->pefuncs->set_error_cb ||
687                 NULL == engine->pefuncs->set_domain ||
688                 NULL == engine->pefuncs->get_nlu_base_info ||
689                 //NULL == engine->pefuncs->set_nlu_result_cb ||
690                 NULL == engine->pefuncs->set_private_data ||
691                 NULL == engine->pefuncs->get_private_data ||
692                 NULL == engine->pefuncs->process_text ||
693                 NULL == engine->pefuncs->process_list_event ||
694                 NULL == engine->pefuncs->process_haptic_event) {
695                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid");
696                 return VCD_ERROR_OPERATION_FAILED;
697         }
698
699         /* initalize engine */
700         if (0 != engine->pefuncs->initialize()) {
701                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc-engine");
702                 return VCD_ERROR_OPERATION_FAILED;
703         }
704
705         if (0 != engine->pefuncs->set_result_cb(__result_cb, NULL)) {
706                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set result callback of vc-engine");
707                 return VCD_ERROR_OPERATION_FAILED;
708         }
709
710         if (0 != engine->pefuncs->set_asr_result_cb(__asr_result_cb, NULL)) {
711                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set asr result callback of vc-engine");
712                 return VCD_ERROR_OPERATION_FAILED;
713         }
714
715         if (0 != engine->pefuncs->set_nlg_result_cb(__nlg_result_cb, NULL)) {
716                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set nlg result callback of vc-engine");
717                 return VCD_ERROR_OPERATION_FAILED;
718         }
719
720         if (0 != engine->pefuncs->set_error_cb(__error_cb, NULL)) {
721                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set error callback of vc-engine");
722                 return VCD_ERROR_OPERATION_FAILED;
723         }
724
725         /* load engine */
726         if (true == engine->pefuncs->is_lang_supported(g_default_lang)) {
727                 if (0 != engine->pefuncs->set_language(g_default_lang)) {
728                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load current engine");
729                         return VCD_ERROR_OPERATION_FAILED;
730                 }
731                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded !!!", engine->engine_name);
732                 engine->is_loaded = true;
733         } else {
734                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang);
735                 engine->is_loaded = false;
736         }
737
738         return 0;
739 }
740
741 int vcd_engine_agent_load_current_engine()
742 {
743         if (false == g_agent_init) {
744                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
745                 return VCD_ERROR_OPERATION_FAILED;
746         }
747
748         if (true == g_dynamic_engine.is_set) {
749                 if (0 != __load_engine(&g_dynamic_engine)) {
750                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load dynamic engine");
751
752                         /* need to initialize dynamic engine data */
753                         g_dynamic_engine.is_loaded = false;
754                 } else {
755                         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Load dynamic engine");
756                 }
757         }
758
759         return 0;
760 }
761
762 int vcd_engine_agent_unload_current_engine()
763 {
764         if (false == g_agent_init) {
765                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized ");
766                 return VCD_ERROR_OPERATION_FAILED;
767         }
768
769         if (true == g_dynamic_engine.is_set) {
770                 /* unload dynamic engine */
771                 if (true == g_dynamic_engine.is_loaded) {
772                         /* shutdown engine */
773                         g_dynamic_engine.pefuncs->deinitialize();
774                         g_dynamic_engine.vcp_unload_engine();
775                         dlclose(g_dynamic_engine.handle);
776                         g_dynamic_engine.handle = NULL;
777                         g_dynamic_engine.is_loaded = false;
778                 }
779         }
780         return 0;
781 }
782
783
784 /*
785 * VCS Engine Interfaces for client
786 */
787
788 int vcd_engine_set_commands()
789 {
790         if (false == g_agent_init) {
791                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
792                 return VCD_ERROR_OPERATION_FAILED;
793         }
794
795         int ret = -1;
796
797         if (true == g_dynamic_engine.is_loaded) {
798                 /* Set dynamic command */
799                 ret = g_dynamic_engine.pefuncs->set_commands((vcp_cmd_h)0);
800                 if (0 != ret) {
801                         SLOG(LOG_WARN, TAG_VCD, "[Engine Agent ERROR] Fail to set command of dynamic engine : error(%d)", ret);
802                         g_dynamic_engine.is_command_ready = false;
803                 } else {
804                         g_dynamic_engine.is_command_ready = true;
805                 }
806
807                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] set command");
808         } else {
809                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Dynamic engine is not available");
810         }
811
812         return 0;
813 }
814
815 int vcd_engine_recognize_start(bool silence)
816 {
817         if (false == g_agent_init) {
818                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
819                 return VCD_ERROR_OPERATION_FAILED;
820         }
821
822         int ret = -1;
823         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] silence is %s", silence ? "true" : "false");
824
825         if (true == g_dynamic_engine.is_loaded && true == g_dynamic_engine.is_command_ready) {
826                 ret = g_dynamic_engine.pefuncs->start(silence);
827                 if (0 != ret) {
828                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to start engine error(%d)", ret);
829                         return VCD_ERROR_OPERATION_FAILED;
830                 }
831         } else {
832                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine is not available (Cannot start)");
833                 return VCD_ERROR_OPERATION_FAILED;
834         }
835
836         SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine start");
837         return 0;
838 }
839
840 int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected)
841 {
842         if (false == g_agent_init) {
843                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
844                 return VCD_ERROR_OPERATION_FAILED;
845         }
846
847         if (NULL == data) {
848                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
849                 return VCD_ERROR_INVALID_PARAMETER;
850         }
851
852         int ret = -1;
853
854         if (true == g_dynamic_engine.is_loaded) {
855                 ret = g_dynamic_engine.pefuncs->set_recording(data, length, speech_detected);
856                 if (0 != ret) {
857                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set recording dynamic engine error(%d)", ret);
858                         if (VCP_ERROR_OUT_OF_NETWORK == ret) {
859                                 return VCD_ERROR_TIMED_OUT;
860                         }
861                         return VCD_ERROR_OPERATION_FAILED;
862                 }
863         }
864
865         return 0;
866 }
867
868 int vcd_engine_recognize_stop()
869 {
870         if (false == g_agent_init) {
871                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
872                 return VCD_ERROR_OPERATION_FAILED;
873         }
874
875         if (true == g_dynamic_engine.is_loaded) {
876                 int ret = -1;
877                 ret = g_dynamic_engine.pefuncs->stop();
878                 if (0 != ret) {
879                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to stop dynamic engine error(%d)", ret);
880                         return VCD_ERROR_OPERATION_FAILED;
881                 }
882         } else {
883                 SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Dynamic engine is not recording state");
884                 return VCD_ERROR_OPERATION_FAILED;
885         }
886
887         return 0;
888 }
889
890 int vcd_engine_recognize_cancel()
891 {
892         if (false == g_agent_init) {
893                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
894                 return VCD_ERROR_OPERATION_FAILED;
895         }
896
897         int ret = -1;
898         if (true == g_dynamic_engine.is_loaded) {
899                 ret = g_dynamic_engine.pefuncs->cancel();
900                 if (0 != ret) {
901                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to cancel dynamic engine error(%d)", ret);
902                         return VCD_ERROR_OPERATION_FAILED;
903                 }
904         }
905
906         return 0;
907 }
908
909 int vcd_engine_set_audio_type(const char* audio)
910 {
911         if (false == g_agent_init) {
912                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
913                 return VCD_ERROR_OPERATION_FAILED;
914         }
915
916         int ret = -1;
917         if (true == g_dynamic_engine.is_loaded) {
918                 ret = g_dynamic_engine.pefuncs->set_audio_type(audio);
919                 if (0 != ret) {
920                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set audio type(%d)", ret);
921                         return VCD_ERROR_OPERATION_FAILED;
922                 }
923         }
924
925         return 0;
926 }
927
928 int vcd_engine_set_domain(int pid, const char* domain)
929 {
930         if (false == g_agent_init) {
931                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
932                 return VCD_ERROR_OPERATION_FAILED;
933         }
934
935         int ret = -1;
936         if (true == g_dynamic_engine.is_loaded) {
937                 ret = g_dynamic_engine.pefuncs->set_domain(domain);
938                 if (0 != ret) {
939                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set domain (%d)", ret);
940                         return VCD_ERROR_OPERATION_FAILED;
941                 }
942         }
943
944         return 0;
945 }
946
947 int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value)
948 {
949         if (NULL == value) {
950                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
951                 return VCD_ERROR_INVALID_PARAMETER;
952         }
953
954         if (false == g_agent_init) {
955                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
956                 return VCD_ERROR_OPERATION_FAILED;
957         }
958
959         int ret = -1;
960         if (true == g_dynamic_engine.is_loaded) {
961                 ret = g_dynamic_engine.pefuncs->get_nlu_base_info(key, value);
962                 if (0 != ret) {
963                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get nlu base info (%d)", ret);
964                         return VCD_ERROR_OPERATION_FAILED;
965                 }
966         }
967
968         return 0;
969 }
970
971 int vcd_engine_set_private_data(int pid, const char* key, const char* data)
972 {
973         if (false == g_agent_init) {
974                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
975                 return VCD_ERROR_OPERATION_FAILED;
976         }
977
978         int ret = -1;
979         if (true == g_dynamic_engine.is_loaded) {
980                 ret = g_dynamic_engine.pefuncs->set_private_data(key, data);
981                 if (0 != ret) {
982                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set private data (%d)", ret);
983                         return VCD_ERROR_OPERATION_FAILED;
984                 }
985         }
986
987         return 0;
988 }
989
990 int vcd_engine_get_private_data(int pid, const char* key, char** data)
991 {
992         if (NULL == data) {
993                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
994                 return VCD_ERROR_INVALID_PARAMETER;
995         }
996
997         if (false == g_agent_init) {
998                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
999                 return VCD_ERROR_OPERATION_FAILED;
1000         }
1001
1002         int ret = -1;
1003         if (true == g_dynamic_engine.is_loaded) {
1004                 ret = g_dynamic_engine.pefuncs->get_private_data(key, data);
1005                 if (0 != ret) {
1006                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get private data (%d)", ret);
1007                         return VCD_ERROR_OPERATION_FAILED;
1008                 }
1009         }
1010
1011         return 0;
1012 }
1013
1014 int vcd_engine_process_text(int pid, const char* text)
1015 {
1016         if (false == g_agent_init) {
1017                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1018                 return VCD_ERROR_OPERATION_FAILED;
1019         }
1020
1021         int ret = -1;
1022         if (true == g_dynamic_engine.is_loaded) {
1023                 ret = g_dynamic_engine.pefuncs->process_text(text);
1024                 if (0 != ret) {
1025                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process text (%d)", ret);
1026                         return VCD_ERROR_OPERATION_FAILED;
1027                 }
1028         }
1029
1030         return 0;
1031 }
1032
1033 int vcd_engine_process_list_event(int pid, const char* event)
1034 {
1035         if (false == g_agent_init) {
1036                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1037                 return VCD_ERROR_OPERATION_FAILED;
1038         }
1039
1040         int ret = -1;
1041         if (true == g_dynamic_engine.is_loaded) {
1042                 ret = g_dynamic_engine.pefuncs->process_list_event(event);
1043                 if (0 != ret) {
1044                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process list event (%d)", ret);
1045                         return VCD_ERROR_OPERATION_FAILED;
1046                 }
1047         }
1048
1049         return 0;
1050 }
1051
1052 int vcd_engine_process_haptic_event(int pid, const char* event)
1053 {
1054         if (false == g_agent_init) {
1055                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1056                 return VCD_ERROR_OPERATION_FAILED;
1057         }
1058
1059         int ret = -1;
1060         if (true == g_dynamic_engine.is_loaded) {
1061                 ret = g_dynamic_engine.pefuncs->process_haptic_event(event);
1062                 if (0 != ret) {
1063                         SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process haptic event (%d)", ret);
1064                         return VCD_ERROR_OPERATION_FAILED;
1065                 }
1066         }
1067
1068         return 0;
1069 }
1070
1071 /*
1072 * VCS Engine Interfaces for client and setting
1073 */
1074
1075 int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels)
1076 {
1077         if (false == g_agent_init) {
1078                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1079                 return VCD_ERROR_OPERATION_FAILED;
1080         }
1081
1082         if (true != g_dynamic_engine.is_loaded) {
1083                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded");
1084         }
1085
1086         if (NULL == g_dynamic_engine.pefuncs->get_recording_format) {
1087                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!");
1088                 return VCD_ERROR_OPERATION_FAILED;
1089         }
1090
1091         int ret = g_dynamic_engine.pefuncs->get_recording_format(audio_id, types, rate, channels);
1092         if (0 != ret) {
1093                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get recording format(%d)", ret);
1094                 return VCD_ERROR_OPERATION_FAILED;
1095         }
1096
1097         return 0;
1098 }
1099
1100 bool __supported_language_cb(const char* language, void* user_data)
1101 {
1102         GList** lang_list = (GList**)user_data;
1103
1104         if (NULL == language || NULL == lang_list) {
1105                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL in callback!!!!");
1106                 return false;
1107         }
1108
1109         SLOG(LOG_DEBUG, TAG_VCD, "-- Language(%s)", language);
1110
1111         char* temp_lang = g_strdup(language);
1112
1113         *lang_list = g_list_append(*lang_list, temp_lang);
1114
1115         return true;
1116 }
1117
1118 int vcd_engine_supported_langs(GList** lang_list)
1119 {
1120         if (false == g_agent_init) {
1121                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1122                 return VCD_ERROR_OPERATION_FAILED;
1123         }
1124
1125         if (true != g_dynamic_engine.is_loaded) {
1126                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded");
1127         }
1128
1129         if (NULL == g_dynamic_engine.pefuncs->foreach_langs) {
1130                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!");
1131                 return VCD_ERROR_OPERATION_FAILED;
1132         }
1133
1134         int ret = g_dynamic_engine.pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list);
1135         if (0 != ret) {
1136                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get language list error(%d)", ret);
1137                 return VCD_ERROR_OPERATION_FAILED;
1138         }
1139
1140         return 0;
1141 }
1142
1143
1144 int vcd_engine_get_current_language(char** lang)
1145 {
1146         if (false == g_agent_init) {
1147                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1148                 return VCD_ERROR_OPERATION_FAILED;
1149         }
1150
1151         if (NULL == lang) {
1152                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
1153                 return VCD_ERROR_INVALID_PARAMETER;
1154         }
1155
1156         /* get default language */
1157         *lang = g_strdup(g_default_lang);
1158
1159         return 0;
1160 }
1161
1162 int vcd_engine_set_current_language(const char* language)
1163 {
1164         if (false == g_agent_init) {
1165                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized");
1166                 return VCD_ERROR_OPERATION_FAILED;
1167         }
1168
1169         if (NULL == language) {
1170                 SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter");
1171                 return VCD_ERROR_INVALID_PARAMETER;
1172         }
1173
1174         int ret;
1175
1176         if (true == g_dynamic_engine.is_loaded) {
1177                 g_dynamic_engine.is_command_ready = false;
1178
1179                 ret = g_dynamic_engine.pefuncs->set_language(language);
1180                 if (0 != ret) {
1181                         SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Fail to set language of dynamic engine error(%d, %s)", ret, language);
1182                 }
1183         } else {
1184                 SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Dynamic engine is not available (Cannot start)");
1185         }
1186
1187         return 0;
1188 }
1189
1190 void __free_language_list(GList* lang_list)
1191 {
1192         GList *iter = NULL;
1193         char* data = NULL;
1194
1195         /* if list have item */
1196         if (g_list_length(lang_list) > 0) {
1197                 /* Get a first item */
1198                 iter = g_list_first(lang_list);
1199
1200                 while (NULL != iter) {
1201                         data = iter->data;
1202
1203                         if (NULL != data)
1204                                 free(data);
1205
1206                         lang_list = g_list_remove_link(lang_list, iter);
1207
1208                         iter = g_list_first(lang_list);
1209                 }
1210         }
1211 }
1212
1213 int __log_enginelist()
1214 {
1215         GList *iter = NULL;
1216         vcengine_info_s *data = NULL;
1217
1218         if (0 < g_list_length(g_engine_list)) {
1219
1220                 /* Get a first item */
1221                 iter = g_list_first(g_engine_list);
1222
1223                 SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @");
1224
1225                 int i = 1;
1226                 while (NULL != iter) {
1227                         /* Get handle data from list */
1228                         data = iter->data;
1229
1230                         SLOG(LOG_DEBUG, TAG_VCD, "[%dth]", i);
1231                         SLOG(LOG_DEBUG, TAG_VCD, "  engine uuid : %s", data->engine_uuid);
1232                         SLOG(LOG_DEBUG, TAG_VCD, "  engine name : %s", data->engine_name);
1233                         SLOG(LOG_DEBUG, TAG_VCD, "  engine path : %s", data->engine_path);
1234                         iter = g_list_next(iter);
1235                         i++;
1236                 }
1237                 SLOG(LOG_DEBUG, TAG_VCD, "@@@@");
1238         } else {
1239                 SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @");
1240                 SLOG(LOG_DEBUG, TAG_VCD, "  No Engine in engine directory");
1241                 SLOG(LOG_DEBUG, TAG_VCD, "@@@@");
1242         }
1243
1244         return 0;
1245 }