|
ipcq 0.12.0
|
Queue BasicReader class. More...
#include <reader.hpp>
Public Member Functions | |
Accessors | |
| char const * | TopicName () const noexcept |
| Get queue topic name. | |
| constexpr bool | IsClosed () const noexcept |
| Query whether queue is closed or not. | |
| constexpr size_t | Capacity () const noexcept |
| Query queue capacity, which is the number of elements the queue can hold. | |
| constexpr size_t | Size () const noexcept |
| Query number of elements in the queue. | |
| constexpr size_t | NumAvailable () const noexcept |
| Query number of elements that is currently available for reading. | |
Read operations | |
| template<class Operation, class Rep, class Period> | |
| std::pair< std::error_code, size_t > | Read (Operation &&op, size_t count, std::chrono::duration< Rep, Period > timeout) noexcept(std::is_nothrow_invocable_v< Operation, T const & >) |
| Reads available data if any, or waits for notification from writer, and then reads available data from queue. | |
| template<class Rep, class Period> | |
| std::pair< std::error_code, size_t > | Skip (size_t count, std::chrono::duration< Rep, Period > timeout) noexcept |
Skip up to count elements from queue. | |
Modifiers | |
| constexpr void | Synchronize () noexcept |
| Synchronizes internal state from shared memory. | |
| std::error_code | Reset (std::size_t keep=0u) noexcept |
| Reset internal reader state to synchronize with writer and recover from ipcq::Error::InconsistentState. | |
Construction | |
| BasicReader (char const *topic_name) | |
| Create and connect reader to existing queue. | |
| template<class Rep, class Period> | |
| static BasicReader | MakeReader (char const *topic_name, std::chrono::duration< Rep, Period > timeout) |
| Factory function that retries to create a reader until success or timeout. | |
Queue BasicReader class.
| T | Type of elements in queue. |
| ConditionPolicy | Policy used to determine how readers are notified when queue has new elements appeneded to it. |
| ShmTraits | Implementation details. Leave default. |
Basic Usage:
struct MyTopicType {
...
};
// Create reader for the topic "topicname" with type MyTopicType.
// If the Writer is not yet created, this function will retry until it gives up
// after the given timeout.
auto reader = ipcq::Reader<MyTopicType>::MakeReader("topicname", 30s);
while (true) {
MyTopicType sample;
// Read sample or timeout after 2s
auto err = reader.Read(ipcq::OutputIteratorAdapter(&sample), 2s);
if (err) {
// Handle error
break;
}
// Process sample
...
}
Definition at line 73 of file reader.hpp.
|
inlineexplicit |
Create and connect reader to existing queue.
| topic_name | Name of topic to associate reader with. |
| boost::interprocess::interprocess_exception | if attaching to shared memory fails. |
| std::system_error | with ipcq::Error::TypeMismatch if T or ConditionPolicy does not match types in queue. ipcq::Error::Closed if queue is closed, not yet ready or writer process does not exist. |
Definition at line 181 of file reader.hpp.
|
inlinenodiscardconstexprnoexcept |
Query queue capacity, which is the number of elements the queue can hold.
Definition at line 232 of file reader.hpp.
|
inlinenodiscardconstexprnoexcept |
Query whether queue is closed or not.
Definition at line 223 of file reader.hpp.
|
inlinestaticnodiscard |
Factory function that retries to create a reader until success or timeout.
Definition at line 190 of file reader.hpp.
|
inlinenodiscardconstexprnoexcept |
Query number of elements that is currently available for reading.
In other words it's the number of unread elements.
This can e.g. be used to calculate how near the reader is to be overwritten as the following approaches zero:
Definition at line 261 of file reader.hpp.
|
inlinenodiscardnoexcept |
Reads available data if any, or waits for notification from writer, and then reads available data from queue.
count elements.Reads a maximum of count elements from the queue synchronously by invoking the provided Operation op once with each element. The reader advances the next element to read automatically.
If any data is already available then no waiting will occur. If no data is available then it will wait for writer notification and then read a maximum of count elements. If no notification occurs before specified timeout duration no reads will occur and ipcq::Error::Timeout is returned.
| op | Operation function used to operate on read element. Is invoked once for each element. Adapters to standard containers can be used as operation c.f. ipcq::OutputIteratorAdapter and ipcq::BackInserter. |
| count | Maximum number of elements to read from queue. |
| timeout | Maximum time to wait for any data, if no data is not already available to read. Value range and precision is guaranteed to 1 microsecond in range 1 microsecond to 256 hours. |
| Operation | callable with requirements: `std::is_invocable_v<Operation, T const&>, e.g. a callable with signature @cvoid Operation(T const& element). or @cvoid Operation(T const& element) noexcept`. |
| Exceptions | originating from op. Function provides strong exception guarantee for side-effects in the class itself but not in provided read-operation `op`. User may attempt to read the same elements again by issuing a new call to Read.. |
Definition at line 321 of file reader.hpp.
|
inlinenodiscardnoexcept |
Reset internal reader state to synchronize with writer and recover from ipcq::Error::InconsistentState.
To reset successfully the queue cannot be empty, as the reader must get state information from the queue to know what to expect next. In this case it returns ipcq::error::WouldBlock instead of waiting for data. Caller can then make the choice to assume the queue is in its initial state. If it was not the next read operation will fail with ipcq::Error::InconsistentState.
| keep | Number of samples to keep as unread. Default is to keep 0 which is to say the next element to read is the next written. keep is automatically truncated to number of available elements. |
keep is 0 (i.e. reading will not be possible after Reset()). Definition at line 388 of file reader.hpp.
|
inlinenodiscardconstexprnoexcept |
Query number of elements in the queue.
Definition at line 243 of file reader.hpp.
|
inlinenodiscardnoexcept |
Skip up to count elements from queue.
Read with a no-op op.Definition at line 338 of file reader.hpp.
|
inlineconstexprnoexcept |
Synchronizes internal state from shared memory.
This is mainly useful to explicitly synchronize state to update non-synchronizing methods like:
Definition at line 361 of file reader.hpp.
|
inlinenodiscardnoexcept |