OMNET QUEUE is a container class that act as a queue.
Member functions in queues in Oment++
- front() which returns pointer to the object at the front.
- insert(obj), it inserts an objects into the queue head.
- back(), returns pointer to the object at the back.
- pop(), returns and removes object from the front.
- insertAfter(obj-where, obj_what).
- remove(obj), it removes that object from the queue.
- insertBefore(obj_where, obj_what).
- length(), returns the number of items in the queue.
- empty(), tells whether there is anything in the queue.
Omnet++ Queue Length functions is mainly used due to number of items in the queue can be obtained.
Sample Omnet++ Queue Examples
This is the code for take and put operations in queue.
#include "Queue.h" #include "QueueMessage_m.h" #include <omnetpp.h> void Queue::initialize() { } void Queue::handleMessage(cMessage* msg) { QueueMessage* message = check_and_cast<QueueMessage*>(msg); if (message->getOperationType() == REQUEST_PUT) { queue.insert(message); } else if (message->getOperationType() == REQUEST_TAKE) { if (!queue.isEmpty()) { QueueMessage* reply = check_and_cast<QueueMessage*>(queue.pop()); send(reply, msg->getSenderGate()); } else { //Wait for queue to not be empty... Somehow... } } }