93bbd50ef5b587141977064ecfc137bd4f4188a3
[platform/core/uifw/tts.git] / server / ttsd_data.cpp
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 #include <list>
15 #include <pthread.h>
16 #include <vector>
17
18 #include "ttsd_main.h"
19 #include "ttsd_data.h"
20
21 using namespace std;
22
23 typedef struct
24 {
25         char*   lang;
26         int     vctype;
27 }used_voice_s;
28
29 typedef struct
30 {
31         int             pid;
32         int             uid;
33         int             utt_id_stopped;
34         app_tts_state_e state;
35
36         std::list<speak_data_s*> m_speak_data;
37         std::list<sound_data_s*> m_wav_data;
38
39         std::list<used_voice_s> m_used_voice;
40 }app_data_s;
41
42 static vector<app_data_s> g_app_list;
43
44 static pthread_mutex_t g_speak_data_mutex = PTHREAD_MUTEX_INITIALIZER;
45 static pthread_mutex_t g_sound_data_mutex = PTHREAD_MUTEX_INITIALIZER;
46
47 /*
48 * functions for debug
49 */
50 int __data_show_list()
51 {
52         int vsize = g_app_list.size();
53
54         SLOG(LOG_DEBUG, tts_tag(), "----- client list -----");
55
56         for (int i=0; i < vsize; i++) {
57                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[%dth] pid(%d), uid(%d), state(%d)", i, g_app_list[i].pid, g_app_list[i].uid, g_app_list[i].state);
58         }
59
60         if (0 == vsize) {
61                 SLOG(LOG_DEBUG, tts_tag(), "No Client");
62         }
63
64         SLOG(LOG_DEBUG, tts_tag(), "-----------------------");
65
66         return TTSD_ERROR_NONE;
67 }
68
69 int __data_show_sound_list(int index)
70 {
71         SLOG(LOG_DEBUG, tts_tag(), "----- Sound list -----");
72
73         unsigned int i = 0;
74         std::list<sound_data_s*>::iterator iter;
75         for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); ++iter) {
76                 SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)", 
77                         i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
78                 i++;
79         }
80
81         if (i == 0) {
82                 SLOG(LOG_DEBUG, tts_tag(), "No Sound Data");
83         }
84
85         SLOG(LOG_DEBUG, tts_tag(), "----------------------");
86         return TTSD_ERROR_NONE;
87 }
88
89 int __data_show_text_list(int index)
90 {
91         SLOG(LOG_DEBUG, tts_tag(), "----- Text list -----");
92
93         unsigned int i = 0;
94         std::list<speak_data_s*>::iterator iter;
95         for (iter = g_app_list[index].m_speak_data.begin(); iter != g_app_list[index].m_speak_data.end(); ++iter) {
96                 SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)", 
97                         i + 1, *iter, (*iter)->lang, (*iter)->vctype, (*iter)->speed, (*iter)->utt_id, (*iter)->text);
98                 i++;
99         }
100
101         if (0 == i) {
102                 SLOG(LOG_DEBUG, tts_tag(), "No Text Data");
103         }
104
105         SLOG(LOG_DEBUG, tts_tag(), "---------------------");
106         return TTSD_ERROR_NONE;
107 }
108
109 int __data_show_used_voice_list(int index)
110 {
111         SLOG(LOG_DEBUG, tts_tag(), "----- Used voice list -----");
112
113         unsigned int i = 0;
114         std::list<used_voice_s>::iterator iter;
115         for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
116                 SLOG(LOG_DEBUG, tts_tag(), "[%dth] lang(%s), vctype(%d)", i + 1, iter->lang, iter->vctype);
117                 i++;
118         }
119
120         if (0 == i) {
121                 SLOG(LOG_DEBUG, tts_tag(), "No Voice Data");
122         }
123
124         SLOG(LOG_DEBUG, tts_tag(), "---------------------------");
125         return TTSD_ERROR_NONE;
126 }
127
128 /*
129 * ttsd data functions
130 */
131
132 int ttsd_data_new_client(int pid, int uid)
133 {
134         if( -1 != ttsd_data_is_client(uid) ) {
135                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
136                 return TTSD_ERROR_INVALID_PARAMETER;
137         }
138
139         app_data_s app;
140         app.pid = pid;
141         app.uid = uid;
142         app.utt_id_stopped = 0;
143         app.state = APP_STATE_READY;
144
145         g_app_list.insert(g_app_list.end(), app);
146
147 #ifdef DATA_DEBUG
148         __data_show_list();
149 #endif
150         return TTSD_ERROR_NONE;
151 }
152
153 int ttsd_data_delete_client(int uid)
154 {
155         int index = 0;
156
157         index = ttsd_data_is_client(uid);
158
159         if (index < 0) {
160                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
161                 return -1;
162         }
163
164         if (0 != ttsd_data_clear_data(uid)) {
165                 SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] Fail to clear data");
166                 return -1;
167         }
168
169         g_app_list.erase(g_app_list.begin()+index);
170
171 #ifdef DATA_DEBUG
172         __data_show_list();
173 #endif
174         return TTSD_ERROR_NONE;
175 }
176
177 int ttsd_data_is_client(int uid)
178 {
179         int vsize = g_app_list.size();
180
181         for (int i = 0; i < vsize; i++) {
182                 if(g_app_list[i].uid == uid) {
183                         return i;
184                 }
185         }
186
187         return -1;
188 }
189
190 int ttsd_data_get_client_count()
191 {
192         return g_app_list.size();
193 }
194
195 int ttsd_data_get_pid(int uid)
196 {
197         int index;
198
199         index = ttsd_data_is_client(uid);
200
201         if (index < 0)  {
202                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
203                 return TTSD_ERROR_INVALID_PARAMETER;
204         }
205
206         return g_app_list[index].pid;
207 }
208
209 int ttsd_data_get_speak_data_size(int uid)
210 {
211         int index = 0;
212         index = ttsd_data_is_client(uid);
213
214         if (index < 0) {
215                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
216                 return TTSD_ERROR_INVALID_PARAMETER;
217         }
218
219         /* mutex is locked */
220         pthread_mutex_lock(&g_speak_data_mutex);
221         int size = g_app_list[index].m_speak_data.size();
222
223         /* mutex is unlocked */
224         pthread_mutex_unlock(&g_speak_data_mutex);
225
226         return size;
227 }
228
229 int ttsd_data_set_used_voice(int uid, const char* lang, int type)
230 {
231         int index = 0;
232         index = ttsd_data_is_client(uid);
233
234         if (index < 0) {
235                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
236                 return TTSD_ERROR_INVALID_PARAMETER;
237         }
238
239         /* Find voice */
240         std::list<used_voice_s>::iterator iter;
241
242         for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end();++iter) {
243                 if (0 == strcmp(lang, iter->lang) && type == iter->vctype) {
244                         SLOG(LOG_DEBUG, tts_tag(), "[DATA] The voice is already registered (%s)(%d)", lang, type);
245                         return 0;
246                 }
247         }
248
249         /* Add voice */
250         used_voice_s used_voice;
251         used_voice.lang = strdup(lang);
252         used_voice.vctype = type;
253
254         try {
255                 iter = g_app_list[index].m_used_voice.insert(g_app_list[index].m_used_voice.end(), used_voice);
256         } catch (const std::bad_alloc&) {
257                 SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_used_voice (bad_alloc)");
258                 return -1;
259         }
260         SLOG(LOG_ERROR, tts_tag(), "[DATA] lang(%s), vctype(%d)", iter->lang, iter->vctype);
261
262 #ifdef DATA_DEBUG
263         __data_show_used_voice_list(index);
264 #endif
265
266         return -1;      /* Need to load voice*/
267 }
268
269 int ttsd_data_reset_used_voice(int uid, ttsd_used_voice_cb callback)
270 {
271         int index = 0;
272         index = ttsd_data_is_client(uid);
273
274         if (index < 0) {
275                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
276                 return TTSD_ERROR_INVALID_PARAMETER;
277         }
278
279         if (NULL == callback) {
280                 SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] Used voice callback is NULL");
281         }
282
283         /* Find voice */
284         std::list<used_voice_s>::iterator iter;
285
286         for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
287                 if (NULL != callback) {
288                         callback(iter->lang, iter->vctype);
289                 }
290
291                 if (NULL != iter->lang) {
292                         free(iter->lang);
293                         iter->lang = NULL;
294                 }
295         }
296
297         g_app_list[index].m_used_voice.clear();
298
299 #ifdef DATA_DEBUG
300         __data_show_used_voice_list(index);
301 #endif
302
303         return TTSD_ERROR_NONE;
304 }
305
306 int ttsd_data_add_speak_data(int uid, speak_data_s* data)
307 {
308         int index = 0;
309         index = ttsd_data_is_client(uid);
310
311         if (index < 0) {
312                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
313                 return TTSD_ERROR_INVALID_PARAMETER;
314         }
315
316         /* mutex is locked */
317         pthread_mutex_lock(&g_speak_data_mutex);
318
319         std::list<speak_data_s*>::iterator iter;
320
321         try {
322                 iter = g_app_list[index].m_speak_data.insert(g_app_list[index].m_speak_data.end(), data);
323         } catch (const std::bad_alloc&) {
324                 SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_speak_data (bad_alloc)");
325                 pthread_mutex_unlock(&g_speak_data_mutex);
326
327                 return TTSD_ERROR_OUT_OF_MEMORY;
328         }
329         SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), text(%s), lang(%s), vctype(%d), speed(%d)", 
330                         *iter, (*iter)->utt_id, (*iter)->text, (*iter)->lang, (*iter)->vctype, (*iter)->speed);
331
332         if (1 == data->utt_id)
333                 g_app_list[index].utt_id_stopped = 0;
334
335 #ifdef DATA_DEBUG
336         __data_show_text_list(index);
337 #endif
338         pthread_mutex_unlock(&g_speak_data_mutex);
339
340         return TTSD_ERROR_NONE;
341 }
342
343 int ttsd_data_get_speak_data(int uid, speak_data_s** data)
344 {
345         int index = 0;
346         index = ttsd_data_is_client(uid);
347
348         if (index < 0) {
349                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid(%d)", uid);
350                 return TTSD_ERROR_INVALID_PARAMETER;
351         }
352
353         /* mutex is locked */
354         pthread_mutex_lock(&g_speak_data_mutex);
355
356         if (0 == g_app_list[index].m_speak_data.size()) {
357 #ifdef DATA_DEBUG
358                 SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
359 #endif
360                 pthread_mutex_unlock(&g_speak_data_mutex);
361                 return -1;
362         }
363
364         std::list<speak_data_s*>::iterator iter = g_app_list[index].m_speak_data.begin();
365         *data = *iter;
366         if (!g_app_list[index].m_speak_data.empty())
367                 g_app_list[index].m_speak_data.pop_front();
368
369 #ifdef DATA_DEBUG
370         __data_show_text_list(index);
371 #endif
372         pthread_mutex_unlock(&g_speak_data_mutex);
373
374         return TTSD_ERROR_NONE;
375 }
376
377 int ttsd_data_add_sound_data(int uid, sound_data_s* data)
378 {
379         int index = 0;
380         index = ttsd_data_is_client(uid);
381
382         if(index < 0) {
383                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
384                 return TTSD_ERROR_INVALID_PARAMETER;
385         }
386
387         if (NULL == data) {
388                 SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] sound data is NULL");
389                 return TTSD_ERROR_INVALID_PARAMETER;
390         }
391         /* mutex is locked */
392         pthread_mutex_lock(&g_sound_data_mutex);
393
394         std::list<sound_data_s*>::iterator iter;
395
396         try {
397                 iter = g_app_list[index].m_wav_data.insert(g_app_list[index].m_wav_data.end(), data);
398         } catch (const std::bad_alloc&) {
399                 SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_sound_data (bad_alloc)");
400                 pthread_mutex_unlock(&g_sound_data_mutex);
401
402                 return TTSD_ERROR_OUT_OF_MEMORY;
403         }
404         SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), data(%p)", *iter, (*iter)->utt_id, (*iter)->data);
405
406 #ifdef DATA_DEBUG
407         __data_show_sound_list(index);
408 #endif
409
410         /* mutex is unlocked */
411         pthread_mutex_unlock(&g_sound_data_mutex);
412
413         return TTSD_ERROR_NONE;
414 }
415
416 int ttsd_data_get_sound_data(int uid, sound_data_s** data)
417 {
418         int index = 0;
419         index = ttsd_data_is_client(uid);
420
421         if (index < 0)  {
422                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
423                 return TTSD_ERROR_INVALID_PARAMETER;
424         }
425
426         /* mutex is locked */
427         pthread_mutex_lock(&g_sound_data_mutex);
428
429         if (0 == g_app_list[index].m_wav_data.size()) {
430 #ifdef DATA_DEBUG
431                 SLOG(LOG_DEBUG, tts_tag(), "[DATA] There is no wav data");
432 #endif
433                 /* mutex is unlocked */
434                 pthread_mutex_unlock(&g_sound_data_mutex);
435                 return -1;
436         }
437
438         std::list<sound_data_s*>::iterator iter = g_app_list[index].m_wav_data.begin();
439         *data = *iter;
440         if (!g_app_list[index].m_wav_data.empty())
441                 g_app_list[index].m_wav_data.pop_front();
442
443 #ifdef DATA_DEBUG
444         __data_show_sound_list(index);
445 #endif
446
447         /* mutex is unlocked */
448         pthread_mutex_unlock(&g_sound_data_mutex);
449
450         return TTSD_ERROR_NONE;
451 }
452
453 int ttsd_data_get_sound_data_size(int uid)
454 {
455         int index = 0;
456         int data_size = 0;
457         index = ttsd_data_is_client(uid);
458
459         if (index < 0)  {
460                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
461                 return TTSD_ERROR_INVALID_PARAMETER;
462         }
463
464         /* mutex is locked */
465         pthread_mutex_lock(&g_sound_data_mutex);
466         data_size = g_app_list[index].m_wav_data.size();
467
468         /* mutex is unlocked */
469         pthread_mutex_unlock(&g_sound_data_mutex);
470
471         return data_size;
472 }
473
474 int ttsd_data_clear_data(int uid)
475 {
476         int index = 0;
477
478         index = ttsd_data_is_client(uid);
479         if (index < 0) {
480                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
481                 return TTSD_ERROR_INVALID_PARAMETER;
482         }
483
484         int removed_last_uttid = -1;
485         speak_data_s* temp_speak = NULL;
486         sound_data_s* temp_sound = NULL;
487
488         /* free allocated data */
489         while(1) {
490                 if (0 != ttsd_data_get_speak_data(uid, &temp_speak)) {
491                         break;
492                 }
493
494                 if (NULL != temp_speak) {
495                         SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] utt(%d), text(%s), lang(%s), vctype(%d) speed(%d)", 
496                                         temp_speak->utt_id, temp_speak->text, temp_speak->lang, temp_speak->vctype, temp_speak->speed);
497
498                         if (NULL != temp_speak->text) {
499                                 free(temp_speak->text);
500                                 temp_speak->text = NULL;
501                         }
502                         if (NULL != temp_speak->lang) {
503                                 free(temp_speak->lang);
504                                 temp_speak->lang = NULL;
505                         }
506                         removed_last_uttid = temp_speak->utt_id;
507
508                         free(temp_speak);
509                         temp_speak = NULL;
510                 }
511         }
512
513         if (-1 != removed_last_uttid) {
514                 g_app_list[index].utt_id_stopped = removed_last_uttid;
515         }
516
517         while(1) {
518                 if (0 != ttsd_data_get_sound_data(uid, &temp_sound)) {
519                         break;
520                 }
521
522                 if (NULL != temp_sound) {
523                         SLOG(LOG_ERROR, tts_tag(), "[DEBUG][%p] uid(%d), event(%d) data(%p) size(%d) rate(%d) utt(%d)", 
524                                 temp_sound, uid, temp_sound->event, temp_sound->data, temp_sound->data_size, temp_sound->rate, temp_sound->utt_id);
525
526                         if (NULL != temp_sound->data) {
527                                 free(temp_sound->data);
528                                 temp_sound->data = NULL;
529                         }
530
531                         free(temp_sound);
532                         temp_sound = NULL;
533                 }
534         }
535
536         pthread_mutex_lock(&g_speak_data_mutex);
537         g_app_list[index].m_speak_data.clear();
538         pthread_mutex_unlock(&g_speak_data_mutex);
539
540         pthread_mutex_lock(&g_sound_data_mutex);
541         g_app_list[index].m_wav_data.clear();
542         pthread_mutex_unlock(&g_sound_data_mutex);
543
544         return TTSD_ERROR_NONE;
545 }
546
547 int ttsd_data_get_client_state(int uid, app_tts_state_e* state)
548 {
549         int index = 0;
550
551         index = ttsd_data_is_client(uid);
552         if (index < 0)  {
553                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
554                 return TTSD_ERROR_INVALID_PARAMETER;
555         }
556
557         *state = g_app_list[index].state;
558
559         return TTSD_ERROR_NONE;
560 }
561
562 int ttsd_data_set_client_state(int uid, app_tts_state_e state)
563 {
564         int index = 0;
565
566         index = ttsd_data_is_client(uid);
567         if (index < 0)  {
568                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
569                 return TTSD_ERROR_INVALID_PARAMETER;
570         }
571
572         /* The client of playing state of all clients is only one. need to check state. */
573         if (APP_STATE_PLAYING == state) {
574                 int vsize = g_app_list.size();
575                 for (int i = 0; i < vsize; i++) {
576                         if(g_app_list[i].state == APP_STATE_PLAYING) {
577                                 SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] A playing client has already existed.");
578                                 return -1;
579                         }
580                 }
581         }
582
583         g_app_list[index].state = state;
584
585         return TTSD_ERROR_NONE;
586 }
587
588 int ttsd_data_get_current_playing()
589 {
590         int vsize = g_app_list.size();
591
592         for (int i = 0; i < vsize; i++) {
593                 if (APP_STATE_PLAYING == g_app_list[i].state) {
594                         SLOG(LOG_DEBUG, tts_tag(), "[DATA] uid(%d) is playing", g_app_list[i].uid);
595                         return g_app_list[i].uid;
596                 }
597         }
598
599         return -1;
600 }
601
602 int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data)
603 {
604         if (NULL == callback) {
605                 SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] input data is NULL!!");
606                 return -1;
607         }
608
609 #ifdef DATA_DEBUG
610         __data_show_list();
611 #endif
612
613         /* Copy app info */
614         vector<app_data_s> temp_app_list;
615         int vsize = g_app_list.size();
616
617         int i = 0;
618         for (i = 0;i < vsize;i++) {
619                 app_data_s app;
620                 app.pid = g_app_list[i].pid;
621                 app.uid = g_app_list[i].uid;
622                 app.utt_id_stopped = 0;
623                 app.state = g_app_list[i].state;
624
625                 temp_app_list.insert(temp_app_list.end(), app);
626         }
627
628         for (i = 0;i < vsize;i++) {
629                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[%dth] pid(%d), uid(%d), state(%d)", i, temp_app_list[i].pid, temp_app_list[i].uid, temp_app_list[i].state);
630                 if (false == callback(temp_app_list[i].pid, temp_app_list[i].uid, temp_app_list[i].state, user_data)) {
631                         break;
632                 }
633         }
634
635         for (i = 0;i < vsize;i++) {
636                 temp_app_list.erase(temp_app_list.begin());
637         }
638
639         return 0;
640 }
641
642 bool ttsd_data_is_uttid_valid(int uid, int uttid)
643 {
644         int index = 0;
645
646         index = ttsd_data_is_client(uid);
647         if (index < 0)  {
648                 SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
649                 return false;
650         }
651
652         if (uttid < g_app_list[index].utt_id_stopped)
653                 return false;
654
655         return true;
656 }
657
658 int ttsd_data_is_current_playing()
659 {
660         int vsize = g_app_list.size();
661
662         for (int i = 0; i < vsize; i++) {
663                 if(g_app_list[i].state == APP_STATE_PLAYING) {
664                         return g_app_list[i].uid;
665                 }
666         }
667
668         return -1;
669 }
670
671 int ttsd_data_get_same_pid_client_count(int pid)
672 {
673         int vsize = g_app_list.size();
674         int number = 0;
675
676         for (int i = 0;i < vsize;i++) {
677                 if(g_app_list[i].pid == pid) {
678                         number++;
679                 }
680         }
681
682         return number;
683 }
684
685 int ttsd_data_save_error_log(int uid, FILE* fp)
686 {
687         int ret;
688         int pid;
689         /* pid */
690         pid = ttsd_data_get_pid(uid);
691         if (0 > pid) {
692                 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get pid");
693         } else {
694                 fprintf(fp, "pid - %d", pid);
695         }
696         /* app state */
697         app_tts_state_e state;
698         ret = ttsd_data_get_client_state(uid, &state);
699         if (0 != ret) {
700                 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get app state");
701         } else {
702                 fprintf(fp, "app state - %d", state);
703         }
704
705         int index = 0;
706         unsigned int i;
707
708         index = ttsd_data_is_client(uid);
709         if (0 > index) {
710                 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid client");
711                 return -1;
712         }
713
714         /* get sound data */
715         fprintf(fp, "----- Sound list -----");
716
717         i = 0;
718         std::list<sound_data_s*>::iterator iter;
719         for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); ++iter) {
720                 SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)",
721                         i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
722                 i++;
723         }
724
725         fprintf(fp, "----------------------");
726
727         /* get speck data */
728         fprintf(fp, "----- Text list -----");
729
730         i = 0;
731         std::list<speak_data_s*>::iterator iter_speak;
732         for (iter_speak = g_app_list[index].m_speak_data.begin(); iter_speak != g_app_list[index].m_speak_data.end(); ++iter_speak) {
733                 SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)",
734                         i, *iter_speak, (*iter_speak)->lang, (*iter_speak)->vctype, (*iter_speak)->speed, (*iter_speak)->utt_id, (*iter_speak)->text);
735                 i++;
736         }
737         fprintf(fp, "---------------------");
738
739         return 0;
740 }