Fix build error on gcc-13 Build
[platform/core/uifw/voice-control.git] / client / vc_mgr_client.c
1 /*
2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include "vc_main.h"
19 #include "vc_mgr_client.h"
20
21 typedef struct {
22         /* base info */
23         int     pid;
24
25         vc_mgr_all_result_cb            all_result_cb;
26         void*                           all_result_user_data;
27         vc_result_cb                    result_cb;
28         void*                           result_user_data;
29         vc_mgr_pre_result_cb            pre_result_cb;
30         void*                           pre_result_user_data;
31
32         vc_error_cb                     error_cb;
33         void*                           error_user_data;
34         vc_service_state_changed_cb     service_state_changed_cb;
35         void*                           service_state_changed_user_data;
36         vc_state_changed_cb             state_changed_cb;
37         void*                           state_changed_user_data;
38         vc_mgr_begin_speech_detected_cb speech_detected_cb;
39         void*                           speech_detected_user_data;
40         vc_current_language_changed_cb  current_lang_changed_cb;
41         void*                           current_lang_changed_user_data;
42         vc_mgr_dialog_request_cb        dialog_request_cb;
43         void*                           dialog_request_user_data;
44         vc_mgr_private_data_set_cb      private_data_set_cb;
45         void*                           private_data_set_user_data;
46         vc_mgr_private_data_requested_cb        private_data_requested_cb;
47         void*                           private_data_requested_user_data;
48         vc_mgr_specific_engine_result_cb        specific_engine_result_cb;
49         void*                           specific_engine_result_user_data;
50
51         /* for TTS feedback */
52         vc_mgr_feedback_audio_format_cb feedback_audio_format_cb;
53         void*                           feedback_audio_format_user_data;
54         vc_mgr_feedback_streaming_cb    feedback_streaming_cb;
55         void*                           feedback_streaming_user_data;
56         vc_mgr_vc_tts_streaming_cb              vc_tts_streaming_cb;
57         void*                                                   vc_tts_streaming_user_data;
58
59         /* All result */
60         vc_result_event_e       all_result_event;
61         char*                   all_result_text;
62
63         /* exclusive command flag */
64         bool                    exclusive_cmd_option;
65
66         /* system result */
67         int                     result_event;
68         char*                   result_text;
69
70         /* service state */
71         vc_service_state_e      service_state;
72
73         vc_internal_state_e     internal_state;
74
75         /* state */
76         vc_state_e              previous_state;
77         vc_state_e              current_state;
78
79         /* language */
80         char*                   previous_language;
81         char*                   current_language;
82
83         /* audio type */
84         char*                   audio_id;
85
86         /* disabled command type */
87         int                             disabled_cmd_type;
88
89         /* recognition mode */
90         vc_recognition_mode_e   recognition_mode;
91
92         /* mutex */
93         int                     cb_ref_count;
94
95         /* error data */
96         int                     reason;
97         char*                   err_msg;
98
99         /* Authorized */
100         GSList*                 authorized_client_list;
101         int                     valid_authorized_pid;
102         bool                    start_by_client;
103
104         /* foreground pid */
105         int                     foreground_pid;
106
107         /* multi-assistant */
108         vc_audio_streaming_mode_e       streaming_mode;
109 } vc_mgr_client_s;
110
111 typedef struct {
112         int pid;
113 } vc_authorized_client_s;
114
115 static vc_mgr_client_s *g_mgr_client = NULL;
116
117 int vc_mgr_client_create()
118 {
119         if (NULL != g_mgr_client) {
120                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] A manager client is already exist.");
121                 return VC_ERROR_NONE;
122         }
123
124         g_mgr_client = (vc_mgr_client_s*)calloc(1, sizeof(vc_mgr_client_s));
125         if (NULL == g_mgr_client) {
126                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to allocate memory");
127                 return VC_ERROR_OUT_OF_MEMORY;
128         }
129
130         /* initialize client data */
131         g_mgr_client->pid = getpid();
132
133         g_mgr_client->all_result_cb = NULL;
134         g_mgr_client->all_result_user_data = NULL;
135         g_mgr_client->result_cb = NULL;
136         g_mgr_client->result_user_data = NULL;
137         g_mgr_client->pre_result_cb = NULL;
138         g_mgr_client->pre_result_user_data = NULL;
139
140         g_mgr_client->error_cb = NULL;
141         g_mgr_client->error_user_data = NULL;
142         g_mgr_client->service_state_changed_cb = NULL;
143         g_mgr_client->service_state_changed_user_data = NULL;
144         g_mgr_client->state_changed_cb = NULL;
145         g_mgr_client->state_changed_user_data = NULL;
146         g_mgr_client->speech_detected_cb = NULL;
147         g_mgr_client->speech_detected_user_data = NULL;
148         g_mgr_client->current_lang_changed_cb = NULL;
149         g_mgr_client->current_lang_changed_user_data = NULL;
150         g_mgr_client->dialog_request_cb = NULL;
151         g_mgr_client->dialog_request_user_data = NULL;
152         g_mgr_client->private_data_set_cb = NULL;
153         g_mgr_client->private_data_set_user_data = NULL;
154         g_mgr_client->private_data_requested_cb = NULL;
155         g_mgr_client->private_data_requested_user_data = NULL;
156         g_mgr_client->specific_engine_result_cb = NULL;
157         g_mgr_client->specific_engine_result_user_data = NULL;
158
159         g_mgr_client->feedback_audio_format_cb = NULL;
160         g_mgr_client->feedback_audio_format_user_data = NULL;
161         g_mgr_client->feedback_streaming_cb = NULL;
162         g_mgr_client->feedback_streaming_user_data = NULL;
163         g_mgr_client->vc_tts_streaming_cb = NULL;
164         g_mgr_client->vc_tts_streaming_user_data = NULL;
165
166         g_mgr_client->exclusive_cmd_option = false;
167
168         g_mgr_client->all_result_event = 0;
169         g_mgr_client->all_result_text = NULL;
170
171         g_mgr_client->result_event = -1;
172         g_mgr_client->result_text = NULL;
173
174         g_mgr_client->service_state = VC_SERVICE_STATE_NONE;
175
176         g_mgr_client->internal_state = VC_INTERNAL_STATE_NONE;
177
178         g_mgr_client->previous_state = VC_STATE_INITIALIZED;
179         g_mgr_client->current_state = VC_STATE_INITIALIZED;
180
181         g_mgr_client->previous_language = NULL;
182         g_mgr_client->current_language = NULL;
183
184         g_mgr_client->audio_id = NULL;
185         g_mgr_client->recognition_mode = VC_RECOGNITION_MODE_STOP_BY_SILENCE;
186
187         g_mgr_client->reason = 0;
188         g_mgr_client->err_msg = NULL;
189
190         g_mgr_client->cb_ref_count = 0;
191
192         g_mgr_client->disabled_cmd_type = 0x00;
193
194         /* Authority */
195         g_mgr_client->authorized_client_list = NULL;
196         g_mgr_client->valid_authorized_pid = -1;
197         g_mgr_client->start_by_client = false;
198
199         g_mgr_client->foreground_pid = VC_RUNTIME_INFO_NO_FOREGROUND;
200
201         g_mgr_client->streaming_mode = VC_AUDIO_STREAMING_MODE_VC_SERVICE;
202
203         return VC_ERROR_NONE;
204 }
205
206 int vc_mgr_client_destroy()
207 {
208         if (NULL == g_mgr_client) {
209                 SLOG(LOG_ERROR, TAG_VCM, "A manager client is already NULL"); //LCOV_EXCL_LINE
210                 return VC_ERROR_NONE;
211         }
212
213         while (0 != g_mgr_client->cb_ref_count) {
214                 /* wait for release callback function */
215                 usleep(10000);
216         }
217
218         if (NULL != g_mgr_client->audio_id) {
219                 free(g_mgr_client->audio_id);
220         }
221
222         if (NULL != g_mgr_client->all_result_text) {
223                 free(g_mgr_client->all_result_text);
224         }
225
226         if (NULL != g_mgr_client->err_msg) {
227                 free(g_mgr_client->err_msg);
228         }
229
230         free(g_mgr_client);
231         g_mgr_client = NULL;
232
233         return VC_ERROR_NONE;
234 }
235
236 bool vc_mgr_client_is_valid()
237 {
238         /* check handle */
239         if (NULL == g_mgr_client) {
240                 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] manager client not allocated");
241                 return false;
242         }
243
244         return true;
245 }
246
247 int vc_mgr_client_get_pid(int* pid)
248 {
249         /* check handle */
250         if (NULL == g_mgr_client) {
251                 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] manager client not allocated");
252                 return VC_ERROR_OPERATION_FAILED;
253         }
254
255         *pid = g_mgr_client->pid;
256         return VC_ERROR_NONE;
257 }
258
259 /* set/get callback function */
260 int vc_mgr_client_set_all_result_cb(vc_mgr_all_result_cb callback, void* user_data)
261 {
262         /* check handle */
263         if (NULL == g_mgr_client)
264                 return VC_ERROR_OPERATION_FAILED;
265
266         g_mgr_client->all_result_cb = callback;
267         g_mgr_client->all_result_user_data = user_data;
268
269         return VC_ERROR_NONE;
270 }
271
272 int vc_mgr_client_get_all_result_cb(vc_mgr_all_result_cb* callback, void** user_data)
273 {
274         /* check handle */
275         if (NULL == g_mgr_client)
276                 return VC_ERROR_OPERATION_FAILED;
277
278         *callback = g_mgr_client->all_result_cb;
279         *user_data = g_mgr_client->all_result_user_data;
280
281         return VC_ERROR_NONE;
282 }
283
284 int vc_mgr_client_set_result_cb(vc_result_cb callback, void* user_data)
285 {
286         /* check handle */
287         if (NULL == g_mgr_client)
288                 return VC_ERROR_OPERATION_FAILED;
289
290         g_mgr_client->result_cb = callback;
291         g_mgr_client->result_user_data = user_data;
292
293         return VC_ERROR_NONE;
294 }
295
296 int vc_mgr_client_get_result_cb(vc_result_cb* callback, void** user_data)
297 {
298         /* check handle */
299         if (NULL == g_mgr_client)
300                 return VC_ERROR_OPERATION_FAILED;
301
302         *callback = g_mgr_client->result_cb;
303         *user_data = g_mgr_client->result_user_data;
304
305         return VC_ERROR_NONE;
306 }
307
308 int vc_mgr_client_set_pre_result_cb(vc_mgr_pre_result_cb callback, void* user_data)
309 {
310         /* check handle */
311         if (NULL == g_mgr_client)
312                 return VC_ERROR_OPERATION_FAILED;
313
314         g_mgr_client->pre_result_cb = callback;
315         g_mgr_client->pre_result_user_data = user_data;
316
317         return VC_ERROR_NONE;
318 }
319
320 int vc_mgr_client_get_pre_result_cb(vc_mgr_pre_result_cb* callback, void** user_data)
321 {
322         /* check handle */
323         if (NULL == g_mgr_client)
324                 return VC_ERROR_OPERATION_FAILED;
325
326         *callback = g_mgr_client->pre_result_cb;
327         *user_data = g_mgr_client->pre_result_user_data;
328
329         return VC_ERROR_NONE;
330 }
331
332 int vc_mgr_client_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
333 {
334         /* check handle */
335         if (NULL == g_mgr_client)
336                 return VC_ERROR_OPERATION_FAILED;
337
338         g_mgr_client->service_state_changed_cb = callback;
339         g_mgr_client->service_state_changed_user_data = user_data;
340
341         return VC_ERROR_NONE;
342 }
343
344 int vc_mgr_client_get_service_state_changed_cb(vc_service_state_changed_cb* callback, void** user_data)
345 {
346         /* check handle */
347         if (NULL == g_mgr_client)
348                 return VC_ERROR_OPERATION_FAILED;
349
350         *callback = g_mgr_client->service_state_changed_cb;
351         *user_data = g_mgr_client->service_state_changed_user_data;
352
353         return VC_ERROR_NONE;
354 }
355
356 int vc_mgr_client_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
357 {
358         /* check handle */
359         if (NULL == g_mgr_client)
360                 return VC_ERROR_OPERATION_FAILED;
361
362         g_mgr_client->state_changed_cb = callback;
363         g_mgr_client->state_changed_user_data = user_data;
364
365         return VC_ERROR_NONE;
366 }
367
368 int vc_mgr_client_get_state_changed_cb(vc_state_changed_cb* callback, void** user_data)
369 {
370         /* check handle */
371         if (NULL == g_mgr_client)
372                 return VC_ERROR_OPERATION_FAILED;
373
374         *callback = g_mgr_client->state_changed_cb;
375         *user_data = g_mgr_client->state_changed_user_data;
376
377         return VC_ERROR_NONE;
378 }
379
380 int vc_mgr_client_set_speech_detected_cb(vc_mgr_begin_speech_detected_cb callback, void* user_data)
381 {
382         /* check handle */
383         if (NULL == g_mgr_client)
384                 return VC_ERROR_OPERATION_FAILED;
385
386         g_mgr_client->speech_detected_cb = callback;
387         g_mgr_client->speech_detected_user_data = user_data;
388
389         return VC_ERROR_NONE;
390 }
391
392 int vc_mgr_client_get_speech_detected_cb(vc_mgr_begin_speech_detected_cb* callback, void** user_data)
393 {
394         /* check handle */
395         if (NULL == g_mgr_client)
396                 return VC_ERROR_OPERATION_FAILED;
397
398         *callback = g_mgr_client->speech_detected_cb;
399         *user_data = g_mgr_client->speech_detected_user_data;
400
401         return VC_ERROR_NONE;
402 }
403
404 int vc_mgr_client_set_current_lang_changed_cb(vc_current_language_changed_cb callback, void* user_data)
405 {
406         /* check handle */
407         if (NULL == g_mgr_client)
408                 return VC_ERROR_OPERATION_FAILED;
409
410         g_mgr_client->current_lang_changed_cb = callback;
411         g_mgr_client->current_lang_changed_user_data = user_data;
412
413         return VC_ERROR_NONE;
414 }
415
416 int vc_mgr_client_get_current_lang_changed_cb(vc_current_language_changed_cb* callback, void** user_data)
417 {
418         /* check handle */
419         if (NULL == g_mgr_client)
420                 return VC_ERROR_OPERATION_FAILED;
421
422         *callback = g_mgr_client->current_lang_changed_cb;
423         *user_data = g_mgr_client->current_lang_changed_user_data;
424
425         return VC_ERROR_NONE;
426 }
427
428 int vc_mgr_client_set_error_cb(vc_error_cb callback, void* user_data)
429 {
430         /* check handle */
431         if (NULL == g_mgr_client)
432                 return VC_ERROR_OPERATION_FAILED;
433
434         g_mgr_client->error_cb = callback;
435         g_mgr_client->error_user_data = user_data;
436
437         return VC_ERROR_NONE;
438 }
439
440 int vc_mgr_client_get_error_cb(vc_error_cb* callback, void** user_data)
441 {
442         /* check handle */
443         if (NULL == g_mgr_client)
444                 return VC_ERROR_OPERATION_FAILED;
445
446         *callback = g_mgr_client->error_cb;
447         *user_data = g_mgr_client->error_user_data;
448
449         return VC_ERROR_NONE;
450 }
451
452 int vc_mgr_client_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_data)
453 {
454         /* check handle */
455         if (NULL == g_mgr_client)
456                 return VC_ERROR_OPERATION_FAILED;
457
458         g_mgr_client->dialog_request_cb = callback;
459         g_mgr_client->dialog_request_user_data = user_data;
460
461         return VC_ERROR_NONE;
462 }
463
464 int vc_mgr_client_get_dialog_request_cb(vc_mgr_dialog_request_cb* callback, void** user_data)
465 {
466         /* check handle */
467         if (NULL == g_mgr_client)
468                 return VC_ERROR_OPERATION_FAILED;
469
470         *callback = g_mgr_client->dialog_request_cb;
471         *user_data = g_mgr_client->dialog_request_user_data;
472
473         return VC_ERROR_NONE;
474 }
475
476
477 int vc_mgr_client_set_private_data_set_cb(vc_mgr_private_data_set_cb callback, void* user_data)
478 {
479         /* check handle */
480         if (NULL == g_mgr_client)
481                 return VC_ERROR_OPERATION_FAILED;
482
483         g_mgr_client->private_data_set_cb = callback;
484         g_mgr_client->private_data_set_user_data = user_data;
485
486         return VC_ERROR_NONE;
487 }
488
489 int vc_mgr_client_get_private_data_set_cb(vc_mgr_private_data_set_cb* callback, void** user_data)
490 {
491         /* check handle */
492         if (NULL == g_mgr_client)
493                 return VC_ERROR_OPERATION_FAILED;
494
495         *callback = g_mgr_client->private_data_set_cb;
496         *user_data = g_mgr_client->private_data_set_user_data;
497
498         return VC_ERROR_NONE;
499 }
500
501 int vc_mgr_client_set_private_data_requested_cb(vc_mgr_private_data_requested_cb callback, void* user_data)
502 {
503         /* check handle */
504         if (NULL == g_mgr_client)
505                 return VC_ERROR_OPERATION_FAILED;
506
507         g_mgr_client->private_data_requested_cb = callback;
508         g_mgr_client->private_data_requested_user_data = user_data;
509
510         return VC_ERROR_NONE;
511 }
512
513 int vc_mgr_client_get_private_data_requested_cb(vc_mgr_private_data_requested_cb* callback, void** user_data)
514 {
515         /* check handle */
516         if (NULL == g_mgr_client)
517                 return VC_ERROR_OPERATION_FAILED;
518
519         *callback = g_mgr_client->private_data_requested_cb;
520         *user_data = g_mgr_client->private_data_requested_user_data;
521
522         return VC_ERROR_NONE;
523 }
524
525 int vc_mgr_client_set_feedback_audio_format_cb(vc_mgr_feedback_audio_format_cb callback, void* user_data)
526 {
527         /* check handle */
528         if (NULL == g_mgr_client)
529                 return VC_ERROR_OPERATION_FAILED;
530
531         g_mgr_client->feedback_audio_format_cb = callback;
532         g_mgr_client->feedback_audio_format_user_data = user_data;
533
534         return VC_ERROR_NONE;
535 }
536
537 int vc_mgr_client_get_feedback_audio_format_cb(vc_mgr_feedback_audio_format_cb* callback, void** user_data)
538 {
539         /* check handle */
540         if (NULL == g_mgr_client)
541                 return VC_ERROR_OPERATION_FAILED;
542
543         *callback = g_mgr_client->feedback_audio_format_cb;
544         *user_data = g_mgr_client->feedback_audio_format_user_data;
545
546         return VC_ERROR_NONE;
547 }
548
549 int vc_mgr_client_set_feedback_streaming_cb(vc_mgr_feedback_streaming_cb callback, void* user_data)
550 {
551         /* check handle */
552         if (NULL == g_mgr_client)
553                 return VC_ERROR_OPERATION_FAILED;
554
555         g_mgr_client->feedback_streaming_cb = callback;
556         g_mgr_client->feedback_streaming_user_data = user_data;
557
558         return VC_ERROR_NONE;
559 }
560
561 int vc_mgr_client_get_feedback_streaming_cb(vc_mgr_feedback_streaming_cb* callback, void** user_data)
562 {
563         /* check handle */
564         if (NULL == g_mgr_client)
565                 return VC_ERROR_OPERATION_FAILED;
566
567         *callback = g_mgr_client->feedback_streaming_cb;
568         *user_data = g_mgr_client->feedback_streaming_user_data;
569
570         return VC_ERROR_NONE;
571 }
572
573 int vc_mgr_client_set_vc_tts_streaming_cb(vc_mgr_vc_tts_streaming_cb callback, void* user_data)
574 {
575         /* check handle */
576         if (NULL == g_mgr_client)
577                 return VC_ERROR_OPERATION_FAILED;
578
579         g_mgr_client->vc_tts_streaming_cb = callback;
580         g_mgr_client->vc_tts_streaming_user_data = user_data;
581
582         return VC_ERROR_NONE;
583 }
584
585 int vc_mgr_client_get_vc_tts_streaming_cb(vc_mgr_vc_tts_streaming_cb* callback, void** user_data)
586 {
587         /* check handle */
588         if (NULL == g_mgr_client)
589                 return VC_ERROR_OPERATION_FAILED;
590
591         *callback = g_mgr_client->vc_tts_streaming_cb;
592         *user_data = g_mgr_client->vc_tts_streaming_user_data;
593
594         return VC_ERROR_NONE;
595 }
596
597 /* set/get option */
598 int vc_mgr_client_set_service_state(vc_service_state_e state)
599 {
600         /* check handle */
601         if (NULL == g_mgr_client)
602                 return VC_ERROR_OPERATION_FAILED;
603
604         g_mgr_client->service_state = state;
605
606         return VC_ERROR_NONE;
607 }
608
609 int vc_mgr_client_get_service_state(vc_service_state_e* state)
610 {
611         /* check handle */
612         if (NULL == g_mgr_client)
613                 return VC_ERROR_OPERATION_FAILED;
614
615         *state = g_mgr_client->service_state;
616
617         return VC_ERROR_NONE;
618 }
619
620 int vc_mgr_client_set_internal_state(vc_internal_state_e state)
621 {
622         /* check handle */
623         if (NULL == g_mgr_client)
624                 return VC_ERROR_OPERATION_FAILED;
625
626         g_mgr_client->internal_state = state;
627
628         return VC_ERROR_NONE;
629 }
630
631 int vc_mgr_client_get_internal_state(vc_internal_state_e* state)
632 {
633         /* check handle */
634         if (NULL == g_mgr_client)
635                 return VC_ERROR_OPERATION_FAILED;
636
637         *state = g_mgr_client->internal_state;
638
639         return VC_ERROR_NONE;
640 }
641
642 int vc_mgr_client_set_client_state(vc_state_e state)
643 {
644         /* check handle */
645         if (NULL == g_mgr_client)
646                 return VC_ERROR_OPERATION_FAILED;
647
648         g_mgr_client->previous_state = g_mgr_client->current_state;
649         g_mgr_client->current_state = state;
650
651         return VC_ERROR_NONE;
652 }
653
654 int vc_mgr_client_get_client_state(vc_state_e* state)
655 {
656         /* check handle */
657         if (NULL == g_mgr_client)
658                 return VC_ERROR_OPERATION_FAILED;
659
660         *state = g_mgr_client->current_state;
661
662         return VC_ERROR_NONE;
663 }
664
665 int vc_mgr_client_get_previous_state(vc_state_e* state, vc_state_e* previous_state)
666 {
667         /* check handle */
668         if (NULL == g_mgr_client)
669                 return VC_ERROR_OPERATION_FAILED;
670
671         *previous_state = g_mgr_client->previous_state;
672         *state = g_mgr_client->current_state;
673
674         return VC_ERROR_NONE;
675 }
676
677 int vc_mgr_client_set_error(int reason)
678 {
679         /* check handle */
680         if (NULL == g_mgr_client)
681                 return VC_ERROR_OPERATION_FAILED;
682
683         g_mgr_client->reason = reason;
684
685         return VC_ERROR_NONE;
686 }
687
688 int vc_mgr_client_get_error(int* reason)
689 {
690         /* check handle */
691         if (NULL == g_mgr_client)
692                 return VC_ERROR_OPERATION_FAILED;
693
694         *reason = g_mgr_client->reason;
695
696         return VC_ERROR_NONE;
697 }
698
699 int vc_mgr_client_set_error_message(const char* err_msg)
700 {
701         /* check handle */
702         if (NULL == g_mgr_client)
703                 return VC_ERROR_OPERATION_FAILED;
704
705         if (NULL != g_mgr_client->err_msg) {
706                 free(g_mgr_client->err_msg);
707                 g_mgr_client->err_msg = NULL;
708         }
709
710         if (NULL != err_msg) {
711                 g_mgr_client->err_msg = strdup(err_msg);
712                 if (NULL == g_mgr_client->err_msg) {
713                         return VC_ERROR_OUT_OF_MEMORY;
714                 }
715         }
716
717         return VC_ERROR_NONE;
718 }
719
720 int vc_mgr_client_get_error_message(char** err_msg)
721 {
722         /* check handle */
723         if (NULL == g_mgr_client)
724                 return VC_ERROR_OPERATION_FAILED;
725
726         if (NULL != g_mgr_client->err_msg) {
727                 *err_msg = strdup(g_mgr_client->err_msg);
728                 if (NULL == *err_msg) {
729                         return VC_ERROR_OUT_OF_MEMORY;
730                 }
731         }
732
733         return VC_ERROR_NONE;
734 }
735
736 int vc_mgr_client_enable_command_type(vc_cmd_type_e cmd_type)
737 {
738         SLOG(LOG_INFO, TAG_VCM, "[Manager INFO] enable command type (%d)", cmd_type);
739
740         /* check handle */
741         if (NULL == g_mgr_client)
742                 return VC_ERROR_OPERATION_FAILED;
743
744         g_mgr_client->disabled_cmd_type &= ~(1 << cmd_type);
745
746         return VC_ERROR_NONE;
747 }
748
749 int vc_mgr_client_disable_command_type(vc_cmd_type_e cmd_type)
750 {
751         SLOG(LOG_INFO, TAG_VCM, "[Manager INFO] disable command type (%d)", cmd_type);
752
753         /* check handle */
754         if (NULL == g_mgr_client)
755                 return VC_ERROR_OPERATION_FAILED;
756
757         g_mgr_client->disabled_cmd_type |= (1 << cmd_type);
758
759         return VC_ERROR_NONE;
760 }
761
762 int vc_mgr_client_get_disabled_command_type(int* disabled_cmd_type)
763 {
764         SLOG(LOG_INFO, TAG_VCM, "[Manager INFO] get disabled command type");
765
766         /* check handle */
767         if (NULL == g_mgr_client)
768                 return VC_ERROR_OPERATION_FAILED;
769
770         *disabled_cmd_type = g_mgr_client->disabled_cmd_type;
771
772         return VC_ERROR_NONE;
773 }
774
775 int vc_mgr_client_set_exclusive_command(bool value)
776 {
777         /* check handle */
778         if (NULL == g_mgr_client)
779                 return VC_ERROR_OPERATION_FAILED;
780
781         g_mgr_client->exclusive_cmd_option = value;
782
783         return VC_ERROR_NONE;
784 }
785
786 bool vc_mgr_client_get_exclusive_command()
787 {
788         /* check handle */
789         if (NULL == g_mgr_client)
790                 return VC_ERROR_OPERATION_FAILED;
791
792         return g_mgr_client->exclusive_cmd_option;
793 }
794
795 int vc_mgr_client_set_all_result(int event, const char* result_text)
796 {
797         /* check handle */
798         if (NULL == g_mgr_client)
799                 return VC_ERROR_OPERATION_FAILED;
800
801         g_mgr_client->all_result_event = event;
802
803         if (NULL != g_mgr_client->all_result_text) {
804                 free(g_mgr_client->all_result_text);
805                 g_mgr_client->all_result_text = NULL;
806         }
807         if (NULL != result_text) {
808                 g_mgr_client->all_result_text = strdup(result_text);
809         }
810
811         return VC_ERROR_NONE;
812 }
813
814 int vc_mgr_client_get_all_result(int* event, char** result_text)
815 {
816         /* check handle */
817         if (NULL == g_mgr_client)
818                 return VC_ERROR_OPERATION_FAILED;
819
820         *event = g_mgr_client->all_result_event;
821         if (NULL != result_text) {
822                 if (NULL != g_mgr_client->all_result_text) {
823                         *result_text = strdup(g_mgr_client->all_result_text);
824                 }
825         }
826
827         return VC_ERROR_NONE;
828 }
829
830 int vc_mgr_client_unset_all_result()
831 {
832         /* check handle */
833         if (NULL == g_mgr_client)
834                 return VC_ERROR_OPERATION_FAILED;
835
836         g_mgr_client->all_result_event = -1;
837
838         if (NULL != g_mgr_client->all_result_text) {
839                 free(g_mgr_client->all_result_text);
840                 g_mgr_client->all_result_text = NULL;
841         }
842
843         return VC_ERROR_NONE;
844 }
845
846 int vc_mgr_client_set_audio_type(const char* audio_id)
847 {
848         /* check handle */
849         if (NULL == g_mgr_client)
850                 return VC_ERROR_OPERATION_FAILED;
851
852         if (NULL != audio_id) {
853                 if (NULL != g_mgr_client->audio_id) {
854                         free(g_mgr_client->audio_id);
855                         g_mgr_client->audio_id = NULL;
856                 }
857                 g_mgr_client->audio_id = strdup(audio_id);
858         }
859
860         return VC_ERROR_NONE;
861 }
862
863 int vc_mgr_client_get_audio_type(char** audio_id)
864 {
865         if (NULL == audio_id)   {
866                 return VC_ERROR_INVALID_PARAMETER;
867         }
868
869         /* check handle */
870         if (NULL == g_mgr_client)
871                 return VC_ERROR_OPERATION_FAILED;
872
873         if (NULL != g_mgr_client->audio_id)
874                 *audio_id = strdup(g_mgr_client->audio_id);
875         else
876                 *audio_id = NULL;
877
878         return VC_ERROR_NONE;
879 }
880
881 int vc_mgr_client_set_recognition_mode(vc_recognition_mode_e mode)
882 {
883         /* check handle */
884         if (NULL == g_mgr_client)
885                 return VC_ERROR_OPERATION_FAILED;
886
887         g_mgr_client->recognition_mode = mode;
888
889         return VC_ERROR_NONE;
890 }
891
892 int vc_mgr_client_get_recognition_mode(vc_recognition_mode_e* mode)
893 {
894         if (NULL == mode) {
895                 return VC_ERROR_INVALID_PARAMETER;
896         }
897
898         /* check handle */
899         if (NULL == g_mgr_client)
900                 return VC_ERROR_OPERATION_FAILED;
901
902         *mode = g_mgr_client->recognition_mode;
903         return VC_ERROR_NONE;
904 }
905
906 int vc_mgr_client_set_foreground(int pid, bool value)
907 {
908         /* check handle */
909         if (NULL == g_mgr_client)
910                 return VC_ERROR_OPERATION_FAILED;
911
912         if (true == value) {
913                 g_mgr_client->foreground_pid = pid;
914         } else {
915                 if (pid == g_mgr_client->foreground_pid) {
916                         g_mgr_client->foreground_pid = VC_RUNTIME_INFO_NO_FOREGROUND;
917                 }
918         }
919
920         return VC_ERROR_NONE;
921 }
922
923 int vc_mgr_client_get_foreground(int* pid)
924 {
925         /* check handle */
926         if (NULL == g_mgr_client)
927                 return VC_ERROR_OPERATION_FAILED;
928
929         *pid = g_mgr_client->foreground_pid;
930         return VC_ERROR_NONE;
931 }
932
933 /* utils */
934 int vc_mgr_client_use_callback()
935 {
936         /* check handle */
937         if (NULL == g_mgr_client)
938                 return VC_ERROR_OPERATION_FAILED;
939
940         g_mgr_client->cb_ref_count++;
941         return VC_ERROR_NONE;
942 }
943
944 int vc_mgr_client_not_use_callback()
945 {
946         /* check handle */
947         if (NULL == g_mgr_client)
948                 return VC_ERROR_OPERATION_FAILED;
949
950         g_mgr_client->cb_ref_count--;
951         return VC_ERROR_NONE;
952 }
953
954 /* Authority */
955 int vc_mgr_client_add_authorized_client(int pid)
956 {
957         /* check handle */
958         if (NULL == g_mgr_client)
959                 return VC_ERROR_OPERATION_FAILED;
960
961         vc_authorized_client_s *authorized_client = NULL;
962
963         authorized_client = (vc_authorized_client_s*)calloc(1, sizeof(vc_authorized_client_s));
964         if (NULL == authorized_client) {
965                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to make authorized client");
966                 return VC_ERROR_OPERATION_FAILED;
967         }
968
969         authorized_client->pid = pid;
970
971         g_mgr_client->authorized_client_list = g_slist_append(g_mgr_client->authorized_client_list, authorized_client);
972
973         SLOG(LOG_DEBUG, TAG_VCM, "Add authorized client - %d", pid);
974
975         return VC_ERROR_NONE;
976 }
977
978 int vc_mgr_client_remove_authorized_client(int pid)
979 {
980         /* check handle */
981         if (NULL == g_mgr_client)
982                 return VC_ERROR_OPERATION_FAILED;
983
984         vc_authorized_client_s *data = NULL;
985
986         int count = g_slist_length(g_mgr_client->authorized_client_list);
987         int i;
988
989         for (i = 0; i < count; i++) {
990                 data = g_slist_nth_data(g_mgr_client->authorized_client_list, i);
991
992                 if (NULL != data) {
993                         if (pid == data->pid) {
994                                 g_mgr_client->authorized_client_list = g_slist_remove(g_mgr_client->authorized_client_list, data);
995
996                                 free(data);
997                                 data = NULL;
998
999                                 SLOG(LOG_DEBUG, TAG_VCM, "Remove authorized client - %d", pid);
1000                                 return VC_ERROR_NONE;
1001                         }
1002                 }
1003         }
1004
1005         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] client Not found");
1006
1007         return VC_ERROR_OPERATION_FAILED;
1008 }
1009
1010 bool vc_mgr_client_is_authorized_client(int pid)
1011 {
1012         /* check handle */
1013         if (NULL == g_mgr_client)
1014                 return VC_ERROR_OPERATION_FAILED;
1015
1016         vc_authorized_client_s *data = NULL;
1017
1018         int count = g_slist_length(g_mgr_client->authorized_client_list);
1019         int i;
1020
1021         for (i = 0; i < count; i++) {
1022                 data = g_slist_nth_data(g_mgr_client->authorized_client_list, i);
1023
1024                 if (NULL != data) {
1025                         if (pid == data->pid) {
1026                                 SLOG(LOG_DEBUG, TAG_VCM, "Authorized client - %d", pid);
1027                                 return true;
1028                         }
1029                 }
1030         }
1031
1032         SLOG(LOG_DEBUG, TAG_VCM, "Un-Authorized client - %d", pid);
1033
1034         return false;
1035 }
1036
1037 int vc_mgr_client_set_valid_authorized_client(int pid)
1038 {
1039         /* check handle */
1040         if (NULL == g_mgr_client)
1041                 return VC_ERROR_OPERATION_FAILED;
1042
1043         g_mgr_client->valid_authorized_pid = pid;
1044
1045         return VC_ERROR_NONE;
1046 }
1047
1048 int vc_mgr_client_get_valid_authorized_client(int* pid)
1049 {
1050         /* check handle */
1051         if (NULL == g_mgr_client)
1052                 return VC_ERROR_OPERATION_FAILED;
1053
1054         *pid = g_mgr_client->valid_authorized_pid;
1055
1056         return VC_ERROR_NONE;
1057 }
1058
1059 bool vc_mgr_client_is_valid_authorized_client(int pid)
1060 {
1061         /* check handle */
1062         if (NULL == g_mgr_client)
1063                 return VC_ERROR_OPERATION_FAILED;
1064
1065         if (pid == g_mgr_client->valid_authorized_pid)
1066                 return true;
1067         else
1068                 return false;
1069 }
1070
1071 int vc_mgr_client_set_start_by_client(bool option)
1072 {
1073         /* check handle */
1074         if (NULL == g_mgr_client)
1075                 return VC_ERROR_OPERATION_FAILED;
1076
1077         g_mgr_client->start_by_client = option;
1078
1079         return VC_ERROR_NONE;
1080 }
1081
1082 int vc_mgr_client_get_start_by_client(bool* option)
1083 {
1084         /* check handle */
1085         if (NULL == g_mgr_client)
1086                 return VC_ERROR_OPERATION_FAILED;
1087
1088         *option = g_mgr_client->start_by_client;
1089
1090         return VC_ERROR_NONE;
1091 }
1092
1093 int vc_mgr_client_set_specific_engine_result_cb(vc_mgr_specific_engine_result_cb callback, void* user_data)
1094 {
1095         /* check handle */
1096         if (NULL == g_mgr_client)
1097                 return VC_ERROR_OPERATION_FAILED;
1098
1099         g_mgr_client->specific_engine_result_cb = callback;
1100         g_mgr_client->specific_engine_result_user_data = user_data;
1101
1102         return VC_ERROR_NONE;
1103 }
1104
1105 int vc_mgr_client_get_specific_engine_result_cb(vc_mgr_specific_engine_result_cb* callback, void** user_data)
1106 {
1107         /* check handle */
1108         if (NULL == g_mgr_client)
1109                 return VC_ERROR_OPERATION_FAILED;
1110
1111         *callback = g_mgr_client->specific_engine_result_cb;
1112         *user_data = g_mgr_client->specific_engine_result_user_data;
1113
1114         return VC_ERROR_NONE;
1115 }
1116
1117 int vc_mgr_client_set_audio_streaming_mode(vc_audio_streaming_mode_e streaming_mode)
1118 {
1119         /* check handle */
1120         if (NULL == g_mgr_client)
1121                 return VC_ERROR_OPERATION_FAILED;
1122
1123         g_mgr_client->streaming_mode = streaming_mode;
1124
1125         return VC_ERROR_NONE;
1126 }
1127
1128 int vc_mgr_client_get_audio_streaming_mode(vc_audio_streaming_mode_e* streaming_mode)
1129 {
1130         /* check handle */
1131         if (NULL == g_mgr_client)
1132                 return VC_ERROR_OPERATION_FAILED;
1133
1134         *streaming_mode = g_mgr_client->streaming_mode;
1135
1136         return VC_ERROR_NONE;
1137 }