API Documentation

Shared Memory

The Shared Memory API provides an interface to read and write data to and from a shared memory queue.

In Linux, this is an implementation similar to POSIX message queues.

For an image-data specific queue, see the SharedMemoryImageData subclass.

Usage #include <PolySyncSharedMemory.hpp>

SharedMemory

The Shared Memory class is a base class interface to read and write data with a shared memory queue.

SharedMemoryImageData is an example of a subclass with a specific data format.

SharedMemory::SharedMemory ( … )

This constructor will take a shared memory key, which is then used to attach and access the data queue.

Parameters
in/out type name description
in int key The shared memory key used to represent and access the data queue.

SharedMemory::~SharedMemory ( )

This destructor will release the resources used.

In order to override this routine, users will need to manually release resources.

virtual SharedMemory::attach ( )

This is used to attach to an existing shared memory queue.

Typically, when a Dynamic Driver interface is running, it takes care of creating and publishing data to the queue. The Dynamic Driver interface key is defined in the System Design File.

Once an application is attached to the queue, then SharedMemory::pop and SharedMemory::tryPop are called to access the queued data for reading.

virtual SharedMemory::create ( … )

This will create and attach a shared memory queue using the key argument passed in to the constructor.

This should only be called if the application is writing data to shared memory.

Parameters
in/out type name description
in ulong maxQueueSize The maximum length of the shared memory queue.

Exceptions

  • DTCException - If it is not successful

virtual SharedMemory::destroy ( )

This will destroy a queue, and should only be called by the application that created the queue with SharedMemory::create.

Exceptions

  • DTCException - If it is not successful

virtual std::vector< uchar > getData ( )

This will return data from the internal _sharedMemoryBuffer.

The raw data is stored at a variable location depending on the SharedData message type.

Returns
  • std::vector< uchar > - Vector containing the binary data from the queue

SharedMemory::getMessageType ( )

This will get the reference to the message type of the data stored in the _sharedMemoryBuffer.

Returns
  • ps_msg_type - Message type reference for the data stored in the internal queue

virtual SharedMemory::pop ( )

This will populate the _sharedMemoryBuffer with data from the shared memory queue.

This function will block until data is available.

virtual SharedMemory::push ( )

This will add data to the shared memory queue.

This must call SharedMemory::setData and SharedMemory::setMessageType prior to pushing data to the queue.

virtual SharedMemory::setBufferSize ( … )

This will set the queue’s buffer size for pushing and popping routines.

Parameters
in/out type name description
in ulong size The size of the queue to push/pop to.

virtual SharedMemory::setData ( … )

This will set the data in the shared memory _sharedMemoryBuffer, directly after the message header.

Note that if a subclass is being used, do not forget to call SharedMemory::setBufferSize prior to populating the buffer.

Parameters
in/out type name description
in std::vector< uchar > & data The data that will be written to the queue.

virtual SharedMemory::setMessageType ( … )

This will set the message type contained by this shared memory buffer.

It must be called prior to writing to a shared space, allowing readers of the queue to properly parse data.

Parameters
in/out type name description
in ps_msg_type messageType The message type for the data that will live in the shared memory queue.

virtual SharedMemory::tryPop ( )

This will attempt to populate the _sharedMemoryBuffer with data from the shared memory queue.

This is a non-blocking routine.

The queue must be properly sized prior to popping data.

Returns
  • Bool - Returns false if data is not available, and true if the pop was successful

Exceptions

  • DTCException - If it is not successful