/* * oma-ds-agent * Copyright (c) 2012 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @OMA_DS_Platform_Event_Handler.c * @version 0.1 * @brief This file is the source file of implementation of event callback function(from platform) */ #include #include #include "framework/event/oma_ds_platform_event_handler.h" #include "framework/task/oma_ds_engine_controller_task.h" #include "framework/san-parser/pm_sanparser.h" #include "common/common_define_internal.h" #include "common/common_util.h" #ifndef OMADS_AGENT_LOG #undef LOG_TAG #define LOG_TAG "OMA_DS_COMMON" #endif 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); 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); 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) { _INNER_FUNC_ENTER; unsigned int request_msg_id_to_cancel = 0; get_periodic_sync_request_id(&request_msg_id_to_cancel); _INNER_FUNC_EXIT; } 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) { _INNER_FUNC_ENTER; unsigned int request_msg_id_to_cancel = 0; get_san_sync_request_id(&request_msg_id_to_cancel); _INNER_FUNC_EXIT; } int san_callback_parse(int item_id, void *user_data) { _EXTERN_FUNC_ENTER; san_package_s *pSanPackage = NULL; int accountID = -1; char *sync_mode = NULL; char *server_id = NULL; bool result; sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; sync_agent_fw_account_s *fw_account = NULL; GList *account_info_list = NULL; GList *iter = NULL; pmci_san_incoming_s *incoming_data = (pmci_san_incoming_s *) user_data; switch (incoming_data->version) { case 11: { pSanPackage = san_package_11_parser(incoming_data->msg_body, incoming_data->msg_size); } break; case 12: { pSanPackage = san_package_12_parser(incoming_data->msg_body, incoming_data->msg_size); } break; default: break; } sync_agent_da_return_e da_err = sync_agent_open_agent(); if (da_err != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("da_err = %d", da_err); goto return_part; } if (pSanPackage == NULL) { _DEBUG_ERROR("pSanPackage is NULL"); goto return_part; } sync_agent_fw_account_query_s query; query.query = ACCOUNT_QUERY_BY_NONE; acc_err = sync_agent_query_fw_account(&query, &account_info_list); if (acc_err != SYNC_AGENT_ACC_SUCCESS) { _DEBUG_ERROR("sync_agent_query_fw_account is failed"); goto return_part; } for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { fw_account = (sync_agent_fw_account_s *) iter->data; result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode); if (result == true) { /*One device MUST NOT register multi account at same server... */ if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) { result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id); if (result == true) { /*One device MUST NOT register multi account at same server... */ if (strcmp(pSanPackage->server_id, server_id) == 0) { accountID = fw_account->account_id; break; } } else { _DEBUG_ERROR("failed in get_Config"); goto return_part; } } } else { _DEBUG_ERROR("failed in get_Config"); goto return_part; } } if (accountID < 0) goto return_part; char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH); void *in_param_value_array[3] = { &accountID, &syncMode, &pSanPackage }; int in_param_index_array[3] = { 0, 1, 2 }; 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 }; unsigned int request_msg_id = 0; 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); insert_request_msg_info(SYNC_MODE_SAN, request_msg_id); sync_agent_close_agent(); if (pSanPackage != NULL) sanPackageParserFree((void *)pSanPackage); _EXTERN_FUNC_EXIT; return 1; return_part: sync_agent_free_fw_account_list(account_info_list); if (sync_mode != NULL) free(sync_mode); if (server_id != NULL) free(server_id); /* if( incoming_data != NULL){ if (incoming_data->msg_body != NULL) free((void *)incoming_data->msg_body); free(incoming_data); }*/ if (pSanPackage != NULL) sanPackageParserFree((void *)pSanPackage); sync_agent_close_agent(); _EXTERN_FUNC_EXIT; return 0; } void send_periodic_sync_msg(int scheduler_id, void *data) { _EXTERN_FUNC_ENTER; _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!##########"); _DEBUG_INFO("schedulerId = %d", scheduler_id); int accountId = -1; int alarmId = 0; char *alarmId_str = NULL; bool result; sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; sync_agent_fw_account_s *fw_account = NULL; GList *account_info_list = NULL; GList *iter = NULL; sync_agent_da_return_e da_err = sync_agent_open_agent(); if (da_err != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("failed in sync_agent_open_agent"); goto error; } sync_agent_fw_account_query_s query; query.query = ACCOUNT_QUERY_BY_NONE; acc_err = sync_agent_query_fw_account(&query, &account_info_list); if (acc_err != SYNC_AGENT_ACC_SUCCESS) { _DEBUG_ERROR("sync_agent_query_fw_account is failed"); goto error; } for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { fw_account = (sync_agent_fw_account_s *) iter->data; if (alarmId_str != NULL) free(alarmId_str); result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str); if (result == false) { _DEBUG_ERROR("failed in get_Config"); goto error; } alarmId = atoi(alarmId_str); _DEBUG_INFO("alarm id = %d", alarmId); if (alarmId == scheduler_id) { _DEBUG_INFO("account_list[i] = %d", fw_account->account_id); accountId = fw_account->account_id; break; } } if (accountId != -1) { int in_param_index_array[3] = { 0, 1, 2 }; 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 }; char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC); void *in_param_value_array[3] = { &accountId, &syncMode, NULL }; unsigned int request_msg_id = 0; 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); insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id); } error: sync_agent_free_fw_account_list(account_info_list); if (alarmId_str != NULL) free(alarmId_str); sync_agent_close_agent(); _EXTERN_FUNC_EXIT; } int send_ip_push_sync_msg(char *data) { _EXTERN_FUNC_ENTER; san_package_s *pSanPackage = NULL; char *id = NULL; char *server_id = NULL; int accountId = -1; bool result = false; sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; GList *account_info_list = NULL; GList *iter = NULL; sync_agent_fw_account_s *account_info = NULL; sync_agent_da_return_e da_err = sync_agent_open_agent(); if (da_err != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("failed in sync_agent_open_agent"); goto error; } result = parse_ip_push_msg(data, &pSanPackage, &id); if (result != true) { _DEBUG_ERROR("Failed in parseIPPushMsg"); goto error; } cancel_current_sync_task(); sync_agent_fw_account_query_s query; query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; query.access_name = "DIVE"; acc_err = sync_agent_query_fw_account(&query, &account_info_list); for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { account_info = (sync_agent_fw_account_s *) iter->data; _DEBUG_INFO("accountId = %d", account_info->account_id); result = get_config(account_info->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id); if (result == true) { if (strcmp(pSanPackage->server_id, server_id) == 0) { accountId = account_info->account_id; break; } } else { _DEBUG_ERROR("failed in get_Config"); goto error; } } if (accountId < 0) goto error; char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH); void *in_param_value_array[3] = { &accountId, &syncMode, &pSanPackage }; int in_param_index_array[3] = { 0, 1, 2 }; 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 }; unsigned int request_msg_id = 0; 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); insert_request_msg_info(SYNC_MODE_SAN, request_msg_id); sync_agent_free_fw_account_list(account_info_list); if (server_id != NULL) free(server_id); // if (pSanPackage != NULL) // sanPackageParserFree((void *)pSanPackage); sync_agent_close_agent(); _EXTERN_FUNC_EXIT; return 1; error: sync_agent_free_fw_account_list(account_info_list); if (server_id != NULL) free(server_id); if (pSanPackage != NULL) sanPackageParserFree((void *)pSanPackage); sync_agent_close_agent(); _EXTERN_FUNC_EXIT; return 0; }