job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.
Dependents: JobSchedulerDemo Borsch
Diff: jobService.cpp
- Revision:
- 0:806403f3d0d1
- Child:
- 9:ee21cd055a97
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jobService.cpp Tue Jul 11 00:16:08 2017 +0000 @@ -0,0 +1,51 @@ +#include "jobService.h" + +namespace JobScheduler { + +jobFunc* JobType::Job() +{ + return this->_job; +} + +bool JobType::AscendingExcl(JobType *j2) +{ + return this->_jobTypeID < j2->_jobTypeID; +} + +bool JobType::IsEqual(JobType *j2) +{ + return this->_jobTypeID == j2->_jobTypeID; +} + +bool jtAscending(JobType *j1, JobType *j2) +{ + return j1->AscendingExcl(j2); +} + +bool jtIsEqual(JobType *j1, JobType *j2) +{ + return j1->IsEqual(j2); +} + +Error JobService::Register(int jobTypeID, jobFunc *job) +{ + JobType *jt = new JobType(jobTypeID, job); + node<JobType> *tmp = _jobs.insertOrdered(jt, jtAscending); + if (NULL == tmp) { + error("[JobService::Register] failed to insertOrdered"); + return Error(1); + } + return NoError; +} + +jobFunc* JobService::GetJob(int jobTypeID) +{ + JobType search = JobType(jobTypeID, NULL); + node<JobType> *found = _jobs.pop(&search, jtIsEqual); + if (found == NULL) { + return NULL; + } + return found->data->Job(); +} + +} // end of namespace \ No newline at end of file