job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.
Dependents: JobSchedulerDemo Borsch
Diff: jobService.h
- Revision:
- 0:806403f3d0d1
- Child:
- 9:ee21cd055a97
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jobService.h Tue Jul 11 00:16:08 2017 +0000 @@ -0,0 +1,62 @@ +#pragma once + +#include "LinkedList.h" + +namespace JobScheduler { + + typedef void (jobFunc)(void); + + // Error type uses zero to indicate no Error. + // Any other value is an error with error code. + typedef int Error; + + const Error NoError = Error(0); + + /** + JobType connects job type ID to job function. + */ + class JobType { + public: + JobType(int jobTypeID, jobFunc *job) + : _jobTypeID(jobTypeID), _job(job) {} + + jobFunc *Job(); + + bool AscendingExcl(JobType *d2); + bool IsEqual(JobType *d2); + + private: + int _jobTypeID; + jobFunc *_job; + }; + + /** + JobService connects job type ID to job function. + */ + class JobService { + public: + + JobService() {} + + /** + Register associates jobTypeID with job and stores association. + @returns Error if failed to register. + */ + Error Register(int jobTypeID, jobFunc *job); + + /** + GetJob returns job function based on jobTypeID. + @returns NULL if job is not found. + */ + jobFunc* GetJob(int jobTypeID); + + private: + /* + _jobs stores job registrations. + Current implementation uses LinkedList, because it assumes that + number of jobs is no more than 10 or 20. + */ + LinkedList<JobType> _jobs; + }; + +} // end of namespace \ No newline at end of file