PiImageStreamer
Loading...
Searching...
No Matches
SWE4211RPi::QueueManager Class Reference

Singleton that owns one CommandQueue per component and routes messages to them by internal queue ID. More...

#include <QueueManager.h>

Collaboration diagram for SWE4211RPi::QueueManager:

Public Member Functions

CommandQueue & getQueueInstance (int queueID)
 
void sendBroadcastMessage (CommandQueueEntry value)
 
bool sendMessage (int destination, CommandQueueEntry value)
 

Static Public Member Functions

static QueueManager & getSingleton ()
 

Static Protected Attributes

static QueueManager * singleton = nullptr
 

Private Member Functions

 QueueManager (int numberOfQueues)
 
virtual ~QueueManager ()
 

Private Attributes

int queueCount
 
CommandQueue ** queues
 
CommandQueue dummyQueue
 

Detailed Description

Singleton that owns one CommandQueue per component and routes messages to them by internal queue ID.

Constructor & Destructor Documentation

◆ QueueManager()

QueueManager::QueueManager ( int  numberOfQueues)
private

This will instantiate a new instance of the queue manager.

Parameters
numberOfQueuesThis is the number of queues that are to be managed by this manager.
Exceptions
std::invalid_argumentif the number of queues is negative.

This will instantiate a new instance of the queue manager.

Parameters
numberOfQueuesThis is the number of queues that are to be managed by this manager.
  1. Check to make sure the number of queues is not negative. If it is negative, throw an invalid_argument exception indicating that the value can not be negative.

    1. The number of queues is negative. Throw an invalid argument indicating this.

  2. Continue with the constructor. Set the queue count accordingly and set the queues to be an array of pointers to number of queue instances.

  3. Loop queuecount times, instantiating a new Command queue and placing a pointer to it in the array.

◆ ~QueueManager()

QueueManager::~QueueManager ( )
privatevirtual

This is the destructor which will clean up.

Delete all of the queues that were allocated in the constructor, and then the array that held them.

Member Function Documentation

◆ getQueueInstance()

CommandQueue & QueueManager::getQueueInstance ( int  queueID)

This method will obtain a reference to the desired queue. The queue ID is the numeric definition for the given component's queue (see QueueCfg.h).

Parameters
queueIDThis is the queue that is to be communicated with.
Returns
A reference to the given queue.
Exceptions
std::invalid_argumentif the queue ID is out of range.
  1. Check to see if the queue ID is out of the range of 0 to queueCount - 1.

    1. The queue id is out of range. Throw an invalid argument exception.

  2. Check to see that the queue ID is in the range of 0 to queueCount - 1. Because of the check above, this is always true.

    1. Return a reference to the appropriate queue from the array of queues.

  3. Return the dummyQueue if the code has not already returned. This is not reached, but keeps every path returning a value.

Here is the caller graph for this function:

◆ getSingleton()

QueueManager & QueueManager::getSingleton ( )
static

This method will return a reference to the singleton instance of this class.

Returns
A reference to the singleton will be returned.

This method will return a reference to the singleton instance of this class. If there is no instance already, an instance will be created and then returned. The method used is referred to as double-checked locking. See https://en.wikipedia.org/wiki/Double-checked_locking for details.

Returns
A reference to the singleton will be returned.
  1. Determine if the singleton is null.

    1. The singleton is null.
    2. Lock the mutex

    3. Determine if the singleton is still null.

      1. If the singleton is null, instantiate a new queue manager, with the NUMBER_OF_INTERNAL_QUEUES from QueueCfg.h as the parameter.

    4. Unlock the mutex.

  2. Return the reference.

Here is the caller graph for this function:

◆ sendBroadcastMessage()

void QueueManager::sendBroadcastMessage ( CommandQueueEntry  value)

This method will send a broadcast message. A broadcast message will be enqueued on all queues to be received by all components. Only broadcast, status report, and heartbeat message types are sent; any other type is ignored.

Parameters
valueThis is the value to be enqueued as a broadcast message to all queues.

This method will send a broadcast message. A broadcast message will be enqueued on all queues to be received by all components.

Parameters
valueThis is the value to be enqueued as a broadcast message to all queues. Note that it must have a broadcast, status report, or heartbeat command type; any other type is ignored.
  1. If the type is a broadcast, status, or heartbeat message

    1. Loop over all of the queues and enqueue the message

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage()

bool QueueManager::sendMessage ( int  destination,
CommandQueueEntry  value 
)

This method will send a message to the given destination. Broadcast messages are not accepted; use sendBroadcastMessage().

Parameters
destinationThis is the destination internal queue ID.
valueThis is the message to be enqueued.
Returns
The return will be true if the message is successfully enqueued or false otherwise.

This method will send a message to the given destination.

Parameters
destinationThis is the destination queue.
valueThis is the message to be enqueued.
Returns
The return will be true if the message is successfully enqueued or false otherwise.

If the destination is in range and the message is not a broadcast message, enqueue it to the appropriate queue.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dummyQueue

CommandQueue SWE4211RPi::QueueManager::dummyQueue
private

This is a dummy queue. getQueueInstance() now throws for an invalid queue ID, so this queue is not normally returned.

◆ queueCount

int SWE4211RPi::QueueManager::queueCount
private

This integer stores the number of queues that are being managed.

◆ queues

CommandQueue** SWE4211RPi::QueueManager::queues
private

This is the array of pointers to queues. It will be used to properly dispatch queues to the components.

◆ singleton

QueueManager * QueueManager::singleton = nullptr
staticprotected

This is the singleton instance for the queue manager.

This is the singleton instance, which is a nullptr if it has not yet been instantiated.


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