#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 |
Abstract base class for single-server queues. Contains special optimization for zero service time (i.e. it does not schedule the endService timer then).
Definition at line 30 of file AbstractQueue.h.
AbstractQueue::AbstractQueue | ( | ) |
Definition at line 23 of file AbstractQueue.cc.
{ msgServiced = NULL; endServiceMsg = NULL; }
AbstractQueue::~AbstractQueue | ( | ) | [virtual] |
Definition at line 29 of file AbstractQueue.cc.
{ delete msgServiced; cancelAndDelete(endServiceMsg); }
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().
void AbstractQueue::doEndService | ( | ) | [private] |
Definition at line 73 of file AbstractQueue.cc.
Referenced by doStartService(), and handleMessage().
{ endService( msgServiced ); if (queue.empty()) { msgServiced = NULL; } else { msgServiced = queue.pop(); doStartService(); } }
void AbstractQueue::doStartService | ( | ) | [private] |
Definition at line 64 of file AbstractQueue.cc.
Referenced by doEndService(), and handleMessage().
{ simtime_t serviceTime = startService( msgServiced ); if (serviceTime != 0) scheduleAt( simTime()+serviceTime, endServiceMsg ); else doEndService(); }
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().
void AbstractQueue::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 42 of file AbstractQueue.cc.
{ if (msg==endServiceMsg) { doEndService(); } else if (!msgServiced) { cPacket *msg2 = arrivalWhenIdle( PK(msg) ); if (msg2) { msgServiced = msg2; doStartService(); } } else { arrival( PK(msg) ); } }
void AbstractQueue::initialize | ( | ) | [protected, virtual] |
Reimplemented in QueueBase, QueueWithQoS, IP, and IPv6.
Definition at line 35 of file AbstractQueue.cc.
{ msgServiced = NULL; endServiceMsg = new cMessage("end-service"); queue.setName("queue"); }
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().
cMessage* AbstractQueue::endServiceMsg [private] |
Definition at line 38 of file AbstractQueue.h.
Referenced by AbstractQueue(), doStartService(), handleMessage(), initialize(), and ~AbstractQueue().
cPacket* AbstractQueue::msgServiced [private] |
Definition at line 37 of file AbstractQueue.h.
Referenced by AbstractQueue(), doEndService(), doStartService(), handleMessage(), initialize(), and ~AbstractQueue().
cPacketQueue AbstractQueue::queue [protected] |
The queue.
Definition at line 48 of file AbstractQueue.h.
Referenced by QueueWithQoS::arrival(), QueueBase::arrival(), doEndService(), and initialize().