X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=client%2Ftts_client.c;h=4ce1855f7790677f8dc66ded094796cf2a428387;hb=c3fa9b4a5913fdb9a587769219297544c71cb821;hp=574e095507432ec0429ec44ce6f3070e29514cc3;hpb=af3c28bef954884542e62e4db31e06016a2f0e64;p=platform%2Fcore%2Fuifw%2Ftts.git diff --git a/client/tts_client.c b/client/tts_client.c old mode 100755 new mode 100644 index 574e095..4ce1855 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,9 +37,17 @@ static int __client_generate_uid(int pid) int tts_client_new(tts_h* tts) { tts_client_s* client = NULL; - client = (tts_client_s*)g_malloc0 (sizeof(tts_client_s)); - - tts_h temp = (tts_h)g_malloc0(sizeof(struct tts_s)); + client = (tts_client_s*)calloc(1, sizeof(tts_client_s)); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory"); + return TTS_ERROR_OUT_OF_MEMORY; + } + tts_h temp = (tts_h)calloc(1, sizeof(struct tts_s)); + if (NULL == temp) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory"); + free(client); + return TTS_ERROR_OUT_OF_MEMORY; + } temp->handle = __client_generate_uid(getpid()); /* initialize client data */ @@ -50,7 +58,7 @@ int tts_client_new(tts_h* tts) client->state_changed_cb = NULL; client->state_changed_user_data = NULL; - + client->utt_started_cb = NULL; client->utt_started_user_data = NULL; client->utt_completeted_cb = NULL; @@ -58,6 +66,10 @@ int tts_client_new(tts_h* tts) client->error_cb = NULL; client->error_user_data = NULL; + client->default_voice_changed_cb = NULL; + client->default_voice_changed_user_data = NULL; + client->supported_voice_cb = NULL; + client->supported_voice_user_data = NULL; client->mode = TTS_MODE_DEFAULT; client->before_state = TTS_STATE_CREATED; @@ -65,21 +77,33 @@ int tts_client_new(tts_h* tts) client->cb_ref_count = 0; + client->utt_id = 0; + client->reason = 0; + client->err_msg = NULL; + + client->conn_timer = NULL; + + client->credential = NULL; + client->credential_needed = false; + client->internal = false; + + client->text_repeat = NULL; + g_client_list = g_list_append(g_client_list, client); *tts = temp; SLOG(LOG_DEBUG, TAG_TTSC, "[Success] Create client object : uid(%d)", client->uid); - return 0; + return TTS_ERROR_NONE; } int tts_client_destroy(tts_h tts) { if (tts == NULL) { SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL"); - return 0; - } + return TTS_ERROR_INVALID_PARAMETER; + } GList *iter = NULL; tts_client_s *data = NULL; @@ -94,14 +118,35 @@ int tts_client_destroy(tts_h tts) if (tts->handle == data->tts->handle) { g_client_list = g_list_remove_link(g_client_list, iter); - while (0 != data->cb_ref_count) - { + while (0 != data->cb_ref_count) { /* wait for release callback function */ } + + if (NULL != data->err_msg) { + free(data->err_msg); + data->err_msg = NULL; + } + + if (NULL != data->credential) { + free(data->credential); + data->credential = NULL; + } + + if (NULL != data->text_repeat) { + free(data->text_repeat); + data->text_repeat = NULL; + } + free(data); free(tts); - return 0; + data = NULL; + tts = NULL; + + SLOG(LOG_DEBUG, TAG_TTSC, "Client destroy"); + g_list_free(iter); + + return TTS_ERROR_NONE; } /* Next item */ @@ -110,7 +155,7 @@ int tts_client_destroy(tts_h tts) } SLOG(LOG_ERROR, TAG_TTSC, "Fail to destroy client : handle is not valid"); - return -1; + return TTS_ERROR_INVALID_PARAMETER; } tts_client_s* tts_client_get(tts_h tts) @@ -216,4 +261,32 @@ int tts_client_get_connected_client_count() } } return number; -} \ No newline at end of file +} + +int tts_client_get_mode_client_count(tts_mode_e mode) +{ + GList *iter = NULL; + tts_client_s *data = NULL; + int number = 0; + + if (g_list_length(g_client_list) > 0) { + /* Get a first item */ + iter = g_list_first(g_client_list); + + while (NULL != iter) { + data = iter->data; + if (0 < data->current_state && data->mode == mode) { + number++; + } + + /* Next item */ + iter = g_list_next(iter); + } + } + return number; +} + +GList* tts_client_get_client_list() +{ + return g_client_list; +}