tasks.h 3.6 KB
Newer Older
ram's avatar
ram committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
/* tasks.h - definitions of TaskState, TaskControlBlock and xxxTCB 
 * The subclasses of TaskControlBlock differ only in their
 * implementation of the action function 				  */

#ifndef TASKS

#define TASKS

#include "types.h"

/*
// TaskState
*/

class TaskState {
    protected:
        BOOLEAN packetPending, taskWaiting, taskHolding;
	
    public:
        /* initializing */
        TaskState() {packetPending = TRUE; taskWaiting = taskHolding = FALSE;}
	void PacketPending() {packetPending = TRUE; taskHolding = taskWaiting = FALSE;}
	void Waiting() {packetPending = taskHolding = FALSE; taskWaiting = TRUE;}
	void Running() {packetPending = taskWaiting = taskHolding = FALSE;}
	void WaitingWithPacket() {packetPending = taskWaiting = TRUE; taskHolding = FALSE;}
	/* accessing */
	BOOLEAN IsPacketPending() {return packetPending;}
	BOOLEAN IsTaskWaiting() {return taskWaiting;}
	BOOLEAN IsTaskHolding() {return taskHolding;}
	void SetTaskHolding(BOOLEAN state) {taskHolding = state;}
	void SetTaskWaiting(BOOLEAN state) {taskWaiting = state;}
	/* testing */
	BOOLEAN IsRunning() {return !packetPending && !taskWaiting && !taskHolding;}
	BOOLEAN IsTaskHoldingOrWaiting() {return taskHolding || !packetPending && taskWaiting;}
	BOOLEAN IsWaiting() {return !packetPending && taskWaiting && !taskHolding;}
	BOOLEAN IsWaitingWithPacket() {return packetPending && taskWaiting && !taskHolding;}
};

/*
// TaskControlBlock
*/

class TaskControlBlock : public TaskState {

    protected:
        TaskControlBlock *link;
	Identity ident;
	int priority;
	Packet *input;
	void *handle;
	
    public:
        /* initializing */
        TaskControlBlock(TaskControlBlock *l, Identity id, int prio,
                         Packet *initialWork, TaskState *initialState,
                         void *privateData);
	/* accessing */
        Identity Ident() {return ident;}
        int Priority() {return priority;}
        TaskControlBlock *Link() {return link;}
	/* scheduling */
        TaskControlBlock *AddPacket(Packet *p, TaskControlBlock *old);
        virtual TaskControlBlock *ActionFunc(Packet *p, void *handle);
        TaskControlBlock *RunTask();
};

/*
// DeviceTCB 
*/

class DeviceTCB : public TaskControlBlock {
    public:
        DeviceTCB(TaskControlBlock *l, Identity id, int prio,
                  Packet *initialWork, TaskState *initialState,
                  void *privateData) :
                 (l, id, prio, initialWork, initialState, privateData){}
        TaskControlBlock *ActionFunc(Packet *p, void *handle);
};


/*
// HandlerTCB
*/

class HandlerTCB : public TaskControlBlock {
    public:
        HandlerTCB(TaskControlBlock *l, Identity id, int prio,
                   Packet *initialWork, TaskState *initialState,
                   void *privateData) :
                  (l, id, prio, initialWork, initialState, privateData){}
        TaskControlBlock *ActionFunc(Packet *p, void *handle);
};


/*
// IdlerTCB
*/

class IdlerTCB : public TaskControlBlock {
    public:
        IdlerTCB(TaskControlBlock *l, Identity id, int prio,
                 Packet *initialWork, TaskState *initialState,
                 void *privateData) :
                (l, id, prio, initialWork, initialState, privateData){}
        TaskControlBlock *ActionFunc(Packet *p, void *handle);
};


/*
// WorkerTCB
*/

class WorkerTCB : public TaskControlBlock {
    public:
        WorkerTCB(TaskControlBlock *l, Identity id, int prio,
                  Packet *initialWork, TaskState *initialState,
                  void *privateData) :
                 (l, id, prio, initialWork, initialState, privateData){}
        TaskControlBlock *ActionFunc(Packet *p, void *handle);
};

#endif