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

Abstract base class for passive queues. More...

#include <PassiveQueueBase.h>

Inheritance diagram for inet::PassiveQueueBase:
inet::IPassiveQueue inet::DropTailQueue inet::FIFOQueue

Public Member Functions

virtual void requestPacket () override
 The queue should send a packet whenever this method is invoked. More...
 
virtual int getNumPendingRequests () override
 Returns number of pending requests. More...
 
virtual void clear () override
 Clear all queued packets and stored requests. More...
 
virtual cMessage * pop () override
 Return a packet from the queue directly. More...
 
virtual void addListener (IPassiveQueueListener *listener) override
 Implementation of IPassiveQueue::addListener(). More...
 
virtual void removeListener (IPassiveQueueListener *listener) override
 Implementation of IPassiveQueue::removeListener(). More...
 
- Public Member Functions inherited from inet::IPassiveQueue
virtual ~IPassiveQueue ()
 
virtual bool isEmpty ()=0
 Return true when queue is empty, otherwise return false. More...
 

Static Public Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 Signal with packet when received it. More...
 
static simsignal_t enqueuePkSignal = registerSignal("enqueuePk")
 Signal with packet when enqueued it. More...
 
static simsignal_t dequeuePkSignal = registerSignal("dequeuePk")
 Signal with packet when sent out it. More...
 
static simsignal_t dropPkByQueueSignal = registerSignal("dropPkByQueue")
 Signal with packet when dropped it. More...
 
static simsignal_t queueingTimeSignal = registerSignal("queueingTime")
 Signal with value of delaying time when sent out a packet. More...
 

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
virtual void notifyListeners ()
 
virtual cMessage * enqueue (cMessage *msg)=0
 Inserts packet into the queue or the priority queue, or drops it (or another packet). More...
 
virtual cMessage * dequeue ()=0
 Returns a packet from the queue, or nullptr if the queue is empty. More...
 
virtual void sendOut (cMessage *msg)=0
 Should be redefined to send out the packet; e.g. More...
 

Protected Attributes

std::list< IPassiveQueueListener * > listeners
 
int packetRequested
 
int numQueueReceived
 
int numQueueDropped
 

Detailed Description

Abstract base class for passive queues.

Implements IPassiveQueue. Enqueue/dequeue have to be implemented in virtual functions in subclasses; the actual queue or piority queue data structure also goes into subclasses.

Member Function Documentation

void inet::PassiveQueueBase::addListener ( IPassiveQueueListener listener)
overridevirtual

Implementation of IPassiveQueue::addListener().

Implements inet::IPassiveQueue.

114 {
115  auto it = find(listeners.begin(), listeners.end(), listener);
116  if (it == listeners.end())
117  listeners.push_back(listener);
118 }
std::list< IPassiveQueueListener * > listeners
Definition: PassiveQueueBase.h:38
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::PassiveQueueBase::clear ( )
overridevirtual

Clear all queued packets and stored requests.

Implements inet::IPassiveQueue.

95 {
96  cMessage *msg;
97 
98  while (nullptr != (msg = dequeue()))
99  delete msg;
100 
101  packetRequested = 0;
102 }
virtual cMessage * dequeue()=0
Returns a packet from the queue, or nullptr if the queue is empty.
int packetRequested
Definition: PassiveQueueBase.h:41
virtual cMessage* inet::PassiveQueueBase::dequeue ( )
protectedpure virtual

Returns a packet from the queue, or nullptr if the queue is empty.

Implemented in inet::DropTailQueue, and inet::FIFOQueue.

Referenced by clear(), pop(), and requestPacket().

virtual cMessage* inet::PassiveQueueBase::enqueue ( cMessage *  msg)
protectedpure virtual

Inserts packet into the queue or the priority queue, or drops it (or another packet).

Returns nullptr if successful, or the pointer of the dropped packet.

Implemented in inet::DropTailQueue, and inet::FIFOQueue.

Referenced by handleMessage().

void inet::PassiveQueueBase::finish ( )
overrideprotectedvirtual
110 {
111 }
virtual int inet::PassiveQueueBase::getNumPendingRequests ( )
inlineoverridevirtual

Returns number of pending requests.

Implements inet::IPassiveQueue.

94 { return packetRequested; }
int packetRequested
Definition: PassiveQueueBase.h:41
void inet::PassiveQueueBase::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
44 {
46 
47  emit(rcvdPkSignal, msg);
48 
49  if (packetRequested > 0) {
51  emit(enqueuePkSignal, msg);
52  emit(dequeuePkSignal, msg);
53  emit(queueingTimeSignal, SIMTIME_ZERO);
54  sendOut(msg);
55  }
56  else {
57  msg->setArrivalTime(simTime());
58  cMessage *droppedMsg = enqueue(msg);
59  if (msg != droppedMsg)
60  emit(enqueuePkSignal, msg);
61 
62  if (droppedMsg) {
64  emit(dropPkByQueueSignal, droppedMsg);
65  delete droppedMsg;
66  }
67  else
69  }
70 }
static simsignal_t rcvdPkSignal
Signal with packet when received it.
Definition: PassiveQueueBase.h:49
virtual void notifyListeners()
Definition: PassiveQueueBase.cc:127
static simsignal_t queueingTimeSignal
Signal with value of delaying time when sent out a packet.
Definition: PassiveQueueBase.h:57
virtual cMessage * enqueue(cMessage *msg)=0
Inserts packet into the queue or the priority queue, or drops it (or another packet).
int numQueueReceived
Definition: PassiveQueueBase.h:44
int packetRequested
Definition: PassiveQueueBase.h:41
static simsignal_t enqueuePkSignal
Signal with packet when enqueued it.
Definition: PassiveQueueBase.h:51
virtual void sendOut(cMessage *msg)=0
Should be redefined to send out the packet; e.g.
static simsignal_t dequeuePkSignal
Signal with packet when sent out it.
Definition: PassiveQueueBase.h:53
static simsignal_t dropPkByQueueSignal
Signal with packet when dropped it.
Definition: PassiveQueueBase.h:55
int numQueueDropped
Definition: PassiveQueueBase.h:45
void inet::PassiveQueueBase::initialize ( )
overrideprotectedvirtual

