Sergei G
/
JobSchedulerDemo
run once and run periodic example work
source/main.cpp
- Committer:
- sgnezdov
- Date:
- 2017-07-11
- Revision:
- 6:b0bca03d9f3a
- Parent:
- 5:79cbf6d8b5f0
- Child:
- 8:8a65353ec8f3
File content as of revision 6:b0bca03d9f3a:
#include "mbed.h" #include "scheduler.h" #include "LinkedList.h" #include "jobService.h" #include "schedules.h" void jobA() { printf("Job A\n"); } void jobB() { printf("Job B\n"); } void runScheduler() { JobScheduler::JobService js; JobScheduler::Scheduler scheduler(&js); js.Register(1, jobA); js.Register(2, jobB); scheduler.Start(); time_t nowSecs = time(NULL); JobScheduler::Response<JobScheduler::JobID> res = scheduler.JobAdd(1, new JobScheduler::RunOnceSchedule(nowSecs + 2), NULL); printf("job A add response error: %d, jobID: %d\n", res.error, res.data); wait(5); printf("periodic with 2 sec period and limit 3\n"); res = scheduler.JobAdd(2, new JobScheduler::RunPeriodicSchedule(2, 3), NULL); printf("job B add response error: %d, jobID: %d\n", res.error, res.data); wait(10); scheduler.Stop(); scheduler.WaitToStop(); } int main() { printf("\nJob Scheduler Demo\n"); runScheduler(); printf("done\n"); exit(0); }