25 #ifndef INCLUDED_IPCRingBuffer_h_GUID_4F33BDA7_1BEB_4E81_B96C_1ADA1CBD1997
26 #define INCLUDED_IPCRingBuffer_h_GUID_4F33BDA7_1BEB_4E81_B96C_1ADA1CBD1997
44 typedef shared_ptr<IPCPutResult> IPCPutResultPtr;
46 typedef shared_ptr<IPCGetResult> IPCGetResultPtr;
67 typedef uint8_t BackendType;
68 typedef uint16_t alignment_type;
69 typedef uint16_t entry_count_type;
70 typedef uint32_t entry_size_type;
71 typedef uint32_t abi_level_type;
75 OSVR_COMMON_EXPORT Options(std::string
const &name);
77 OSVR_COMMON_EXPORT Options(std::string
const &name,
80 BackendType getBackend()
const {
return m_shmBackend; }
84 Options &
setName(std::string
const &name);
85 std::string
const &getName()
const {
return m_name; }
91 alignment_type getAlignment()
const {
return m_alignment; }
96 entry_count_type getEntries()
const {
return m_entries; }
101 entry_size_type getEntrySize()
const {
return m_entrySize; }
105 BackendType m_shmBackend;
106 alignment_type m_alignment = 16;
107 entry_count_type m_entries = 16;
108 entry_size_type m_entrySize = 65536;
115 OSVR_COMMON_EXPORT
static abi_level_type
getABILevel();
133 OSVR_COMMON_EXPORT BackendType
getBackend()
const;
137 OSVR_COMMON_EXPORT std::string
const &
getName()
const;
144 OSVR_COMMON_EXPORT uint16_t
getEntries()
const;
151 typedef uint8_t value_type;
152 typedef value_type *pointer_type;
153 typedef value_type
const *pointer_to_const_type;
155 typedef shared_ptr<value_type> smart_pointer_type;
170 std::swap(m_data, other.m_data);
175 std::swap(m_data, other.m_data);
179 operator pointer_type()
const {
return get(); }
181 pointer_type
get()
const {
return m_buf; }
183 sequence_type getSequenceNumber()
const {
return m_seq; }
187 IPCRingBufferPtr &&shm);
188 friend class IPCRingBuffer;
191 detail::IPCPutResultPtr m_data;
207 explicit operator bool()
const {
return nullptr != m_buf; }
210 pointer_to_const_type
get()
const {
return m_buf; }
219 pointer_to_const_type operator*()
const {
return m_buf; }
220 pointer_to_const_type operator->()
const {
return m_buf; }
223 BufferReadProxy(detail::IPCGetResultPtr &&data,
224 IPCRingBufferPtr &&shm);
225 friend class IPCRingBuffer;
228 detail::IPCGetResultPtr m_data;
235 OSVR_COMMON_EXPORT sequence_type
236 put(pointer_to_const_type data,
size_t len);
242 OSVR_COMMON_EXPORT BufferWriteProxy
put();
246 OSVR_COMMON_EXPORT BufferReadProxy
get(sequence_type num);
251 OSVR_COMMON_EXPORT BufferReadProxy
getLatest();
257 static IPCRingBufferPtr m_constructorHelper(
Options const &
opts,
260 IPCRingBuffer(unique_ptr<Impl> &&impl);
261 unique_ptr<Impl> m_impl;
267 #endif // INCLUDED_IPCRingBuffer_h_GUID_4F33BDA7_1BEB_4E81_B96C_1ADA1CBD1997
Options & setAlignment(alignment_type alignment)
Sets the alignment for each entry, which must be a power of 2 (rounded up to the nearest if it's not)...
Header wrapping the C99 standard stdint header.
Options & setName(std::string const &name)
sets the name, after sanitizing the input string.
BufferReadProxy getLatest()
Gets access to the most recent element in the buffer: returns a proxy object that behaves mostly like...
Header to bring unique_ptr into the osvr namespace.
Header to bring shared_ptr into the osvr namespace.
shared_ptr< IPCRingBuffer > IPCRingBufferPtr
Pointer type for holding a shared memory ring buffer.
static IPCRingBufferPtr find(Options const &opts)
Named constructor, for use by client processes: accesses an IPC ring buffer using the options structu...
uint16_t getEntries() const
Returns the total capacity, in number of buffer entries, of this ring buffer.
~IPCRingBuffer()
Destructor.
sequence_type getSequenceNumber() const
Gets the sequence number associated with this entry.
static 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.
uint32_t sequence_type
The sequence number is automatically incremented with each "put" into the buffer. Note that...
BufferWriteProxy & operator=(BufferWriteProxy &&other)
move-assignable
A ring buffer for interprocess communication, with managed occupancy.
BufferWriteProxy(BufferWriteProxy &&other)
move-constructible
BackendType getBackend() const
Returns an integer identifying the IPC backend used.
BufferWriteProxy(BufferWriteProxy const &)=delete
not copyable
std::string const & getName() const
Returns the name string used to create or find this ring buffer.
Options & setEntries(entry_count_type entries)
Sets the number of entries in the ring buffer.
BufferWriteProxy & operator=(BufferWriteProxy const &)=delete
not copy-assignable
Options & setEntrySize(entry_size_type entrySize)
Sets the size of each entry in the ring buffer.
A class providing access to an entry in the ring buffer, holding a sharable mutex lock preventing it ...
Automatically-generated export header - do not edit!
smart_pointer_type getBufferSmartPointer() const
Gets a smart pointer to the buffer that shares ownership of the underlying resources of this object...
uint32_t getEntrySize() const
Returns the size of each individual buffer entry, in bytes.
BufferWriteProxy put()
Gets a proxy object for putting data in the next element in the buffer. You're responsible for doing ...
A class providing write access to the next available element in the ring buffer, owning the appropria...
static IPCRingBufferPtr create(Options const &opts)
Named constructor, for use by server processes: creates a shared memory ring buffer given the options...