join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicConsumer< Policy > Class Template Reference

shared memory consumer. More...

#include <shared.hpp>

Inheritance diagram for join::BasicConsumer< Policy >:
Collaboration diagram for join::BasicConsumer< Policy >:

Public Member Functions

 BasicConsumer (const std::string &name, uint64_t elementSize=1472, uint64_t capacity=144)
 create instance.
 
 BasicConsumer (const BasicConsumer &other)=delete
 copy constructor.
 
BasicConsumeroperator= (const BasicConsumer &other)=delete
 copy assignment operator.
 
 ~BasicConsumer ()=default
 destroy the instance.
 
int tryPop (void *element) noexcept
 try to pop element from the ring buffer.
 
int pop (void *element) noexcept
 pop element from the ring buffer.
 
template<class Rep , class Period >
int timedPop (void *element, std::chrono::duration< Rep, Period > timeout) noexcept
 try to pop element from the ring buffer until timeout expire.
 
uint64_t pending () const noexcept
 get the number of pending elements for reading.
 
bool empty () const noexcept
 check if the ring buffer is empty.
 
- Public Member Functions inherited from join::BasicQueue< Policy >
 BasicQueue (const std::string &name, uint64_t elementSize=1472, uint64_t capacity=144)
 create instance.
 
 BasicQueue (const BasicQueue &other)=delete
 copy constructor.
 
BasicQueueoperator= (const BasicQueue &other)=delete
 copy assignment operator.
 
virtual ~BasicQueue ()
 destroy the instance.
 
int open () override
 open or create the shared memory segment.
 
void close () noexcept override
 close the shared memory segment.
 
const void * get (uint64_t offset=0) const override
 get a const pointer to the shared memory data region at a given offset.
 
void * get (uint64_t offset=0) override
 get a pointer to the shared memory data region at a given offset.
 
uint64_t elementSize () const noexcept
 get the element size of the shared memory region.
 
uint64_t capacity () const noexcept
 get the capacity of the shared memory region.
 
uint64_t size () const noexcept override
 get the size of the shared memory region.
 
- Public Member Functions inherited from join::SharedMemory
 SharedMemory (const std::string &name, uint64_t size)
 create instance.
 
virtual ~SharedMemory ()
 destroy the instance.
 
bool opened () const noexcept
 check if shared memory is opened.
 

Additional Inherited Members

- Static Public Member Functions inherited from join::SharedMemory
static int unlink (const std::string &name) noexcept
 destroy synchronization primitives and unlink the shared memory segment.
 
- Protected Attributes inherited from join::BasicQueue< Policy >
Policy _policy
 shared memory segment policy.
 
uint64_t _elementSize = 0
 shared memory segment element size.
 
uint64_t _capacity = 0
 shared memory segment capacity.
 
uint64_t _totalSize = 0
 total shared memory size.
 
uint64_t _userSize = 0
 user shared memory size.
 
SharedSegment_segment = nullptr
 shared memory segment.
 
- Protected Attributes inherited from join::SharedMemory
std::string _name
 shared memory name.
 
uint64_t _size = 0
 shared memory size.
 
void * _ptr = nullptr
 pointer to mapped shared memory.
 
int _fd = -1
 shared memory file descriptor.
 

Detailed Description

template<typename Policy>
class join::BasicConsumer< Policy >

shared memory consumer.

Constructor & Destructor Documentation

◆ BasicConsumer() [1/2]

template<typename Policy >
join::BasicConsumer< Policy >::BasicConsumer ( const std::string & name,
uint64_t elementSize = 1472,
uint64_t capacity = 144 )
inline

create instance.

Parameters
nameshared memory segment name.
elementSizeshared memory segment element size.
capacityshared memory segment capacity.

◆ BasicConsumer() [2/2]

template<typename Policy >
join::BasicConsumer< Policy >::BasicConsumer ( const BasicConsumer< Policy > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ ~BasicConsumer()

template<typename Policy >
join::BasicConsumer< Policy >::~BasicConsumer ( )
default

destroy the instance.

Member Function Documentation

◆ empty()

template<typename Policy >
bool join::BasicConsumer< Policy >::empty ( ) const
inlinenoexcept

check if the ring buffer is empty.

Returns
true if empty, false otherwise.

◆ operator=()

template<typename Policy >
BasicConsumer & join::BasicConsumer< Policy >::operator= ( const BasicConsumer< Policy > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ pending()

template<typename Policy >
uint64_t join::BasicConsumer< Policy >::pending ( ) const
inlinenoexcept

get the number of pending elements for reading.

Returns
number of elements pending in the ring buffer.

◆ pop()

template<typename Policy >
int join::BasicConsumer< Policy >::pop ( void * element)
inlinenoexcept

pop element from the ring buffer.

Parameters
elementpointer to output element.
Returns
0 on success, -1 otherwise.

◆ timedPop()

template<typename Policy >
template<class Rep , class Period >
int join::BasicConsumer< Policy >::timedPop ( void * element,
std::chrono::duration< Rep, Period > timeout )
inlinenoexcept

try to pop element from the ring buffer until timeout expire.

Parameters
elementpointer to output element.
timeouttimeout.
Returns
0 on success, -1 otherwise.

◆ tryPop()

template<typename Policy >
int join::BasicConsumer< Policy >::tryPop ( void * element)
inlinenoexcept

try to pop element from the ring buffer.

Parameters
elementpointer to output element.
Returns
0 on success, -1 otherwise.

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