--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "ActionState.h"
+
+using namespace ctx;
+
+ActionState::ActionState(JobState* prevState) :
+ JobState(prevState)
+{
+ _ENTER;
+ //TODO: Check whether the timeout expired.
+}
+
+ActionState::~ActionState()
+{
+ _EXIT;
+}
+
+bool ActionState::execute()
+{
+ //TODO: Set a timeout for waiting the client finishes the job.
+ // If the timeout expires, let the client know that the device is about to suspend.
+ // And goto ClosingState.
+ return true;
+}
+
+void ActionState::setClient(IClient* client)
+{
+ //TODO: Notify the client which job has been expired (once).
+ // Notify the client if the timeout already expired (once).
+}
+
+void ActionState::jobFinished()
+{
+ //TODO: cancel the timeout and goto ClosingState.
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_ACTION_STATE_H__
+#define __CONTEXT_JOB_SCHEDULER_ACTION_STATE_H__
+
+#include <WakeLock.h>
+#include "JobState.h"
+
+namespace ctx {
+
+ class ActionState : public JobState {
+ public:
+ ActionState(JobState* prevState);
+ ~ActionState();
+
+ bool execute();
+
+ void setClient(IClient* client);
+ void jobFinished();
+
+ private:
+ WakeLock __wakeLock;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_ACTION_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "ClosingState.h"
+
+using namespace ctx;
+
+ClosingState::ClosingState(JobRunner* runner) :
+ JobState(runner)
+{
+ _ENTER;
+}
+
+ClosingState::ClosingState(JobState* prevState) :
+ JobState(prevState)
+{
+ _ENTER;
+}
+
+ClosingState::~ClosingState()
+{
+ _EXIT;
+}
+
+bool ClosingState::execute()
+{
+ //TODO: restart or terminate the job.
+ return false;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_CLOSING_STATE_H__
+#define __CONTEXT_JOB_SCHEDULER_CLOSING_STATE_H__
+
+#include <WakeLock.h>
+#include "JobState.h"
+
+namespace ctx {
+
+ class ClosingState : public JobState {
+ public:
+ ClosingState(JobRunner* runner);
+ ClosingState(JobState* prevState);
+ ~ClosingState();
+
+ bool execute();
+
+ private:
+ WakeLock __wakeLock;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_CLOSING_STATE_H__ */
#include <JobAction.h>
#include "ContextManager.h"
#include "SchedTimer.h"
-#include "JobRunner.h"
+#include "OnDemandJobRunner.h"
+#include "PeriodicJobRunner.h"
#include "JobManager.h"
using namespace ctx;
*/
#include <stdexcept>
-#include "SchedTimer.h"
#include "JobManager.h"
#include "JobState.h"
#include "JobRunner.h"
using namespace ctx;
-unsigned int PeriodicJobRunner::__activePeriodicJobCnt = 0;
-
JobRunner::JobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
__jobManager(mgr),
__jobInfo(info),
if (__state)
__state->jobFinished();
}
-
-
-PeriodicJobRunner::PeriodicJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
- JobRunner(mgr, owner, info),
- __lastScheduledTime(0)
-{
-}
-
-PeriodicJobRunner::~PeriodicJobRunner()
-{
-}
-
-void PeriodicJobRunner::start()
-{
- __jobInfo->setStarted(true);
- setState(new TimerStandbyState(this));
-
- __activePeriodicJobCnt++;
-
- if (__activePeriodicJobCnt == TimerStandbyState::getCount())
- SchedTimer::reset();
-}
-
-void PeriodicJobRunner::stop()
-{
- __jobInfo->setStarted(false);
- setState(NULL);
-
- __activePeriodicJobCnt--;
-
- if (__activePeriodicJobCnt == TimerStandbyState::getCount())
- SchedTimer::reset();
-}
-
-void PeriodicJobRunner::restart()
-{
- setState(new TimerStandbyState(this));
-
- if (__activePeriodicJobCnt == TimerStandbyState::getCount())
- SchedTimer::reset();
-}
-
-void PeriodicJobRunner::terminate()
-{
- setState(NULL);
- __jobManager->removeRunner(this);
-
- __activePeriodicJobCnt--;
-
- if (__activePeriodicJobCnt == TimerStandbyState::getCount())
- SchedTimer::reset();
-}
-
-time_t PeriodicJobRunner::getLastTime()
-{
- return __lastScheduledTime;
-}
-
-void PeriodicJobRunner::setLastTime(time_t t)
-{
- __lastScheduledTime = t;
-}
-
-
-OnDemandJobRunner::OnDemandJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
- JobRunner(mgr, owner, info)
-{
-}
-
-void OnDemandJobRunner::start()
-{
- __jobInfo->setStarted(true);
- setState(new TriggerStandbyState(this));
-}
-
-void OnDemandJobRunner::stop()
-{
- __jobInfo->setStarted(false);
- setState(NULL);
-}
-
-void OnDemandJobRunner::restart()
-{
- setState(new TriggerStandbyState(this));
-}
-
-void OnDemandJobRunner::terminate()
-{
- setState(NULL);
- __jobManager->removeRunner(this);
-}
JobState* __state;
};
-
- class PeriodicJobRunner : public JobRunner {
- public:
- PeriodicJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info);
- ~PeriodicJobRunner();
-
- void start();
- void stop();
- void restart();
- void terminate();
-
- time_t getLastTime();
- void setLastTime(time_t t);
-
- private:
- time_t __lastScheduledTime;
- static unsigned int __activePeriodicJobCnt;
- };
-
-
- class OnDemandJobRunner : public JobRunner {
- public:
- OnDemandJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info);
-
- void start();
- void stop();
- void restart();
- void terminate();
- };
-
}
#endif /* __CONTEXT_JOB_SCHEDULER_JOB_RUNNER_H__ */
* limitations under the License.
*/
-#include <Conf.h>
#include "JobRunner.h"
#include "JobState.h"
-#define ENTER _I("ENTER: Job-%d of '%s'", getJobId(), getOwner().c_str())
-#define EXIT _I("EXIT : Job-%d of '%s'", getJobId(), getOwner().c_str())
-
-#define SEC_PER_MIN 60
-
using namespace ctx;
-unsigned int TimerStandbyState::__timerStandbyStateCnt = 0;
-
JobState::JobState(JobRunner* runner) :
__jobRunner(runner)
{
{
__jobRunner->setState(nextState);
}
-
-
-TimerStandbyState::TimerStandbyState(JobRunner* runner) :
- JobState(runner)
-{
- ENTER;
- ++__timerStandbyStateCnt;
-}
-
-TimerStandbyState::~TimerStandbyState()
-{
- EXIT;
- --__timerStandbyStateCnt;
- SchedTimer::remove(this);
-}
-
-bool TimerStandbyState::execute()
-{
- return __setTimer();
-}
-
-void TimerStandbyState::onSchedTimerExpired()
-{
- transit(new ReqVerificationState(this));
-}
-
-unsigned int TimerStandbyState::getCount()
-{
- return __timerStandbyStateCnt;
-}
-
-bool TimerStandbyState::__setTimer()
-{
- PeriodicJobRunner* runner = static_cast<PeriodicJobRunner*>(getJobRunner());
- time_t interval = static_cast<time_t>(static_cast<PeriodicJobInfo*>(getJobInfo())->getInterval()) * SEC_PER_MIN;
-
- time_t lastTime = [&]()->time_t {
- if (runner->getLastTime() != 0)
- return runner->getLastTime();
-
- time_t now = time(NULL);
- time_t anchor = static_cast<PeriodicJobInfo*>(getJobInfo())->getAnchor();
-
- anchor = anchor % interval;
- return static_cast<time_t>((now - anchor) / interval) * interval + anchor;
- }();
-
- time_t nextTime = lastTime + interval;
- unsigned int margin = static_cast<double>(interval) * CTX_PERIOD_MARGIN;
-
- runner->setLastTime(nextTime);
-
- _I("Set a timer at %ld with %us margin", static_cast<long>(nextTime), margin);
- return SchedTimer::set(this, nextTime, margin);
-}
-
-
-TriggerStandbyState::TriggerStandbyState(JobRunner* runner) :
- JobState(runner)
-{
- ENTER;
-}
-
-TriggerStandbyState::~TriggerStandbyState()
-{
- EXIT;
-}
-
-bool TriggerStandbyState::execute()
-{
- //TODO: Subscribe the trigger contexts.
- // If a context expires, verify its attributes, and transit to ReqVerificationState.
- return true;
-}
-
-
-ReqVerificationState::ReqVerificationState(JobState* prevState) :
- JobState(prevState)
-{
- ENTER;
-}
-
-ReqVerificationState::~ReqVerificationState()
-{
- EXIT;
-}
-
-bool ReqVerificationState::execute()
-{
- //TODO: Read the requirement contexts.
- // If all satisfied, goto ActionState.
- // If the RequirementTimeout == 0, goto restart the machine.
- // Set the timeout.
- // If the timeout expires, read the requirements again.
- // If all mandatory satisfied, goto ActionState, restart otherwise.
- return true;
-}
-
-
-ActionState::ActionState(JobState* prevState) :
- JobState(prevState)
-{
- ENTER;
- //TODO: Check whether the timeout expired.
-}
-
-ActionState::~ActionState()
-{
- EXIT;
-}
-
-bool ActionState::execute()
-{
- //TODO: Set a timeout for waiting the client finishes the job.
- // If the timeout expires, let the client know that the device is about to suspend.
- // And goto ClosingState.
- return true;
-}
-
-void ActionState::setClient(IClient* client)
-{
- //TODO: Notify the client which job has been expired (once).
- // Notify the client if the timeout already expired (once).
-}
-
-void ActionState::jobFinished()
-{
- //TODO: cancel the timeout and goto ClosingState.
-}
-
-
-ClosingState::ClosingState(JobRunner* runner) :
- JobState(runner)
-{
- ENTER;
-}
-
-ClosingState::ClosingState(JobState* prevState) :
- JobState(prevState)
-{
- ENTER;
-}
-
-ClosingState::~ClosingState()
-{
- EXIT;
-}
-
-bool ClosingState::execute()
-{
- //TODO: restart or terminate the job.
- return false;
-}
#define __CONTEXT_JOB_SCHEDULER_JOB_STATE_H__
#include <string>
-#include <WakeLock.h>
#include <IClient.h>
#include <JobInfo.h>
-#include "SchedTimer.h"
+
+#define _ENTER _I("ENTER: Job-%d of '%s'", getJobId(), getOwner().c_str())
+#define _EXIT _I("EXIT : Job-%d of '%s'", getJobId(), getOwner().c_str())
namespace ctx {
class JobRunner;
-
class JobState {
public:
virtual ~JobState();
JobRunner* __jobRunner;
};
-
- class TimerStandbyState : public JobState, public ISchedTimerListener {
- public:
- TimerStandbyState(JobRunner* runner);
- ~TimerStandbyState();
-
- bool execute();
-
- void onSchedTimerExpired();
-
- static unsigned int getCount();
-
- private:
- bool __setTimer();
-
- time_t __lastExpiredTime;
- static unsigned int __timerStandbyStateCnt;
- };
-
-
- class TriggerStandbyState : public JobState {
- public:
- TriggerStandbyState(JobRunner* runner);
- ~TriggerStandbyState();
-
- bool execute();
- };
-
-
- class ReqVerificationState : public JobState {
- public:
- ReqVerificationState(JobState* prevState);
- ~ReqVerificationState();
-
- bool execute();
-
- private:
- WakeLock __wakeLock;
- };
-
-
- class ActionState : public JobState {
- public:
- ActionState(JobState* prevState);
- ~ActionState();
-
- bool execute();
-
- void setClient(IClient* client);
- void jobFinished();
-
- private:
- WakeLock __wakeLock;
- };
-
-
- class ClosingState : public JobState {
- public:
- ClosingState(JobRunner* runner);
- ClosingState(JobState* prevState);
- ~ClosingState();
-
- bool execute();
-
- private:
- WakeLock __wakeLock;
- };
-
}
#endif /* __CONTEXT_JOB_SCHEDULER_JOB_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "JobManager.h"
+#include "TriggerStandbyState.h"
+#include "OnDemandJobRunner.h"
+
+using namespace ctx;
+
+OnDemandJobRunner::OnDemandJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
+ JobRunner(mgr, owner, info)
+{
+}
+
+void OnDemandJobRunner::start()
+{
+ __jobInfo->setStarted(true);
+ setState(new TriggerStandbyState(this));
+}
+
+void OnDemandJobRunner::stop()
+{
+ __jobInfo->setStarted(false);
+ setState(NULL);
+}
+
+void OnDemandJobRunner::restart()
+{
+ setState(new TriggerStandbyState(this));
+}
+
+void OnDemandJobRunner::terminate()
+{
+ setState(NULL);
+ __jobManager->removeRunner(this);
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_ON_DEMAND_JOB_RUNNER_H__
+#define __CONTEXT_JOB_SCHEDULER_ON_DEMAND_JOB_RUNNER_H__
+
+#include "JobRunner.h"
+
+namespace ctx {
+
+ class OnDemandJobRunner : public JobRunner {
+ public:
+ OnDemandJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info);
+
+ void start();
+ void stop();
+ void restart();
+ void terminate();
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_ON_DEMAND_JOB_RUNNER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "SchedTimer.h"
+#include "JobManager.h"
+#include "TimerStandbyState.h"
+#include "PeriodicJobRunner.h"
+
+using namespace ctx;
+
+unsigned int PeriodicJobRunner::__activePeriodicJobCnt = 0;
+
+PeriodicJobRunner::PeriodicJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info) :
+ JobRunner(mgr, owner, info),
+ __lastScheduledTime(0)
+{
+}
+
+PeriodicJobRunner::~PeriodicJobRunner()
+{
+}
+
+void PeriodicJobRunner::start()
+{
+ __jobInfo->setStarted(true);
+ setState(new TimerStandbyState(this));
+
+ __activePeriodicJobCnt++;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
+ SchedTimer::reset();
+}
+
+void PeriodicJobRunner::stop()
+{
+ __jobInfo->setStarted(false);
+ setState(NULL);
+
+ __activePeriodicJobCnt--;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
+ SchedTimer::reset();
+}
+
+void PeriodicJobRunner::restart()
+{
+ setState(new TimerStandbyState(this));
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
+ SchedTimer::reset();
+}
+
+void PeriodicJobRunner::terminate()
+{
+ setState(NULL);
+ __jobManager->removeRunner(this);
+
+ __activePeriodicJobCnt--;
+
+ if (__activePeriodicJobCnt == TimerStandbyState::getCount())
+ SchedTimer::reset();
+}
+
+time_t PeriodicJobRunner::getLastTime()
+{
+ return __lastScheduledTime;
+}
+
+void PeriodicJobRunner::setLastTime(time_t t)
+{
+ __lastScheduledTime = t;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_PERIODIC_JOB_RUNNER_H__
+#define __CONTEXT_JOB_SCHEDULER_PERIODIC_JOB_RUNNER_H__
+
+#include "JobRunner.h"
+
+namespace ctx {
+
+ class PeriodicJobRunner : public JobRunner {
+ public:
+ PeriodicJobRunner(JobManager* mgr, const std::string& owner, JobInfo* info);
+ ~PeriodicJobRunner();
+
+ void start();
+ void stop();
+ void restart();
+ void terminate();
+
+ time_t getLastTime();
+ void setLastTime(time_t t);
+
+ private:
+ time_t __lastScheduledTime;
+ static unsigned int __activePeriodicJobCnt;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_PERIODIC_JOB_RUNNER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "ReqVerificationState.h"
+
+using namespace ctx;
+
+ReqVerificationState::ReqVerificationState(JobState* prevState) :
+ JobState(prevState)
+{
+ _ENTER;
+}
+
+ReqVerificationState::~ReqVerificationState()
+{
+ _EXIT;
+}
+
+bool ReqVerificationState::execute()
+{
+ //TODO: Read the requirement contexts.
+ // If all satisfied, goto ActionState.
+ // If the RequirementTimeout == 0, goto restart the machine.
+ // Set the timeout.
+ // If the timeout expires, read the requirements again.
+ // If all mandatory satisfied, goto ActionState, restart otherwise.
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_REQ_VERIFICATION_STATE_H__
+#define __CONTEXT_JOB_SCHEDULER_REQ_VERIFICATION_STATE_H__
+
+#include <WakeLock.h>
+#include "JobState.h"
+
+namespace ctx {
+
+ class ReqVerificationState : public JobState {
+ public:
+ ReqVerificationState(JobState* prevState);
+ ~ReqVerificationState();
+
+ bool execute();
+
+ private:
+ WakeLock __wakeLock;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_REQ_VERIFICATION_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <Conf.h>
+#include "PeriodicJobRunner.h"
+#include "ReqVerificationState.h"
+#include "TimerStandbyState.h"
+
+#define SEC_PER_MIN 60
+
+using namespace ctx;
+
+unsigned int TimerStandbyState::__timerStandbyStateCnt = 0;
+
+TimerStandbyState::TimerStandbyState(JobRunner* runner) :
+ JobState(runner)
+{
+ _ENTER;
+ ++__timerStandbyStateCnt;
+}
+
+TimerStandbyState::~TimerStandbyState()
+{
+ _EXIT;
+ --__timerStandbyStateCnt;
+ SchedTimer::remove(this);
+}
+
+bool TimerStandbyState::execute()
+{
+ return __setTimer();
+}
+
+void TimerStandbyState::onSchedTimerExpired()
+{
+ transit(new ReqVerificationState(this));
+}
+
+unsigned int TimerStandbyState::getCount()
+{
+ return __timerStandbyStateCnt;
+}
+
+bool TimerStandbyState::__setTimer()
+{
+ PeriodicJobRunner* runner = static_cast<PeriodicJobRunner*>(getJobRunner());
+ time_t interval = static_cast<time_t>(static_cast<PeriodicJobInfo*>(getJobInfo())->getInterval()) * SEC_PER_MIN;
+
+ time_t lastTime = [&]()->time_t {
+ if (runner->getLastTime() != 0)
+ return runner->getLastTime();
+
+ time_t now = time(NULL);
+ time_t anchor = static_cast<PeriodicJobInfo*>(getJobInfo())->getAnchor();
+
+ anchor = anchor % interval;
+ return static_cast<time_t>((now - anchor) / interval) * interval + anchor;
+ }();
+
+ time_t nextTime = lastTime + interval;
+ unsigned int margin = static_cast<double>(interval) * CTX_PERIOD_MARGIN;
+
+ runner->setLastTime(nextTime);
+
+ _I("Set a timer at %ld with %us margin", static_cast<long>(nextTime), margin);
+ return SchedTimer::set(this, nextTime, margin);
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_TIMER_STANDBY_STATE_H__
+#define __CONTEXT_JOB_SCHEDULER_TIMER_STANDBY_STATE_H__
+
+#include <WakeLock.h>
+#include "SchedTimer.h"
+#include "JobState.h"
+
+namespace ctx {
+
+ class TimerStandbyState : public JobState, public ISchedTimerListener {
+ public:
+ TimerStandbyState(JobRunner* runner);
+ ~TimerStandbyState();
+
+ bool execute();
+
+ void onSchedTimerExpired();
+
+ static unsigned int getCount();
+
+ private:
+ bool __setTimer();
+
+ time_t __lastExpiredTime;
+ static unsigned int __timerStandbyStateCnt;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_TIMER_STANDBY_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "TriggerStandbyState.h"
+
+using namespace ctx;
+
+TriggerStandbyState::TriggerStandbyState(JobRunner* runner) :
+ JobState(runner)
+{
+ _ENTER;
+}
+
+TriggerStandbyState::~TriggerStandbyState()
+{
+ _EXIT;
+}
+
+bool TriggerStandbyState::execute()
+{
+ //TODO: Subscribe the trigger contexts.
+ // If a context expires, verify its attributes, and transit to ReqVerificationState.
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_TRIGGER_STANDBY_STATE_H__
+#define __CONTEXT_JOB_SCHEDULER_TRIGGER_STANDBY_STATE_H__
+
+#include <WakeLock.h>
+#include "JobState.h"
+
+namespace ctx {
+
+ class TriggerStandbyState : public JobState {
+ public:
+ TriggerStandbyState(JobRunner* runner);
+ ~TriggerStandbyState();
+
+ bool execute();
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_TRIGGER_STANDBY_STATE_H__ */