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.
19 * @OMA_DS_Platform_Event_Handler.c
21 * @brief This file is the source file of implementation of event callback function(from platform)
24 #include <sync_agent.h>
25 #include <plugin/plugin_slp_sysnoti_wap_push.h>
27 #include "framework/event/oma_ds_platform_event_handler.h"
28 #include "framework/task/oma_ds_engine_controller_task.h"
29 #include "framework/san-parser/pm_sanparser.h"
30 #include "common/common_define_internal.h"
31 #include "common/common_util.h"
33 #ifndef OMADS_AGENT_LOG
35 #define LOG_TAG "OMA_DS_COMMON"
38 static void _request_periodic_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data);
40 static void _request_san_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data);
42 static void _request_periodic_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data)
46 unsigned int request_msg_id_to_cancel = 0;
47 get_periodic_sync_request_id(&request_msg_id_to_cancel);
53 static void _request_san_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data)
57 unsigned int request_msg_id_to_cancel = 0;
58 get_san_sync_request_id(&request_msg_id_to_cancel);
63 int san_callback_parse(int item_id, void *user_data)
66 san_package_s *pSanPackage = NULL;
68 char *sync_mode = NULL;
69 char *server_id = NULL;
72 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
73 sync_agent_fw_account_s *fw_account = NULL;
74 GList *account_info_list = NULL;
77 pmci_san_incoming_s *incoming_data = (pmci_san_incoming_s *) user_data;
79 switch (incoming_data->version) {
82 pSanPackage = san_package_11_parser(incoming_data->msg_body, incoming_data->msg_size);
87 pSanPackage = san_package_12_parser(incoming_data->msg_body, incoming_data->msg_size);
94 sync_agent_da_return_e da_err = sync_agent_open_agent();
95 if (da_err != SYNC_AGENT_DA_SUCCESS) {
96 _DEBUG_ERROR("da_err = %d", da_err);
100 if (pSanPackage == NULL) {
101 _DEBUG_ERROR("pSanPackage is NULL");
105 sync_agent_fw_account_query_s query;
106 query.query = ACCOUNT_QUERY_BY_NONE;
108 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
109 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
110 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
114 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
115 fw_account = (sync_agent_fw_account_s *) iter->data;
116 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode);
117 if (result == true) {
118 /*One device MUST NOT register multi account at same server... */
119 if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) {
120 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
121 if (result == true) {
122 /*One device MUST NOT register multi account at same server... */
123 if (strcmp(pSanPackage->server_id, server_id) == 0) {
124 accountID = fw_account->account_id;
128 _DEBUG_ERROR("failed in get_Config");
133 _DEBUG_ERROR("failed in get_Config");
142 char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH);
144 void *in_param_value_array[3] = { &accountID, &syncMode, &pSanPackage };
145 int in_param_index_array[3] = { 0, 1, 2 };
146 sync_agent_ec_value_type_e in_param_type[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT };
147 unsigned int request_msg_id = 0;
148 sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_type, in_param_value_array, _request_san_sync_task_finish_callback, NULL, (int *)&request_msg_id);
150 insert_request_msg_info(SYNC_MODE_SAN, request_msg_id, accountID);
152 sync_agent_close_agent();
154 if (pSanPackage != NULL)
155 sanPackageParserFree((void *)pSanPackage);
162 sync_agent_free_fw_account_list(account_info_list);
164 if (sync_mode != NULL)
167 if (server_id != NULL)
170 /* if( incoming_data != NULL){
171 if (incoming_data->msg_body != NULL)
172 free((void *)incoming_data->msg_body);
177 if (pSanPackage != NULL)
178 sanPackageParserFree((void *)pSanPackage);
180 sync_agent_close_agent();
186 void send_periodic_sync_msg(int scheduler_id, void *data)
190 _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!##########");
191 _DEBUG_INFO("schedulerId = %d", scheduler_id);
195 char *alarmId_str = NULL;
198 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
199 sync_agent_fw_account_s *fw_account = NULL;
200 GList *account_info_list = NULL;
203 sync_agent_da_return_e da_err = sync_agent_open_agent();
204 if (da_err != SYNC_AGENT_DA_SUCCESS) {
205 _DEBUG_ERROR("failed in sync_agent_open_agent");
209 sync_agent_fw_account_query_s query;
210 query.query = ACCOUNT_QUERY_BY_NONE;
212 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
213 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
214 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
218 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
219 fw_account = (sync_agent_fw_account_s *) iter->data;
220 if (alarmId_str != NULL)
223 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
224 if (result == false) {
225 _DEBUG_ERROR("failed in get_Config");
228 alarmId = atoi(alarmId_str);
229 _DEBUG_INFO("alarm id = %d", alarmId);
230 if (alarmId == scheduler_id) {
231 _DEBUG_INFO("account_list[i] = %d", fw_account->account_id);
232 accountId = fw_account->account_id;
237 if (accountId != -1) {
238 int in_param_index_array[3] = { 0, 1, 2 };
239 sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT,
240 SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT
242 char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
244 void *in_param_value_array[3] = { &accountId, &syncMode, NULL };
246 unsigned int request_msg_id = 0;
247 sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_value_type_array, in_param_value_array, _request_periodic_sync_task_finish_callback, NULL, (int *)&request_msg_id);
249 insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id, accountId);
254 sync_agent_free_fw_account_list(account_info_list);
256 if (alarmId_str != NULL)
259 sync_agent_close_agent();
264 int send_ip_push_sync_msg(char *data)
268 san_package_s *pSanPackage = NULL;
270 char *server_id = NULL;
274 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
275 GList *account_info_list = NULL;
277 sync_agent_fw_account_s *account_info = NULL;
279 sync_agent_da_return_e da_err = sync_agent_open_agent();
280 if (da_err != SYNC_AGENT_DA_SUCCESS) {
281 _DEBUG_ERROR("failed in sync_agent_open_agent");
285 result = parse_ip_push_msg(data, &pSanPackage, &id);
286 if (result != true) {
287 _DEBUG_ERROR("Failed in parseIPPushMsg");
291 cancel_current_sync_task();
293 sync_agent_fw_account_query_s query;
294 query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
295 query.access_name = "DIVE";
297 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
299 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
300 account_info = (sync_agent_fw_account_s *) iter->data;
302 _DEBUG_INFO("accountId = %d", account_info->account_id);
303 result = get_config(account_info->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
304 if (result == true) {
305 if (strcmp(pSanPackage->server_id, server_id) == 0) {
306 accountId = account_info->account_id;
310 _DEBUG_ERROR("failed in get_Config");
318 char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH);
320 void *in_param_value_array[3] = { &accountId, &syncMode, &pSanPackage };
321 int in_param_index_array[3] = { 0, 1, 2 };
322 sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT };
323 unsigned int request_msg_id = 0;
324 sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_value_type_array, in_param_value_array, _request_san_sync_task_finish_callback, NULL, (int *)&request_msg_id);
326 insert_request_msg_info(SYNC_MODE_SAN, request_msg_id, accountId);
328 sync_agent_free_fw_account_list(account_info_list);
330 if (server_id != NULL)
333 // if (pSanPackage != NULL)
334 // sanPackageParserFree((void *)pSanPackage);
336 sync_agent_close_agent();
343 sync_agent_free_fw_account_list(account_info_list);
345 if (server_id != NULL)
348 if (pSanPackage != NULL)
349 sanPackageParserFree((void *)pSanPackage);
351 sync_agent_close_agent();