CustusX  2021.04.21-dev+develop.337f9
An IGT application
cx::SharedMemoryServer Class Reference

Shared Memory Server. More...

#include <cxSharedMemory.h>

Public Member Functions

 SharedMemoryServer (QString key, int buffers, int sizeEach, QObject *parent=0)
 
 ~SharedMemoryServer ()
 
int size ()
 
int buffers ()
 
QString key ()
 
void * buffer ()
 Grab and lock a write buffer. More...
 
void release ()
 Release our write buffer. Buffer will not be used before it is released. More...
 
QDateTime lastTimestamp ()
 
bool hasBuffer ()
 

Detailed Description

Shared Memory Server.

Implements a circular buffer in shared memory using a client-server model, where you have one writer and potentially multiple readers. Note that if you have more readers than buffers, you can end up with all buffers busy when you want to write new data. Readers always grab the latest buffer. Things go more smooth when all users release their buffers as soon as they are done.Implements a circular buffer in shared memory using a client-server model, where you have one writer and potentially multiple readers. Note that if you have more readers than buffers, you can end up with all buffers busy when you want to write new data. Readers always grab the latest buffer. Things go more smooth when all users release their buffers as soon as they are done.

See also
SharedMemoryClient

Definition at line 40 of file cxSharedMemory.h.

Constructor & Destructor Documentation

cx::SharedMemoryServer::SharedMemoryServer ( QString  key,
int  buffers,
int  sizeEach,
QObject *  parent = 0 
)

Constructor.

Parameters
keyA string identifying this resource. Must be unique system wide
buffersThe number of buffers to allocate. This should be set to the maximum number of concurrent readers to this resource + 2, allowing one buffer for the writer (this class), one for each reader and a spare so there is always a buffer for the writer to switch to.
sizeEachThe size of each buffer.
parentThe Qt parent object

Definition at line 28 of file cxSharedMemory.cpp.

cx::SharedMemoryServer::~SharedMemoryServer ( )

Definition at line 60 of file cxSharedMemory.cpp.

Member Function Documentation

void * cx::SharedMemoryServer::buffer ( )

Grab and lock a write buffer.

Definition at line 65 of file cxSharedMemory.cpp.

int cx::SharedMemoryServer::buffers ( )
inline

Definition at line 62 of file cxSharedMemory.h.

bool cx::SharedMemoryServer::hasBuffer ( )
inline

Return true if a write buffer is currently held, false otherwise

Definition at line 73 of file cxSharedMemory.h.

QString cx::SharedMemoryServer::key ( )
inline

Definition at line 63 of file cxSharedMemory.h.

QDateTime cx::SharedMemoryServer::lastTimestamp ( )
inline

Return the timestamp of the last buffer written to

Definition at line 69 of file cxSharedMemory.h.

void cx::SharedMemoryServer::release ( )

Release our write buffer. Buffer will not be used before it is released.

Definition at line 123 of file cxSharedMemory.cpp.

int cx::SharedMemoryServer::size ( )
inline

Definition at line 61 of file cxSharedMemory.h.


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