Add line coverage tags
[platform/core/uifw/stt.git] / client / stt_client.c
index f9e28e2..a9eef07 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 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
@@ -41,16 +41,25 @@ int stt_client_new(stt_h* stt)
 {
        stt_client_s *client = NULL;
 
-       client = (stt_client_s*)g_malloc0 (sizeof(stt_client_s));
+       client = (stt_client_s*)calloc(1, sizeof(stt_client_s));
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
 
-       stt_h temp = (stt_h)g_malloc0(sizeof(struct stt_s));
-       temp->handle = __client_generate_uid(getpid()); 
+       stt_h temp = (stt_h)calloc(1, sizeof(struct stt_s));
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
+               free(client);
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+       temp->handle = __client_generate_uid(getpid());
 
        /* initialize client data */
        client->stt = temp;
-       client->pid = getpid(); 
+       client->pid = getpid();
        client->uid = temp->handle;
-       
+
        client->recognition_result_cb = NULL;
        client->recognition_result_user_data = NULL;
        client->state_changed_cb = NULL;
@@ -59,8 +68,11 @@ int stt_client_new(stt_h* stt)
        client->error_user_data = NULL;
        client->default_lang_changed_cb = NULL;
        client->default_lang_changed_user_data = NULL;
+       client->speech_status_cb = NULL;
+       client->speech_status_user_data = NULL;
 
        client->current_engine_id = NULL;
+       client->credential = NULL;
 
        client->silence_supported = false;
        client->silence = STT_OPTION_SILENCE_DETECTION_AUTO;
@@ -70,24 +82,31 @@ int stt_client_new(stt_h* stt)
        client->data_count = 0;
        client->msg = NULL;
 
+       client->reason = 0;
+       client->err_msg = NULL;
+
        client->before_state = STT_STATE_CREATED;
        client->current_state = STT_STATE_CREATED;
 
        client->internal_state = STT_INTERNAL_STATE_NONE;
 
+       client->speech_status = -1;
+
        client->cb_ref_count = 0;
 
+       client->internal = false;
+
        g_client_list = g_list_append(g_client_list, client);
 
        *stt = temp;
 
-       return 0;       
+       return 0;
 }
 
 int stt_client_destroy(stt_h stt)
 {
        if (stt == NULL) {
-               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); //LCOV_EXCL_LINE
                return 0;
        }
 
@@ -104,17 +123,28 @@ int stt_client_destroy(stt_h stt)
                        if (stt->handle == data->stt->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->current_engine_id) {
                                        free(data->current_engine_id);
                                }
 
+                               if (NULL != data->err_msg) {
+                                       free(data->err_msg);
+                                       data->err_msg = NULL;
+                               }
+
+                               if (NULL != data->credential) {
+                                       free(data->credential);
+                                       data->credential = NULL;
+                               }
+
                                free(data);
                                free(stt);
+                               data = NULL;
+                               stt = NULL;
 
                                return 0;
                        }
@@ -124,7 +154,7 @@ int stt_client_destroy(stt_h stt)
                }
        }
 
-       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] client Not founded");
+       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] client Not founded"); //LCOV_EXCL_LINE
 
        return -1;
 }
@@ -133,7 +163,7 @@ int stt_client_destroy(stt_h stt)
 stt_client_s* stt_client_get(stt_h stt)
 {
        if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
                return NULL;
        }
 
@@ -147,7 +177,7 @@ stt_client_s* stt_client_get(stt_h stt)
                while (NULL != iter) {
                        data = iter->data;
                        if (NULL != data) {
-                               if (stt->handle == data->stt->handle) 
+                               if (stt->handle == data->stt->handle)
                                        return data;
                        }
                        /* Next item */
@@ -163,7 +193,7 @@ stt_client_s* stt_client_get(stt_h stt)
 stt_client_s* stt_client_get_by_uid(const int uid)
 {
        if (uid < 0) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] out of range : handle");
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] out of range : handle"); //LCOV_EXCL_LINE
                return NULL;
        }
 
@@ -185,7 +215,7 @@ stt_client_s* stt_client_get_by_uid(const int uid)
                }
        }
 
-       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get client by uid");
+       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get client by uid"); //LCOV_EXCL_LINE
 
        return NULL;
 }
@@ -215,4 +245,4 @@ int stt_client_get_use_callback(stt_client_s* client)
 GList* stt_client_get_client_list()
 {
        return g_client_list;
-}
\ No newline at end of file
+}