INET Framework for OMNeT++/OMNEST
AbstractQueue Class Reference

#include <AbstractQueue.h>

Inheritance diagram for AbstractQueue:
QueueBase QueueWithQoS IP IPv6

List of all members.

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

Detailed Description

Abstract base class for single-server queues. Contains special optimization for zero service time (i.e. it does not schedule the endService timer then).


Constructor & Destructor Documentation

AbstractQueue::AbstractQueue ( )
{
    msgServiced = NULL;
    endServiceMsg = NULL;
}
AbstractQueue::~AbstractQueue ( ) [virtual]
{
    delete msgServiced;
    cancelAndDelete(endServiceMsg);
}

Member Function Documentation

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:

  1. simply return the the same pointer (usual behaviour), or
  2. discard the message and return NULL pointer (the effect being this message being ignored)
  3. or modify the message, wrap in into another message etc, and return the (new) message's pointer.

Most straightforward implementation: return msg;

Implemented in QueueBase, and QueueWithQoS.

Referenced by handleMessage().

void AbstractQueue::doEndService ( ) [private]

Referenced by doStartService(), and handleMessage().

{
    endService( msgServiced );
    if (queue.empty())
    {
        msgServiced = NULL;
    }
    else
    {
        msgServiced = queue.pop();
        doStartService();
    }
}
void AbstractQueue::doStartService ( ) [private]

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");

Implemented in IP, and IPv6.

Referenced by doEndService().

void AbstractQueue::handleMessage ( cMessage *  msg) [protected, virtual]
{
    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.

{
    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().


Member Data Documentation

cPacketQueue AbstractQueue::queue [protected]

The documentation for this class was generated from the following files: