BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(context-common-server)
SET(target "${PROJECT_NAME}-server-genuine")
-SET(DEPS "${DEPS} jsoncpp sqlite3 context-common-server")
+SET(DEPS "${DEPS} jsoncpp sqlite3 vconf context-common-server")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
using namespace ctx;
-unsigned int PeriodicJobRunner::__periodicJobRunnerCnt = 0;
+unsigned int PeriodicJobRunner::__activePeriodicJobCnt = 0;
JobRunner::JobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
__jobManager(mgr),
JobRunner(mgr, owner, info),
__lastScheduledTime(0)
{
- ++__periodicJobRunnerCnt;
}
PeriodicJobRunner::~PeriodicJobRunner()
{
- --__periodicJobRunnerCnt;
}
void PeriodicJobRunner::start()
__jobInfo->setStarted(true);
setState(new TimerStandbyState(this));
- if (__periodicJobRunnerCnt == TimerStandbyState::getCount())
+ __activePeriodicJobCnt++;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
SchedTimer::reset();
}
__jobInfo->setStarted(false);
setState(NULL);
- if (__periodicJobRunnerCnt == TimerStandbyState::getCount())
+ __activePeriodicJobCnt--;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
SchedTimer::reset();
}
{
setState(new TimerStandbyState(this));
- if (__periodicJobRunnerCnt == TimerStandbyState::getCount())
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
SchedTimer::reset();
}
setState(NULL);
__jobManager->removeRunner(this);
- if (__periodicJobRunnerCnt == TimerStandbyState::getCount())
+ __activePeriodicJobCnt--;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
SchedTimer::reset();
}
private:
time_t __lastScheduledTime;
- static unsigned int __periodicJobRunnerCnt;
+ static unsigned int __activePeriodicJobCnt;
};
{
EXIT;
--__timerStandbyStateCnt;
+ SchedTimer::remove(this);
}
bool TimerStandbyState::execute()
SchedTimer::SchedTimer() :
__scheduledTime(0),
- __paused(false)
+ __paused(false),
+ __listeningPmState(false)
{
}
SchedTimer::~SchedTimer()
{
+ __unlistenPmState();
}
bool SchedTimer::init()
time_t limit = time(NULL);
ISchedTimerListener* listener = NULL;
+ _D("Checking the scheduled jobs");
while ((listener = __timeLine.pop(limit))) {
listener->onSchedTimerExpired();
}
__scheduledTime = next;
__timer.cancelAll();
- IF_FAIL_VOID(next != 0);
+ if (next == 0) {
+ __unlistenPmState();
+ return;
+ }
unsigned int intervalMin = (next - time(NULL) + 59) / 60;
if (intervalMin < 1) {
}
__timer.addAlarm(intervalMin, this, NULL);
-
- //TODO: g_timeout to catch the device wakeups caused by other reasons.
+ __listenPmState();
}
void SchedTimer::__pause()
__reset();
}
+void SchedTimer::__listenPmState()
+{
+ IF_FAIL_VOID(!__listeningPmState);
+
+ _D("Subscribing the power state");
+ vconf_notify_key_changed(VCONFKEY_PM_STATE, __pmStateChanged, this);
+
+ __listeningPmState = true;
+}
+
+void SchedTimer::__unlistenPmState()
+{
+ IF_FAIL_VOID(__listeningPmState);
+
+ _D("Unsubscribing the power state");
+ vconf_ignore_key_changed(VCONFKEY_PM_STATE, __pmStateChanged);
+
+ __listeningPmState = false;
+}
+
+void SchedTimer::__pmStateChanged(keynode_t* key, void* data)
+{
+ static time_t expiredTime = 0;
+ static int pmState = VCONFKEY_PM_STATE_NORMAL;
+
+ int prevState = pmState;
+ int err = vconf_get_int(VCONFKEY_PM_STATE, &pmState);
+
+ IF_FAIL_VOID_TAG(err == E_NONE, _E, "Cannot get %s", VCONFKEY_PM_STATE);
+ IF_FAIL_VOID(prevState >= VCONFKEY_PM_STATE_LCDOFF);
+
+ time_t now = time(NULL);
+ IF_FAIL_VOID(now - expiredTime > DIFF_THRESHOLD);
+
+ static_cast<SchedTimer*>(data)->onTimerExpired(0, 0, NULL);
+ expiredTime = now;
+}
+
+
SchedTimer::TimeLineEntry::TimeLineEntry(ISchedTimerListener* l, time_t t, unsigned int m) :
listener(l),
scheduledTime(t),
#define __CONTEXT_JOB_SCHEDULER_SCHED_TIMER_H__
#include <list>
+#include <vconf.h>
#include <Timer.h>
#include <ITimerListener.h>
void __pause();
void __resume();
+ void __listenPmState();
+ void __unlistenPmState();
+
+ static void __pmStateChanged(keynode_t* key, void* data);
+
struct TimeLineEntry {
ISchedTimerListener* listener;
time_t scheduledTime;
Timer __timer;
time_t __scheduledTime;
bool __paused;
+ bool __listeningPmState;
static SchedTimer* __instance;
};