job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.
Dependents: JobSchedulerDemo Borsch
Diff: scheduler.cpp
- Revision:
- 1:ec6a1d054065
- Parent:
- 0:806403f3d0d1
- Child:
- 2:9bf5366ad5a2
--- a/scheduler.cpp Tue Jul 11 00:16:08 2017 +0000 +++ b/scheduler.cpp Tue Jul 11 18:07:11 2017 +0000 @@ -1,10 +1,15 @@ #include "scheduler.h" -//#include "core-util/atomic_ops.h" void update(void *target) { }; namespace JobScheduler { + + struct JobAddReq: Action { + JobTypeID jobTID; + Response<JobID> response; + JobAddReq(JobTypeID typeID) : Action(JobAddAT), jobTID(typeID), response(NoError, 0) {} + }; Scheduler::Scheduler(JobService *jobService) : _jobService(jobService) { } @@ -27,17 +32,16 @@ _updater.join(); } - JobRes* Scheduler::JobAdd(int typeID) { - Action action(ActionJobAdd, (void*)typeID); - _actions.put(&action); + Response<JobID> Scheduler::JobAdd(JobTypeID jobTID) { + JobAddReq req(jobTID); + _actions.put(&req); // default is wait forever - osEvent evt = action.response.get(); + osEvent evt = req.resQueue.get(); if (evt.status == osEventMessage) { printf("[Scheduler::JobAdd] completed ok\n"); - return (JobRes*)evt.value.p; + //return (JobRes*)evt.value.p; } - printf("[Scheduler::JobAdd] completed UNEXPECTEDLY\n"); - return new JobRes(NoError, 0); + return req.response; } void Scheduler::JobRemove(int jobID) { @@ -60,8 +64,16 @@ void Scheduler::process(Action *action) { - JobRes *jr = new JobRes(NoError, 0); - action->response.put(jr); + switch(action->type) { + case JobAddAT: { + JobAddReq *req = static_cast<JobAddReq*>(action); + action->resQueue.put(&req->response); + break; + } + default: + printf("[Scheduler::process] unknown action type\n"); + action->resQueue.put(NULL); + } } } \ No newline at end of file