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