job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.
Dependents: JobSchedulerDemo Borsch
Diff: scheduler.cpp
- Revision:
- 0:806403f3d0d1
- Child:
- 1:ec6a1d054065
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scheduler.cpp Tue Jul 11 00:16:08 2017 +0000 @@ -0,0 +1,67 @@ +#include "scheduler.h" +//#include "core-util/atomic_ops.h" + +void update(void *target) { +}; + +namespace JobScheduler { + + Scheduler::Scheduler(JobService *jobService) + : _jobService(jobService) { } + + void Scheduler::updateAdapter(void *thisPointer) { + Scheduler *self = static_cast<Scheduler*>(thisPointer); + self->updateHandler(); + } + + void Scheduler::Start() { + _updater.start(callback(Scheduler::updateAdapter, this)); + } + + void Scheduler::Stop() { + // it is not thread-safe, but impact is non-existent. + _quit = true; + } + + void Scheduler::WaitToStop() { + _updater.join(); + } + + JobRes* Scheduler::JobAdd(int typeID) { + Action action(ActionJobAdd, (void*)typeID); + _actions.put(&action); + // default is wait forever + osEvent evt = action.response.get(); + if (evt.status == osEventMessage) { + printf("[Scheduler::JobAdd] completed ok\n"); + return (JobRes*)evt.value.p; + } + printf("[Scheduler::JobAdd] completed UNEXPECTEDLY\n"); + return new JobRes(NoError, 0); + } + + void Scheduler::JobRemove(int jobID) { + } + + void Scheduler::updateHandler() { + while (!_quit) { + printf("[Scheduler::updateHandler] waiting for action\n"); + // wait forever ... + osEvent evt = _actions.get(); + if (evt.status == osEventMessage) { + printf("[Scheduler::updateHandler] process action\n"); + this->process((Action*)evt.value.p); + } else { + printf("[Scheduler::updateHandler] NOT osEventMessage\n"); + } + wait(2); + } + } + + void Scheduler::process(Action *action) + { + JobRes *jr = new JobRes(NoError, 0); + action->response.put(jr); + } + +} \ No newline at end of file