Reimplemented in inet::FIFOQueue, and inet::DropTailQueue.

Referenced by inet::DropTailQueue::initialize(), and inet::FIFOQueue::initialize().

31 {
32  // state
33  packetRequested = 0;
34  WATCH(packetRequested);
35 
36  // statistics
37  numQueueReceived = 0;
38  numQueueDropped = 0;
39  WATCH(numQueueReceived);
40  WATCH(numQueueDropped);
41 }
int numQueueReceived
Definition: PassiveQueueBase.h:44
int packetRequested
Definition: PassiveQueueBase.h:41
int numQueueDropped
Definition: PassiveQueueBase.h:45
void inet::PassiveQueueBase::notifyListeners ( )
protectedvirtual

Referenced by handleMessage().

128 {
129  for (auto & elem : listeners)
130  (elem)->packetEnqueued(this);
131 }
std::list< IPassiveQueueListener * > listeners
Definition: PassiveQueueBase.h:38
cMessage * inet::PassiveQueueBase::pop ( )
overridevirtual

Return a packet from the queue directly.

Implements inet::IPassiveQueue.

105 {
106  return dequeue();
107 }
virtual cMessage * dequeue()=0
Returns a packet from the queue, or nullptr if the queue is empty.
void inet::PassiveQueueBase::refreshDisplay ( ) const
overrideprotectedvirtual
73 {
74  char buf[100];
75  sprintf(buf, "q rcvd: %d\nq dropped: %d", numQueueReceived, numQueueDropped);
76  getDisplayString().setTagArg("t", 0, buf);
77 }
int numQueueReceived
Definition: PassiveQueueBase.h:44
int numQueueDropped
Definition: PassiveQueueBase.h:45
void inet::PassiveQueueBase::removeListener ( IPassiveQueueListener listener)
overridevirtual

Implementation of IPassiveQueue::removeListener().

Implements inet::IPassiveQueue.

121 {
122  auto it = find(listeners.begin(), listeners.end(), listener);
123  if (it != listeners.end())
124  listeners.erase(it);
125 }
std::list< IPassiveQueueListener * > listeners
Definition: PassiveQueueBase.h:38
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::PassiveQueueBase::requestPacket ( )
overridevirtual

The queue should send a packet whenever this method is invoked.

If the queue is currently empty, it should send a packet when when one becomes available.

Implements inet::IPassiveQueue.

80 {
81  Enter_Method("requestPacket()");
82 
83  cMessage *msg = dequeue();
84  if (msg == nullptr) {
86  }
87  else {
88  emit(dequeuePkSignal, msg);
89  emit(queueingTimeSignal, simTime() - msg->getArrivalTime());
90  sendOut(msg);
91  }
92 }
static simsignal_t queueingTimeSignal
Signal with value of delaying time when sent out a packet.
Definition: PassiveQueueBase.h:57
virtual cMessage * dequeue()=0
Returns a packet from the queue, or nullptr if the queue is empty.
int packetRequested
Definition: PassiveQueueBase.h:41
virtual void sendOut(cMessage *msg)=0
Should be redefined to send out the packet; e.g.
static simsignal_t dequeuePkSignal
Signal with packet when sent out it.
Definition: PassiveQueueBase.h:53
virtual void inet::PassiveQueueBase::sendOut ( cMessage *  msg)
protectedpure virtual

Should be redefined to send out the packet; e.g.

send(msg,"out").

Implemented in inet::DropTailQueue, and inet::FIFOQueue.

Referenced by handleMessage(), and requestPacket().

Member Data Documentation

simsignal_t inet::PassiveQueueBase::dequeuePkSignal = registerSignal("dequeuePk")
static

Signal with packet when sent out it.

Referenced by handleMessage(), and requestPacket().

simsignal_t inet::PassiveQueueBase::dropPkByQueueSignal = registerSignal("dropPkByQueue")
static
simsignal_t inet::PassiveQueueBase::enqueuePkSignal = registerSignal("enqueuePk")
static

Signal with packet when enqueued it.

Referenced by handleMessage().

std::list<IPassiveQueueListener *> inet::PassiveQueueBase::listeners
protected
int inet::PassiveQueueBase::numQueueDropped
protected
int inet::PassiveQueueBase::numQueueReceived
protected
int inet::PassiveQueueBase::packetRequested
protected
simsignal_t inet::PassiveQueueBase::queueingTimeSignal = registerSignal("queueingTime")
static

Signal with value of delaying time when sent out a packet.

Referenced by handleMessage(), and requestPacket().

simsignal_t inet::PassiveQueueBase::rcvdPkSignal = registerSignal("rcvdPk")
static

Signal with packet when received it.

Referenced by handleMessage().


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