MT Core (C++)
Core library for replacing C++ standard in project usage
|
Represents a pub/sub publisher which can publish messages of type T Supports blocking and non-blocking publishing. More...
#include <pub_sub.hpp>
Public Types | |
using | Message = T |
Public Member Functions | |
Result< void, AllocationError > | init (Allocator &alloc, size_t queueSize=10) |
Initializes a publisher. | |
void | close () |
Closes a pub/sub channel All subscribers will sbe notified of closure. | |
void | deinit (Allocator &alloc) |
Closes a pub/sub channel and dereferences broker Broker will be cleaned up once all subscribers are cleaned up Note: all threads that are publishing should be joined prior to calling this method. | |
Result< Subscription< T >, AllocationError > | subscribe () |
Creates a new Subscription to pub/sub channel. | |
Result< void, ChannelSendBlockErrors > | send_block (const T &message) |
Sends a message to all subscribers Will block if needed to ensure all subscribers get Queue Guarantees a message is delivered to all or blocks indefinitely. | |
Result< void, PubSubSendBlockGrowErrors > | send_block (Allocator &alloc, const T &message) |
Sends a message to all subscribers Will try to increase subscriber Queue sizes if there is not enough room If a Queue cannot be increased, then the message will be dropped for that subscriber. | |
template<typename Clock, typename Duration> | |
Result< void, ChannelSendBeforeErrors > | send_before (const T &message, const std::chrono::time_point< Clock, Duration > &timePoint) |
Sends a message to all subscribers Will block if needed to ensure all subscribers get Queue Guarantees a message is delivered to all or blocks It will timeout it the current time exceeds the provided time point. | |
template<typename Clock, typename Duration> | |
Result< void, PubSubSendBeforeGrowsError > | send_before (Allocator &alloc, const T &message, const std::chrono::time_point< Clock, Duration > &timePoint) |
Sends a message to all subscribers Will try to increase subscriber Queue sizes if there is not enough room If a Queue cannot be increased, then the message will be dropped for that subscriber Will timeout if cannot send in time. | |
Result< void, PubSubTrySendGrowsError > | try_send (const T &message) |
Sends a message to all subscribers Will not block. | |
Result< void, PubSubTrySendGrowsError > | try_send (Allocator &alloc, const T &message) |
Sends a message to all subscribers Will not block. | |
Public Attributes | |
Arc< impl::Broker< T > > | broker |
Represents a pub/sub publisher which can publish messages of type T Supports blocking and non-blocking publishing.
Locks:
Condition Variables:
Non-Blocking Availability:
T | Message Type |
Definition at line 253 of file pub_sub.hpp.
using mtcore::thread::Publisher< T >::Message = T |
Definition at line 254 of file pub_sub.hpp.
|
inline |
Closes a pub/sub channel All subscribers will sbe notified of closure.
Definition at line 280 of file pub_sub.hpp.
|
inline |
Closes a pub/sub channel and dereferences broker Broker will be cleaned up once all subscribers are cleaned up Note: all threads that are publishing should be joined prior to calling this method.
Definition at line 295 of file pub_sub.hpp.
|
inline |
Initializes a publisher.
alloc | Allocates a publisher |
queueSize | Initial Queue size |
Definition at line 264 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will try to increase subscriber Queue sizes if there is not enough room If a Queue cannot be increased, then the message will be dropped for that subscriber Will timeout if cannot send in time.
Clock | Clock to get time from |
Duration | Duration of time point |
alloc | Allocator for increasing Queue size |
message | Message to send |
timePoint | When to time out |
Definition at line 484 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will block if needed to ensure all subscribers get Queue Guarantees a message is delivered to all or blocks It will timeout it the current time exceeds the provided time point.
Clock | Clock to get time from |
Duration | Duration of time point |
message | Message to send |
timePoint | When to time out |
Definition at line 430 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will try to increase subscriber Queue sizes if there is not enough room If a Queue cannot be increased, then the message will be dropped for that subscriber.
Definition at line 382 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will block if needed to ensure all subscribers get Queue Guarantees a message is delivered to all or blocks indefinitely.
message | Message to send |
Definition at line 337 of file pub_sub.hpp.
|
inline |
Creates a new Subscription to pub/sub channel.
Definition at line 307 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will not block.
If blocking is required, will simply fail If there is not enough room, will try to grow a subscriber's Queue If growing fails, will not send to that subscriber
Definition at line 574 of file pub_sub.hpp.
|
inline |
Sends a message to all subscribers Will not block.
If blocking is required, will simply fail Guarantees a message is delivered to all or not at all
message | Message to send |
Definition at line 533 of file pub_sub.hpp.
Arc<impl::Broker<T> > mtcore::thread::Publisher< T >::broker |
Definition at line 256 of file pub_sub.hpp.