Fix build error on gcc-13 Build
[platform/core/uifw/voice-control.git] / client / vc_mgr_tidl.c
1 /*
2 * Copyright (c) 2022 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 #include <pthread.h>
18
19 #include <rpc-port.h>
20
21 #include "vc_main.h"
22 #include "vc_mgr_client.h"
23 #include "vc_mgr_tidl.h"
24 #include "vc_mgr_proxy.h"
25 #include "vc_mgr_stub.h"
26 #include "vc_mgr_core.h"
27
28 typedef struct {
29         bool connected;
30         bool connection_requesting;
31         bool register_callback_invoked;
32         rpc_port_proxy_vc_mgr_proxy_vc_mgr_h rpc_h;
33         rpc_port_proxy_vc_mgr_proxy_vc_mgr_notify_cb_h notify_cb_h;
34         rpc_port_proxy_vc_mgr_proxy_vc_mgr_send_buffer_cb_h send_buffer_cb_h;
35 } vc_mgr_tidl_info_s;
36
37 typedef struct {
38         bool connected;
39         bool register_callback_requesting;
40 } vcd_mgr_tidl_info_s;
41
42 static vc_mgr_tidl_info_s* g_proxy_tidl_info = NULL;
43
44 static vcd_mgr_tidl_info_s* g_stub_tidl_info = NULL;
45
46 static pthread_mutex_t g_tidl_mutex = PTHREAD_MUTEX_INITIALIZER;
47
48 static rpc_port_stub_vc_mgr_stub_vcd_mgr_callback_s g_mgr_callback;
49
50 static int g_volume_count = 0;
51
52 static void __notify_cb(void *user_data, bundle *msg)
53 {
54         char *method = NULL;
55         char *val = NULL;
56
57         SLOG(LOG_DEBUG, TAG_VCM, "__notify_cb is invoked");
58
59         bundle_get_str(msg, VC_BUNDLE_METHOD, &method);
60
61         if (0 == strncmp(VCD_MANAGER_METHOD_SET_VOLUME, method, strlen(VCD_MANAGER_METHOD_SET_VOLUME))) {
62                 bundle_get_str(msg, VC_BUNDLE_VOLUME, &val);
63                 float volume = 0;
64
65                 if (val) {
66                         volume = atof(val);
67                 }
68                 if (10 == g_volume_count) {
69                         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume");
70                         SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume);
71                         g_volume_count = 0;
72                 }
73
74                 if (val) {
75                         vc_mgr_core_send_set_volume(volume);
76                         g_volume_count++;
77                 }
78         } /* VCD_MANAGER_METHOD_SET_VOLUME */
79
80         else if (0 == strncmp(VCD_METHOD_SET_SERVICE_STATE, method, strlen(VCD_METHOD_SET_SERVICE_STATE))) {
81                 bundle_get_str(msg, VC_BUNDLE_SERVICE_STATE, &val);
82                 int state = 0;
83                 if (val) {
84                         state = atoi(val);
85                         SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state);
86                         vc_mgr_core_send_service_state(state);
87                 }
88         } /* VCD_METHOD_SET_SERVICE_STATE */
89
90         else if (0 == strncmp(VCD_MANAGER_METHOD_SPEECH_DETECTED, method, strlen(VCD_MANAGER_METHOD_SPEECH_DETECTED))) {
91                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get Speech detected");
92
93                 vc_mgr_core_send_speech_detected();
94         } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */
95
96         else if (0 == strncmp(VCD_MANAGER_METHOD_ALL_RESULT, method, strlen(VCD_MANAGER_METHOD_ALL_RESULT))) {
97                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get All Result");
98
99                 bundle_get_str(msg, VC_BUNDLE_RESULT, &val);
100
101                 if (val) {
102                         vc_mgr_core_send_all_result((vc_result_type_e)atoi(val));
103                 }
104         } /* VCD_MANAGER_METHOD_ALL_RESULT */
105
106         else if (0 == strncmp(VCD_MANAGER_METHOD_PRE_RESULT, method, strlen(VCD_MANAGER_METHOD_PRE_RESULT))) {
107                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get Pre Result");
108                 char* event = NULL;
109                 char* pre_result = NULL;
110
111                 bundle_get_str(msg, VC_BUNDLE_EVENT, &event);
112                 bundle_get_str(msg, VC_BUNDLE_PRE_RESULT, &pre_result);
113
114                 if (NULL != pre_result) {
115                         vc_mgr_core_send_pre_result((vc_pre_result_event_e)atoi(event), pre_result);
116                 }
117         } /* VCD_MANAGER_METHOD_PRE_RESULT */
118
119         else if (0 == strncmp(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT, method, strlen(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT))) {
120                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get specific engine result");
121                 char* engine_app_id = NULL;
122                 char* event = NULL;
123                 char* result = NULL;
124
125                 bundle_get_str(msg, VC_BUNDLE_ENGINE_APP_ID, &engine_app_id);
126                 bundle_get_str(msg, VC_BUNDLE_EVENT, &event);
127                 bundle_get_str(msg, VC_BUNDLE_RESULT, &result);
128
129                 if (NULL != result) {
130                         gsize decodingSize=0;
131                         gchar *gDecodedResult = (gchar *)g_base64_decode((const gchar *)result, &decodingSize);
132                         if (gDecodedResult)
133                         {
134                                 SLOG(LOG_WARN, TAG_VCM, "@@@ Get specific engine result --> %s", gDecodedResult);
135                                 vc_mgr_core_send_specific_engine_result(engine_app_id, event, gDecodedResult);
136                                 g_free(gDecodedResult);
137                         }
138                 }
139         } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */
140
141         else if (0 == strncmp(VCD_MANAGER_METHOD_RESULT, method, strlen(VCD_MANAGER_METHOD_RESULT))) {
142                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get System Result");
143
144                 vc_mgr_core_send_system_result();
145         } /* VCD_MANAGER_METHOD_RESULT */
146
147         else if (0 == strncmp(VCD_MANAGER_METHOD_DIALOG, method, strlen(VCD_MANAGER_METHOD_DIALOG))) {
148                 SLOG(LOG_INFO, TAG_VCM, "@@@ Request Dialog");
149                 char* pid = NULL;
150                 char* disp_text = NULL;
151                 char* utt_text = NULL;
152                 char* continuous = NULL;
153
154                 bundle_get_str(msg, VC_BUNDLE_PID, &pid);
155                 bundle_get_str(msg, VC_BUNDLE_DISP_TEXT, &disp_text);
156                 bundle_get_str(msg, VC_BUNDLE_UTT_TEXT, &utt_text);
157                 bundle_get_str(msg, VC_BUNDLE_CONTINUOUS, &continuous);
158
159                 if (!strncmp(disp_text, "#NULL", strlen("#NULL") + 1))
160                         disp_text = NULL;
161                 if (!strncmp(utt_text, "#NULL", strlen("#NULL") + 1))
162                         utt_text = NULL;
163
164                 vc_mgr_core_send_dialog(atoi(pid), disp_text, utt_text, (bool)atoi(continuous));
165         } /* VCD_MANAGER_METHOD_DIALOG */
166
167         else if (0 == strncmp(VCD_MANAGER_METHOD_ERROR, method, strlen(VCD_MANAGER_METHOD_ERROR))) {
168                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error");
169                 char* reason = NULL;
170                 char* daemon_pid = NULL;
171                 char* err_msg = NULL;
172
173                 bundle_get_str(msg, VC_BUNDLE_REASON, &reason);
174                 bundle_get_str(msg, VC_BUNDLE_DAEMON_PID, &daemon_pid);
175                 bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg);
176
177                 char* temp_msg = NULL;
178                 if (NULL != err_msg && strncmp(err_msg, "#NULL", strlen("#NULL") + 1)) {
179                         temp_msg = strdup(err_msg);
180                 }
181                 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", atoi(reason), atoi(daemon_pid), (temp_msg) ? temp_msg : "NULL");
182                 vc_mgr_core_send_error(atoi(reason), atoi(daemon_pid), temp_msg);
183                 if (NULL != temp_msg) {
184                         free(temp_msg);
185                         temp_msg = NULL;
186                 }
187         } /* VCD_MANAGER_METHOD_ERROR */
188
189         else if (0 == strncmp(VCD_MANAGER_METHOD_SET_PRIVATE_DATA, method, strlen(VCD_MANAGER_METHOD_SET_PRIVATE_DATA))) {
190                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get request set private data");
191                 char* tmp_pid = NULL;
192                 char* key = NULL;
193                 char* private_data = NULL;
194
195                 bundle_get_str(msg, VC_BUNDLE_PID, &tmp_pid);
196                 bundle_get_str(msg, VC_BUNDLE_KEY, &key);
197                 bundle_get_str(msg, VC_BUNDLE_PRIVATE_DATA, &private_data);
198
199                 int pid = atoi(tmp_pid);
200                 SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid);
201                 if (pid > 0) {
202                         vc_mgr_core_send_private_data_set(key, private_data);
203                 } else {
204                         SLOG(LOG_ERROR, TAG_VCM, "@@ got invalid pid(%d)", pid);
205                 }
206         } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */
207
208         else if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT))) {
209                 SLOG(LOG_INFO, TAG_VCM, "@@@ Get request feedback audio format");
210                 char* channel = NULL;
211                 char* audio_type = NULL;
212                 char* rate = NULL;
213
214                 bundle_get_str(msg, VC_BUNDLE_AUDIO_CHANNEL, &channel);
215                 bundle_get_str(msg, VC_BUNDLE_AUDIO_TYPE, &audio_type);
216                 bundle_get_str(msg, VC_BUNDLE_AUDIO_RATE, &rate);
217
218                 vc_mgr_core_send_feedback_audio_format(atoi(rate), (vc_audio_channel_e)atoi(channel), (vc_audio_type_e)atoi(audio_type));
219         } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */
220
221         // TODO: uncomment this line after vcc done
222         // NEED2CHECK: when vcc send 'set_foreground', __vcd_mgr_set_foreground_cb will be invoked...
223         // else if (0 == strncmp(VCC_MANAGER_METHOD_SET_FOREGROUND, method, strlen(VCC_MANAGER_METHOD_SET_FOREGROUND))) {
224         //      SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground");
225         //      char* temp_pid = NULL;
226         //      char* temp_value = NULL;
227         //      int pid = 0;
228         //      int value = 0;
229
230         //      bundle_get_str(msg, VC_BUNDLE_PID, &temp_pid);
231         //      bundle_get_str(msg, VC_BUNDLE_VALUE, &temp_value);
232         //      pid = atoi(temp_pid);
233         //      value = atoi(temp_value);
234
235         //      SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false");
236
237         //      vc_mgr_core_send_set_foreground(pid, (bool)value);
238         // } /* VCC_MANAGER_METHOD_SET_FOREGROUND */
239
240         else {
241                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg");
242         }
243
244         SLOG(LOG_DEBUG, TAG_VCM, "@@@ __notify_cb DONE");
245 }
246
247 static void __send_buffer_cb(void *user_data, rpc_port_proxy_vc_mgr_proxy_array_char_h data_in, bundle *msg)
248 {
249         char *method = NULL;
250         char *val = NULL;
251
252         SLOG(LOG_DEBUG, TAG_VCM, "__send_buffer_cb is invoked");
253
254         bundle_get_str(msg, VC_BUNDLE_METHOD, &method);
255
256         if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_STREAMING, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_STREAMING))) {
257                 char *utt_id = NULL;
258                 char *event = NULL;
259                 char* buffer = NULL;
260                 int len = 0;
261
262                 bundle_get_str(msg, VC_BUNDLE_PID, &val);
263                 bundle_get_str(msg, VC_BUNDLE_UTT_ID, &utt_id);
264                 bundle_get_str(msg, VC_BUNDLE_EVENT, &event);
265
266                 rpc_port_proxy_vc_mgr_proxy_array_char_get(data_in, &buffer, &len);
267                 vc_mgr_core_send_feedback_streaming(atoi(val), atoi(utt_id), atoi(event), buffer, len);
268                 free(buffer);
269
270                 SLOG(LOG_INFO, TAG_VCM, "@@@ __send_buffer_cb DONE");
271         } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */
272
273         else {
274                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg");
275         }
276
277 }
278
279 static void __on_connected(rpc_port_proxy_vc_mgr_proxy_vc_mgr_h h, void *user_data)
280 {
281         RETM_IF(NULL == g_proxy_tidl_info, TAG_VCM, "[ERROR] Fail to get tidl info");
282
283         g_proxy_tidl_info->connected = true;
284         g_proxy_tidl_info->connection_requesting = false;
285         g_proxy_tidl_info->register_callback_invoked = false;
286
287         SLOG(LOG_INFO, TAG_VCM, "Connected to server");
288 }
289
290 static void __on_disconnected(rpc_port_proxy_vc_mgr_proxy_vc_mgr_h h, void *user_data)
291 {
292         RETM_IF(NULL == g_proxy_tidl_info, TAG_VCM, "[ERROR] Fail to get tidl info");
293
294         g_proxy_tidl_info->connected = false;
295         g_proxy_tidl_info->connection_requesting = false;
296         g_proxy_tidl_info->register_callback_invoked = false;
297
298         SLOG(LOG_INFO, TAG_VCM, "Disonnected to server");
299
300         vc_mgr_core_send_error(VC_ERROR_SERVICE_RESET, -1, "Server Disconnected");
301 }
302
303 static void __on_rejected(rpc_port_proxy_vc_mgr_proxy_vc_mgr_h h, void *user_data)
304 {
305         RETM_IF(NULL == g_proxy_tidl_info, TAG_VCM, "[ERROR] Fail to get tidl info");
306
307         g_proxy_tidl_info->connection_requesting = false;
308         g_proxy_tidl_info->register_callback_invoked = false;
309
310         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Rejected from server");
311 }
312
313
314 static rpc_port_proxy_vc_mgr_proxy_vc_mgr_h __create_rpc_port(const char* engine_app_id)
315 {
316         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __create_rpc_port");
317         rpc_port_proxy_vc_mgr_proxy_vc_mgr_callback_s rpc_callback = {
318                 .connected = __on_connected,
319                 .disconnected = __on_disconnected,
320                 .rejected = __on_rejected
321         };
322
323         rpc_port_proxy_vc_mgr_proxy_vc_mgr_h handle = NULL;
324         if (0 != rpc_port_proxy_vc_mgr_proxy_vc_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) {
325                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy");
326                 return NULL;
327         }
328
329         return handle;
330 }
331
332 static void __vcd_mgr_create_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, void *user_data)
333 {
334         g_stub_tidl_info->connected = true;
335         g_stub_tidl_info->register_callback_requesting = false;
336
337         SLOG(LOG_DEBUG, TAG_VCM, "Connected to server");
338
339         char *sender = NULL;
340
341         rpc_port_stub_vc_mgr_stub_vcd_mgr_context_get_sender(context, &sender);
342         if (!sender) {
343                 SLOG(LOG_ERROR, TAG_VCM, "@@@ Sender is NULL");
344                 return;
345         }
346
347         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Server connect. appid(%s)", sender);
348         free(sender);
349 }
350
351 static void __vcd_mgr_terminate_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, void *user_data)
352 {
353         if (NULL != g_stub_tidl_info) {
354                 g_stub_tidl_info->connected = false;
355                 g_stub_tidl_info->register_callback_requesting = false;
356         }
357
358         rpc_port_stub_vc_mgr_stub_vcd_mgr_context_set_tag(context, NULL);
359
360         char *sender = NULL;
361         rpc_port_stub_vc_mgr_stub_vcd_mgr_context_get_sender(context, &sender);
362         if (!sender)
363                 return;
364
365         SLOG(LOG_INFO, TAG_VCM, "@@@ Server disconnect. appid(%s)", sender);
366         free(sender);
367 }
368
369 static void __vcd_mgr_set_foreground_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, int value, void *user_data)
370 {
371         SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground");
372         SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false");
373
374         vc_mgr_core_send_set_foreground(pid, (bool)value);
375
376         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set foreground DONE");
377 }
378
379 static int __vcd_mgr_get_private_data_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, const char *key, char **data, void *user_data)
380 {
381         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request get private data");
382         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid);
383
384         int ret = -1;
385         char *temp_data = NULL;
386
387         ret = vc_mgr_core_send_private_data_requested(key, &temp_data);
388         if (0 != ret) {
389                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
390                 return ret;
391         }
392         if (NULL == temp_data) {
393                 SLOG(LOG_INFO, TAG_VCM, "data parameter is NULL");
394                 temp_data = strdup("#NULL");
395         }
396         *data = temp_data;
397         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request get private data DONE");
398
399         return ret;
400 }
401
402 static int __vcd_mgr_auth_enable_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, void *user_data)
403 {
404         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth enable");
405         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth enable : pid(%d)", pid);
406
407         int ret = -1;
408
409         ret = vc_mgr_core_request_auth_enable(pid);
410         if (0 != ret) {
411                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
412         }
413
414         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth enable DONE");
415
416         return ret;
417 }
418
419 static int __vcd_mgr_auth_disable_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, void *user_data)
420 {
421         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth disable");
422         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth disable : pid(%d)", pid);
423
424         int ret = -1;
425
426         ret = vc_mgr_core_request_auth_disable(pid);
427         if (0 != ret) {
428                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
429         }
430
431         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth disable DONE");
432
433         return ret;
434 }
435
436 static int __vcd_mgr_auth_start_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, void *user_data)
437 {
438         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth start");
439         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth start : pid(%d)", pid);
440
441         int ret = -1;
442
443         ret = vc_mgr_core_request_auth_start(pid);
444         if (0 != ret) {
445                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
446         }
447
448         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth start DONE");
449
450         return ret;
451 }
452
453 static int __vcd_mgr_auth_stop_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, void *user_data)
454 {
455         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth stop");
456         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth stop : pid(%d)", pid);
457
458         int ret = -1;
459
460         ret = vc_mgr_core_request_auth_stop(pid);
461         if (0 != ret) {
462                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
463         }
464
465         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth stop DONE");
466
467         return ret;
468 }
469
470 static int __vcd_mgr_auth_cancel_cb(rpc_port_stub_vc_mgr_stub_vcd_mgr_context_h context, int pid, void *user_data)
471 {
472         SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth cancel");
473         SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth cancel : pid(%d)", pid);
474
475         int ret = -1;
476
477         ret = vc_mgr_core_request_auth_cancel(pid);
478         if (0 != ret) {
479                 SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret);
480         }
481
482         SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth cancel DONE");
483
484         return ret;
485 }
486
487 static int __register_stub_callback()
488 {
489         if (g_stub_tidl_info->register_callback_requesting) {
490                 return VC_ERROR_NONE;
491         }
492
493         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __register_stub_callback");
494
495         g_mgr_callback.create = __vcd_mgr_create_cb;
496         g_mgr_callback.terminate = __vcd_mgr_terminate_cb;
497         g_mgr_callback.set_foreground = __vcd_mgr_set_foreground_cb;
498         g_mgr_callback.get_private_data = __vcd_mgr_get_private_data_cb;
499         g_mgr_callback.auth_enable = __vcd_mgr_auth_enable_cb;
500         g_mgr_callback.auth_disable = __vcd_mgr_auth_disable_cb;
501         g_mgr_callback.auth_start = __vcd_mgr_auth_start_cb;
502         g_mgr_callback.auth_stop = __vcd_mgr_auth_stop_cb;
503         g_mgr_callback.auth_cancel = __vcd_mgr_auth_cancel_cb;
504
505         int ret = -1;
506         ret = rpc_port_stub_vc_mgr_stub_vcd_mgr_register(&g_mgr_callback, NULL);
507         if (0 == ret) {
508                 SLOG(LOG_DEBUG, TAG_VCM, "register callback");
509                 g_stub_tidl_info->register_callback_requesting = true;
510                 return VC_ERROR_NONE;
511         }
512
513         SLOG(LOG_ERROR, TAG_VCM, "Fail to register callback(%d)", ret);
514         return VC_ERROR_OPERATION_FAILED;
515 }
516
517 int vc_mgr_tidl_open_connection()
518 {
519         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_open_connection");
520         pthread_mutex_lock(&g_tidl_mutex);
521
522         if (NULL != g_proxy_tidl_info) {
523                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] g_proxy_tidl_info already created");
524                 pthread_mutex_unlock(&g_tidl_mutex);
525                 return VC_ERROR_NONE;
526         }
527
528         g_proxy_tidl_info = (vc_mgr_tidl_info_s*)calloc(1, sizeof(vc_mgr_tidl_info_s));
529
530         if (NULL == g_proxy_tidl_info) {
531                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vc_mgr_tidl_info_s");
532                 pthread_mutex_unlock(&g_tidl_mutex);
533                 return VC_ERROR_OUT_OF_MEMORY;
534         }
535
536         char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT);
537         if (NULL == engine_app_id) {
538                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL] vconf not found");
539                 free(g_proxy_tidl_info);
540                 g_proxy_tidl_info = NULL;
541                 pthread_mutex_unlock(&g_tidl_mutex);
542                 return VC_ERROR_ENGINE_NOT_FOUND;
543         }
544
545         g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id);
546         if (NULL == g_proxy_tidl_info->rpc_h) {
547                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy");
548                 free(engine_app_id);
549                 free(g_proxy_tidl_info);
550                 g_proxy_tidl_info = NULL;
551                 pthread_mutex_unlock(&g_tidl_mutex);
552                 return VC_ERROR_OPERATION_FAILED;
553         }
554
555         SLOG(LOG_INFO, TAG_VCM, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id);
556         free(engine_app_id);
557
558         g_stub_tidl_info = (vcd_mgr_tidl_info_s*)calloc(1, sizeof(vcd_mgr_tidl_info_s));
559
560         if (NULL == g_stub_tidl_info) {
561                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vcd_mgr_tidl_info_s");
562                 pthread_mutex_unlock(&g_tidl_mutex);
563                 return VC_ERROR_OUT_OF_MEMORY;
564         }
565
566         __register_stub_callback();
567
568         pthread_mutex_unlock(&g_tidl_mutex);
569
570         return VC_ERROR_NONE;
571 }
572
573 int vc_mgr_tidl_close_connection()
574 {
575         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_close_connection");
576         pthread_mutex_lock(&g_tidl_mutex);
577
578         if (NULL == g_proxy_tidl_info) {
579                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
580                 pthread_mutex_unlock(&g_tidl_mutex);
581                 return VC_ERROR_OPERATION_FAILED;
582         }
583
584         if (0 != rpc_port_proxy_vc_mgr_proxy_vc_mgr_destroy(g_proxy_tidl_info->rpc_h)) {
585                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to destroy tidl handle");
586                 pthread_mutex_unlock(&g_tidl_mutex);
587                 return VC_ERROR_OPERATION_FAILED;
588         }
589
590         g_proxy_tidl_info->rpc_h = NULL;
591         g_proxy_tidl_info->notify_cb_h = NULL;
592         g_proxy_tidl_info->send_buffer_cb_h = NULL;
593
594         free(g_proxy_tidl_info);
595         g_proxy_tidl_info = NULL;
596
597         free(g_stub_tidl_info);
598         g_stub_tidl_info = NULL;
599
600         pthread_mutex_unlock(&g_tidl_mutex);
601
602         return VC_ERROR_NONE;
603 }
604
605 static int __convert_unhandled_error(int ret)
606 {
607         if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
608                 return VC_ERROR_OPERATION_FAILED;
609         }
610
611         return ret;
612 }
613
614 static void __request_tidl_connect()
615 {
616         if (g_proxy_tidl_info->connection_requesting) {
617                 return;
618         }
619
620         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_connect(g_proxy_tidl_info->rpc_h);
621         SLOG(LOG_INFO, TAG_VCM, "[INFO] Request connection to stub. ret(%d)", ret);
622
623         if (0 == ret) {
624                 g_proxy_tidl_info->connection_requesting = true;
625         }
626 }
627
628 static int __create_callback_handles()
629 {
630         if (NULL != g_proxy_tidl_info->notify_cb_h) {
631                 rpc_port_proxy_vc_mgr_proxy_vc_mgr_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h);
632                 g_proxy_tidl_info->notify_cb_h = NULL;
633         }
634
635         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_proxy_vc_mgr_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) {
636                 return VC_ERROR_OUT_OF_MEMORY;
637         }
638
639         rpc_port_proxy_vc_mgr_proxy_vc_mgr_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL);
640
641         rpc_port_proxy_vc_mgr_proxy_vc_mgr_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false);
642
643         if (NULL != g_proxy_tidl_info->send_buffer_cb_h) {
644                 rpc_port_proxy_vc_mgr_proxy_vc_mgr_send_buffer_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->send_buffer_cb_h);
645                 g_proxy_tidl_info->send_buffer_cb_h = NULL;
646         }
647
648         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_proxy_vc_mgr_send_buffer_cb_create(&g_proxy_tidl_info->send_buffer_cb_h)) {
649                 return VC_ERROR_OUT_OF_MEMORY;
650         }
651
652         rpc_port_proxy_vc_mgr_proxy_vc_mgr_send_buffer_cb_set_callback(g_proxy_tidl_info->send_buffer_cb_h, __send_buffer_cb, NULL);
653
654         rpc_port_proxy_vc_mgr_proxy_vc_mgr_send_buffer_cb_set_once(g_proxy_tidl_info->send_buffer_cb_h, false);
655
656         return VC_ERROR_NONE;
657 }
658
659 static int __invoke_register_callback()
660 {
661         if (g_proxy_tidl_info->register_callback_invoked) {
662                 SLOG(LOG_ERROR, TAG_VCM, "[INFO] Already register callback is invoked");
663                 return VC_ERROR_NONE;
664         }
665
666         int ret = __create_callback_handles(g_proxy_tidl_info);
667         if (VC_ERROR_NONE != ret) {
668                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create callback handle. ret(%d)", ret);
669                 return VC_ERROR_OPERATION_FAILED;
670         }
671
672         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h, g_proxy_tidl_info->send_buffer_cb_h);
673         g_proxy_tidl_info->register_callback_invoked = true;
674         return VC_ERROR_NONE;
675 }
676
677 int vc_mgr_tidl_request_hello()
678 {
679         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_hello");
680
681         if (NULL == g_proxy_tidl_info) {
682                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get proxy tidl info");
683                 return VC_ERROR_OPERATION_FAILED;
684         }
685
686         if (!g_proxy_tidl_info->connected) {
687                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Proxy Not Connected");
688                 __request_tidl_connect();
689                 return VC_ERROR_OPERATION_FAILED;
690         }
691
692         if (VC_ERROR_NONE != __invoke_register_callback()) {
693                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to invoke register callback");
694                 return VC_ERROR_OPERATION_FAILED;
695         }
696
697         if (NULL == g_stub_tidl_info) {
698                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get stub tidl info");
699                 return VC_ERROR_OPERATION_FAILED;
700         }
701
702         if (!g_stub_tidl_info->connected) {
703                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stub Not Connected");
704                 int ret = __register_stub_callback();
705                 return ret;
706         }
707
708         SLOG(LOG_DEBUG, TAG_VCM, ">>>>> VCM Hello");
709
710         SLOG(LOG_DEBUG, TAG_VCM, "<<<<");
711
712         return VC_ERROR_NONE;
713 }
714
715 int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid)
716 {
717         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_initialize");
718
719         if (NULL == g_proxy_tidl_info) {
720                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
721                 return VC_ERROR_OPERATION_FAILED;
722         }
723
724         int tmp_service_state = 0;
725         int tmp_forground = 0;
726         int tmp_daemon_pid = 0;
727
728         if (!g_proxy_tidl_info->connected) {
729                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
730                 return VC_ERROR_OPERATION_FAILED;
731         }
732
733         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, audio_streaming_mode, &tmp_service_state, &tmp_forground, &tmp_daemon_pid);
734         int exception = get_last_result();
735         if (RPC_PORT_ERROR_NONE != exception) {
736                 ret = __convert_unhandled_error(exception);
737         }
738
739         if (VC_ERROR_NONE != ret) {
740                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager initialize : Fail to invoke message, error(%d)", ret);
741                 return ret;
742         }
743
744         *service_state = tmp_service_state;
745         *foreground = tmp_forground;
746         *daemon_pid = tmp_daemon_pid;
747
748         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc manager initialize: service_state(%d), foreground(%d), daemon_pid(%d)", *service_state, *foreground, *daemon_pid);
749
750         return VC_ERROR_NONE;
751 }
752
753 int vc_mgr_tidl_request_finalize(int pid)
754 {
755         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_finalize");
756
757         if (NULL == g_proxy_tidl_info) {
758                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
759                 return VC_ERROR_OPERATION_FAILED;
760         }
761
762         if (!g_proxy_tidl_info->connected) {
763                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
764                 return VC_ERROR_OPERATION_FAILED;
765         }
766
767         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_finalize(g_proxy_tidl_info->rpc_h, pid);
768         int exception = get_last_result();
769         if (RPC_PORT_ERROR_NONE != exception) {
770                 ret = __convert_unhandled_error(exception);
771         }
772
773         if (VC_ERROR_NONE != ret) {
774                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager finalize : Fail to invoke finalize, error(%d)", ret);
775                 return ret;
776         }
777
778         ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_disconnect(g_proxy_tidl_info->rpc_h);
779         exception = get_last_result();
780         if (RPC_PORT_ERROR_NONE != exception) {
781                 ret = __convert_unhandled_error(exception);
782         }
783
784         if (VC_ERROR_NONE != ret) {
785                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager finalize : Fail to disconnect, error(%d)", ret);
786                 return ret;
787         }
788
789         return VC_ERROR_NONE;
790 }
791
792 int vc_mgr_tidl_request_set_command(int pid)
793 {
794         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_command");
795
796         if (NULL == g_proxy_tidl_info) {
797                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
798                 return VC_ERROR_OPERATION_FAILED;
799         }
800
801         if (!g_proxy_tidl_info->connected) {
802                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
803                 return VC_ERROR_OPERATION_FAILED;
804         }
805
806         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_command(g_proxy_tidl_info->rpc_h, pid);
807         int exception = get_last_result();
808         if (RPC_PORT_ERROR_NONE != exception) {
809                 ret = __convert_unhandled_error(exception);
810         }
811
812         if (VC_ERROR_NONE != ret) {
813                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set command : Fail to invoke message, error(%d)", ret);
814                 return ret;
815         }
816
817         return VC_ERROR_NONE;
818 }
819
820 int vc_mgr_tidl_request_unset_command(int pid)
821 {
822         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_unset_command");
823
824         if (NULL == g_proxy_tidl_info) {
825                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
826                 return VC_ERROR_OPERATION_FAILED;
827         }
828
829         if (!g_proxy_tidl_info->connected) {
830                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
831                 return VC_ERROR_OPERATION_FAILED;
832         }
833
834         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_unset_command(g_proxy_tidl_info->rpc_h, pid);
835         int exception = get_last_result();
836         if (RPC_PORT_ERROR_NONE != exception) {
837                 ret = __convert_unhandled_error(exception);
838         }
839
840         if (VC_ERROR_NONE != ret) {
841                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager unset command : Fail to invoke message, error(%d)", ret);
842                 return ret;
843         }
844
845         return VC_ERROR_NONE;
846 }
847
848 int vc_mgr_tidl_request_demandable_client(int pid)
849 {
850         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_demandable_client");
851
852         if (NULL == g_proxy_tidl_info) {
853                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
854                 return VC_ERROR_OPERATION_FAILED;
855         }
856
857         if (!g_proxy_tidl_info->connected) {
858                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
859                 return VC_ERROR_OPERATION_FAILED;
860         }
861
862         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_demandable_client(g_proxy_tidl_info->rpc_h, pid);
863         int exception = get_last_result();
864         if (RPC_PORT_ERROR_NONE != exception) {
865                 ret = __convert_unhandled_error(exception);
866         }
867
868         if (VC_ERROR_NONE != ret) {
869                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager demandable client : Fail to invoke message, error(%d)", ret);
870                 return ret;
871         }
872
873         return VC_ERROR_NONE;
874 }
875
876 int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type)
877 {
878         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_type");
879
880         if (NULL == g_proxy_tidl_info) {
881                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
882                 return VC_ERROR_OPERATION_FAILED;
883         }
884
885         if (!g_proxy_tidl_info->connected) {
886                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
887                 return VC_ERROR_OPERATION_FAILED;
888         }
889
890         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_audio_type(g_proxy_tidl_info->rpc_h, pid, audio_type);
891         int exception = get_last_result();
892         if (RPC_PORT_ERROR_NONE != exception) {
893                 ret = __convert_unhandled_error(exception);
894         }
895
896         if (VC_ERROR_NONE != ret) {
897                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set audio type : Fail to invoke message, error(%d)", ret);
898                 return ret;
899         }
900
901         return VC_ERROR_NONE;
902 }
903
904 int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type)
905 {
906         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_audio_type");
907
908         if (NULL == g_proxy_tidl_info) {
909                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
910                 return VC_ERROR_OPERATION_FAILED;
911         }
912
913         if (!g_proxy_tidl_info->connected) {
914                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
915                 return VC_ERROR_OPERATION_FAILED;
916         }
917
918         char *tmp = NULL;
919         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_get_audio_type(g_proxy_tidl_info->rpc_h, pid, &tmp);
920         int exception = get_last_result();
921         if (RPC_PORT_ERROR_NONE != exception) {
922                 ret = __convert_unhandled_error(exception);
923         }
924
925         if (VC_ERROR_NONE != ret) {
926                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get audio type : Fail to invoke message, error(%d)", ret);
927                 *audio_type = NULL;
928                 free(tmp);
929                 return ret;
930         }
931         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get audio type : Success");
932
933         *audio_type = tmp;
934
935         return VC_ERROR_NONE;
936 }
937
938 int vc_mgr_tidl_request_set_private_data(int pid, const char* key, const char* data)
939 {
940         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_private_data");
941
942         if (NULL == g_proxy_tidl_info) {
943                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
944                 return VC_ERROR_OPERATION_FAILED;
945         }
946
947         if (!g_proxy_tidl_info->connected) {
948                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
949                 return VC_ERROR_OPERATION_FAILED;
950         }
951
952         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_private_data(g_proxy_tidl_info->rpc_h, pid, key, data);
953
954         return VC_ERROR_NONE;
955 }
956
957 int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data)
958 {
959         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_private_data");
960
961         if (NULL == g_proxy_tidl_info) {
962                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
963                 return VC_ERROR_OPERATION_FAILED;
964         }
965
966         if (!g_proxy_tidl_info->connected) {
967                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
968                 return VC_ERROR_OPERATION_FAILED;
969         }
970
971         char *tmp = NULL;
972         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_get_private_data(g_proxy_tidl_info->rpc_h, pid, key, &tmp);
973         int exception = get_last_result();
974         if (RPC_PORT_ERROR_NONE != exception) {
975                 ret = __convert_unhandled_error(exception);
976         }
977
978         if (VC_ERROR_NONE != ret) {
979                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get private data : Fail to invoke message, error(%d)", ret);
980                 *data = NULL;
981                 free(tmp);
982                 return ret;
983         }
984         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get private data : Success");
985
986         *data = tmp;
987
988         return VC_ERROR_NONE;
989 }
990
991 int vc_mgr_tidl_request_set_client_info(int pid)
992 {
993         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_client_info");
994
995         if (NULL == g_proxy_tidl_info) {
996                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
997                 return VC_ERROR_OPERATION_FAILED;
998         }
999
1000         if (!g_proxy_tidl_info->connected) {
1001                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1002                 return VC_ERROR_OPERATION_FAILED;
1003         }
1004
1005         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_client_info(g_proxy_tidl_info->rpc_h, pid);
1006         int exception = get_last_result();
1007         if (RPC_PORT_ERROR_NONE != exception) {
1008                 ret = __convert_unhandled_error(exception);
1009         }
1010
1011         if (VC_ERROR_NONE != ret) {
1012                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set client info : Fail to invoke message, error(%d)", ret);
1013                 return ret;
1014         }
1015
1016         return VC_ERROR_NONE;
1017 }
1018
1019 int vc_mgr_tidl_request_set_domain(int pid, const char* domain)
1020 {
1021         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_domain");
1022
1023         if (NULL == g_proxy_tidl_info) {
1024                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1025                 return VC_ERROR_OPERATION_FAILED;
1026         }
1027
1028         if (!g_proxy_tidl_info->connected) {
1029                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1030                 return VC_ERROR_OPERATION_FAILED;
1031         }
1032
1033         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_domain(g_proxy_tidl_info->rpc_h, pid, domain);
1034         int exception = get_last_result();
1035         if (RPC_PORT_ERROR_NONE != exception) {
1036                 ret = __convert_unhandled_error(exception);
1037         }
1038
1039         if (VC_ERROR_NONE != ret) {
1040                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set domain : Fail to invoke message, error(%d)", ret);
1041                 return ret;
1042         }
1043
1044         return VC_ERROR_NONE;
1045 }
1046
1047 int vc_mgr_tidl_request_do_action(int pid, vc_send_event_type_e type, char* send_event)
1048 {
1049         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_do_action");
1050
1051         if (NULL == g_proxy_tidl_info) {
1052                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1053                 return VC_ERROR_OPERATION_FAILED;
1054         }
1055
1056         if (!g_proxy_tidl_info->connected) {
1057                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1058                 return VC_ERROR_OPERATION_FAILED;
1059         }
1060
1061         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_do_action(g_proxy_tidl_info->rpc_h, pid, type, send_event);
1062
1063         return VC_ERROR_NONE;
1064 }
1065
1066 int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type)
1067 {
1068         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_start");
1069
1070         if (NULL == g_proxy_tidl_info) {
1071                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1072                 return VC_ERROR_OPERATION_FAILED;
1073         }
1074
1075         if (!g_proxy_tidl_info->connected) {
1076                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1077                 return VC_ERROR_OPERATION_FAILED;
1078         }
1079
1080         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_start(g_proxy_tidl_info->rpc_h, pid, recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type);
1081         int exception = get_last_result();
1082         if (RPC_PORT_ERROR_NONE != exception) {
1083                 ret = __convert_unhandled_error(exception);
1084         }
1085
1086         if (VC_ERROR_NONE != ret) {
1087                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager start : Fail to invoke message, error(%d)", ret);
1088                 return ret;
1089         }
1090
1091         return VC_ERROR_NONE;
1092 }
1093
1094 int vc_mgr_tidl_request_stop(int pid)
1095 {
1096         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_stop");
1097
1098         if (NULL == g_proxy_tidl_info) {
1099                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1100                 return VC_ERROR_OPERATION_FAILED;
1101         }
1102
1103         if (!g_proxy_tidl_info->connected) {
1104                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1105                 return VC_ERROR_OPERATION_FAILED;
1106         }
1107
1108         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_stop(g_proxy_tidl_info->rpc_h, pid);
1109         int exception = get_last_result();
1110         if (RPC_PORT_ERROR_NONE != exception) {
1111                 ret = __convert_unhandled_error(exception);
1112         }
1113
1114         if (VC_ERROR_NONE != ret) {
1115                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager stop : Fail to invoke message, error(%d)", ret);
1116                 return ret;
1117         }
1118
1119         return VC_ERROR_NONE;
1120 }
1121
1122 int vc_mgr_tidl_request_cancel(int pid)
1123 {
1124         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_cancel");
1125
1126         if (NULL == g_proxy_tidl_info) {
1127                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1128                 return VC_ERROR_OPERATION_FAILED;
1129         }
1130
1131         if (!g_proxy_tidl_info->connected) {
1132                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1133                 return VC_ERROR_OPERATION_FAILED;
1134         }
1135
1136         int ret = rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_cancel(g_proxy_tidl_info->rpc_h, pid);
1137         int exception = get_last_result();
1138         if (RPC_PORT_ERROR_NONE != exception) {
1139                 ret = __convert_unhandled_error(exception);
1140         }
1141
1142         if (VC_ERROR_NONE != ret) {
1143                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager cancel : Fail to invoke message, error(%d)", ret);
1144                 return ret;
1145         }
1146
1147         return VC_ERROR_NONE;
1148 }
1149
1150 int vc_mgr_tidl_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode)
1151 {
1152         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_streaming_mode");
1153
1154         if (NULL == g_proxy_tidl_info) {
1155                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1156                 return VC_ERROR_OPERATION_FAILED;
1157         }
1158
1159         if (!g_proxy_tidl_info->connected) {
1160                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1161                 return VC_ERROR_OPERATION_FAILED;
1162         }
1163
1164         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_set_audio_streaming_mode(g_proxy_tidl_info->rpc_h, pid, mode);
1165
1166         return VC_ERROR_NONE;
1167 }
1168
1169 int vc_mgr_tidl_send_result_selection(int pid)
1170 {
1171         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection");
1172
1173         if (NULL == g_proxy_tidl_info) {
1174                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1175                 return VC_ERROR_OPERATION_FAILED;
1176         }
1177
1178         if (!g_proxy_tidl_info->connected) {
1179                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1180                 return VC_ERROR_OPERATION_FAILED;
1181         }
1182
1183         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_send_result_selection(g_proxy_tidl_info->rpc_h, pid);
1184
1185         return VC_ERROR_NONE;
1186 }
1187
1188 int vc_mgr_tidl_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
1189 {
1190         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection");
1191
1192         if (NULL == g_proxy_tidl_info) {
1193                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1194                 return VC_ERROR_OPERATION_FAILED;
1195         }
1196
1197         if (!g_proxy_tidl_info->connected) {
1198                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1199                 return VC_ERROR_OPERATION_FAILED;
1200         }
1201
1202         gchar *gEncodedRequest = g_base64_encode((const guchar*)request, strlen(request));
1203
1204         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_send_specific_engine_request(g_proxy_tidl_info->rpc_h, pid, engine_app_id, event, gEncodedRequest);
1205
1206         if (gEncodedRequest)
1207                 g_free(gEncodedRequest);
1208
1209         return VC_ERROR_NONE;
1210 }
1211
1212 int vc_mgr_tidl_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status)
1213 {
1214         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_utterance_status");
1215
1216         if (NULL == g_proxy_tidl_info) {
1217                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1218                 return VC_ERROR_OPERATION_FAILED;
1219         }
1220
1221         if (!g_proxy_tidl_info->connected) {
1222                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1223                 return VC_ERROR_OPERATION_FAILED;
1224         }
1225
1226         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_send_utterance_status(g_proxy_tidl_info->rpc_h, pid, utt_id, utt_status);
1227
1228         return VC_ERROR_NONE;
1229 }
1230
1231 int vc_mgr_tidl_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len)
1232 {
1233         SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_audio_streaming");
1234
1235         if (NULL == g_proxy_tidl_info) {
1236                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info");
1237                 return VC_ERROR_OPERATION_FAILED;
1238         }
1239
1240         if (!g_proxy_tidl_info->connected) {
1241                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected");
1242                 return VC_ERROR_OPERATION_FAILED;
1243         }
1244
1245         rpc_port_proxy_vc_mgr_proxy_array_char_h data = NULL;
1246         rpc_port_proxy_vc_mgr_proxy_array_char_create(&data);
1247         if (NULL == data) {
1248                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create data handle");
1249                 return VC_ERROR_OUT_OF_MEMORY;
1250         }
1251
1252         if (NULL != buffer && 0 < len) {
1253                 rpc_port_proxy_vc_mgr_proxy_array_char_set(data, (char*)buffer, len);
1254         } else {
1255                 SLOG(LOG_ERROR, TAG_VCM, "[TIDL] buffer is empty");
1256         }
1257
1258         rpc_port_proxy_vc_mgr_proxy_vc_mgr_invoke_send_audio_streaming(g_proxy_tidl_info->rpc_h, pid, event, data);
1259         rpc_port_proxy_vc_mgr_proxy_array_char_destroy(data);
1260
1261         return VC_ERROR_NONE;
1262 }