2 * Copyright (c) 2011 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.
16 #include "ttsd_main.h"
17 #include "ttsd_config.h"
23 int ttsd_config_get_char_type(const char* key, char** value)
25 if (NULL == key || NULL == value) {
26 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
27 return TTSD_ERROR_INVALID_PARAMETER;
30 *value = vconf_get_str(key);
32 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to get char type from config : key(%s)\n", key);
39 int ttsd_config_set_char_type(const char* key, const char* value)
41 if (NULL == key || NULL == value) {
42 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
43 return TTSD_ERROR_INVALID_PARAMETER;
46 if (0 != vconf_set_str(key, value)) {
47 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to set char type \n");
54 int ttsd_config_get_bool_type(const char* key, bool* value)
56 if (NULL == key || NULL == value) {
57 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
58 return TTSD_ERROR_INVALID_PARAMETER;
62 if (0 != vconf_get_int(key, &result)) {
63 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to get bool type config : key(%s)\n", key);
67 *value = (bool) result;
72 int ttsd_config_set_bool_type(const char* key, const bool value)
75 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
76 return TTSD_ERROR_INVALID_PARAMETER;
79 int result = (int)value;
80 if (0 != vconf_set_int(key, result)) {
81 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to set bool type config : key(%s)\n", key);
88 int ttsd_config_get_int_type(const char* key, int* value)
90 if (NULL == key || NULL == value) {
91 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
92 return TTSD_ERROR_INVALID_PARAMETER;
95 if (0 != vconf_get_int(key, value)) {
96 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to get bool type config : key(%s)\n", key);
103 int ttsd_config_set_int_type(const char* key, const int value)
106 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Input parameter is NULL\n");
107 return TTSD_ERROR_INVALID_PARAMETER;
110 if (0 != vconf_set_int(key, value)) {
111 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to set int type config : key(%s)\n", key);
119 * interface for engine plug-in
122 int config_make_key_for_engine(const char* engine_id, const char* key, char** out_key)
124 int key_size = strlen(TTSD_CONFIG_PREFIX) + strlen(engine_id) + strlen(key) + 2; /* 2 is '/' and '\0' */
126 *out_key = (char*) g_malloc0( sizeof(char) * key_size);
128 if (*out_key == NULL) {
129 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] Not enough memory!! \n");
132 snprintf(*out_key, key_size, "%s%s/%s", TTSD_CONFIG_PREFIX, engine_id, key );
133 SLOG(LOG_DEBUG, TAG_TTSD, "[Config DEBUG] make key (%s) \n", *out_key);
139 int ttsd_config_set_persistent_data(const char* engine_id, const char* key, const char* value)
141 char* vconf_key = NULL;
143 if (0 != config_make_key_for_engine(engine_id, key, &vconf_key)) {
144 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail config_make_key_for_engine()\n");
148 if (0 != vconf_set_str(vconf_key, value)) {
149 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to set key, value\n");
151 if(vconf_key != NULL)
157 SLOG(LOG_DEBUG, TAG_TTSD, "[Config DEBUG] Set data : key(%s), value(%s) \n", vconf_key, value);
159 if (vconf_key != NULL)
165 int ttsd_config_get_persistent_data(const char* engine_id, const char* key, char** value)
167 char* vconf_key = NULL;
169 if (0 != config_make_key_for_engine(engine_id, key, &vconf_key)) {
170 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail config_make_key_for_engine()\n");
175 temp = vconf_get_str(vconf_key);
177 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to get value\n");
179 if(vconf_key != NULL)
185 *value = g_strdup(temp);
187 SLOG(LOG_DEBUG, TAG_TTSD, "[Config DEBUG] Get data : key(%s), value(%s) \n", vconf_key, *value);
189 if (NULL != vconf_key)
198 int ttsd_config_remove_persistent_data(const char* engine_id, const char* key)
200 char* vconf_key = NULL;
203 if (0 != config_make_key_for_engine(engine_id, key, &vconf_key)) {
204 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail config_make_key_for_engine()\n");
208 if( NULL == vconf_key )
211 if (0 != vconf_unset(vconf_key)) {
212 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR] fail to remove key\n");
215 SLOG(LOG_DEBUG, TAG_TTSD, "[Config DEBUG] Remove data : key(%s)", vconf_key);
218 if( vconf_key != NULL )