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

Dependencies:   LinkedList

Dependents:   JobSchedulerDemo Borsch

Revision:
1:ec6a1d054065
Parent:
0:806403f3d0d1
Child:
2:9bf5366ad5a2
--- a/scheduler.h	Tue Jul 11 00:16:08 2017 +0000
+++ b/scheduler.h	Tue Jul 11 18:07:11 2017 +0000
@@ -7,9 +7,10 @@
 namespace JobScheduler {
     
     typedef int JobID;
+    typedef int JobTypeID;
     typedef int ActionType;
     
-    const ActionType ActionJobAdd(1);
+    const ActionType JobAddAT(1);
     
     /**
     Declares concept of the schedule.
@@ -21,17 +22,24 @@
             virtual ~ISchedule() = 0;
     };
     
-    struct JobRes {
+    /** 
+    ResBase provide common properties for Scheduler response queue.
+    */
+    struct ResBase {
         Error error;
-        JobID jobID;
-        JobRes(Error err, JobID id): error(err), jobID(id) {}
+        ResBase(Error err) : error(err) {}
     };
     
+    template<typename T>
+    struct Response : ResBase {
+       T Data;
+       Response(Error err, T data) : ResBase(err), Data(data) {}
+    };
+       
     struct Action {
         ActionType type;
-        void *data;
-        Queue<JobRes, 1> response;
-        Action(ActionType t, void *d): type(t), data(d) {}
+        Queue<ResBase, 1> resQueue;
+        Action(ActionType t): type(t) {}
     };
        
     /**
@@ -40,19 +48,19 @@
     class Job {
         public:
         
-        Job(JobID id, int typeID): _id(id), _typeID(typeID) {};
+        Job(JobID id, JobTypeID typeID): _id(id), _typeID(typeID) {};
 
         JobID GetID() const {
             return _id;
         };
         
-        int GetTypeID() const {
+        JobTypeID GetTypeID() const {
             return _typeID;
         };
         
         private:
             JobID _id;
-            int _typeID;
+            JobTypeID _typeID;
     };
     
    
@@ -76,11 +84,12 @@
             void WaitToStop();
             
             /** JobAdd adds job of typeID and returns ID of added job. */
-            JobRes* JobAdd(int typeID);
+            Response<JobID> JobAdd(int typeID);
             void JobRemove(int jobID);
         private:
             static void updateAdapter(void *target);
             void updateHandler();
+            
             void process(Action *action);
         private:
             Thread _updater;