Add to set playing mode to decide where the synthesized pcm data will be played
[platform/core/uifw/tts.git] / client / tts_client.c
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #include "tts_client.h"
16
17 /* Constant value */
18 static const int MAX_HANDLE_NUM = 999;
19 static const int INVALID_HANDLE = -1;
20
21 /* allocated handle */
22 static unsigned int g_allocated_handle = 0;
23 /* client list */
24 static GList *g_client_list = NULL;
25
26 /* pthread mutex */
27 static pthread_mutex_t g_allocated_handle_mutex = PTHREAD_MUTEX_INITIALIZER;
28 static pthread_mutex_t g_client_list_mutex = PTHREAD_MUTEX_INITIALIZER;
29 static pthread_mutex_t g_repeat_text_mutex = PTHREAD_MUTEX_INITIALIZER;
30
31
32 static unsigned int __client_generate_uid(unsigned int pid)
33 {
34         pthread_mutex_lock(&g_allocated_handle_mutex);
35         g_allocated_handle++;
36
37         if (g_allocated_handle > MAX_HANDLE_NUM) {
38                 g_allocated_handle = 1;
39         }
40
41         /* generate uid, handle number should be smaller than 1000 */
42         unsigned int uid = pid * 1000u + g_allocated_handle;
43         pthread_mutex_unlock(&g_allocated_handle_mutex);
44
45         return uid;
46 }
47
48 static inline void __set_state_changed_cb(tts_client_s* client, tts_state_changed_cb callback, void* user_data)
49 {
50         if (callback != NULL) {
51                 client->registered_event_mask |= TTS_EVENT_MASK_STATE_CHANGED;
52         } else {
53                 client->registered_event_mask &= ~TTS_EVENT_MASK_STATE_CHANGED;
54         }
55
56         client->state_changed_cb = callback;
57         client->state_changed_user_data = user_data;
58 }
59
60 static inline void __set_utterance_started_cb(tts_client_s* client, tts_utterance_started_cb callback, void* user_data)
61 {
62         if (callback != NULL) {
63                 client->registered_event_mask |= TTS_EVENT_MASK_UTTERANCE_STARTED;
64         } else {
65                 client->registered_event_mask &= ~TTS_EVENT_MASK_UTTERANCE_STARTED;
66         }
67
68         client->utt_started_cb = callback;
69         client->utt_started_user_data = user_data;
70 }
71
72 static inline void __set_utterance_completed_cb(tts_client_s* client, tts_utterance_completed_cb callback, void* user_data)
73 {
74         if (callback != NULL) {
75                 client->registered_event_mask |= TTS_EVENT_MASK_UTTERANCE_COMPLETED;
76         } else {
77                 client->registered_event_mask &= ~TTS_EVENT_MASK_UTTERANCE_COMPLETED;
78         }
79
80         client->utt_completed_cb = callback;
81         client->utt_completed_user_data = user_data;
82 }
83
84 static inline void __set_error_cb(tts_client_s* client, tts_error_cb callback, void* user_data)
85 {
86         if (callback != NULL) {
87                 client->registered_event_mask |= TTS_EVENT_MASK_ERROR;
88         } else {
89                 client->registered_event_mask &= ~TTS_EVENT_MASK_ERROR;
90         }
91
92         client->error_cb = callback;
93         client->error_user_data = user_data;
94 }
95
96 static inline void __set_default_voice_changed_cb(tts_client_s* client, tts_default_voice_changed_cb callback, void* user_data)
97 {
98         if (callback != NULL) {
99                 client->registered_event_mask |= TTS_EVENT_MASK_DEFAULT_VOICE_CHANGED;
100         } else {
101                 client->registered_event_mask &= ~TTS_EVENT_MASK_DEFAULT_VOICE_CHANGED;
102         }
103
104         client->default_voice_changed_cb = callback;
105         client->default_voice_changed_user_data = user_data;
106 }
107
108 static inline void __set_engine_changed_cb(tts_client_s* client, tts_engine_changed_cb callback, void* user_data)
109 {
110         if (callback != NULL) {
111                 client->registered_event_mask |= TTS_EVENT_MASK_ENGINE_CHANGED;
112         } else {
113                 client->registered_event_mask &= ~TTS_EVENT_MASK_ENGINE_CHANGED;
114         }
115
116         client->engine_changed_cb = callback;
117         client->engine_changed_user_data = user_data;
118 }
119
120 static inline void __set_screen_reader_changed_cb(tts_client_s* client, tts_screen_reader_changed_cb callback, void* user_data)
121 {
122         if (callback != NULL) {
123                 client->registered_event_mask |= TTS_EVENT_MASK_SCREEN_READER_CHANGED;
124         } else {
125                 client->registered_event_mask &= ~TTS_EVENT_MASK_SCREEN_READER_CHANGED;
126         }
127
128         client->screen_reader_changed_cb = callback;
129         client->screen_reader_changed_user_data = user_data;
130 }
131
132 static inline void __set_supported_voice_cb(tts_client_s* client, tts_supported_voice_cb callback, void* user_data)
133 {
134         client->supported_voice_cb = callback;
135         client->supported_voice_user_data = user_data;
136 }
137
138 static inline void __set_service_state_changed_cb(tts_client_s* client, tts_service_state_changed_cb callback, void* user_data)
139 {
140         if (callback != NULL) {
141                 client->registered_event_mask |= TTS_EVENT_MASK_SERVICE_STATE_CHANGED;
142         } else {
143                 client->registered_event_mask &= ~TTS_EVENT_MASK_SERVICE_STATE_CHANGED;
144         }
145
146         client->service_state_changed_cb = callback;
147         client->service_state_changed_user_data = user_data;
148 }
149
150 static inline void __set_synthesized_pcm_cb(tts_client_s* client, tts_synthesized_pcm_cb callback, void* user_data)
151 {
152         client->synthesized_pcm_cb = callback;
153         client->synthesized_pcm_user_data = user_data;
154 }
155
156 int tts_client_new(tts_h* tts)
157 {
158         tts_client_s* client = (tts_client_s*)calloc(1, sizeof(tts_client_s));
159         if (NULL == client) {
160                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
161                 return TTS_ERROR_OUT_OF_MEMORY;
162         }
163
164         tts_h temp = (tts_h)calloc(1, sizeof(struct tts_s));
165         if (NULL == temp) {
166                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
167                 free(client);
168                 return TTS_ERROR_OUT_OF_MEMORY;
169         }
170
171         temp->handle = __client_generate_uid((unsigned int)getpid());
172
173         /* initialize client data */
174         client->tts = temp;
175         client->pid = getpid();
176         client->uid = temp->handle;
177         client->current_service_state = TTS_SERVICE_STATE_NONE;
178
179         pthread_mutex_lock(&g_client_list_mutex);
180         g_client_list = g_list_append(g_client_list, client);
181         pthread_mutex_unlock(&g_client_list_mutex);
182
183         *tts = temp;
184
185         SLOG(LOG_ERROR, TAG_TTSC, "[Success] Create client object : uid(%u)", client->uid);
186
187         return TTS_ERROR_NONE;
188 }
189
190 int tts_client_destroy(tts_h tts)
191 {
192         if (tts == NULL) {
193                 SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
194                 return TTS_ERROR_INVALID_PARAMETER;
195         }
196
197         GList *iter = NULL;
198         tts_client_s *data = NULL;
199
200         pthread_mutex_lock(&g_client_list_mutex);
201         /* if list have item */
202         if (g_list_length(g_client_list) > 0) {
203                 /* Get a first item */
204                 iter = g_list_first(g_client_list);
205
206                 while (NULL != iter) {
207                         data = iter->data;
208                         if (tts->handle == data->tts->handle) {
209                                 tts->handle = TTS_INVALID_UID;
210                                 g_client_list = g_list_remove_link(g_client_list, iter);
211
212                                 while (0 != data->cb_ref_count) {
213                                         /* wait for release callback function */
214                                 }
215
216                                 unsigned int uid = data->uid;
217
218                                 free(data->err_msg);
219                                 free(data->credential);
220
221                                 pthread_mutex_lock(&g_repeat_text_mutex);
222                                 free(data->text_repeat);
223                                 data->text_repeat = NULL;
224                                 pthread_mutex_unlock(&g_repeat_text_mutex);
225
226                                 memset(data, 0, sizeof(tts_client_s));
227
228                                 free(data);
229                                 data = NULL;
230
231                                 free(tts);
232                                 tts = NULL;
233
234                                 g_list_free(iter);
235
236                                 pthread_mutex_unlock(&g_client_list_mutex);
237                                 SLOG(LOG_ERROR, TAG_TTSC, "Client destroy : uid(%u)", uid);
238                                 return TTS_ERROR_NONE;
239                         }
240
241                         /* Next item */
242                         iter = g_list_next(iter);
243                 }
244         }
245         pthread_mutex_unlock(&g_client_list_mutex);
246         SLOG(LOG_ERROR, TAG_TTSC, "Fail to destroy client : handle is not valid");
247
248         return TTS_ERROR_INVALID_PARAMETER;
249 }
250
251 tts_client_s* tts_client_get(tts_h tts)
252 {
253         if (tts == NULL) {
254                 SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
255                 return NULL;
256         }
257
258         GList *iter = NULL;
259         tts_client_s *data = NULL;
260
261         pthread_mutex_lock(&g_client_list_mutex);
262         if (g_list_length(g_client_list) > 0) {
263                 /* Get a first item */
264                 iter = g_list_first(g_client_list);
265
266                 while (NULL != iter) {
267                         data = iter->data;
268
269                         if (tts->handle == data->tts->handle) {
270                                 pthread_mutex_unlock(&g_client_list_mutex);
271                                 return data;
272                         }
273
274                         /* Next item */
275                         iter = g_list_next(iter);
276                 }
277         }
278
279         pthread_mutex_unlock(&g_client_list_mutex);
280         SLOG(LOG_ERROR, TAG_TTSC, "handle is not valid");
281
282         return NULL;
283 }
284
285 tts_client_s* tts_client_get_by_uid(unsigned int uid)
286 {
287         if (uid == TTS_INVALID_UID) {
288                 SLOG(LOG_ERROR, TAG_TTSC, "out of range : handle");
289                 return NULL;
290         }
291
292         GList *iter = NULL;
293         tts_client_s *data = NULL;
294
295         pthread_mutex_lock(&g_client_list_mutex);
296         if (g_list_length(g_client_list) > 0) {
297                 /* Get a first item */
298                 iter = g_list_first(g_client_list);
299
300                 while (NULL != iter) {
301                         data = iter->data;
302                         if (uid == data->uid) {
303                                 pthread_mutex_unlock(&g_client_list_mutex);
304                                 return data;
305                         }
306
307                         /* Next item */
308                         iter = g_list_next(iter);
309                 }
310         }
311
312         pthread_mutex_unlock(&g_client_list_mutex);
313         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] uid(%u) is not valid", uid);
314
315         return NULL;
316 }
317
318 bool tts_client_is_valid_uid(unsigned int uid)
319 {
320         if (NULL == tts_client_get_by_uid(uid)) {
321                 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Uid is not valid");
322                 return false;
323         }
324
325         return true;
326 }
327
328 bool tts_client_is_valid_client(tts_client_s* client)
329 {
330         if (NULL == client) {
331                 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] Client is NULL");
332                 return false;
333         }
334
335         pthread_mutex_lock(&g_client_list_mutex);
336         if (g_list_length(g_client_list) > 0) {
337                 GList *iter = g_list_first(g_client_list);
338                 while (NULL != iter) {
339                         if (iter->data == client) {
340                                 pthread_mutex_unlock(&g_client_list_mutex);
341                                 return true;
342                         }
343
344                         iter = g_list_next(iter);
345                 }
346         }
347         pthread_mutex_unlock(&g_client_list_mutex);
348
349         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client(%p) is not valid", client);
350         return false;
351 }
352
353 tts_h tts_client_get_handle(tts_client_s* client)
354 {
355         if (false == tts_client_is_valid_client(client)) {
356                 return NULL;
357         }
358
359         return client->tts;
360 }
361
362 unsigned int tts_client_get_size()
363 {
364         pthread_mutex_lock(&g_client_list_mutex);
365         unsigned int size = g_list_length(g_client_list);
366         pthread_mutex_unlock(&g_client_list_mutex);
367
368         return size;
369 }
370
371 int tts_client_use_callback(tts_client_s* client)
372 {
373         client->cb_ref_count++;
374         return 0;
375 }
376
377 int tts_client_not_use_callback(tts_client_s* client)
378 {
379         client->cb_ref_count--;
380         return 0;
381 }
382
383 int tts_client_get_use_callback(tts_client_s* client)
384 {
385         return client->cb_ref_count;
386 }
387
388 GList* tts_client_get_client_list()
389 {
390         GList* copy_list = NULL;
391         pthread_mutex_lock(&g_client_list_mutex);
392         copy_list = g_list_copy(g_client_list);
393         pthread_mutex_unlock(&g_client_list_mutex);
394
395         return copy_list;
396 }
397
398 unsigned int tts_client_get_uid(tts_client_s* client)
399 {
400         if (NULL == client || false == tts_client_is_valid_client(client)) {
401                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client(%p) is not valid", client);
402                 return TTS_INVALID_UID;
403         }
404
405         return client->uid;
406 }
407
408 void tts_client_set_current_state(tts_client_s* client, tts_state_e state)
409 {
410         if (false == tts_client_is_valid_client(client)) {
411                 return;
412         }
413
414         client->before_state = client->current_state;
415         client->current_state = state;
416 }
417
418 tts_state_e tts_client_get_current_state(tts_client_s* client)
419 {
420         if (false == tts_client_is_valid_client(client)) {
421                 return TTS_STATE_INVALID;
422         }
423
424         return client->current_state;
425 }
426
427 void tts_client_set_current_service_state(tts_client_s* client, tts_service_state_e service_state)
428 {
429         if (false == tts_client_is_valid_client(client)) {
430                 return;
431         }
432
433         client->current_service_state = service_state;
434 }
435
436 tts_service_state_e tts_client_get_current_service_state(tts_client_s* client)
437 {
438         if (false == tts_client_is_valid_client(client)) {
439                 return TTS_SERVICE_STATE_NONE;
440         }
441
442         return client->current_service_state;
443 }
444
445 void tts_client_set_start_listening(unsigned int uid, bool is_listening_started)
446 {
447         tts_client_s* client = tts_client_get_by_uid(uid);
448         if (NULL == client) {
449                 return;
450         }
451
452         client->start_listening = is_listening_started;
453 }
454
455 bool tts_client_is_listening_started(unsigned int uid)
456 {
457         tts_client_s* client = tts_client_get_by_uid(uid);
458         if (NULL == client) {
459                 return false;
460         }
461
462         return client->start_listening;
463 }
464
465 void tts_client_set_reprepared(tts_client_s* client, bool is_reprepared)
466 {
467         if (false == tts_client_is_valid_client(client)) {
468                 return;
469         }
470
471         client->reprepared = is_reprepared;
472 }
473
474 bool tts_client_is_reprepared(tts_client_s* client)
475 {
476         if (false == tts_client_is_valid_client(client)) {
477                 return INVALID_HANDLE;
478         }
479
480         return client->reprepared;
481 }
482
483 void tts_client_set_service_out(tts_client_s* client, bool is_service_out)
484 {
485         if (false == tts_client_is_valid_client(client)) {
486                 return;
487         }
488
489         client->service_out = is_service_out;
490 }
491
492 bool tts_client_is_service_out(tts_client_s* client)
493 {
494         if (false == tts_client_is_valid_client(client)) {
495                 return false;
496         }
497
498         return client->service_out;
499 }
500
501 void tts_client_set_mode(tts_client_s* client, tts_mode_e mode)
502 {
503         if (false == tts_client_is_valid_client(client)) {
504                 return;
505         }
506
507         client->mode = mode;
508 }
509
510 tts_mode_e tts_client_get_mode(tts_client_s* client)
511 {
512         if (false == tts_client_is_valid_client(client)) {
513                 return INVALID_HANDLE;
514         }
515
516         return client->mode;
517 }
518
519 void tts_client_set_playing_mode(tts_client_s* client, tts_playing_mode_e mode)
520 {
521         if (false == tts_client_is_valid_client(client)) {
522                 return;
523         }
524
525         client->playing_mode = mode;
526 }
527
528 tts_playing_mode_e tts_client_get_playing_mode(tts_client_s* client)
529 {
530         if (false == tts_client_is_valid_client(client)) {
531                 return INVALID_HANDLE;
532         }
533
534         return client->playing_mode;
535 }
536
537 void tts_client_set_repeat_text(tts_client_s* client, const char* text)
538 {
539         if (NULL == client || false == tts_client_is_valid_client(client)) {
540                 return;
541         }
542
543         pthread_mutex_lock(&g_repeat_text_mutex);
544         if (NULL != client->text_repeat) {
545                 free(client->text_repeat);
546         }
547
548         if (NULL != text) {
549                 client->text_repeat = strdup(text);
550         } else {
551                 client->text_repeat = NULL;
552         }
553         pthread_mutex_unlock(&g_repeat_text_mutex);
554 }
555
556 char* tts_client_get_repeat_text(tts_client_s* client)
557 {
558         if (NULL == client || false == tts_client_is_valid_client(client)) {
559                 return NULL;
560         }
561
562         char *repeat_text = NULL;
563         pthread_mutex_lock(&g_repeat_text_mutex);
564         if (NULL != client->text_repeat) {
565                 repeat_text = strdup(client->text_repeat);
566         }
567         pthread_mutex_unlock(&g_repeat_text_mutex);
568
569         return repeat_text;
570 }
571
572 int tts_client_new_utterance_id(tts_client_s* client)
573 {
574         if (NULL == client || false == tts_client_is_valid_client(client)) {
575                 return INVALID_HANDLE;
576         }
577
578         client->current_utt_id++;
579         if (client->current_utt_id == 10000) {
580                 client->current_utt_id = 1;
581         }
582
583         return client->current_utt_id;
584 }
585
586 void tts_client_set_error_message(tts_client_s* client, const char* error_message)
587 {
588         if (false == tts_client_is_valid_client(client)) {
589                 return;
590         }
591
592         if (NULL != client->err_msg) {
593                 free(client->err_msg);
594                 client->err_msg = NULL;
595         }
596
597         if (NULL != error_message) {
598                 client->err_msg = strdup(error_message);
599         }
600 }
601
602 const char* tts_client_get_error_message(tts_client_s* client)
603 {
604         if (false == tts_client_is_valid_client(client)) {
605                 return NULL;
606         }
607
608         return client->err_msg;
609 }
610
611 void tts_client_set_credential_key(tts_client_s* client, const char* credential_key)
612 {
613         if (false == tts_client_is_valid_client(client)) {
614                 return;
615         }
616
617         free(client->credential);
618         client->credential = NULL;
619
620         if (NULL != credential_key) {
621                 client->credential = strdup(credential_key);
622         }
623 }
624
625 const char* tts_client_get_credential_key(tts_client_s* client)
626 {
627         if (false == tts_client_is_valid_client(client)) {
628                 return NULL;
629         }
630
631         return client->credential;
632 }
633
634 void tts_client_set_state_changed_cb(tts_client_s* client, tts_state_changed_cb callback, void* user_data)
635 {
636         if (false == tts_client_is_valid_client(client)) {
637                 return;
638         }
639
640         if (NULL == callback) {
641                 if (NULL != client->notify_state_timer) {
642                         ecore_timer_del(client->notify_state_timer);
643                         client->notify_state_timer = NULL;
644                 }
645         }
646         __set_state_changed_cb(client, callback, user_data);
647 }
648
649 void tts_client_set_utterance_started_cb(tts_client_s* client, tts_utterance_started_cb callback, void* user_data)
650 {
651         if (false == tts_client_is_valid_client(client)) {
652                 return;
653         }
654         __set_utterance_started_cb(client, callback, user_data);
655 }
656
657 void tts_client_set_utterance_completed_cb(tts_client_s* client, tts_utterance_completed_cb callback, void* user_data)
658 {
659         if (false == tts_client_is_valid_client(client)) {
660                 return;
661         }
662         __set_utterance_completed_cb(client, callback, user_data);
663 }
664
665 void tts_client_set_error_cb(tts_client_s* client, tts_error_cb callback, void* user_data)
666 {
667         if (false == tts_client_is_valid_client(client)) {
668                 return;
669         }
670
671         if (NULL == callback) {
672                 if (NULL != client->notify_error_timer) {
673                         ecore_timer_del(client->notify_error_timer);
674                         client->notify_error_timer = NULL;
675                 }
676         }
677         __set_error_cb(client, callback, user_data);
678 }
679
680 void tts_client_set_default_voice_changed_cb(tts_client_s* client, tts_default_voice_changed_cb callback, void* user_data)
681 {
682         if (false == tts_client_is_valid_client(client)) {
683                 return;
684         }
685         __set_default_voice_changed_cb(client, callback, user_data);
686 }
687
688 void tts_client_set_engine_changed_cb(tts_client_s* client, tts_engine_changed_cb callback, void* user_data)
689 {
690         if (false == tts_client_is_valid_client(client)) {
691                 return;
692         }
693         __set_engine_changed_cb(client, callback, user_data);
694 }
695
696 void tts_client_set_screen_reader_changed_cb(tts_client_s* client, tts_screen_reader_changed_cb callback, void* user_data)
697 {
698         if (false == tts_client_is_valid_client(client)) {
699                 return;
700         }
701         __set_screen_reader_changed_cb(client, callback, user_data);
702 }
703
704 void tts_client_set_supported_voice_cb(tts_client_s* client, tts_supported_voice_cb callback, void* user_data)
705 {
706         if (false == tts_client_is_valid_client(client)) {
707                 return;
708         }
709         __set_supported_voice_cb(client, callback, user_data);
710 }
711
712 void tts_client_set_service_state_changed_cb(tts_client_s* client, tts_service_state_changed_cb callback, void* user_data)
713 {
714         if (false == tts_client_is_valid_client(client)) {
715                 return;
716         }
717         __set_service_state_changed_cb(client, callback, user_data);
718 }
719
720 void tts_client_set_synthesized_pcm_cb(tts_client_s* client, tts_synthesized_pcm_cb callback, void* user_data)
721 {
722         if (false == tts_client_is_valid_client(client)) {
723                 return;
724         }
725         __set_synthesized_pcm_cb(client, callback, user_data);
726 }
727
728 tts_state_changed_cb tts_client_get_state_changed_cb(tts_client_s* client)
729 {
730         if (false == tts_client_is_valid_client(client)) {
731                 return NULL;
732         }
733         return client->state_changed_cb;
734 }
735
736 void* tts_client_get_state_changed_user_data(tts_client_s* client)
737 {
738         if (false == tts_client_is_valid_client(client)) {
739                 return NULL;
740         }
741         return client->state_changed_user_data;
742 }
743
744 tts_utterance_started_cb tts_client_get_utterance_started_cb(tts_client_s* client)
745 {
746         if (false == tts_client_is_valid_client(client)) {
747                 return NULL;
748         }
749         return client->utt_started_cb;
750 }
751
752 void* tts_client_get_utterance_started_user_data(tts_client_s* client)
753 {
754         if (false == tts_client_is_valid_client(client)) {
755                 return NULL;
756         }
757         return client->utt_started_user_data;
758 }
759
760 tts_utterance_completed_cb tts_client_get_utterance_completed_cb(tts_client_s* client)
761 {
762         if (false == tts_client_is_valid_client(client)) {
763                 return NULL;
764         }
765         return client->utt_completed_cb;
766 }
767
768 void* tts_client_get_utterance_completed_user_data(tts_client_s* client)
769 {
770         if (false == tts_client_is_valid_client(client)) {
771                 return NULL;
772         }
773         return client->utt_completed_user_data;
774 }
775
776 tts_error_cb tts_client_get_error_cb(tts_client_s* client)
777 {
778         if (false == tts_client_is_valid_client(client)) {
779                 return NULL;
780         }
781         return client->error_cb;
782 }
783
784 void* tts_client_get_error_user_data(tts_client_s* client)
785 {
786         if (false == tts_client_is_valid_client(client)) {
787                 return NULL;
788         }
789         return client->error_user_data;
790 }
791
792 //LCOV_EXCL_START
793 tts_default_voice_changed_cb tts_client_get_default_voice_changed_cb(tts_client_s* client)
794 {
795         if (false == tts_client_is_valid_client(client)) {
796                 return NULL;
797         }
798         return client->default_voice_changed_cb;
799 }
800
801 void* tts_client_get_default_voice_changed_user_data(tts_client_s* client)
802 {
803         if (false == tts_client_is_valid_client(client)) {
804                 return NULL;
805         }
806         return client->default_voice_changed_user_data;
807 }
808
809 tts_engine_changed_cb tts_client_get_engine_changed_cb(tts_client_s* client)
810 {
811         if (false == tts_client_is_valid_client(client)) {
812                 return NULL;
813         }
814         return client->engine_changed_cb;
815 }
816
817 void* tts_client_get_engine_changed_user_data(tts_client_s* client)
818 {
819         if (false == tts_client_is_valid_client(client)) {
820                 return NULL;
821         }
822         return client->engine_changed_user_data;
823 }
824 //LCOV_EXCL_STOP
825
826 tts_screen_reader_changed_cb tts_client_get_screen_reader_changed_cb(tts_client_s* client)
827 {
828         if (false == tts_client_is_valid_client(client)) {
829                 return NULL;
830         }
831         return client->screen_reader_changed_cb;
832 }
833
834 void* tts_client_get_screen_reader_changed_user_data(tts_client_s* client)
835 {
836         if (false == tts_client_is_valid_client(client)) {
837                 return NULL;
838         }
839         return client->screen_reader_changed_user_data;
840 }
841
842 tts_supported_voice_cb tts_client_get_supported_voice_cb(tts_client_s* client)
843 {
844         if (false == tts_client_is_valid_client(client)) {
845                 return NULL;
846         }
847         return client->supported_voice_cb;
848 }
849
850 void* tts_client_get_supported_voice_user_data(tts_client_s* client)
851 {
852         if (false == tts_client_is_valid_client(client)) {
853                 return NULL;
854         }
855         return client->supported_voice_user_data;
856 }
857
858 tts_service_state_changed_cb tts_client_get_service_state_changed_cb(tts_client_s* client)
859 {
860         if (false == tts_client_is_valid_client(client)) {
861                 return NULL;
862         }
863         return client->service_state_changed_cb;
864 }
865
866 void* tts_client_get_service_state_changed_user_data(tts_client_s* client)
867 {
868         if (false == tts_client_is_valid_client(client)) {
869                 return NULL;
870         }
871         return client->service_state_changed_user_data;
872 }
873
874 tts_synthesized_pcm_cb tts_client_get_synthesized_pcm_cb(tts_client_s* client)
875 {
876         if (false == tts_client_is_valid_client(client)) {
877                 return NULL;
878         }
879         return client->synthesized_pcm_cb;
880 }
881
882 void* tts_client_get_synthesized_pcm_user_data(tts_client_s* client)
883 {
884         if (false == tts_client_is_valid_client(client)) {
885                 return NULL;
886         }
887         return client->synthesized_pcm_user_data;
888 }
889
890 int tts_client_get_registered_event_mask(tts_client_s* client)
891 {
892         if (false == tts_client_is_valid_client(client)) {
893                 return 0;
894         }
895         return client->registered_event_mask;
896 }
897
898 void tts_client_unset_all_cb(tts_client_s* client)
899 {
900         if (false == tts_client_is_valid_client(client)) {
901                 return;
902         }
903
904         if (NULL != client->notify_state_timer) {
905                 ecore_timer_del(client->notify_state_timer);
906                 client->notify_state_timer = NULL;
907         }
908
909         if (NULL != client->notify_error_timer) {
910                 ecore_timer_del(client->notify_error_timer);
911                 client->notify_error_timer = NULL;
912         }
913
914         __set_state_changed_cb(client, NULL, NULL);
915         __set_utterance_started_cb(client, NULL, NULL);
916         __set_utterance_completed_cb(client, NULL, NULL);
917         __set_error_cb(client, NULL, NULL);
918         __set_default_voice_changed_cb(client, NULL, NULL);
919         __set_engine_changed_cb(client, NULL, NULL);
920         __set_supported_voice_cb(client, NULL, NULL);
921         __set_service_state_changed_cb(client, NULL, NULL);
922         __set_synthesized_pcm_cb(client, NULL, NULL);
923 }