diff options
Diffstat (limited to 'src/agent/service-engine/se_sync.c')
-rwxr-xr-x | src/agent/service-engine/se_sync.c | 128 |
1 files changed, 115 insertions, 13 deletions
diff --git a/src/agent/service-engine/se_sync.c b/src/agent/service-engine/se_sync.c index c946921..367b89b 100755 --- a/src/agent/service-engine/se_sync.c +++ b/src/agent/service-engine/se_sync.c @@ -39,6 +39,8 @@ #define LOG_TAG "OMA_DS_SE" #endif +static int __convert_alert_to_sync_type_value(alert_type_e sync_type); +static int __convert_src_uri_value(char *src_uri); static se_error_type_e _session_process(int account_id, alert_type_e server_sync_type, sync_progress_e process, sync_error_e error); static se_error_type_e __process_update(int account_id, alert_type_e server_sync_type, sync_progress_status_e progress_status, operation_type_e operation_type, int content_type, bool is_from_server, bool need_to_save, sync_result_s * sync_result); static se_error_type_e _write_sync_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client); @@ -88,6 +90,64 @@ static inline long myclock() return (tv.tv_sec * 1000 + tv.tv_usec / 1000); } +static int __convert_alert_to_sync_type_value(alert_type_e sync_type) +{ + _INNER_FUNC_ENTER; + + int sync_type_value = 0; + _DEBUG_INFO("sync_type: [%d]", sync_type); + + switch (sync_type) { + case ALERT_TWO_WAY: + sync_type_value = SYNC_TYPE_UPDATE_BOTH; + break; + case ALERT_SLOW_SYNC: + sync_type_value = SYNC_TYPE_FULL_SYNC; + break; + case ALERT_ONE_WAY_FROM_CLIENT: + sync_type_value = SYNC_TYPE_UPDATE_TO_SERVER; + break; + case ALERT_REFRESH_FROM_CLIENT: + sync_type_value = SYNC_TYPE_REFRESH_FROM_PHONE; + break; + case ALERT_ONE_WAY_FROM_SERVER: + sync_type_value = SYNC_TYPE_UPDATE_TO_PHONE; + break; + case ALERT_REFRESH_FROM_SERVER: + sync_type_value = SYNC_TYPE_REFRESH_FROM_SERVER; + break; + default: + _DEBUG_ERROR("sync_type is invalid!!"); + break; + } + + _INNER_FUNC_EXIT; + return sync_type_value; +} + +static int __convert_src_uri_value(char *src_uri) +{ + _INNER_FUNC_ENTER; + + int src_uri_value = 0; + _DEBUG_INFO("src_uri: [%s]", src_uri); + + if (strcmp(src_uri,DEFINE_SOURCE_CONTACT_URI) == 0) { + src_uri_value = SRC_URI_CONTACT; + } else if (strcmp(src_uri,DEFINE_SOURCE_CALENDAR_URI)) { + src_uri_value = SRC_URI_CALENDAR; + } else if (strcmp(src_uri,DEFINE_SOURCE_MEMO_URI)) { + src_uri_value = SRC_URI_MEMO; + } else if (strcmp(src_uri,DEFINE_SOURCE_CALLLOG_URI)) { + src_uri_value = SRC_URI_CALLLOG; + } else { + _DEBUG_ERROR("src_uri is invalid!!"); + } + + _INNER_FUNC_EXIT; + return src_uri_value; +} + static se_error_type_e _session_process(int account_id, alert_type_e server_sync_type, sync_progress_e process, sync_error_e error) { _INNER_FUNC_ENTER; @@ -95,6 +155,7 @@ static se_error_type_e _session_process(int account_id, alert_type_e server_sync char *profileDirName = NULL; se_error_type_e err = SE_INTERNAL_OK; bool result; + int sync_type_value = 0; result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); if (result == false) { @@ -103,8 +164,11 @@ static se_error_type_e _session_process(int account_id, alert_type_e server_sync goto error; } + sync_type_value = __convert_alert_to_sync_type_value(server_sync_type); + _DEBUG_INFO("sync_type_value: [%d]", sync_type_value); + if (profileDirName != NULL) { - err = session_process(profileDirName, server_sync_type, process, error); + err = session_process(profileDirName, sync_type_value, process, error); if (err != SE_INTERNAL_OK) { _DEBUG_ERROR("failed to send noti"); goto error; @@ -112,8 +176,10 @@ static se_error_type_e _session_process(int account_id, alert_type_e server_sync } error: - if (profileDirName != NULL) + if (profileDirName != NULL) { free(profileDirName); + profileDirName = NULL; + } _INNER_FUNC_EXIT; @@ -133,6 +199,8 @@ static se_error_type_e __process_update(int account_id, alert_type_e server_sync char *sync_type = NULL; char *operation = NULL; char *progress = NULL; + int sync_type_value = 0; + int uri_value = 0; bool result; result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); @@ -157,6 +225,8 @@ static se_error_type_e __process_update(int account_id, alert_type_e server_sync } sync_type = __convert_sync_type_str(server_sync_type); + sync_type_value = __convert_alert_to_sync_type_value(server_sync_type); + _DEBUG_INFO("sync_type_value: [%d]", sync_type_value); progress = ___convert_sync_progress_status_str(progress_status); @@ -171,8 +241,15 @@ static se_error_type_e __process_update(int account_id, alert_type_e server_sync if (datastoreinfo_per_content_type[content_type]->source != NULL) uri = strdup(datastoreinfo_per_content_type[content_type]->source); } + if (uri != NULL) { + uri_value = __convert_src_uri_value(uri); + _DEBUG_INFO("uri_value: [%d]", uri_value); + } else { + _DEBUG_ERROR("uri is NULL!!"); + goto error; + } - err = send_noti_process_update(profileDirName, sync_type, uri, progress, operation, is_from_server, 0, 0, sync_result->number_of_change, sync_result->add_count + sync_result->replace_count + sync_result->delete_count); + err = send_noti_process_update(profileDirName, sync_type_value, uri_value, progress, operation, is_from_server, 0, 0, sync_result->number_of_change, sync_result->add_count + sync_result->replace_count + sync_result->delete_count); if (err != SE_INTERNAL_OK) { _DEBUG_ERROR("failed in send_noti_process_update"); goto error; @@ -965,7 +1042,7 @@ static se_error_type_e _assemble_changed_datastores(int account_id, alert_type_e /*_DEBUG_TRACE("sync_agent_refresh_item_tbl_from_service"); sync_agent_refresh_item_tbl_from_service(account_id, datastoreinfo_per_content_type[content_type]->plugin_type);*/ - /* Delete All item (include changelog), before adapting server item data… */ + /* Delete All item (include changelog), before adapting server item data */ _DEBUG_TRACE("sync_agent_begin_service = %d", datastoreinfo_per_content_type[content_type]->datastore_id); sync_agent_begin_service(datastoreinfo_per_content_type[content_type]->datastore_id); sync_agent_begin_transaction(); @@ -1072,7 +1149,16 @@ static se_error_type_e _assemble_changed_datastores(int account_id, alert_type_e } _DEBUG_TRACE("sync_agent_end_service = %d", datastoreinfo_per_content_type[content_type]->datastore_id); - sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 1); + da_err = sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 1); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); + sync_agent_free_item_list(item_list); + + _DEBUG_ERROR("failed in sync_agent_end_service !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); sync_agent_free_item_list(item_list); } @@ -2416,6 +2502,9 @@ static char *_convert_sync_progress_str(sync_progress_e process) case PROGRESS_DONE: syncProcess = DEFINE_SYNC_DONE; break; + case PROGRESS_CANCEL: + syncProcess = DEFINE_SYNC_CANCEL; + break; case PROGRESS_ERROR: syncProcess = DEFINE_SYNC_ERROR; break; @@ -2775,7 +2864,7 @@ bool synchronize(int account_id, char *sync_mode, san_package_s * san_package) bool cancel_status = check_cancel_status(); if (cancel_status) { err = SE_INTERNAL_SUSPEND; - _DEBUG_INFO("cancle flag is on"); + _DEBUG_INFO("cancel_status is on"); goto suspend_part; } } else { @@ -2790,7 +2879,7 @@ bool synchronize(int account_id, char *sync_mode, san_package_s * san_package) bool cancel_status = check_cancel_status(); if (cancel_status) { err = SE_INTERNAL_SUSPEND; - _DEBUG_INFO("cancle flag is on"); + _DEBUG_INFO("cancel_status is on"); goto suspend_part; } } @@ -2838,8 +2927,10 @@ bool synchronize(int account_id, char *sync_mode, san_package_s * san_package) suspend_part: errorCode = suspend_sync(TRANSPORT_TYPE, account_id, server_flag); + if (errorCode != COMMON_OK) { - _DEBUG_ERROR("Failed in suspend_sync = %d", errorCode); + _DEBUG_ERROR("failed in suspend_sync = %d",errorCode); + err = SE_INTERNAL_SA_ERROR; if (errorCode == COMMON_SUSPEND_FAIL) _off_resume_flag(account_id); @@ -2968,8 +3059,6 @@ void convert_common_errorcode(common_error_type_e errorCode, sync_progress_e * p _EXTERN_FUNC_ENTER; switch (errorCode) { - case COMMON_CANCEL: - case COMMON_SUSPEND_FAIL: case COMMON_OK: /*ERROR_INTERNAL_OK */ { /* Do nothing : Error None @@ -2982,6 +3071,13 @@ void convert_common_errorcode(common_error_type_e errorCode, sync_progress_e * p *error = ERROR_NONE; } break; + case COMMON_SUSPEND_FAIL: + case COMMON_CANCEL: + { + *process = PROGRESS_CANCEL; + *error = ERROR_NONE; + } + break; case COMMON_MISCONFIGURATION: /*ERROR_INTERNAL_MISCONFIGURATION : need configure infomation (account_id, id, pw, server_url...) */ { *process = PROGRESS_ERROR; @@ -3046,12 +3142,15 @@ void convert_engine_errorcode(se_error_type_e err, sync_progress_e * process, sy _EXTERN_FUNC_ENTER; switch (err) { - case SE_INTERNAL_SUSPEND: - case SE_INTERNAL_CANCEL: case SE_INTERNAL_OK: *process = PROGRESS_DONE; *error = ERROR_NONE; break; + case SE_INTERNAL_SUSPEND: + case SE_INTERNAL_CANCEL: + *process = PROGRESS_CANCEL; + *error = ERROR_NONE; + break; case ERROR_UNKNOWN: case SE_INTERNAL_SA_ERROR: case SE_INTERNAL_SCHEDULER_ERROR: @@ -3096,8 +3195,11 @@ se_error_type_e session_process(char *profileDirName, alert_type_e server_sync_t char *sync_type = NULL; char *syncProcess = NULL; char *syncError = NULL; + int sync_type_value = 0; sync_type = __convert_sync_type_str(server_sync_type); + sync_type_value = __convert_alert_to_sync_type_value(server_sync_type); + _DEBUG_INFO("sync_type_value: [%d]", sync_type_value); syncProcess = _convert_sync_progress_str(process); @@ -3108,7 +3210,7 @@ se_error_type_e session_process(char *profileDirName, alert_type_e server_sync_t goto error; } - err = send_noti_session_process(profileDirName, sync_type, syncProcess, syncError); + err = send_noti_session_process(profileDirName, sync_type_value, syncProcess, syncError); if (err != SE_INTERNAL_OK) { _DEBUG_ERROR("failed in send_noti_session_process"); goto error; |