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.
17 #include "sttd_main.h"
18 #include "sttd_config.h"
25 int sttd_config_get_char_type(const char* key, char** value)
27 if (NULL == key || NULL == value) {
28 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
29 return STTD_ERROR_INVALID_PARAMETER;
32 *value = vconf_get_str(key);
34 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get char type from config : key(%s)", key);
41 int sttd_config_set_char_type(const char* key, const char* value)
43 if (NULL == key || NULL == value) {
44 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
45 return STTD_ERROR_INVALID_PARAMETER;
48 if (0 != vconf_set_str(key, value)) {
49 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set char type");
56 int sttd_config_get_bool_type(const char* key, bool* value)
58 if (NULL == key || NULL == value) {
59 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
60 return STTD_ERROR_INVALID_PARAMETER;
64 if (0 != vconf_get_int(key, &result)) {
65 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
69 *value = (bool) result;
74 int sttd_config_set_bool_type(const char* key, const bool value)
77 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
78 return STTD_ERROR_INVALID_PARAMETER;
81 int result = (int)value;
82 if (0 != vconf_set_int(key, result)) {
83 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
91 * plug-in daemon interface
94 int __make_key_for_engine(const char* engine_id, const char* key, char** out_key)
96 int key_size = strlen(STTD_CONFIG_PREFIX) + strlen(engine_id) + strlen(key) + 2; /* 2 means both '/' and '\0'*/
98 *out_key = (char*) malloc( sizeof(char) * key_size);
100 snprintf(*out_key, key_size, "%s%s/%s", STTD_CONFIG_PREFIX, engine_id, key );
105 int sttd_config_set_persistent_data(const char* engine_id, const char* key, const char* value)
107 if (NULL == engine_id || NULL == key || NULL == value) {
108 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter");
109 return STTD_ERROR_INVALID_PARAMETER;
112 char* vconf_key = NULL;
113 if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
114 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
118 if (NULL == vconf_key)
121 if (0 != vconf_set_str(vconf_key, value)) {
122 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set key, value");
124 if (vconf_key != NULL)
130 SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_set_persistent_data : key(%s), value(%s)", vconf_key, value);
132 if (NULL != vconf_key)
138 int sttd_config_get_persistent_data(const char* engine_id, const char* key, char** value)
140 if (NULL == engine_id) {
141 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter");
142 return STTD_ERROR_INVALID_PARAMETER;
145 char* vconf_key = NULL;
147 if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
148 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
152 if (NULL == vconf_key)
156 temp = vconf_get_str(vconf_key);
158 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get value");
160 if(vconf_key != NULL)
166 *value = g_strdup(temp);
168 SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_get_persistent_data : key(%s), value(%s)", vconf_key, *value);
170 if (vconf_key != NULL) free(vconf_key);
171 if (temp != NULL) free(temp);
176 int sttd_config_remove_persistent_data(const char* engine_id, const char* key)
178 if (NULL == engine_id || NULL == key) {
179 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter");
180 return STTD_ERROR_INVALID_PARAMETER;
183 char* vconf_key = NULL;
184 if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
185 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
189 if (NULL == vconf_key)
192 if (0 != vconf_unset(vconf_key)) {
193 SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to remove key");
195 if(vconf_key != NULL)
201 SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_remove_persistent_data : key(%s)", vconf_key);
203 if( NULL != vconf_key )