job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.

Dependencies:   LinkedList

Dependents:   JobSchedulerDemo Borsch

jobService.h

Committer:
sgnezdov
Date:
2017-07-11
Revision:
0:806403f3d0d1
Child:
9:ee21cd055a97

File content as of revision 0:806403f3d0d1:

#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