summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sync-client/sync_manager.c4
-rw-r--r--src/sync-service/CMakeLists.txt3
-rw-r--r--src/sync-service/SyncManager_CurrentSyncContext.cpp2
-rw-r--r--src/sync-service/SyncManager_CurrentSyncJobQueue.cpp16
-rw-r--r--src/sync-service/SyncManager_CurrentSyncJobQueue.h1
-rw-r--r--src/sync-service/SyncManager_ISyncJob.h1
-rw-r--r--src/sync-service/SyncManager_ManageIdleState.cpp96
-rw-r--r--src/sync-service/SyncManager_ManageIdleState.h57
-rw-r--r--src/sync-service/SyncManager_PeriodicSyncJob.cpp3
-rw-r--r--src/sync-service/SyncManager_PeriodicSyncScheduler.cpp3
-rw-r--r--src/sync-service/SyncManager_RepositoryEngine.cpp97
-rw-r--r--src/sync-service/SyncManager_RepositoryEngine.h10
-rw-r--r--src/sync-service/SyncManager_SyncAdapterAggregator.cpp7
-rw-r--r--src/sync-service/SyncManager_SyncDefines.h1
-rw-r--r--src/sync-service/SyncManager_SyncJob.cpp3
-rw-r--r--src/sync-service/SyncManager_SyncJob.h4
-rw-r--r--src/sync-service/SyncManager_SyncJobDispatcher.cpp22
-rw-r--r--src/sync-service/SyncManager_SyncJobQueue.cpp1
-rw-r--r--src/sync-service/SyncManager_SyncJobsAggregator.cpp42
-rw-r--r--src/sync-service/SyncManager_SyncJobsAggregator.h11
-rw-r--r--src/sync-service/SyncManager_SyncManager.cpp45
-rw-r--r--src/sync-service/SyncManager_SyncManager.h8
-rw-r--r--src/sync-service/SyncManager_SyncService.cpp256
-rw-r--r--src/sync-service/SyncManager_SyncService.h2
-rw-r--r--src/sync-service/SyncManager_SyncStatusInfo.cpp1
-rw-r--r--src/sync-service/SyncManager_SyncWorker.cpp11
-rw-r--r--src/sync-service/main.cpp16
27 files changed, 651 insertions, 72 deletions
diff --git a/src/sync-client/sync_manager.c b/src/sync-client/sync_manager.c
index e08f8d5..8c185d5 100644
--- a/src/sync-client/sync_manager.c
+++ b/src/sync-client/sync_manager.c
@@ -288,9 +288,9 @@ int sync_manager_add_periodic_sync_job(account_h account, const char *sync_job_n
LOG_LOGC("sync client: account_get_account_id failure");
return SYNC_ERROR_SYSTEM;
}
- LOG_LOGC("appid [%s] accid [%d] sync_job_name [%s] ", g_sync_manager->appid, id, sync_job_name);
+ LOG_LOGC("appid [%s] accid [%d] sync_job_name [%s]", g_sync_manager->appid, id, sync_job_name);
} else
- LOG_LOGC("appid [%s] sync_job_name [%s] ", g_sync_manager->appid, sync_job_name);
+ LOG_LOGC("appid [%s] sync_job_name [%s]", g_sync_manager->appid, sync_job_name);
int sync_interval = get_interval(sync_period);
diff --git a/src/sync-service/CMakeLists.txt b/src/sync-service/CMakeLists.txt
index f8c1105..f8a6446 100644
--- a/src/sync-service/CMakeLists.txt
+++ b/src/sync-service/CMakeLists.txt
@@ -61,7 +61,8 @@ SET(SRCS
SyncManager_SyncAdapterAggregator.cpp
SyncManager_SyncJobsAggregator.cpp
SyncManager_SyncJobsInfo.cpp
- SyncManager_DataSyncJob.cpp)
+ SyncManager_DataSyncJob.cpp
+ SyncManager_ManageIdleState.cpp)
IF(_SEC_FEATURE_CONTAINER_ENABLE)
diff --git a/src/sync-service/SyncManager_CurrentSyncContext.cpp b/src/sync-service/SyncManager_CurrentSyncContext.cpp
index 307568e..38c1a64 100644
--- a/src/sync-service/SyncManager_CurrentSyncContext.cpp
+++ b/src/sync-service/SyncManager_CurrentSyncContext.cpp
@@ -32,6 +32,8 @@
CurrentSyncContext::CurrentSyncContext(SyncJob* pSyncJob)
{
__pCurrentSyncJob = pSyncJob;
+ __startTime = 0;
+ __timerId = -1;
}
diff --git a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
index 9c08065..4caa6a4 100644
--- a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
+++ b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
@@ -68,8 +68,18 @@ CurrentSyncJobQueue::AddSyncJobToCurrentSyncQueue(SyncJob* syncJob)
LOG_LOGD("Failed to construct CurrentSyncContext instance");
return SYNC_ERROR_OUT_OF_MEMORY;
}
- //adding timeout of 30 seconds
- pCurrentSyncContext->SetTimerId(g_timeout_add (300000, CurrentSyncJobQueue::OnTimerExpired, pCurrentSyncContext));
+
+ if (syncJob->GetSyncType() == SYNC_TYPE_PERIODIC) {
+ SyncJobsAggregator* pSyncJobsAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator();
+ LOG_LOGD("pSyncJobsAggregator->GetMinPeriod() [%d]", pSyncJobsAggregator->GetMinPeriod());
+ LOG_LOGD("pSyncJobsAggregator->GetLimitTime() [%d]", pSyncJobsAggregator->GetLimitTime());
+
+ guint interval = (guint)(pSyncJobsAggregator->GetLimitTime() * 60 * 1000);
+
+ pCurrentSyncContext->SetTimerId(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));
if (ret.second == false)
@@ -106,7 +116,7 @@ CurrentSyncJobQueue::OnTimerExpired(void* data)
}
else
{
- LOG_LOGD(" context null");
+ LOG_LOGD("context null");
}
LOG_LOGD("CurrentSyncJobQueue::onTimerExpired Ends");
diff --git a/src/sync-service/SyncManager_CurrentSyncJobQueue.h b/src/sync-service/SyncManager_CurrentSyncJobQueue.h
index 5034673..70d1425 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_ISyncJob.h b/src/sync-service/SyncManager_ISyncJob.h
index 380b2f4..7f88255 100644
--- a/src/sync-service/SyncManager_ISyncJob.h
+++ b/src/sync-service/SyncManager_ISyncJob.h
@@ -47,6 +47,7 @@ class ISyncJob
public:
ISyncJob()
: __syncJobId(-1)
+ , __syncType(SYNC_TYPE_UNKNOWN)
{
}
diff --git a/src/sync-service/SyncManager_ManageIdleState.cpp b/src/sync-service/SyncManager_ManageIdleState.cpp
new file mode 100644
index 0000000..9a0556f
--- /dev/null
+++ b/src/sync-service/SyncManager_ManageIdleState.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+/**
+ * @file SyncManager_ManageIdleState.cpp
+ * @brief This is the implementation file for the ManageIdleState class.
+ */
+
+#include <stdlib.h>
+#include "SyncManager_ManageIdleState.h"
+#include "SyncManager_SyncService.h"
+#include "SyncManager_SyncDefines.h"
+#include "SyncManager_SyncManager.h"
+#include "sync-log.h"
+
+#define SYNC_TERM_SEC 10
+
+/*namespace _SyncManager
+{*/
+
+
+ManageIdleState::ManageIdleState(void)
+{
+ __termTimerId = -1;
+}
+
+
+ManageIdleState::~ManageIdleState(void)
+{
+}
+
+
+void terminate_service(void);
+
+int
+ManageIdleState::OnTermTimerExpired(gpointer)
+{
+ LOG_LOGD("Sync service auto-termination timer is expired");
+ terminate_service();
+
+ return 0;
+}
+
+
+void
+ManageIdleState::SetTermTimerId(long timerId)
+{
+ __termTimerId = timerId;
+}
+
+
+long
+ManageIdleState::GetTermTimerId() const
+{
+ return __termTimerId;
+}
+
+
+void
+ManageIdleState::SetTermTimer()
+{
+ guint termTimer = SYNC_TERM_SEC * 1000;
+ SetTermTimerId(g_timeout_add(termTimer, ManageIdleState::OnTermTimerExpired, NULL));
+ LOG_LOGD("Sync service auto-termination timer is Set as [%d] sec", SYNC_TERM_SEC);
+}
+
+
+void
+ManageIdleState::UnsetTermTimer()
+{
+ LOG_LOGD("Sync service auto-termination timer is Unset");
+ g_source_remove((guint)GetTermTimerId());
+}
+
+
+void
+ManageIdleState::ResetTermTimer()
+{
+ LOG_LOGD("Sync service auto-termination timer is Reset");
+ g_source_remove((guint)GetTermTimerId());
+ SetTermTimer();
+}
+
diff --git a/src/sync-service/SyncManager_ManageIdleState.h b/src/sync-service/SyncManager_ManageIdleState.h
new file mode 100644
index 0000000..034ddfc
--- /dev/null
+++ b/src/sync-service/SyncManager_ManageIdleState.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+/**
+ * @file SyncManager_ManageIdleState.h
+ * @brief This is the header file for the ManageIdleState class.
+ */
+
+#ifndef SYNC_SERVICE_MANAGE_IDLE_STATE_H
+#define SYNC_SERVICE_MANAGE_IDLE_STATE_H
+
+#include <glib.h>
+
+/*namespace _SyncManager
+{
+*/
+
+using namespace std;
+
+class ManageIdleState
+{
+public:
+ ManageIdleState(void);
+
+ ~ManageIdleState(void);
+
+ static int OnTermTimerExpired(gpointer);
+
+ void SetTermTimerId(long timerId);
+
+ long GetTermTimerId() const;
+
+ void SetTermTimer(void);
+
+ void UnsetTermTimer(void);
+
+ void ResetTermTimer(void);
+
+private:
+ long __termTimerId;
+};
+
+//}//_SyncManager
+#endif // SYNC_SERVICE_MANAGE_IDLE_STATE_H
diff --git a/src/sync-service/SyncManager_PeriodicSyncJob.cpp b/src/sync-service/SyncManager_PeriodicSyncJob.cpp
index 7ad91eb..5dec349 100644
--- a/src/sync-service/SyncManager_PeriodicSyncJob.cpp
+++ b/src/sync-service/SyncManager_PeriodicSyncJob.cpp
@@ -42,6 +42,7 @@ PeriodicSyncJob::PeriodicSyncJob(const string appId, const string syncJobName, i
PeriodicSyncJob::PeriodicSyncJob(const PeriodicSyncJob& other)
: SyncJob(other)
+ , __period(other.__period)
{
/* this->__accountHandle = other.__accountHandle;
this->__capability = other.__capability;
@@ -139,7 +140,7 @@ void
PeriodicSyncJob::Reset(int accountId, bundle* pUserData, int syncOption, long frequency)
{
SyncJob::Reset(accountId, pUserData, syncOption);
- __period = frequency;
+ __period = frequency/60;
}
//}//_SyncManager
diff --git a/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp b/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp
index b5cf94f..4554cd7 100644
--- a/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp
+++ b/src/sync-service/SyncManager_PeriodicSyncScheduler.cpp
@@ -89,11 +89,12 @@ PeriodicSyncScheduler::SchedulePeriodicSyncJob(PeriodicSyncJob* periodicSyncJob)
{
string jobKey = periodicSyncJob->__key;
- /// Remove previous alarms, if set already
+ //Remove previous alarms, if set already
int 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);
if (ret == ALARMMGR_RESULT_SUCCESS)
{
diff --git a/src/sync-service/SyncManager_RepositoryEngine.cpp b/src/sync-service/SyncManager_RepositoryEngine.cpp
index 938325a..2668c88 100644
--- a/src/sync-service/SyncManager_RepositoryEngine.cpp
+++ b/src/sync-service/SyncManager_RepositoryEngine.cpp
@@ -37,7 +37,6 @@
#include "sync-log.h"
#include "sync-error.h"
-
/*namespace _SyncManager
{
*/
@@ -72,7 +71,7 @@ static const xmlChar XML_ATTR_CAPABILITY[] = "capability";
static const xmlChar XML_ATTR_SYNCABLE[] = "syncable";
static const xmlChar XML_NODE_PERIODIC_SYNC[] = "periodicSync";
-static const xmlChar XML_ATTR_PERIODIC_SYNC_PEIOD[] = "period";
+static const xmlChar XML_ATTR_PERIODIC_SYNC_PERIOD[] = "period";
static const xmlChar XML_ATTR_PERIODIC_SYNC_FLEX[] = "flex";
static const xmlChar XML_NODE_SYNC_EXTRA[] = "extra";
@@ -153,6 +152,7 @@ RepositoryEngine::OnBooting()
ReadSyncJobsData();
}
+
//Test method
/*
static void
@@ -162,10 +162,52 @@ bndl_iterator_test(const char* pKey, const char* pVal, void* pData)
}
*/
+
+bool
+RepositoryEngine::CheckSyncJobsData(void)
+{
+ char* pDocName;
+ xmlDocPtr doc = NULL;
+ xmlNodePtr cur = NULL;
+
+ pDocName = PATH_SYNCJOBS;
+ doc = xmlParseFile(pDocName);
+
+ if (doc == NULL)
+ {
+ LOG_LOGD("Failed to parse syncjobs.xml.");
+ return false;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ LOG_LOGD("Found empty document while parsing syncjobs.xml.");
+ xmlFreeDoc(doc);
+ return false;
+ }
+
+ if (xmlStrcmp(cur->name, XML_NODE_JOBS)) {
+ LOG_LOGD("Found empty document while parsing syncjobs.xml.");
+ xmlFreeDoc(doc);
+ return false;
+ } else {
+ xmlChar* pTotalJobsCount = xmlGetProp(cur, XML_ATTR_JOBS_COUNT);
+ int totalcount = (pTotalJobsCount == NULL) ? 0 : atoi((char*)pTotalJobsCount);
+ LOG_LOGD("Total Sync jobs [%d]", totalcount);
+
+ if (totalcount == 0) {
+ return false;
+ }
+
+ return true;
+ }
+}
+
+
void
RepositoryEngine::ReadSyncJobsData(void)
{
- LOG_LOGD("Read Sync jobs");
+ LOG_LOGD("Reading Sync jobs");
//Parse the Xml file
char* pDocName;
@@ -202,6 +244,11 @@ RepositoryEngine::ReadSyncJobsData(void)
int totalcount = (pTotalJobsCount == NULL) ? 0 : atoi((char*)pTotalJobsCount);
LOG_LOGD("Total Sync jobs [%d]", totalcount);
+ if (totalcount == 0) {
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+ pManageIdleState->SetTermTimer();
+ }
+
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
@@ -253,8 +300,11 @@ RepositoryEngine::ReadSyncJobsData(void)
}
*/
//Till here
+
+ LOG_LOGD("sync jobs are figured out");
}
+
void
RepositoryEngine::ReadSyncAdapters(void)
{
@@ -332,11 +382,10 @@ bndl_iterator(const char* pKey, const char* pVal, void* pData)
}
-
void
RepositoryEngine::WriteSyncJobsData(void)
{
- LOG_LOGD("Starts");
+ LOG_LOGD("Writing sync jobs");
xmlDocPtr doc;
xmlNodePtr rootNode, jobNode;
@@ -420,7 +469,7 @@ RepositoryEngine::WriteSyncJobsData(void)
continue;
}
ss<<(int)pPeriodJob->__period;
- xmlNewProp(jobNode, XML_ATTR_PERIODIC_SYNC_PEIOD, (const xmlChar*)ss.str().c_str());
+ xmlNewProp(jobNode, XML_ATTR_PERIODIC_SYNC_PERIOD, (const xmlChar*)ss.str().c_str());
ss.str(string());
}
}
@@ -443,7 +492,7 @@ RepositoryEngine::WriteSyncJobsData(void)
void
RepositoryEngine::WriteSyncAdapters(void)
{
- LOG_LOGD(" Starts");
+ LOG_LOGD("Writing sync adapters");
xmlDocPtr doc;
xmlNodePtr rootNode, saNode;
@@ -509,7 +558,6 @@ RepositoryEngine::ParseExtras(xmlNodePtr cur, bundle* pExtra)
void
RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage)
{
-
xmlChar* pAppId = xmlGetProp(cur, XML_ATTR_JOB_APP_ID);
xmlChar* pAccId = xmlGetProp(cur, XML_ATTR_JOB_ACCOUNT_ID);
xmlChar* pJobId = xmlGetProp(cur, XML_ATTR_JOB_ID);
@@ -518,13 +566,16 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage)
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);
+ int period = (pPeriod == NULL)? 1800 : atoi((char*)pPeriod) * 60;
+
SyncType type = (pJobType == NULL) ? SYNC_TYPE_UNKNOWN : (SyncType)atoi((char*)pJobType);
bool noretry = (pJobNoRetry == NULL) ? false : atoi((char*)pJobNoRetry);
bool expedit = (pJobExpedit == NULL) ? false : atoi((char*)pJobExpedit);
int acountId = (pAccId == NULL) ? -1 : atoi((char*)pAccId);
int jobId = (pJobId == NULL) ? -1 : atoi((char*)pJobId);
- int syncOption = (noretry) ? 0x00 : 0x02;
- syncOption |= (expedit) ? 0x00 : 0x01;
+ int syncOption = (noretry) ? 0x02 : 0x00;
+ syncOption |= (expedit) ? 0x01 : 0x00;
bundle* pExtra = NULL;
cur = cur->xmlChildrenNode;
@@ -549,8 +600,10 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage)
}
case SYNC_TYPE_PERIODIC:
{
- xmlChar* pPeriod = xmlGetProp(cur, XML_ATTR_PERIODIC_SYNC_PEIOD);
- 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;
@@ -576,5 +629,25 @@ RepositoryEngine::SaveCurrentState(void)
}
+void
+RepositoryEngine::SaveCurrentSyncAdapter(void)
+{
+ LOG_LOGD("saving states after adding sync adapter");
+ pthread_mutex_lock(&__capabilityInfoMutex);
+ WriteSyncAdapters();
+ pthread_mutex_unlock(&__capabilityInfoMutex);
+}
+
+
+void
+RepositoryEngine::SaveCurrentSyncJob(void)
+{
+ LOG_LOGD("saving states of current sync job");
+ pthread_mutex_lock(&__capabilityInfoMutex);
+ WriteSyncJobsData();
+ pthread_mutex_unlock(&__capabilityInfoMutex);
+}
+
+
//}//_SyncManager
diff --git a/src/sync-service/SyncManager_RepositoryEngine.h b/src/sync-service/SyncManager_RepositoryEngine.h
index 7994ca0..00fefa0 100644
--- a/src/sync-service/SyncManager_RepositoryEngine.h
+++ b/src/sync-service/SyncManager_RepositoryEngine.h
@@ -33,6 +33,7 @@
#include <list>
#include <map>
#include "SyncManager_CapabilityInfo.h"
+#include "SyncManager_ManageIdleState.h"
#include "SyncManager_SyncStatusInfo.h"
#include "SyncManager_SyncJob.h"
#include "SyncManager_PeriodicSyncJob.h"
@@ -62,11 +63,16 @@ public:
void SaveCurrentState(void);
+ void SaveCurrentSyncAdapter(void);
+
+ void SaveCurrentSyncJob(void);
+
+ bool CheckSyncJobsData(void);
+
public:
static const long NOT_IN_BACKOFF_MODE;
private:
-
RepositoryEngine(void);
RepositoryEngine(const RepositoryEngine&);
@@ -99,8 +105,6 @@ private:
map<string, map<string, SyncJob*> > __Aggr; // Data sync job list to be scheduled
map<int, SyncStatusInfo*> __syncStatus;
- int PENDING_FINISH_TO_WRITE;
-
static RepositoryEngine* __pInstance;
static const long DEFAULT_PERIOD_SEC;
diff --git a/src/sync-service/SyncManager_SyncAdapterAggregator.cpp b/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
index 48c0b3f..7b20eeb 100644
--- a/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
+++ b/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
@@ -54,12 +54,9 @@ SyncAdapterAggregator::~SyncAdapterAggregator(void)
void
SyncAdapterAggregator::AddSyncAdapter(const char* pPackageId, const char* pServiceAppId)
{
- if (HasSyncAdapter(pPackageId))
- {
+ if (HasSyncAdapter(pPackageId)) {
LOG_LOGD("Sync adapter already registered for package [%s]", pPackageId);
- }
- else
- {
+ } else {
LOG_LOGD("Registering sync-adapter [%s] for package [%s]", pServiceAppId, pPackageId);
__syncAdapterList.insert(std::pair<string, string> (pPackageId, pServiceAppId));
}
diff --git a/src/sync-service/SyncManager_SyncDefines.h b/src/sync-service/SyncManager_SyncDefines.h
index 7a7bbeb..a2cbcc4 100644
--- a/src/sync-service/SyncManager_SyncDefines.h
+++ b/src/sync-service/SyncManager_SyncDefines.h
@@ -226,6 +226,7 @@ struct Message
acc = NULL;
pSyncJob = NULL;
res = SYNC_STATUS_UNKNOWN;
+ type = SYNC_CHECK_ALARM;
}
SyncDispatchMessage type;
diff --git a/src/sync-service/SyncManager_SyncJob.cpp b/src/sync-service/SyncManager_SyncJob.cpp
index ce81762..e5b38b9 100644
--- a/src/sync-service/SyncManager_SyncJob.cpp
+++ b/src/sync-service/SyncManager_SyncJob.cpp
@@ -94,6 +94,9 @@ SyncJob::SyncJob(const string appId, const string syncJobName, int account, bund
, __isExpedited(syncOption & SYNC_OPTION_EXPEDITED)
, __noRetry(syncOption & SYNC_OPTION_NO_RETRY)
{
+ LOG_LOGD("syncOption: %d", syncOption);
+ LOG_LOGD("__isExpedited: %d", __isExpedited);
+
if (pExtras)
{
__pExtras = bundle_dup(pExtras);
diff --git a/src/sync-service/SyncManager_SyncJob.h b/src/sync-service/SyncManager_SyncJob.h
index a22134c..778e033 100644
--- a/src/sync-service/SyncManager_SyncJob.h
+++ b/src/sync-service/SyncManager_SyncJob.h
@@ -75,8 +75,8 @@ public:
public:
string __appId;
int __accountId;
- SyncReason __reason;
- SyncSource __syncSource;
+ //SyncReason __reason;
+ //SyncSource __syncSource;
bundle* __pExtras;
string __syncJobName;
string __key;
diff --git a/src/sync-service/SyncManager_SyncJobDispatcher.cpp b/src/sync-service/SyncManager_SyncJobDispatcher.cpp
index 1e19a1a..34ea7ac 100644
--- a/src/sync-service/SyncManager_SyncJobDispatcher.cpp
+++ b/src/sync-service/SyncManager_SyncJobDispatcher.cpp
@@ -212,9 +212,20 @@ SyncJobDispatcher::TryStartingNextJobLocked()
pthread_mutex_lock(&(SyncManager::GetInstance()->__syncJobQueueMutex));
SyncJobQueue* pSyncJobQueue = SyncManager::GetInstance()->GetSyncJobQueue();
+ if (pSyncJobQueue == NULL) {
+ LOG_LOGD("pSyncJobQueue is null");
+ return;
+ }
list< SyncJob* >& jobQueue = pSyncJobQueue->GetSyncJobQueue();
+ if (jobQueue.empty()) {
+ LOG_LOGD("jobQueue is empty");
+ }
+
list< SyncJob* >& priorityJobQueue = pSyncJobQueue->GetPrioritySyncJobQueue();
+ if (priorityJobQueue.empty()) {
+ LOG_LOGD("priorityJobQueue is empty");
+ }
if (jobQueue.empty() && priorityJobQueue.empty())
{
@@ -227,6 +238,7 @@ SyncJobDispatcher::TryStartingNextJobLocked()
if (!jobQueue.empty())
{
+ LOG_LOGD("jobQueue is filled");
SyncJob* nonPrioritySyncJob = jobQueue.front();
if (nonPrioritySyncJob->__waitCounter > NON_PRIORITY_SYNC_WAIT_LIMIT)
{
@@ -246,21 +258,25 @@ SyncJobDispatcher::TryStartingNextJobLocked()
if (syncJobToRun == NULL && !jobQueue.empty())
{
LOG_LOGD("Non priority job found.");
+ LOG_LOGD("Non priority size : %d", jobQueue.size());
syncJobToRun = jobQueue.front();
jobQueue.pop_front();
- LOG_LOGD("Non priority size.%d", jobQueue.size());
+ LOG_LOGD("Non priority size : %d", jobQueue.size());
+ if (syncJobToRun == NULL)
+ LOG_LOGD("syncJobToRun is null");
+
}
+ pthread_mutex_unlock(&(SyncManager::GetInstance()->__syncJobQueueMutex));
if (syncJobToRun != NULL)
{
int ret = DispatchSyncJob(syncJobToRun);
if (ret != SYNC_ERROR_NONE)
{
- SyncManager::GetInstance()->ScheduleSyncJob(syncJobToRun, false);
LOG_LOGD("Failed to dispatch sync job. Adding it back to job queue");
+ SyncManager::GetInstance()->ScheduleSyncJob(syncJobToRun, false);
}
}
- pthread_mutex_unlock(&(SyncManager::GetInstance()->__syncJobQueueMutex));
}
//}//_SyncManager
diff --git a/src/sync-service/SyncManager_SyncJobQueue.cpp b/src/sync-service/SyncManager_SyncJobQueue.cpp
index b464c2e..ecc956e 100644
--- a/src/sync-service/SyncManager_SyncJobQueue.cpp
+++ b/src/sync-service/SyncManager_SyncJobQueue.cpp
@@ -42,6 +42,7 @@ extern "C"
SyncJobQueue::SyncJobQueue(void)
+ : __pSyncRepositoryEngine(NULL)
{
//Empty
}
diff --git a/src/sync-service/SyncManager_SyncJobsAggregator.cpp b/src/sync-service/SyncManager_SyncJobsAggregator.cpp
index 3593ebf..e0e21d8 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
{
@@ -38,6 +39,8 @@
SyncJobsAggregator::SyncJobsAggregator(void)
+ : min_period(0)
+ , limit_time(0)
{
}
@@ -243,10 +246,49 @@ SyncJobsAggregator::GetSyncJobsInfo(const char* pPackageId)
return NULL;
}
+
map<string, SyncJobsInfo*>&
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 = 1;
+ int limit_time = idx;
+
+ for (idx; 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 1c42529..92fc2ca 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);
@@ -99,6 +107,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 b94c71f..29921ad 100644
--- a/src/sync-service/SyncManager_SyncManager.cpp
+++ b/src/sync-service/SyncManager_SyncManager.cpp
@@ -72,7 +72,6 @@ Singleton< SyncManager >::GetInstance()
}
}
return __pInstance;
-
}
@@ -139,7 +138,6 @@ SyncManager::AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int
if (period < 1800)
{
LOG_LOGD("Requested period %d is less than minimum, rounding up to 30 mins", period);
-
period = 1800;
}
@@ -160,7 +158,10 @@ SyncManager::AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int
__pPeriodicSyncScheduler->SchedulePeriodicSyncJob(pRequestedJob);
if (pRequestedJob->IsExpedited())
{
+ LOG_LOGD("The sync job has priority");
ScheduleSyncJob(pRequestedJob);
+ } else {
+ LOG_LOGD("It's non-priority sync job");
}
return SYNC_ERROR_NONE;
@@ -395,8 +396,6 @@ SyncManager::OnBatteryStatusChanged(int value)
}
-
-
static int OnPackageUninstalled(int reqId, const char* pPkgType, const char* pPkgId, const char* pKey,
const char* pVal, const void* pMsg, void* pData)
{
@@ -681,6 +680,7 @@ SyncManager::SyncManager(void)
, __isSimDataConnectionPresent(false)
, __isUPSModeEnabled(false)
, __isSyncPermitted(true)
+ , __pManageIdleState(NULL)
, __pNetworkChangeListener(NULL)
, __pStorageListener(NULL)
, __pBatteryStatusListener(NULL)
@@ -713,6 +713,9 @@ SyncManager::Construct(void)
LOG_LOGE_BOOL(ret == VCONF_OK, "vconf_get_int failed %d", ret);
__isUPSModeEnabled = (upsMode == SETTING_PSMODE_EMERGENCY) ? true : false;
+ __pManageIdleState = new (std::nothrow) ManageIdleState();
+ LOG_LOGE_BOOL(__pManageIdleState, "Failed to construct ManageIdleState");
+
__pNetworkChangeListener = new (std::nothrow) NetworkChangeListener();
LOG_LOGE_BOOL(__pNetworkChangeListener, "Failed to construct NetworkChangeListener");
@@ -783,8 +786,8 @@ SyncManager::Construct(void)
Initialize();
+ //__pSyncRepositoryEngine->OnBooting();
- __pSyncRepositoryEngine->OnBooting();
return true;
}
@@ -893,6 +896,14 @@ SyncManager::GetSyncJobsAggregator()
return __pSyncJobsAggregator;
}
+
+ManageIdleState*
+SyncManager::GetManageIdleState()
+{
+ return __pManageIdleState;
+}
+
+
void
SyncManager::HandleShutdown(void)
{
@@ -902,6 +913,24 @@ SyncManager::HandleShutdown(void)
}
+void
+SyncManager::RecordSyncAdapter(void)
+{
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->SaveCurrentSyncAdapter();
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
+void
+SyncManager::RecordSyncJob(void)
+{
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->SaveCurrentSyncJob();
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
bool
SyncManager::GetSyncSupport(int accountId)
{
@@ -924,6 +953,8 @@ SyncManager::GetSyncSupport(int accountId)
return false;
}
+ LOG_LOGD("The account supports sync");
+
return true;
}
@@ -1015,7 +1046,7 @@ SyncManager::SendSyncAlarmMessage()
void
SyncManager::SendSyncCheckAlarmMessage()
{
- LOG_LOGD("Fire SYNC_CHECK_ALARM ");
+ LOG_LOGD("Fire SYNC_CHECK_ALARM");
Message msg;
msg.type = SYNC_CHECK_ALARM;
//TO DO: Implement code to remove all the pending messages from queue before firing a new one
@@ -1060,7 +1091,7 @@ SyncManager::ScheduleSyncJob(SyncJob* pJob, bool fireCheckAlarm)
{
if(fireCheckAlarm)
{
- LOG_LOGD("Added sync job [%s] to Main queue, Intiating dispatch sequence", pJob->__key.c_str());
+ LOG_LOGD("Added sync job [%s] to Main queue, Initiating dispatch sequence", pJob->__key.c_str());
SendSyncCheckAlarmMessage();
}
}
diff --git a/src/sync-service/SyncManager_SyncManager.h b/src/sync-service/SyncManager_SyncManager.h
index b1f5b44..acd970b 100644
--- a/src/sync-service/SyncManager_SyncManager.h
+++ b/src/sync-service/SyncManager_SyncManager.h
@@ -43,6 +43,7 @@
#include "SyncManager_Singleton.h"
#include "SyncManager_CurrentSyncJobQueue.h"
#include "SyncManager_SyncDefines.h"
+#include "SyncManager_ManageIdleState.h"
/*namespace _SyncManager
@@ -104,6 +105,8 @@ public:
SyncJobsAggregator* GetSyncJobsAggregator();
+ ManageIdleState* GetManageIdleState();
+
void AddSyncAdapter(string packageId, string svcAppId);
void AddRunningAccount(int account_id, int pid);
@@ -126,6 +129,10 @@ public:
void HandleShutdown(void);
+ void RecordSyncAdapter(void);
+
+ void RecordSyncJob(void);
+
void CloseCurrentSyncContext(CurrentSyncContext *activeSyncContext);
protected:
@@ -204,6 +211,7 @@ private:
SyncAdapterAggregator* __pSyncAdapterAggregator;
SyncJobsAggregator* __pSyncJobsAggregator;
+ ManageIdleState* __pManageIdleState;
CurrentSyncJobQueue* __pCurrentSyncJobQueue;
account_subscribe_h __accountSubscriptionHandle;
map<int, int> __runningAccounts;
diff --git a/src/sync-service/SyncManager_SyncService.cpp b/src/sync-service/SyncManager_SyncService.cpp
index 7c97c51..10ee3b4 100644
--- a/src/sync-service/SyncManager_SyncService.cpp
+++ b/src/sync-service/SyncManager_SyncService.cpp
@@ -43,7 +43,11 @@
#include "SyncManager_SyncAdapterAggregator.h"
#include "SyncManager_SyncJobsAggregator.h"
+#define SYNC_MANAGER_DBUS_SERVICE "org.tizen.sync"
+
static GDBusConnection* gdbusConnection = NULL;
+static bool check_jobs = false;
+//static pid_t pInvocationId;
/*namespace _SyncManager
{*/
@@ -83,8 +87,8 @@ void convert_to_path(char app_id[])
int
SyncService::StartService()
{
- __pSyncMangerIntacnce = SyncManager::GetInstance();
- if (__pSyncMangerIntacnce == NULL)
+ __pSyncManagerInstance = SyncManager::GetInstance();
+ if (__pSyncManagerInstance == NULL)
{
LOG_LOGD("Failed to initialize sync manager");
return -1;
@@ -167,6 +171,9 @@ _check_privilege_by_pid(const char *label, const char *access_perm, bool check_r
}
+gboolean sync_adapter_handle_send_result(TizenSyncAdapter* pObject, GDBusMethodInvocation* pInvocation, gint sync_result, const gchar* sync_job_name);
+
+
int
SyncService::TriggerStartSync(const char* appId, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras)
{
@@ -180,7 +187,7 @@ SyncService::TriggerStartSync(const char* appId, int accountId, const char* sync
{
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);
+ 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)
@@ -193,26 +200,62 @@ SyncService::TriggerStartSync(const char* appId, int accountId, const char* sync
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);
+
+ return SYNC_ERROR_SYSTEM;
}
else
{
LOG_LOGD("app is already running");
- }
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appId);
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appId);
- if (pSyncAdapter)
- {
+ if (!pSyncAdapter)
+ {
+ LOG_LOGD("Sync adapter entry not found. Preparing sync adapter object");
+
+ app_context_h app_context = NULL;
+ pid_t pid;
+
+ 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);
+
+ GVariant* pBundle = marshal_bundle(pExtras);
+ 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
+ {
+ LOG_LOGD("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;
-
}
@@ -239,7 +282,7 @@ SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobNam
{
int ret = SYNC_ERROR_NONE;
int syncJobId = -1;
- SyncJobsAggregator* pSyncJobsAggregator = __pSyncMangerIntacnce->GetSyncJobsAggregator();
+ SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator();
ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
if (pSyncJob)
@@ -259,7 +302,7 @@ SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobNam
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncMangerIntacnce->AddOnDemandSync(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
+ ret = __pSyncManagerInstance->AddOnDemandSync(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
}
if (ret == SYNC_ERROR_NONE)
@@ -275,20 +318,28 @@ 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 = __pSyncMangerIntacnce->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);
- SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
+ SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get sync job");
syncJobId = pSyncJobEntry->GetSyncJobId();
LOG_LOGD("Sync request with job name [%s] already found. Sync job id [%d]", pSyncJobName, syncJobId);
pSyncJobEntry->Reset(accountId, pExtras, syncOption, pollFrequency);
- LOG_LOGD("sync parameters are updated with new parameters", pSyncJobName);
+ LOG_LOGD("sync parameters are updated with new parameters");
+
+ if (pSyncJobEntry->IsExpedited()) {
+ LOG_LOGD("sync request with priority. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
+ SyncManager::GetInstance()->ScheduleSyncJob(pSyncJobEntry);
+ }
}
else
{
@@ -296,13 +347,14 @@ SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobNam
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncMangerIntacnce->AddPeriodicSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
+ ret = __pSyncManagerInstance->AddPeriodicSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
}
if (ret == SYNC_ERROR_NONE)
{
*pSyncJobId = syncJobId;
}
+
return ret;
}
@@ -311,20 +363,25 @@ int
SyncService::RequestDataSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId)
{
int ret = SYNC_ERROR_NONE;
- SyncJobsAggregator* pSyncJobsAggregator = __pSyncMangerIntacnce->GetSyncJobsAggregator();
+ SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator();
int syncJobId = -1;
ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
if (pSyncJob)
{
DataSyncJob* pSyncJobEntry = dynamic_cast< DataSyncJob* > (pSyncJob);
- SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
+ SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get sync job");
syncJobId = pSyncJobEntry->GetSyncJobId();
LOG_LOGD("Sync request with job name [%s] already found. Sync job id [%d]", pSyncJobName, syncJobId);
pSyncJobEntry->Reset(accountId, pExtras, syncOption, pCapability);
- LOG_LOGD("sync parameters are updated with new parameters", pSyncJobName);
+ LOG_LOGD("sync job is updated with new parameters");
+
+ if (pSyncJobEntry->IsExpedited()) {
+ LOG_LOGD("sync request with priority. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
+ SyncManager::GetInstance()->ScheduleSyncJob(pSyncJobEntry);
+ }
}
else
{
@@ -332,7 +389,7 @@ SyncService::RequestDataSync(const char* pPackageId, const char* pSyncJobName, i
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncMangerIntacnce->AddDataSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
+ ret = __pSyncManagerInstance->AddDataSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
}
if (ret == SYNC_ERROR_NONE)
@@ -393,7 +450,7 @@ get_caller_pid(GDBusMethodInvocation* pMethodInvocation)
* org.tizen.sync.adapter interface methods
*/
gboolean
-sync_adapter_handle_send_result( TizenSyncAdapter* pObject, GDBusMethodInvocation* pInvocation,
+sync_adapter_handle_send_result(TizenSyncAdapter* pObject, GDBusMethodInvocation* pInvocation,
gint sync_result,
const gchar* sync_job_name)
{
@@ -509,6 +566,12 @@ sync_manager_add_on_demand_sync_job(TizenSyncManager* pObject, GDBusMethodInvoca
else
tizen_sync_manager_complete_add_on_demand_sync_job(pObject, pInvocation, sync_job_id);
+ RepositoryEngine* pRepositoryEngine = SyncManager::GetInstance()->GetSyncRepositoryEngine();
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+
+ if (!pRepositoryEngine->CheckSyncJobsData())
+ pManageIdleState->ResetTermTimer();
+
LOG_LOGD("End of On-Demand Sync request");
return true;
@@ -551,7 +614,17 @@ sync_manager_remove_sync_job(TizenSyncManager* pObject, GDBusMethodInvocation* p
else
tizen_sync_manager_complete_remove_sync_job(pObject, pInvocation);
+ LOG_LOGD("sync service: recoding the change of registered sync job");
+ SyncManager::GetInstance()->RecordSyncJob();
+
+ RepositoryEngine* pRepositoryEngine = SyncManager::GetInstance()->GetSyncRepositoryEngine();
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+
+ if (!pRepositoryEngine->CheckSyncJobsData())
+ pManageIdleState->SetTermTimer();
+
LOG_LOGD("sync service: remove sync job ends");
+
return true;
}
@@ -611,7 +684,17 @@ sync_manager_add_periodic_sync_job(TizenSyncManager* pObject, GDBusMethodInvocat
else
tizen_sync_manager_complete_add_periodic_sync_job(pObject, pInvocation, sync_job_id);
+ RepositoryEngine* pRepositoryEngine = SyncManager::GetInstance()->GetSyncRepositoryEngine();
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+
+ if (!pRepositoryEngine->CheckSyncJobsData())
+ pManageIdleState->UnsetTermTimer();
+
+ LOG_LOGD("sync service: recoding the change of registered sync job");
+ SyncManager::GetInstance()->RecordSyncJob();
+
LOG_LOGD("sync service: add periodic sync job ends");
+
return true;
}
@@ -678,7 +761,69 @@ sync_manager_add_data_change_sync_job(TizenSyncManager* pObject, GDBusMethodInvo
else
tizen_sync_manager_complete_add_data_change_sync_job(pObject, pInvocation, sync_job_id);
+ RepositoryEngine* pRepositoryEngine = SyncManager::GetInstance()->GetSyncRepositoryEngine();
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+
+ if (!pRepositoryEngine->CheckSyncJobsData())
+ pManageIdleState->UnsetTermTimer();
+
+ LOG_LOGD("sync service: recoding the change of registered sync job");
+ SyncManager::GetInstance()->RecordSyncJob();
+
LOG_LOGD("sync service: add data sync job ends");
+
+ return true;
+}
+
+
+static bool
+is_service_app(pid_t pid)
+{
+ char *current_app_id = NULL;
+ int ret = app_manager_get_app_id(pid, &current_app_id);
+ if (ret != APP_MANAGER_ERROR_NONE)
+ {
+ LOG_LOGD("Getting current app id is failed : %d, %s", ret, get_error_message(ret));
+ return false;
+ }
+
+ pkgmgrinfo_appinfo_h current_app_info = NULL;
+
+ ret = pkgmgrinfo_appinfo_get_appinfo(current_app_id, &current_app_info);
+ if (ret != PMINFO_R_OK)
+ {
+ LOG_LOGD("Current app info handle creation error : %d, %s", ret, get_error_message(ret));
+ free(current_app_id);
+ return false;
+ }
+ char *current_app_type = NULL;
+ ret = pkgmgrinfo_appinfo_get_component_type(current_app_info, &current_app_type);
+ if (ret != PMINFO_R_OK)
+ {
+ LOG_LOGD("Current app info getting app type error : %d, %s", ret, get_error_message(ret));
+
+ pkgmgrinfo_appinfo_destroy_appinfo(current_app_info);
+ free(current_app_id);
+ return false;
+ }
+ else
+ {
+ if (!strcmp(current_app_type, "svcapp"))
+ {
+ LOG_LOGD("Current application type : %s", current_app_type);
+ pkgmgrinfo_appinfo_destroy_appinfo(current_app_info);
+ }
+ else
+ {
+ LOG_LOGD("Current app is not a service application : %s", current_app_type);
+ pkgmgrinfo_appinfo_destroy_appinfo(current_app_info);
+ free(current_app_id);
+ return false;
+ }
+ }
+
+ free(current_app_id);
+
return true;
}
@@ -719,6 +864,15 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
int ret = SYNC_ERROR_SYSTEM;
string pkgIdStr;
guint pid = get_caller_pid(pInvocation);
+
+ if (!is_service_app(pid))
+ {
+ GError* error = g_error_new (_sync_error_quark(), SYNC_ERROR_INVALID_OPERATION, "App not supported");
+ g_dbus_method_invocation_return_gerror(pInvocation, error);
+ g_clear_error(&error);
+ return false;
+ }
+
char* pAppId;
ret = app_manager_get_app_id(pid, &pAppId);
if (ret == APP_MANAGER_ERROR_NONE)
@@ -735,6 +889,26 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
if(!pkgIdStr.empty())
{
+ SyncAdapterAggregator* pAggregator = SyncManager::GetInstance()->GetSyncAdapterAggregator();
+ if (pAggregator == NULL) {
+ LOG_LOGD("sync adapter aggregator is NULL");
+ tizen_sync_manager_complete_add_sync_adapter(pObject, pInvocation);
+ return true;
+ }
+ if (pAggregator->HasSyncAdapter(pkgIdStr.c_str())) {
+ const char *registered_app_id = pAggregator->GetSyncAdapter(pkgIdStr.c_str());
+ LOG_LOGD("registered appId is [%s]", registered_app_id);
+ LOG_LOGD("caller appId is [%s]", pAppId);
+ if (strcmp(pAppId, registered_app_id)) {
+ GError* error = g_error_new(_sync_error_quark(), SYNC_ERROR_QUOTA_EXCEEDED, "Sync adapter already registered");
+ g_dbus_method_invocation_return_gerror(pInvocation, error);
+ g_clear_error(&error);
+ return false;
+ } else {
+ check_jobs = true;
+ }
+ }
+
char object_path[50];
snprintf(object_path, 50, "%s%d", SYNC_ADAPTER_DBUS_PATH, pid);
@@ -754,6 +928,7 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
LOG_LOGD("inserting sync adapter ipc %s", pAppId);
g_hash_table_insert(g_hash_table, strdup(pAppId), syncAdapterObj);
+
ret = SYNC_ERROR_NONE;
}
else
@@ -780,7 +955,13 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
else
tizen_sync_manager_complete_add_sync_adapter(pObject, pInvocation);
- LOG_LOGD("End");
+ if (check_jobs) {
+ SyncManager::GetInstance()->AlertForChange();
+ }
+
+ SyncManager::GetInstance()->RecordSyncAdapter();
+
+ LOG_LOGD("sync service: adding sync adapter ends");
return true;
}
@@ -791,6 +972,14 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
{
LOG_LOGD("Request to remove sync adapter");
guint pid = get_caller_pid(pInvocation);
+ if (!is_service_app(pid))
+ {
+ GError* error = g_error_new (_sync_error_quark(), SYNC_ERROR_INVALID_OPERATION, "App not supported");
+ g_dbus_method_invocation_return_gerror(pInvocation, error);
+ g_clear_error(&error);
+ return false;
+ }
+
string pkgIdStr;
char* pAppId;
int ret = app_manager_get_app_id(pid, &pAppId);
@@ -828,7 +1017,9 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
tizen_sync_manager_complete_remove_sync_adapter(pObject, pInvocation);
- LOG_LOGD("End");
+ SyncManager::GetInstance()->RecordSyncAdapter();
+
+ LOG_LOGD("sync service: removing sync adapter ends");
return true;
}
@@ -933,6 +1124,12 @@ sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation*
tizen_sync_manager_complete_get_all_sync_jobs(pObject, pInvocation, outSyncJobList);
}
+ RepositoryEngine* pRepositoryEngine = SyncManager::GetInstance()->GetSyncRepositoryEngine();
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+
+ if (!pRepositoryEngine->CheckSyncJobsData())
+ pManageIdleState->ResetTermTimer();
+
LOG_LOGD("End");
return true;
@@ -980,6 +1177,12 @@ OnBusAcquired (GDBusConnection* pConnection, const gchar* pName, gpointer userDa
gdbusConnection = pConnection;
LOG_LOGD("Sync Service started [%s]", pName);
+ RepositoryEngine* __pSyncRepositoryEngine;
+ __pSyncRepositoryEngine = RepositoryEngine::GetInstance();
+ if (__pSyncRepositoryEngine == NULL)
+ LOG_LOGD("Failed to construct RepositoryEngine");
+ else
+ __pSyncRepositoryEngine->OnBooting();
//g_dbus_object_manager_server_set_connection(pServerManager, connection);
}
@@ -1039,6 +1242,7 @@ SyncService::InitializeDbus(void)
* DBus related initialization done
*/
SyncService::SyncService(void)
+ : __pSyncManagerInstance(NULL)
{
LOG_LOGD("Sync service initialization starts");
diff --git a/src/sync-service/SyncManager_SyncService.h b/src/sync-service/SyncManager_SyncService.h
index 8a4cf6d..9e492d4 100644
--- a/src/sync-service/SyncManager_SyncService.h
+++ b/src/sync-service/SyncManager_SyncService.h
@@ -72,7 +72,7 @@ private:
void InitializeDbus();
private:
- SyncManager* __pSyncMangerIntacnce;
+ SyncManager* __pSyncManagerInstance;
};
//}//_SyncManager
#endif //SYNC_SERVICE_SYNC_SERVICE_H
diff --git a/src/sync-service/SyncManager_SyncStatusInfo.cpp b/src/sync-service/SyncManager_SyncStatusInfo.cpp
index 1cc48a5..595f3f1 100644
--- a/src/sync-service/SyncManager_SyncStatusInfo.cpp
+++ b/src/sync-service/SyncManager_SyncStatusInfo.cpp
@@ -62,6 +62,7 @@ SyncStatusInfo::operator =(SyncStatusInfo& other)
}
SyncStatusInfo::SyncStatusInfo(string statusInfo)
+ : capabilityId(-1)
{
if (statusInfo.empty())
{
diff --git a/src/sync-service/SyncManager_SyncWorker.cpp b/src/sync-service/SyncManager_SyncWorker.cpp
index 49b7a4e..ad1753c 100644
--- a/src/sync-service/SyncManager_SyncWorker.cpp
+++ b/src/sync-service/SyncManager_SyncWorker.cpp
@@ -29,6 +29,13 @@
{*/
SyncWorker::SyncWorker(void)
+ : __pendingRequestsMutex(PTHREAD_MUTEX_INITIALIZER)
+ , __message(SYNC_CHECK_ALARM)
+ , __pContext(NULL)
+ , __pLoop(NULL)
+ , __pChannel(NULL)
+ , __pSource(NULL)
+ , __pThread(NULL)
{
}
@@ -176,7 +183,7 @@ SyncWorker::OnEventReceived(GIOChannel* pChannel, GIOCondition condition, gpoint
SyncWorker* pSyncWorker = static_cast<SyncWorker*>(data);
- if ((condition & G_IO_IN) && pSyncWorker != NULL)
+ if ((condition & G_IO_IN) != 0)
{
uint64_t tmp = 0;
gsize readSize = 0;
@@ -223,7 +230,7 @@ SyncWorker::OnEventReceived(GIOChannel* pChannel, GIOCondition condition, gpoint
gpointer
SyncWorker::ThreadLoop(gpointer data)
{
- LOG_LOGD("Sync worker thread entered");
+ LOG_LOGD("Sync worker thread entered");
GMainLoop* pLoop = static_cast<GMainLoop*>(data);
if (pLoop != NULL)
diff --git a/src/sync-service/main.cpp b/src/sync-service/main.cpp
index 077112b..50d3907 100644
--- a/src/sync-service/main.cpp
+++ b/src/sync-service/main.cpp
@@ -53,20 +53,30 @@ DbusSignalHandler(DBusConnection* pConnection, DBusMessage* pMsg, void* pUserDat
}
-static void
-signal_handler(int signo)
+void
+terminate_service(void)
{
- LOG_LOGD("MainLoop OnTerminate");
+ LOG_LOGD("Sync service will be terminated");
if (ShutdownInitiated == false)
{
ShutdownInitiated = true;
sync_service_finalise();
}
+
g_main_loop_quit(mainloop);
}
+static void
+signal_handler(int signo)
+{
+ LOG_LOGD("Received signal");
+
+ terminate_service();
+}
+
+
int
main(int argc, char **argv)
{