INET Framework for OMNeT++/OMNEST
inet::AbstractQueue Class Referenceabstract

Abstract base class for single-server queues. More...

#include <AbstractQueue.h>

Inheritance diagram for inet::AbstractQueue:
inet::QueueBase inet::GenericNetworkProtocol inet::IPv4 inet::IPv6

Public Member Functions

 AbstractQueue ()
 
virtual ~AbstractQueue ()
 

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void arrival (cPacket *msg)=0
 Functions to (re)define behaviour. More...
 
virtual cPacket * arrivalWhenIdle (cPacket *msg)=0
 Called when a message arrives at the module when the queue is empty. More...
 
virtual simtime_t startService (cPacket *msg)=0
 Called when a message starts service, and should return the service time. More...
 
virtual void endService (cPacket *msg)=0
 Called when a message completes service. More...
 
virtual cPacket * cancelService ()
 If a message is under service, aborts its service and returns the message. More...
 

Protected Attributes

cPacketQueue queue
 The queue. More...
 

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

inet::AbstractQueue::AbstractQueue ( )
25 {
26  msgServiced = nullptr;
27  endServiceMsg = nullptr;
28 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
cMessage * endServiceMsg
Definition: AbstractQueue.h:38
inet::AbstractQueue::~AbstractQueue ( )
virtual
31 {
32  delete msgServiced;
33  cancelAndDelete(endServiceMsg);
34 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
cMessage * endServiceMsg
Definition: AbstractQueue.h:38

Member Function Documentation

virtual void inet::AbstractQueue::arrival ( cPacket *  msg)
protectedpure 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 inet::QueueBase.

Referenced by handleMessage().

virtual cPacket* inet::AbstractQueue::arrivalWhenIdle ( cPacket *  msg)
protectedpure 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 immediately. This method may:

  1. simply return the the same pointer (usual behaviour), or
  2. discard the message and return nullptr 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 inet::QueueBase.

Referenced by handleMessage().

cPacket * inet::AbstractQueue::cancelService ( )
protectedvirtual

If a message is under service, aborts its service and returns the message.

Returns nullptr if no message is being serviced. The caller is free to delete the message, reinsert it into the queue, or handle it otherwise.

Referenced by inet::IPv4::flush().

82 {
83  if (!msgServiced)
84  return nullptr;
85  else {
86  cancelEvent(endServiceMsg);
87  cPacket *ret = msgServiced;
88  msgServiced = nullptr;
89  return ret;
90  }
91 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
cMessage * endServiceMsg
Definition: AbstractQueue.h:38
void inet::AbstractQueue::doEndService ( )
private

Referenced by doStartService(), and handleMessage().

70 {
72  if (queue.isEmpty()) {
73  msgServiced = nullptr;
74  }
75  else {
76  msgServiced = queue.pop();
78  }
79 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
cPacketQueue queue
The queue.
Definition: AbstractQueue.h:48
virtual void endService(cPacket *msg)=0
Called when a message completes service.
void doStartService()
Definition: AbstractQueue.cc:60
void inet::AbstractQueue::doStartService ( )
private

Referenced by doEndService(), and handleMessage().

61 {
62  simtime_t serviceTime = startService(msgServiced);
63  if (serviceTime != SIMTIME_ZERO)
64  scheduleAt(simTime() + serviceTime, endServiceMsg);
65  else
66  doEndService();
67 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
void doEndService()
Definition: AbstractQueue.cc:69
virtual simtime_t startService(cPacket *msg)=0
Called when a message starts service, and should return the service time.
cMessage * endServiceMsg
Definition: AbstractQueue.h:38
virtual void inet::AbstractQueue::endService ( cPacket *  msg)
protectedpure 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 inet::IPv4, inet::IPv6, and inet::GenericNetworkProtocol.

Referenced by doEndService().

void inet::AbstractQueue::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Reimplemented in inet::IPv4, inet::IPv6, and inet::GenericNetworkProtocol.

Referenced by inet::GenericNetworkProtocol::handleMessage(), inet::IPv6::handleMessage(), and inet::IPv4::handleMessage().

44 {
45  if (msg == endServiceMsg) {
46  doEndService();
47  }
48  else if (!msgServiced) {
49  cPacket *msg2 = arrivalWhenIdle(PK(msg));
50  if (msg2) {
51  msgServiced = msg2;
53  }
54  }
55  else {
56  arrival(PK(msg));
57  }
58 }
virtual void arrival(cPacket *msg)=0
Functions to (re)define behaviour.
cPacket * msgServiced
Definition: AbstractQueue.h:37
void doEndService()
Definition: AbstractQueue.cc:69
void doStartService()
Definition: AbstractQueue.cc:60
#define PK(msg)
Definition: INETDefs.h:92
cMessage * endServiceMsg
Definition: AbstractQueue.h:38
virtual cPacket * arrivalWhenIdle(cPacket *msg)=0
Called when a message arrives at the module when the queue is empty.
void inet::AbstractQueue::initialize ( )
overrideprotectedvirtual

Reimplemented in inet::GenericNetworkProtocol, and inet::QueueBase.

Referenced by inet::QueueBase::initialize().

37 {
38  msgServiced = nullptr;
39  endServiceMsg = new cMessage("end-service");
40  queue.setName("queue");
41 }
cPacket * msgServiced
Definition: AbstractQueue.h:37
cPacketQueue queue
The queue.
Definition: AbstractQueue.h:48
cMessage * endServiceMsg
Definition: AbstractQueue.h:38
virtual simtime_t inet::AbstractQueue::startService ( cPacket *  msg)
protectedpure virtual

Called when a message starts service, and should return the service time.

Example implementation: return 1.0;

Implemented in inet::QueueBase.

Referenced by doStartService().

Member Data Documentation

cMessage* inet::AbstractQueue::endServiceMsg
private
cPacket* inet::AbstractQueue::msgServiced
private

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