c194bd8777c7fb2174c4b2f66d3c5e7609c5cdbd
[platform/core/uifw/stt.git] / client / stt_file_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 #include <dlog.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18
19 #include "stt_file_client.h"
20
21 static stt_file_client_s* g_client_info = NULL;
22
23 int stt_file_client_new()
24 {
25         if (NULL != g_client_info) {
26                 SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Already allocated client info");
27                 return STT_FILE_ERROR_INVALID_STATE;
28         }
29
30         g_client_info = (stt_file_client_s*)calloc(1, sizeof(stt_file_client_s));
31
32         /* initialize client data */
33         g_client_info->recognition_result_cb = NULL;
34         g_client_info->recognition_result_user_data = NULL;
35
36         g_client_info->result_time_cb = NULL;
37         g_client_info->result_time_user_data = NULL;
38
39         g_client_info->state_changed_cb = NULL;
40         g_client_info->state_changed_user_data = NULL;
41
42         g_client_info->supported_lang_cb = NULL;
43         g_client_info->supported_lang_user_data = NULL;
44
45         g_client_info->current_engine_id = -1;
46
47         g_client_info->time_info = NULL;
48         
49         g_client_info->before_state = STT_FILE_STATE_READY;
50         g_client_info->current_state = STT_FILE_STATE_READY;
51
52         g_client_info->cb_ref_count = 0;
53
54         return 0;       
55 }
56
57 int stt_file_client_destroy()
58 {
59         if (NULL == g_client_info) {
60                 SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Client info is NULL");
61                 return STT_FILE_ERROR_INVALID_STATE;
62         } else {
63                 while (0 != g_client_info->cb_ref_count) {
64                         /* wait for release callback function */
65                 }
66                 
67                 free(g_client_info);
68
69                 g_client_info = NULL;
70         }
71
72         return 0;
73 }
74
75 stt_file_client_s* stt_file_client_get()
76 {
77         return g_client_info;
78 }
79
80 int stt_file_client_use_callback(stt_file_client_s* client)
81 {
82         client->cb_ref_count++;
83         return 0;
84 }
85
86 int stt_file_client_not_use_callback(stt_file_client_s* client)
87 {
88         client->cb_ref_count--;
89         return 0;
90 }
91
92 int stt_file_client_get_use_callback(stt_file_client_s* client)
93 {
94         return client->cb_ref_count;
95 }