ipcq 0.12.0
Loading...
Searching...
No Matches
ipcq::BasicWriter< T, ConditionPolicy, ShmTraits > Class Template Reference

Queue writer class. More...

#include <writer.hpp>

Public Member Functions

 BasicWriter (char const *topic_name, size_t capacity, std::optional< numapp::MemPolicy > const &mempolicy=std::nullopt)
 Creates a writer and allocates shared memory to have room for capacity Ts.
 
char const * TopicName () const noexcept
 Get queue topic name.
 
constexpr size_t Capacity () const noexcept
 Query queue capacity, which is the number of elements the queue can hold.
 
constexpr size_t Size () noexcept
 Query number of elements in the queue.
 
constexpr bool IsClosed () const noexcept
 Query whether queue is closed or not.
 
constexpr void Close () noexcept
 Close queue for further writing.
 
std::error_code Write (T const &data, Notify notify_readers) noexcept
 Append single element to queue, possibly overwriting the front element.
 
constexpr void Pop () noexcept
 Remove single element from queue.
 
std::error_code Write (const T *data, size_t count, Notify notify_readers) noexcept
 Write count elements to queue.
 

Static Public Member Functions

static std::error_code RemoveShmObject (char const *topic_name) noexcept
 Remove shared memory object from the system.
 

Detailed Description

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
class ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >

Queue writer class.

Template Parameters
TType of elements in queue.
ConditionPolicyis the policy to use to signal readers when new elements have been appended to queue. ipcq provides ipcq::BoostConditionPolicy and ipcq::SpinConditionPolicy.
ShmTraitsImplementation details. Leave default.

Basic Usage:

struct MyTopicType {
   ...
};

// Create writer for the topic "topicname" with type MyTopicType.
auto writer = ipcq::Writer<MyTopicType>("topicname", 100);

while (!shouldStop) {
    MyTopicType sample;
    // Prepare sample
    ...
    auto err = writer.Write(sample, ipcq::Notify::NotifyAll);
    if (err) {
        // Handle error
        break;
    }
}
// Signal to readers that the queue is now closed.
writer.Close();
See also
ipcq::BoostConditionPolicy ipcq::SpinConditionPolicy.

Definition at line 69 of file writer.hpp.

Constructor & Destructor Documentation

◆ BasicWriter()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::BasicWriter ( char const * topic_name,
size_t capacity,
std::optional< numapp::MemPolicy > const & mempolicy = std::nullopt )
inlineexplicit

Creates a writer and allocates shared memory to have room for capacity Ts.

Parameters
topic_nameName of the topic to create, together with the template parameter T this forms the full topic for the queue.
capacityThe queue capacity in number of elements.
mempolicyAn optional memory policy that is used for the shared memory allocation.

Definition at line 95 of file writer.hpp.

Member Function Documentation

◆ Capacity()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
size_t ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Capacity ( ) const
inlinenodiscardconstexprnoexcept

Query queue capacity, which is the number of elements the queue can hold.

Returns
queue capacity in number of elements.

Definition at line 115 of file writer.hpp.

◆ Close()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
void ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Close ( )
inlineconstexprnoexcept

Close queue for further writing.

Any waiting readers will be notified. Once existing data is read out subsequent reads will fail with ipcq::Error::Closed.

Postcondition
Shared memory remains valid but new reader instances will not attach.
Synchronization
Synchronizes with SHM using release semantics.
See also
IsClosed()

Definition at line 149 of file writer.hpp.

◆ IsClosed()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
bool ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::IsClosed ( ) const
inlinenodiscardconstexprnoexcept

Query whether queue is closed or not.

Returns
true if queue is closed, false otherwise.

Definition at line 133 of file writer.hpp.

◆ Pop()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
void ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Pop ( )
inlineconstexprnoexcept

Remove single element from queue.

Synchronization
Synchronizes with SHM using release semantics.
Precondition
Size() > 0
constexpr size_t Size() noexcept
Query number of elements in the queue.
Definition writer.hpp:124

Definition at line 177 of file writer.hpp.

◆ RemoveShmObject()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
static std::error_code ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::RemoveShmObject ( char const * topic_name)
inlinestaticnoexcept

Remove shared memory object from the system.

Note
Internally this unlinks the file.
Parameters
topic_nameTopic name, as provided to BasicWriter constructor.
Returns
0 on success and contents of errno on failure.

Definition at line 82 of file writer.hpp.

◆ Size()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
size_t ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Size ( )
inlinenodiscardconstexprnoexcept

Query number of elements in the queue.

Returns
queue size in number of elements.

Definition at line 124 of file writer.hpp.

◆ TopicName()

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
char const * ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::TopicName ( ) const
inlinenodiscardnoexcept

Get queue topic name.

Returns
topic name in queue.

Definition at line 106 of file writer.hpp.

◆ Write() [1/2]

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
std::error_code ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Write ( const T * data,
size_t count,
Notify notify_readers )
inlinenodiscardnoexcept

Write count elements to queue.

Precondition
count <= Capacity()
constexpr size_t Capacity() const noexcept
Query queue capacity, which is the number of elements the queue can hold.
Definition writer.hpp:115
Note
Function will make room as necessary to write count elements.
Synchronization
Synchronizes with SHM using release semantics.
Returns
Error::Closed if queue is closed.

Definition at line 195 of file writer.hpp.

◆ Write() [2/2]

template<class T, class ConditionPolicy, class ShmTraits = detail::BoostInterprocessTraits>
std::error_code ipcq::BasicWriter< T, ConditionPolicy, ShmTraits >::Write ( T const & data,
Notify notify_readers )
inlinenodiscardnoexcept

Append single element to queue, possibly overwriting the front element.

Synchronization
Synchronizes with SHM using release semantics.
Parameters
dataElement to copy into queue
notify_readersDetermines if readers will be notified (woken up if blocked) that new element is available.
Returns
error value is queue is closed.

Definition at line 165 of file writer.hpp.


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