3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "utility/sync_util.h"
19 #include "utility/fw_ref.h"
20 #include "plugin/account_plugin.h"
22 #include "data-adapter/agent_handler_manager.h"
23 #include "data-adapter/agent_handler_manager_internal.h"
25 #include "account/manager.h"
26 #include "account/util_internal.h"
28 #ifndef SYNC_AGENT_LOG
30 #define LOG_TAG "AF_ACCOUNT"
33 int acc_is_exist_account(int account_id)
37 return da_is_exist_account_id(account_id);
42 int *acc_get_service_account_id_list(int service_type, int *cnt)
46 int *account_id_list = acc_get_account_list(cnt);
48 if ((*cnt != 0) && (account_id_list != NULL)) {
49 int *service_account_id_list = (int *)calloc(*cnt, sizeof(int));
50 if (service_account_id_list == NULL) {
52 if (account_id_list != NULL) {
53 free(account_id_list);
61 for (; i < *cnt; i++) {
62 service_account_id_list[i] = acc_get_service_account_id(service_type, account_id_list[i]);
64 if (account_id_list != NULL) {
65 free(account_id_list);
67 return service_account_id_list;
70 if (account_id_list != NULL) {
71 free(account_id_list);
79 int acc_get_service_account_id(int service_type, int account_id)
83 plugin_get_service_account_id_cb func = plugin_get_function_get_service_account_id(plugin_get_account_plugin_id());
86 int service_account_id = func(service_type, account_id);
88 return service_account_id;
96 int acc_get_fw_account_id(int service_type, int service_account_id, int index)
100 plugin_get_fw_account_id_cb func = plugin_get_function_get_fw_account_id(plugin_get_account_plugin_id());
103 int account_id = func(service_type, service_account_id, index);
113 int *acc_get_account_list(int *cnt)
117 sync_agent_da_return_e da_err = sync_agent_open_agent();
118 _DEBUG_INFO("Done Open Agent DB : %d", da_err);
120 int *account_list = da_get_account_id_list(cnt);
122 da_err = sync_agent_close_agent();
123 _DEBUG_INFO("Done Close Agent DB : %d", da_err);
130 void acc_add_platform_account(int fw_account_id)
134 _DEBUG_INFO("sync_agent_add_platform_account called");
135 plugin_add_platform_account_cb func = plugin_get_function_add_platform_account(plugin_get_account_plugin_id());
138 _DEBUG_INFO("pFunc is not null");
141 _DEBUG_INFO("pFunc is null");
147 void acc_delete_platform_account(int fw_account_id)
151 _DEBUG_INFO("sync_agent_delete_platform_account called");
152 plugin_delete_platform_account_cb func = plugin_get_function_delete_platform_account(plugin_get_account_plugin_id());
155 _DEBUG_INFO("pFunc is not null");
158 _DEBUG_INFO("pFunc is null");
164 int *acc_get_fw_account_id_list(int content_type, int *count)
169 int fw_account_count = 0;
170 int *fw_account_id_list = da_get_account_id_list(&fw_account_count);
172 if (fw_account_count == 0 || fw_account_id_list == NULL) {
174 if (fw_account_id_list != NULL)
175 free(fw_account_id_list);
180 int *account_id_list = (int *)calloc(fw_account_count, sizeof(int));
181 if (account_id_list == NULL) {
183 if (fw_account_id_list != NULL)
184 free(fw_account_id_list);
190 for (; i < fw_account_count; i++) {
191 plugin_has_platform_account_service_cb func_has_platform_account_service = plugin_get_function_has_platform_account_service(plugin_get_account_plugin_id());
192 int has_service_account_id = func_has_platform_account_service(fw_account_id_list[i], content_type);
194 if (has_service_account_id) {
195 account_id_list[*count] = fw_account_id_list[i];
200 if (fw_account_id_list != NULL) {
201 free(fw_account_id_list);
206 return account_id_list;