|
ActiveLib
|
#include <Publisher.h>


Classes | |
| class | SubscriberList |
Public Types | |
| using | Unique = std::unique_ptr<Publisher> |
| Unique pointer. | |
| using | Shared = std::shared_ptr<Publisher> |
| Shared pointer. | |
Public Types inherited from active::utility::NameID | |
| using | Option = std::optional<NameID> |
| Optional. | |
Public Member Functions | |
| Publisher (const utility::NameID &identity=utility::NameID{}) | |
| Publisher (const Publisher &source) | |
| virtual | ~Publisher () |
| Publisher & | operator= (const Publisher &source) |
| bool | publish (const Event &event) |
| bool | add (std::shared_ptr< Subscriber > subscriber) |
| bool | addWeak (std::shared_ptr< Subscriber > subscriber) |
| template<class T , class... Args> | |
| std::shared_ptr< T > | add (Args &&... args) |
| bool | remove (const Subscriber &subscriber) |
| bool | remove (const utility::Guid &id) |
Public Member Functions inherited from active::event::Participant | |
| Participant (const utility::NameID &identity=utility::NameID{}) | |
| virtual | ~Participant ()=default |
| bool | operator== (const Participant &ref) const |
| bool | operator!= (const Participant &ref) const |
Public Member Functions inherited from active::utility::NameID | |
| NameID () | |
| NameID (const String &str, const Guid &guid=Guid{}) | |
| NameID (const char *str, const Guid &guid=Guid{}) | |
| NameID (const Guid &guid, const String &str=String{}) | |
| bool | operator== (const NameID &ref) const |
| bool | operator!= (const NameID &ref) const |
| bool | operator< (const NameID &ref) const |
| operator bool () const | |
| void | clear () |
Protected Member Functions | |
| virtual bool | audit () override |
| virtual bool | attach () override |
| virtual bool | start () override |
| virtual void | stop () override |
Additional Inherited Members | |
Public Attributes inherited from active::utility::NameID | |
| String | name |
| Guid | id |
A class representing an event publisher
Publishers issue Events to Subscribers (as requested). A Publisher typically represents some source of events, e.g. an App UI, a network connection, or even a single control in a UI view, and will publish events relevant to its operation. For example, an App might issue an Event to signal that it is about to shut down, giving Subscribers an opportunity to release resources etc.
| Publisher::Publisher | ( | const utility::NameID & | identity = utility::NameID{} | ) |
Default constructor
| identity | Optional name/ID for the subscriber |
| Publisher::Publisher | ( | const Publisher & | source | ) |
Copy constructor
| source | The object to copy |
|
virtual |
Destructor
|
inline |
Construct and add a new subscriber
| args | The constructor arguments |

| bool Publisher::add | ( | std::shared_ptr< Subscriber > | subscriber | ) |
Add a managed subscriber, i.e. the subscription continues until the publisher is explicitly instructed to end it
| subscriber | The new subscriber |

| bool Publisher::addWeak | ( | std::shared_ptr< Subscriber > | subscriber | ) |
Add a casual subscriber, i.e. the subscription ends as soon as the subscriber disappears
| subscriber | The new subscriber |
|
overrideprotectedvirtual |
Attach participant components to the app (as required)
Reimplemented from active::event::Participant.
|
overrideprotectedvirtual |
Audit the participant environment to ensure it can function
Reimplemented from active::event::Participant.
Assignment operator
| source | The object to copy |
| bool Publisher::publish | ( | const Event & | event | ) |
Publish an event to subscribers
| event | The event to publish (NB: this event can carry data and optionally a postbox to receive subscriber messages |
| bool Publisher::remove | ( | const Subscriber & | subscriber | ) |
Remove a subscriber (by memory address)
| subscriber | A reference to the subscriber to remove |
| bool Publisher::remove | ( | const utility::Guid & | id | ) |
Remove a subscriber by ID
| id | The ID of the subscriber to remove |
|
overrideprotectedvirtual |
Initialise the participant operation
Reimplemented from active::event::Participant.
|
overrideprotectedvirtual |
Shut down event handling
Reimplemented from active::event::Participant.