OSVR-Core
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
osvr::common::IPCRingBuffer Class Reference

A ring buffer for interprocess communication, with managed occupancy. More...

#include <IPCRingBuffer.h>

Inheritance diagram for osvr::common::IPCRingBuffer:

Classes

class  BufferReadProxy
 A class providing access to an entry in the ring buffer, holding a sharable mutex lock preventing it from being overwritten while this object is in scope. More...
 
class  BufferWriteProxy
 A class providing write access to the next available element in the ring buffer, owning the appropriate mutex locks and providing access to the sequence number. More...
 
class  Impl
 
class  Options
 

Public Types

typedef uint8_t BackendType
 
typedef uint16_t alignment_type
 
typedef uint16_t entry_count_type
 
typedef uint32_t entry_size_type
 
typedef uint32_t abi_level_type
 
typedef uint32_t sequence_type
 The sequence number is automatically incremented with each "put" into the buffer. More...
 
typedef uint8_t value_type
 
typedef value_type * pointer_type
 
typedef value_type const * pointer_to_const_type
 
typedef shared_ptr< value_type > smart_pointer_type
 

Public Member Functions

OSVR_COMMON_EXPORT BackendType getBackend () const
 Returns an integer identifying the IPC backend used.
 
OSVR_COMMON_EXPORT std::string const & getName () const
 Returns the name string used to create or find this ring buffer.
 
OSVR_COMMON_EXPORT uint32_t getEntrySize () const
 Returns the size of each individual buffer entry, in bytes.
 
OSVR_COMMON_EXPORT uint16_t getEntries () const
 Returns the total capacity, in number of buffer entries, of this ring buffer. More...
 
OSVR_COMMON_EXPORT sequence_type put (pointer_to_const_type data, size_t len)
 Puts the data in the next element in the buffer (using memcpy). More...
 
OSVR_COMMON_EXPORT BufferWriteProxy put ()
 Gets a proxy object for putting data in the next element in the buffer. More...
 
OSVR_COMMON_EXPORT BufferReadProxy get (sequence_type num)
 Gets access to an element in the buffer by sequence number: returns a proxy object that behaves mostly like a smart pointer. More...
 
OSVR_COMMON_EXPORT BufferReadProxy getLatest ()
 Gets access to the most recent element in the buffer: returns a proxy object that behaves mostly like a smart pointer, and that also contains the associated sequence number. More...
 
OSVR_COMMON_EXPORT ~IPCRingBuffer ()
 Destructor.
 

Static Public Member Functions

static OSVR_COMMON_EXPORT abi_level_type getABILevel ()
 Gets an integer representing a unique arrangement of the internal shared memory layout, such that if two processes try to communicate with different ABI levels, they will (likely) not succeed and thus should not try. More...
 
static OSVR_COMMON_EXPORT IPCRingBufferPtr create (Options const &opts)
 Named constructor, for use by server processes: creates a shared memory ring buffer given the options structure. More...
 
static OSVR_COMMON_EXPORT IPCRingBufferPtr find (Options const &opts)
 Named constructor, for use by client processes: accesses an IPC ring buffer using the options structure. More...
 

Detailed Description

A ring buffer for interprocess communication, with managed occupancy.

Each element in the ring buffer (that is, the contained buffers) is aligned to the given power of 2 alignment.

Designed to provide large-format data transfer in single-producer, roughly broadcast model, with an outside channel for communicating the segment name and signalling new data, and no guarantee that the data you were notified about won't be overwritten - just that if you're currently accessing data, we won't overwrite that.

Member Typedef Documentation

§ sequence_type

The sequence number is automatically incremented with each "put" into the buffer.

Note that, as an unsigned integer, it does have (and uses) well-defined overflow semantics.

Member Function Documentation

§ create()

IPCRingBufferPtr osvr::common::IPCRingBuffer::create ( Options const &  opts)
static

Named constructor, for use by server processes: creates a shared memory ring buffer given the options structure.

If the returned pointer is not valid, the named segment could not be created for some reason.

§ find()

IPCRingBufferPtr osvr::common::IPCRingBuffer::find ( Options const &  opts)
static

Named constructor, for use by client processes: accesses an IPC ring buffer using the options structure.

Only the name field is used from the options.

If the returned pointer is not valid, the named buffer could not be found.

§ get()

IPCRingBuffer::BufferReadProxy osvr::common::IPCRingBuffer::get ( sequence_type  num)

Gets access to an element in the buffer by sequence number: returns a proxy object that behaves mostly like a smart pointer.

§ getABILevel()

IPCRingBuffer::abi_level_type osvr::common::IPCRingBuffer::getABILevel ( )
static

Gets an integer representing a unique arrangement of the internal shared memory layout, such that if two processes try to communicate with different ABI levels, they will (likely) not succeed and thus should not try.

§ getEntries()

uint16_t osvr::common::IPCRingBuffer::getEntries ( ) const

Returns the total capacity, in number of buffer entries, of this ring buffer.

§ getLatest()

IPCRingBuffer::BufferReadProxy osvr::common::IPCRingBuffer::getLatest ( )

Gets access to the most recent element in the buffer: returns a proxy object that behaves mostly like a smart pointer, and that also contains the associated sequence number.

§ put() [1/2]

IPCRingBuffer::sequence_type osvr::common::IPCRingBuffer::put ( pointer_to_const_type  data,
size_t  len 
)

Puts the data in the next element in the buffer (using memcpy).

Buffer sizes are not checked!

This is a convenience wrapper around the other put() signature.

§ put() [2/2]

IPCRingBuffer::BufferWriteProxy osvr::common::IPCRingBuffer::put ( )

Gets a proxy object for putting data in the next element in the buffer.

You're responsible for doing the copying and, once you let the returned object exit scope, the notification (possibly with sequence number)


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