ActiveLib
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
active::event::Publisher Class Reference

#include <Publisher.h>

Inheritance diagram for active::event::Publisher:
Inheritance graph
[legend]
Collaboration diagram for active::event::Publisher:
Collaboration graph
[legend]

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 ()
 
Publisheroperator= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Publisher() [1/2]

Publisher::Publisher ( const utility::NameID & identity = utility::NameID{})

Default constructor

Parameters
identityOptional name/ID for the subscriber

◆ Publisher() [2/2]

Publisher::Publisher ( const Publisher & source)

Copy constructor

Parameters
sourceThe object to copy

◆ ~Publisher()

Publisher::~Publisher ( )
virtual

Destructor

Member Function Documentation

◆ add() [1/2]

template<class T , class... Args>
std::shared_ptr< T > active::event::Publisher::add ( Args &&... args)
inline

Construct and add a new subscriber

Parameters
argsThe constructor arguments
Returns
The new subscriber on success, nullptr on failure
Here is the call graph for this function:

◆ add() [2/2]

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

Parameters
subscriberThe new subscriber
Returns
True if subscriber was added
Here is the caller graph for this function:

◆ addWeak()

bool Publisher::addWeak ( std::shared_ptr< Subscriber > subscriber)

Add a casual subscriber, i.e. the subscription ends as soon as the subscriber disappears

Parameters
subscriberThe new subscriber
Returns
True if subscriber was added

◆ attach()

bool Publisher::attach ( )
overrideprotectedvirtual

Attach participant components to the app (as required)

Returns
True if the participant is able to function

Reimplemented from active::event::Participant.

◆ audit()

bool Publisher::audit ( )
overrideprotectedvirtual

Audit the participant environment to ensure it can function

Returns
True if the participant is able to function

Reimplemented from active::event::Participant.

◆ operator=()

Publisher & Publisher::operator= ( const Publisher & source)

Assignment operator

Parameters
sourceThe object to copy
Returns
A reference to this

◆ publish()

bool Publisher::publish ( const Event & event)

Publish an event to subscribers

Parameters
eventThe event to publish (NB: this event can carry data and optionally a postbox to receive subscriber messages
Returns
True if the event was closed by a subscriber

◆ remove() [1/2]

bool Publisher::remove ( const Subscriber & subscriber)

Remove a subscriber (by memory address)

Parameters
subscriberA reference to the subscriber to remove
Returns
True if subscriber was removed

◆ remove() [2/2]

bool Publisher::remove ( const utility::Guid & id)

Remove a subscriber by ID

Parameters
idThe ID of the subscriber to remove
Returns
True if subscriber was removed

◆ start()

bool Publisher::start ( )
overrideprotectedvirtual

Initialise the participant operation

Returns
True if the participant is able to continue

Reimplemented from active::event::Participant.

◆ stop()

void Publisher::stop ( )
overrideprotectedvirtual

Shut down event handling

Reimplemented from active::event::Participant.


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