diff options
author | Ickhee Woo <ickhee.woo@samsung.com> | 2016-06-03 19:54:09 +0900 |
---|---|---|
committer | Ickhee Woo <ickhee.woo@samsung.com> | 2016-06-07 13:33:25 +0900 |
commit | 460379c8ce75bf1b678d4241f4624ef0bcb81e89 (patch) | |
tree | b22a6b92a51b129729463a53dba19e3cfe5ea892 | |
parent | f82a20cde0df2673b726a13197bb50c6e0a61367 (diff) | |
download | sync-manager-460379c8ce75bf1b678d4241f4624ef0bcb81e89.tar.gz sync-manager-460379c8ce75bf1b678d4241f4624ef0bcb81e89.tar.bz2 sync-manager-460379c8ce75bf1b678d4241f4624ef0bcb81e89.zip |
version up : refactored reading and writing xml filessubmit/tizen/20160607.043921accepted/tizen/wearable/20160607.072030accepted/tizen/mobile/20160607.072049accepted/tizen/common/20160607.194610
Change-Id: I59e4abef8ba3f0e86e939a886c87ad01d9768da8
Signed-off-by: Ickhee Woo <ickhee.woo@samsung.com>
-rw-r--r-- | packaging/sync-manager.spec | 3 | ||||
-rw-r--r-- | src/sync-service/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/sync-service/SyncManager_CurrentSyncJobQueue.cpp | 17 | ||||
-rw-r--r-- | src/sync-service/SyncManager_CurrentSyncJobQueue.h | 1 | ||||
-rw-r--r-- | src/sync-service/SyncManager_DataChangeSyncScheduler.cpp | 2 | ||||
-rw-r--r-- | src/sync-service/SyncManager_NetworkChangeListener.cpp | 4 | ||||
-rw-r--r-- | src/sync-service/SyncManager_PeriodicSyncJob.cpp | 2 | ||||
-rw-r--r-- | src/sync-service/SyncManager_PeriodicSyncScheduler.cpp | 10 | ||||
-rw-r--r-- | src/sync-service/SyncManager_RepositoryEngine.cpp | 22 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncJobQueue.cpp | 2 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncJobsAggregator.cpp | 36 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncJobsAggregator.h | 11 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncManager.cpp | 50 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncManager.h | 4 | ||||
-rw-r--r-- | src/sync-service/SyncManager_SyncService.cpp | 131 |
15 files changed, 198 insertions, 98 deletions
diff --git a/packaging/sync-manager.spec b/packaging/sync-manager.spec index 303879e..5bf68a4 100644 --- a/packaging/sync-manager.spec +++ b/packaging/sync-manager.spec @@ -1,5 +1,5 @@ Name: sync-service -Version: 0.1.4 +Version: 0.1.5 Release: 1 License: Apache-2.0 Summary: Sync manager daemon @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(glib-2.0) >= 2.26 BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(accounts-svc) BuildRequires: pkgconfig(alarm-service) +BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) diff --git a/src/sync-service/CMakeLists.txt b/src/sync-service/CMakeLists.txt index 6598dbb..767681c 100644 --- a/src/sync-service/CMakeLists.txt +++ b/src/sync-service/CMakeLists.txt @@ -95,6 +95,7 @@ SET(PACKAGES vconf vconf-internal-keys accounts-svc + aul libxml-2.0 gio-unix-2.0 alarm-service diff --git a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp index 006c407..cb3fbbe 100644 --- a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp +++ b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp @@ -62,10 +62,13 @@ CurrentSyncJobQueue::AddSyncJobToCurrentSyncQueue(SyncJob* syncJob) { LOG_LOGD("Failed to construct CurrentSyncContext instance"); return SYNC_ERROR_OUT_OF_MEMORY; } - //adding timeout of 5 minutes - guint interval = (guint)(5 * 60 * 1000); - pCurrentSyncContext->SetTimerId(g_timeout_add(interval, CurrentSyncJobQueue::OnTimerExpired, pCurrentSyncContext)); - LOG_LOGD("Sync operation time limit is set as [%d]", (int)interval); + + if (syncJob->GetSyncType() == SYNC_TYPE_PERIODIC) { + SyncJobsAggregator* pSyncJobsAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator(); + guint interval = (guint)(pSyncJobsAggregator->GetLimitTime()); + pCurrentSyncContext->SetTimerId((long)g_timeout_add(interval, CurrentSyncJobQueue::OnTimerExpired, pCurrentSyncContext)); + LOG_LOGD("Sync operation time limit is set as [%d]", (int)interval); + } pair<map<const string, CurrentSyncContext*>::iterator, bool> ret; ret = __currentSyncJobQueue.insert(pair<const string, CurrentSyncContext*>(syncJob->__key, pCurrentSyncContext)); @@ -82,8 +85,8 @@ CurrentSyncJobQueue::AddSyncJobToCurrentSyncQueue(SyncJob* syncJob) { int CurrentSyncJobQueue::OnTimerExpired(void* data) { - LOG_LOGD("CurrentSyncJobQueue::onTimerExpired Starts"); - + LOG_LOGD("CurrentSyncJobQueue::onTimerExpired Starts"); +/* CurrentSyncContext* pSyncContext = static_cast<CurrentSyncContext*>(data); if (pSyncContext) { LOG_LOGD("CurrentSyncJobQueue::onTimerExpired sending sync-cancelled message"); @@ -102,6 +105,8 @@ CurrentSyncJobQueue::OnTimerExpired(void* data) { LOG_LOGD("CurrentSyncJobQueue::onTimerExpired Ends"); return false; +*/ + return 0; } diff --git a/src/sync-service/SyncManager_CurrentSyncJobQueue.h b/src/sync-service/SyncManager_CurrentSyncJobQueue.h index 612a552..8ec07a1 100644 --- a/src/sync-service/SyncManager_CurrentSyncJobQueue.h +++ b/src/sync-service/SyncManager_CurrentSyncJobQueue.h @@ -28,6 +28,7 @@ #include <map> #include <queue> #include "SyncManager_CurrentSyncContext.h" +#include "SyncManager_SyncJobsAggregator.h" /*namespace _SyncManager { diff --git a/src/sync-service/SyncManager_DataChangeSyncScheduler.cpp b/src/sync-service/SyncManager_DataChangeSyncScheduler.cpp index 67f1553..51efd23 100644 --- a/src/sync-service/SyncManager_DataChangeSyncScheduler.cpp +++ b/src/sync-service/SyncManager_DataChangeSyncScheduler.cpp @@ -300,8 +300,6 @@ DataChangeSyncScheduler::RegisterDataChangeListeners(void) { /* LCOV_EXCL_STOP */ } - LOG_LOGD("Registration of DataChangeListener Successfully Ends"); - return SYNC_ERROR_NONE; } diff --git a/src/sync-service/SyncManager_NetworkChangeListener.cpp b/src/sync-service/SyncManager_NetworkChangeListener.cpp index 505bf54..3e4d2e8 100644 --- a/src/sync-service/SyncManager_NetworkChangeListener.cpp +++ b/src/sync-service/SyncManager_NetworkChangeListener.cpp @@ -96,7 +96,9 @@ NetworkChangeListener::IsEthernetConnected() { int ret; connection_ethernet_state_e state = CONNECTION_ETHERNET_STATE_DEACTIVATED; ret = connection_get_ethernet_state(connection, &state); - if (ret != CONNECTION_ERROR_NONE) + if (ret == CONNECTION_ERROR_NOT_SUPPORTED) + LOG_LOGD("Ethernet connection does not be supported on this target"); /* LCOV_EXCL_LINE */ + else if (ret != CONNECTION_ERROR_NONE) LOG_LOGD("Connection ethernet failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */ return (state == CONNECTION_ETHERNET_STATE_CONNECTED); diff --git a/src/sync-service/SyncManager_PeriodicSyncJob.cpp b/src/sync-service/SyncManager_PeriodicSyncJob.cpp index 7dfae8b..1a7ecd5 100644 --- a/src/sync-service/SyncManager_PeriodicSyncJob.cpp +++ b/src/sync-service/SyncManager_PeriodicSyncJob.cpp @@ -140,7 +140,7 @@ PeriodicSyncJob::IsExtraEqual(PeriodicSyncJob* pJob) { void PeriodicSyncJob::Reset(int accountId, bundle* pUserData, int syncOption, long frequency) { SyncJob::Reset(accountId, pUserData, syncOption); - __period = frequency; + __period = frequency / 60; } /* LCOV_EXCL_STOP */ diff --git a/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp b/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp index 5e71c99..5634842 100644 --- a/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp +++ b/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp @@ -42,7 +42,7 @@ PeriodicSyncScheduler::~PeriodicSyncScheduler(void) { int PeriodicSyncScheduler::OnAlarmExpired(alarm_id_t alarm_id, void *user_param) { - LOG_LOGD("Alarm id %d", alarm_id); + LOG_LOGD("Alarm id [%d]", alarm_id); PeriodicSyncScheduler* pPeriodicSyncScheduler = (PeriodicSyncScheduler*) user_param; map<int, PeriodicSyncJob*>::iterator itr = pPeriodicSyncScheduler->__activePeriodicSyncJobs.find(alarm_id); @@ -94,24 +94,26 @@ int PeriodicSyncScheduler::SchedulePeriodicSyncJob(PeriodicSyncJob* periodicSyncJob) { string jobKey = periodicSyncJob->__key; - //Remove previous alarms, if set already + /* Remove previous alarms, if set already */ int ret = SYNC_ERROR_NONE; ret = RemoveAlarmForPeriodicSyncJob(periodicSyncJob); SYNC_LOGE_RET_RES(ret == SYNC_ERROR_NONE, SYNC_ERROR_SYSTEM, "Failed to remove previous alarm for [%s], [%d]", jobKey.c_str(), ret); alarm_id_t alarm_id; ret = alarmmgr_add_periodic_alarm_withcb(periodicSyncJob->__period, QUANTUMIZE, PeriodicSyncScheduler::OnAlarmExpired, this, &alarm_id); + /* ret = alarmmgr_add_periodic_alarm_withcb(2, QUANTUMIZE, PeriodicSyncScheduler::OnAlarmExpired, this, &alarm_id); */ if (ret == ALARMMGR_RESULT_SUCCESS) { LOG_LOGD("Alarm added for %ld min, id %ld", periodicSyncJob->__period, alarm_id); + /* LOG_LOGD("Alarm added for [%ld] min, id [%ld]", 2, alarm_id); */ __activePeriodicSyncJobs.insert(make_pair<int, PeriodicSyncJob*> (alarm_id, periodicSyncJob)); __activeAlarmList.insert(make_pair(jobKey, alarm_id)); } else { - LOG_LOGD("Failed to add Alarm for %ld min, ret %d", periodicSyncJob->__period, ret); /* LCOV_EXCL_LINE */ + LOG_LOGD("Failed to add Alarm for [%ld] min, ret [%d]", periodicSyncJob->__period, ret); /* LCOV_EXCL_LINE */ return SYNC_ERROR_SYSTEM; } - LOG_LOGD("Active periodic alarm count, %d", __activePeriodicSyncJobs.size()); + LOG_LOGD("Active periodic alarm count, [%d]", __activePeriodicSyncJobs.size()); return SYNC_ERROR_NONE; } diff --git a/src/sync-service/SyncManager_RepositoryEngine.cpp b/src/sync-service/SyncManager_RepositoryEngine.cpp index 2374664..ffb7a50 100644 --- a/src/sync-service/SyncManager_RepositoryEngine.cpp +++ b/src/sync-service/SyncManager_RepositoryEngine.cpp @@ -414,9 +414,11 @@ RepositoryEngine::WriteSyncJobsData(void) { xmlNewProp(jobNode, XML_ATTR_JOB_NAME, (const xmlChar*)pJob->__syncJobName.c_str()); ss.str(string()); - if (pJob->__pExtras) { + if (pJob->__pExtras) bundle_iterate(pJob->__pExtras, bndl_iterator, &jobNode); - } + else + LOG_LOGD("There is no user bundle data which will be written in XML"); + if (pJob->GetSyncType() == SYNC_TYPE_PERIODIC) { PeriodicSyncJob* pPeriodJob = dynamic_cast<PeriodicSyncJob*> (pJob); if (pPeriodJob == NULL) { @@ -495,11 +497,10 @@ RepositoryEngine::ParseExtras(xmlNodePtr cur, bundle* pExtra) { xmlChar* pKey = xmlGetProp(cur, XML_ATTR_SYNC_EXTRA_KEY); xmlChar* pVal = xmlGetProp(cur, XML_ATTR_SYNC_EXTRA_VALUE); - if (!pKey || !pVal) { + if (!pKey || !pVal) return; - } - bundle_add(pExtra, (char*)pKey, (char*)pVal); + bundle_add_str(pExtra, (const char*)pKey, (const char*)pVal); } @@ -512,6 +513,8 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) { xmlChar* pJobNoRetry = xmlGetProp(cur, XML_ATTR_JOB_OPTION_NORETRY); xmlChar* pJobExpedit = xmlGetProp(cur, XML_ATTR_JOB_OPTION_EXPEDIT); xmlChar* pJobType = xmlGetProp(cur, XML_ATTR_JOB_TYPE); + xmlChar* pPeriod = xmlGetProp(cur, XML_ATTR_PERIODIC_SYNC_PERIOD); + long period = (pPeriod == NULL)? 1800 : ((atoi((char*)pPeriod) > 1440)? 1440 * 60 : atoi((char*)pPeriod) * 60); SyncType type = (pJobType == NULL) ? SYNC_TYPE_UNKNOWN : (SyncType)atoi((char*)pJobType); bool noretry = (pJobNoRetry == NULL) ? false : atoi((char*)pJobNoRetry); @@ -522,9 +525,10 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) { syncOption |= (expedit) ? 0x01 : 0x00; bundle* pExtra = NULL; + pExtra = bundle_create(); + cur = cur->xmlChildrenNode; while (cur != NULL) { - pExtra = bundle_create(); ParseExtras(cur, pExtra); cur = cur->next; } @@ -539,8 +543,9 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) { break; } case SYNC_TYPE_PERIODIC: { - xmlChar* pPeriod = xmlGetProp(cur, XML_ATTR_PERIODIC_SYNC_PERIOD); - int period = (pPeriod == NULL)? 1800 : atoi((char*)pPeriod); + SyncJobsAggregator* pSyncJobsAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator(); + pSyncJobsAggregator->SetMinPeriod(period / 60); + pSyncJobsAggregator->SetLimitTime(pSyncJobsAggregator->GetMinPeriod()); SyncManager::GetInstance()->AddPeriodicSyncJob((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId, period); break; @@ -551,6 +556,7 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) { break; } } + bundle_free(pExtra); } /* LCOV_EXCL_STOP */ diff --git a/src/sync-service/SyncManager_SyncJobQueue.cpp b/src/sync-service/SyncManager_SyncJobQueue.cpp index 36e0d68..6468e20 100644 --- a/src/sync-service/SyncManager_SyncJobQueue.cpp +++ b/src/sync-service/SyncManager_SyncJobQueue.cpp @@ -75,7 +75,7 @@ SyncJobQueue::AddSyncJob(SyncJob* pSyncJob) { SyncJob* pSyncJobEntry = dynamic_cast< SyncJob* > (pSyncJob); SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get sync job"); - if (pSyncJobEntry ->IsExpedited()) { + if (pSyncJobEntry->IsExpedited()) { LOG_LOGD("Priority SyncJob Queue size, before = [%d]", __prioritySyncJobsQueue.size()); __prioritySyncJobsQueue.push_back(pSyncJob); LOG_LOGD("Priority SyncJob Queue size, after = [%d]", __prioritySyncJobsQueue.size()); diff --git a/src/sync-service/SyncManager_SyncJobsAggregator.cpp b/src/sync-service/SyncManager_SyncJobsAggregator.cpp index b063aa6..485cf87 100644 --- a/src/sync-service/SyncManager_SyncJobsAggregator.cpp +++ b/src/sync-service/SyncManager_SyncJobsAggregator.cpp @@ -31,6 +31,7 @@ #include "SyncManager_CurrentSyncJobQueue.h" #include "SyncManager_SyncDefines.h" +#define MAX_COUNT 12 /*namespace _SyncManager { @@ -224,4 +225,39 @@ SyncJobsAggregator::GetAllSyncJobs() { return __syncJobsContainer; } + +void +SyncJobsAggregator::SetMinPeriod(int min_period) { + this->min_period = min_period; + LOG_LOGD("Minimum period is set as [%d]", this->min_period); +} + + +void +SyncJobsAggregator::SetLimitTime(int min_period) { + int idx; + int limit_time = 1; + + for (idx = 1; idx < MAX_COUNT; idx++) { + limit_time *= 2; + if (min_period < limit_time) { + this->limit_time = limit_time; + LOG_LOGD("Limit time is set as [%d]", this->limit_time); + return; + } + } +} + + +int +SyncJobsAggregator::GetMinPeriod() { + return min_period; +} + + +int +SyncJobsAggregator::GetLimitTime() { + return limit_time; +} + //}//_SyncManager diff --git a/src/sync-service/SyncManager_SyncJobsAggregator.h b/src/sync-service/SyncManager_SyncJobsAggregator.h index 1a8de82..99a42b2 100644 --- a/src/sync-service/SyncManager_SyncJobsAggregator.h +++ b/src/sync-service/SyncManager_SyncJobsAggregator.h @@ -68,6 +68,14 @@ public: map < string, SyncJobsInfo * > &GetAllSyncJobs(); + void SetMinPeriod(int min_period); + + void SetLimitTime(int min_period); + + int GetMinPeriod(void); + + int GetLimitTime(void); + protected: SyncJobsAggregator(void); @@ -100,6 +108,9 @@ private: private: map < string, SyncJobsInfo * > __syncJobsContainer; + int min_period; + int limit_time; + friend class SyncManager; friend class RepositoryEngine; }; diff --git a/src/sync-service/SyncManager_SyncManager.cpp b/src/sync-service/SyncManager_SyncManager.cpp index ad34162..939b9e4 100644 --- a/src/sync-service/SyncManager_SyncManager.cpp +++ b/src/sync-service/SyncManager_SyncManager.cpp @@ -356,7 +356,8 @@ SyncManager::OnBatteryStatusChanged(int value) { } -static int OnPackageUninstalled(unsigned int userId, int reqId, const char* pPkgType, const char* pPkgId, const char* pKey, const char* pVal, const void* pMsg, void* pData) { +static int +OnPackageUninstalled(unsigned int userId, int reqId, const char* pPkgType, const char* pPkgId, const char* pKey, const char* pVal, const void* pMsg, void* pData) { LOG_LOGD("OnPackageUninstalled [type %s] type [pkdId:%s]", pPkgType, pPkgId); if (!strcmp("end", pKey) && !strcmp("ok", pVal)) { SyncManager::GetInstance()->GetSyncAdapterAggregator()->HandlePackageUninstalled(pPkgId); @@ -368,6 +369,41 @@ static int OnPackageUninstalled(unsigned int userId, int reqId, const char* pPkg /* LCOV_EXCL_STOP */ +static int +OnAppStatusChanged(int pid, int status, void *data) { + LOG_LOGD("App Status Callback is invoked"); + char* pAppId = NULL; + + int ret = app_manager_get_app_id((pid_t)pid, &pAppId); + if (ret == APP_MANAGER_ERROR_NONE) { + string pkgIdStr = SyncManager::GetInstance()->GetPkgIdByAppId((const char *)pAppId); + LOG_LOGD("pAppId is [%s]", pAppId); + if (SyncManager::GetInstance()->GetSyncAdapterAggregator()->HasSyncAdapter(pkgIdStr.c_str())) { + /* + * switch (status) { + * case 0: //STATUS_LAUNCHING + * case 3: //STATUS_VISIBLE + * case 5: //STATUS_FOCUS + * case 4: //STATUS_BACKGROUND + * default: // STATUS_UNKNOWN + */ + LOG_LOGD("[%s] status is changed, so its current sync will be written", pkgIdStr.c_str()); + SyncManager::GetInstance()->GetSyncRepositoryEngine()->SaveCurrentState(); + /* + * } + */ + } else { + LOG_LOGD("[%s] doesn't use sync-manager", pkgIdStr.c_str()); + } + free(pAppId); + } else { + LOG_LOGD("getting app id by pid is failed [%d : %s]", ret, get_error_message(ret)); + return -1; + } + return 0; +} + + string SyncManager::GetPkgIdByAppId(const char* pAppId) { pkgmgrinfo_appinfo_h handle; @@ -567,6 +603,17 @@ SyncManager::SetPkgMgrClientStatusChangedListener(void) { } +int +SyncManager::SetAulAppStatusChangedListener(void) { + int ret = aul_listen_app_status_signal(OnAppStatusChanged, NULL); + if (ret != AUL_R_OK) { + printf("Failed to register AppStatusHandler"); + return -1; + } + return 0; +} + + /* LCOV_EXCL_START */ RepositoryEngine* SyncManager::GetSyncRepositoryEngine(void) { @@ -696,6 +743,7 @@ SyncManager::Construct(void) { LOG_LOGE_BOOL(__pPkgmgrClient != NULL, "__pPkgmgrClient is null"); LOG_LOGE_BOOL(SetPkgMgrClientStatusChangedListener() == 0, "Failed to register for uninstall callback."); + LOG_LOGE_BOOL(SetAulAppStatusChangedListener() == 0, "Failed to register for watching app status changed callback."); /* #if !defined(_SEC_FEATURE_CONTAINER_ENABLE) diff --git a/src/sync-service/SyncManager_SyncManager.h b/src/sync-service/SyncManager_SyncManager.h index 577a055..9d05ae0 100644 --- a/src/sync-service/SyncManager_SyncManager.h +++ b/src/sync-service/SyncManager_SyncManager.h @@ -28,6 +28,8 @@ #include <bundle_internal.h> #include <stdio.h> #include <account.h> +#include <aul.h> +#include <aul_svc.h> #include <package-manager.h> #include <media_content_type.h> #include "sync_manager.h" @@ -170,6 +172,8 @@ private: int SetPkgMgrClientStatusChangedListener(void); + int SetAulAppStatusChangedListener(void); + void ClearScheduledSyncJobs(SyncJob* pSyncJob); void CancelActiveSyncJob(SyncJob* pSyncJob); diff --git a/src/sync-service/SyncManager_SyncService.cpp b/src/sync-service/SyncManager_SyncService.cpp index 6620cc7..6bb84ad 100644 --- a/src/sync-service/SyncManager_SyncService.cpp +++ b/src/sync-service/SyncManager_SyncService.cpp @@ -318,6 +318,9 @@ int _check_privilege_contact_read(GDBusMethodInvocation *invocation) { #endif +gboolean sync_adapter_handle_send_result(TizenSyncAdapter* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine, gint sync_result, const gchar* sync_job_name); + + /* LCOV_EXCL_START */ int SyncService::TriggerStartSync(const char* appId, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) { @@ -325,88 +328,66 @@ SyncService::TriggerStartSync(const char* appId, int accountId, const char* sync app_control_h app_control; int ret = SYNC_ERROR_NONE; - GError *error = NULL; - guint pid = -1; - app_context_h app_context = NULL; - ret = app_manager_get_app_context(appId, &app_context); - if (ret == APP_MANAGER_ERROR_NO_SUCH_APP) { - gboolean alreadyRunning = FALSE; - GVariant *result = g_dbus_connection_call_sync(gdbusConnection, "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "NameHasOwner", - g_variant_new("(s)", appId), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (result == NULL) { - LOG_LOGD("g_dbus_connection_call_sync() is failed"); - if (error) { - LOG_LOGD("dbus error message: %s", error->message); - g_error_free(error); - } - } else { - g_variant_get(result, "(b)", &alreadyRunning); + bool isRunning = false; + app_manager_is_running(appId, &isRunning); + if (!isRunning) { + LOG_LOGD("app is not running, launch the app and wait for signal"); + ret = app_control_create(&app_control); + SYNC_LOGE_RET_RES(ret == APP_CONTROL_ERROR_NONE, SYNC_ERROR_SYSTEM, "app control create failed %d", ret); + + ret = app_control_set_app_id(app_control, appId); + if (ret != APP_CONTROL_ERROR_NONE) { + app_control_destroy(app_control); + SYNC_LOGE_RET_RES(ret == APP_CONTROL_ERROR_NONE, SYNC_ERROR_SYSTEM, "app control error [%d : %s]", ret, get_error_message(ret)); } - if (!alreadyRunning) { - LOG_LOGD("Service not running. Start the service "); - GVariant *ret = g_dbus_connection_call_sync(gdbusConnection, "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "StartServiceByName", - g_variant_new("(su)", appId), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (ret != NULL) { - g_variant_get(ret, "(u)", &pid); - g_variant_unref(ret); - } + sa_app_id.clear(); + ret = app_control_send_launch_request(app_control, NULL, NULL); + SYNC_LOGE_RET_RES(ret == APP_CONTROL_ERROR_NONE, SYNC_ERROR_SYSTEM, "app control launch request failed %d", ret); - if (error) { - LOG_LOGD("g_dbus_connection_call_sync gdbus error [%s]", error->message); - g_clear_error(&error); - } - return SYNC_ERROR_SYSTEM; - } + return SYNC_ERROR_SYSTEM; } else { - bool isRunning = false; - app_manager_is_running(appId, &isRunning); - if (!isRunning) { - LOG_LOGD("app is not running, launch the app and wait for signal"); - ret = app_control_create(&app_control); - SYNC_LOGE_RET_RES(ret == APP_CONTROL_ERROR_NONE, SYNC_ERROR_SYSTEM, "app control create failed %d", ret); - - ret = app_control_set_app_id(app_control, appId); - if (ret != APP_CONTROL_ERROR_NONE) { - LOG_LOGD("app control error %d", ret); - app_control_destroy(app_control); - return SYNC_ERROR_SYSTEM; - } + LOG_LOGD("app is already running"); + TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appId); - sa_app_id.clear(); - ret = app_control_send_launch_request(app_control, NULL, NULL); - SYNC_LOGE_RET_RES(ret == APP_CONTROL_ERROR_NONE, SYNC_ERROR_SYSTEM, "app control launch request failed %d", ret); - } else { - LOG_LOGD("app is already running"); - } + if (!pSyncAdapter) { + LOG_LOGD("Sync adapter entry not found. Preparing sync adapter object"); - app_context_destroy(app_context); - } + app_context_h app_context = NULL; + pid_t pid; - TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appId); - if (pSyncAdapter) { + int ret = app_manager_get_app_context(appId, &app_context); + SYNC_LOGE_RET_RES(ret == APP_MANAGER_ERROR_NONE, SYNC_ERROR_SYSTEM, "getting app_context is failed"); + + ret = app_context_get_pid(app_context, &pid); + SYNC_LOGE_RET_RES(ret == APP_MANAGER_ERROR_NONE, SYNC_ERROR_SYSTEM, "getting pid from app_context is failed"); + + GError* error = NULL; + char obj_path[50]; + snprintf(obj_path, 50, "%s%d", SYNC_ADAPTER_DBUS_PATH, pid); + + GDBusInterfaceSkeleton* interface = NULL; + pSyncAdapter = tizen_sync_adapter_skeleton_new(); + + if (pSyncAdapter != NULL) { + interface = G_DBUS_INTERFACE_SKELETON(pSyncAdapter); + if (g_dbus_interface_skeleton_export(interface, gdbusConnection, obj_path, &error)) { + g_signal_connect(pSyncAdapter, "handle-send-result", G_CALLBACK(sync_adapter_handle_send_result), NULL); + + LOG_LOGD("inserting sync adapter ipc %s %x", appId, pSyncAdapter); + g_hash_table_insert(g_hash_table, strdup(appId), pSyncAdapter); + } else { + SYNC_LOGE_RET_RES(!(error->message), SYNC_ERROR_SYSTEM, "export failed [%s]", error->message); + return SYNC_ERROR_SYSTEM; + } + } else { + LOG_LOGD("Remote object creation failed"); + return SYNC_ERROR_SYSTEM; + } + } GVariant* pBundle = marshal_bundle(pExtras); tizen_sync_adapter_emit_start_sync(pSyncAdapter, accountId, syncJobName, isDataSync, pBundle); - } else { - LOG_LOGD("Sync adapter entry not found"); - return SYNC_ERROR_SYSTEM; } return SYNC_ERROR_NONE; @@ -466,9 +447,13 @@ SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobNam int SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId) { int ret = SYNC_ERROR_NONE; - SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator(); int syncJobId = -1; + SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator(); + + pSyncJobsAggregator->SetMinPeriod((int)pollFrequency / 60); + pSyncJobsAggregator->SetLimitTime(pSyncJobsAggregator->GetMinPeriod()); + ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName); if (pSyncJob) { PeriodicSyncJob* pSyncJobEntry = dynamic_cast< PeriodicSyncJob* > (pSyncJob); |