4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JuHak Park <juhaki.park@samsung.com>,
7 * JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8 * SunBong Ha <sunbong.ha@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 * For any sort of issue you concern as to this software,
29 * you may use following point of contact.
30 * All resources contributed on this software
31 * are orinigally written by S-Core Inc., a member of Samsung Group.
33 * SeongWon Shim <seongwon.shim@samsung.com>
39 * @brief This file is the source file of implementation of utility function
42 #include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
43 #include "agent-framework/Utility/fw_log.h"
44 #include "Common/Common_Util.h"
45 #include "Common/Common_Define_Internal.h"
47 #define LOG_TAG "OMA_DS_COMMON"
48 #define MAX_RETRY_COUNT 10
50 bool set_config_str(int accountID, char *key, char *value, char * type, char *accessName)
54 config.config_id = accountID;
58 config.access_name = accessName;
60 result = DACI_Update_Config(&config, 1);
62 if (result == DACI_SUCCESS)
69 bool set_config_int(int accountID, char *key, int value, char * type, char *accessName)
71 char *value_str = NULL;
72 value_str = g_strdup_printf("%u", value);
76 config.config_id = accountID;
78 config.value = value_str;
80 config.access_name = accessName;
82 result = DACI_Update_Config(&config, 1);
84 if (value_str != NULL)
87 if (result == DACI_SUCCESS)
95 bool get_config(int accountId, char *key, char **value)
99 daci.config_id = accountId;
102 result = DACI_Get_Config_By_Key(&daci);
104 if (result == DACI_SUCCESS) {
106 if (daci.type != NULL)
110 /* FIXME temporary solution
111 * Try MAX_RETRY_COUNT when fail to get_config
114 bool success = false;
115 for (i = 0; i < MAX_RETRY_COUNT; i++){
116 result =DACI_Get_Config_By_Key(&daci);
117 if(result == DACI_SUCCESS){
119 if (daci.type != NULL)
132 int get_accountid(char *profile, bool open)
136 char *profileDirName = NULL;
137 int *account_list = 0;
138 int account_list_count = 0;
142 DACI_RETURN da_err = DACI_Open_Agent();
143 if (da_err != DACI_SUCCESS) {
144 FW_LOGE("failed in DACI_Open_Agent");
149 account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
152 for (i = 0; i < account_list_count; i++) {
153 if (profileDirName != NULL)
154 free(profileDirName);
156 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
157 if (result == false) {
158 FW_LOGE("failed in get_Config");
162 FW_LOGV("profileDirName = %s", profileDirName);
163 if(profileDirName == NULL )
166 if (strcmp(profile, profileDirName) == 0) {
167 FW_LOGV("account_list[i] = %d", account_list[i]);
168 accountId = account_list[i];
177 if (account_list_count > 0)
181 free(profileDirName);
189 /*int convert_synctype_value(char *syncType_str)
193 if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) ==0)
194 syncType_value = ALERT_SLOW_SYNC ;
195 else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) ==0)
196 syncType_value = ALERT_TWO_WAY ;
197 else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) ==0)
198 syncType_value = ALERT_ONE_WAY_FROM_CLIENT;
199 else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) ==0)
200 syncType_value = ALERT_ONE_WAY_FROM_SERVER;
201 else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) ==0)
202 syncType_value = ALERT_REFRESH_FROM_SERVER;
203 else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) ==0)
204 syncType_value = ALERT_REFRESH_FROM_CLIENT;
206 syncType_value = ALERT_UNKNOWN;
208 return syncType_value;
211 /*char *convert_synctype_str(char *syncType_value)
213 char *syncType_str = NULL;
215 if (strcmp(syncType_value, DEFINE_ALERT_SLOW_SYNC_VALUE) ==0)
216 syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;
217 else if (strcmp(syncType_value, DEFINE_ALERT_TWO_WAY_VALUE) ==0)
218 syncType_str = DEFINE_ALERT_TWO_WAY_STR;
219 else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
220 syncType_str = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
221 else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
222 syncType_str = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
223 else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_SERVER_VALUE) ==0)
224 syncType_str = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
225 else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_CLIENT_VALUE) ==0)
226 syncType_str = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
228 syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;