#include <AbstractQueue.h>
Public Member Functions | |
AbstractQueue () | |
virtual | ~AbstractQueue () |
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | arrival (cPacket *msg)=0 |
virtual cPacket * | arrivalWhenIdle (cPacket *msg)=0 |
virtual simtime_t | startService (cPacket *msg)=0 |
virtual void | endService (cPacket *msg)=0 |
Protected Attributes | |
cPacketQueue | queue |
Private Member Functions | |
void | doStartService () |
void | doEndService () |
Private Attributes | |
cPacket * | msgServiced |
cMessage * | endServiceMsg |
AbstractQueue::AbstractQueue | ( | ) |
AbstractQueue::~AbstractQueue | ( | ) | [virtual] |
void AbstractQueue::doStartService | ( | ) | [private] |
Referenced by doEndService(), and handleMessage().
00065 { 00066 simtime_t serviceTime = startService( msgServiced ); 00067 if (serviceTime != 0) 00068 scheduleAt( simTime()+serviceTime, endServiceMsg ); 00069 else 00070 doEndService(); 00071 }
void AbstractQueue::doEndService | ( | ) | [private] |
Referenced by doStartService(), and handleMessage().
00074 { 00075 endService( msgServiced ); 00076 if (queue.empty()) 00077 { 00078 msgServiced = NULL; 00079 } 00080 else 00081 { 00082 msgServiced = queue.pop(); 00083 doStartService(); 00084 } 00085 }
void AbstractQueue::initialize | ( | ) | [protected, virtual] |
Reimplemented in QueueBase, QueueWithQoS, IP, and IPv6.
Referenced by QueueWithQoS::initialize(), and QueueBase::initialize().
00036 { 00037 msgServiced = NULL; 00038 endServiceMsg = new cMessage("end-service"); 00039 queue.setName("queue"); 00040 }
void AbstractQueue::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
00043 { 00044 if (msg==endServiceMsg) 00045 { 00046 doEndService(); 00047 } 00048 else if (!msgServiced) 00049 { 00050 cPacket *msg2 = arrivalWhenIdle( PK(msg) ); 00051 if (msg2) 00052 { 00053 msgServiced = msg2; 00054 doStartService(); 00055 } 00056 00057 } 00058 else 00059 { 00060 arrival( PK(msg) ); 00061 } 00062 }
virtual void AbstractQueue::arrival | ( | cPacket * | msg | ) | [protected, pure virtual] |
Functions to (re)define behaviour Called when a message arrives at the module. The method should either enqueue this message (usual behaviour), or discard it. It may also wrap the it into another message, and insert that one in the queue.
Most straightforward implementation: queue.insert(msg);
Implemented in QueueBase, and QueueWithQoS.
Referenced by handleMessage().
virtual cPacket* AbstractQueue::arrivalWhenIdle | ( | cPacket * | msg | ) | [protected, pure virtual] |
Called when a message arrives at the module when the queue is empty. The message doesn't need to be enqueued in this case, it can start service immmediately. This method may:
Most straightforward implementation: return msg;
Implemented in QueueBase, and QueueWithQoS.
Referenced by handleMessage().
virtual simtime_t AbstractQueue::startService | ( | cPacket * | msg | ) | [protected, pure virtual] |
Called when a message starts service, and should return the service time.
Example implementation: return 1.0;
Implemented in QueueBase, and QueueWithQoS.
Referenced by doStartService().
virtual void AbstractQueue::endService | ( | cPacket * | msg | ) | [protected, pure virtual] |
Called when a message completes service. The function may send it to another module, discard it, or in general do anything with it.
Most straightforward implementation: send(msg,"out");
Referenced by doEndService().
cPacket* AbstractQueue::msgServiced [private] |
Referenced by AbstractQueue(), doEndService(), doStartService(), handleMessage(), initialize(), and ~AbstractQueue().
cMessage* AbstractQueue::endServiceMsg [private] |
Referenced by AbstractQueue(), doStartService(), handleMessage(), initialize(), and ~AbstractQueue().
cPacketQueue AbstractQueue::queue [protected] |
The queue.
Referenced by QueueWithQoS::arrival(), QueueBase::arrival(), doEndService(), and initialize().