BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball::BroadcastObserver Class Reference

#include <ball_broadcastobserver.h>

Inheritance diagram for ball::BroadcastObserver:
ball::Observer

Public Types

typedef bsl::unordered_map< bsl::string, bsl::shared_ptr< Observer >, bdlb::TransparentHash, bdlb::TransparentEqualToObserverRegistry
 

Public Member Functions

 BroadcastObserver (bslma::Allocator *basicAllocator=0)
 
 ~BroadcastObserver () BSLS_KEYWORD_OVERRIDE
 
void deregisterAllObservers ()
 Remove all observers from the registry of this broadcast observer.
 
int deregisterObserver (const bsl::string_view &observerName)
 
bsl::shared_ptr< ObserverfindObserver (const bsl::string_view &observerName)
 
template<class t_OBSERVER >
int findObserver (bsl::shared_ptr< t_OBSERVER > *result, const bsl::string_view &observerName, typename bsl::enable_if< bsl::is_convertible< t_OBSERVER *, ball::Observer * >::value, void * >::type=0)
 
void publish (const bsl::shared_ptr< const Record > &record, const Context &context) BSLS_KEYWORD_OVERRIDE
 
int registerObserver (const bsl::shared_ptr< Observer > &observer, const bsl::string_view &observerName)
 
void releaseRecords () BSLS_KEYWORD_OVERRIDE
 
template<class t_VISITOR >
void visitObservers (t_VISITOR &visitor)
 
bsl::shared_ptr< const ObserverfindObserver (const bsl::string_view &observerName) const
 
template<class t_OBSERVER >
int findObserver (bsl::shared_ptr< const t_OBSERVER > *result, const bsl::string_view &observerName, typename bsl::enable_if< bsl::is_convertible< const t_OBSERVER *, const ball::Observer * >::value, void * >::type=0) const
 
int numRegisteredObservers () const
 
template<class t_VISITOR >
void visitObservers (const t_VISITOR &visitor) const
 
virtual void publish (const Record &record, const Context &context)
 
virtual void publish (const bsl::shared_ptr< const Record > &record, const Context &context)
 
- Public Member Functions inherited from ball::Observer
virtual ~Observer ()
 Destroy this observer.
 

Detailed Description

This class provides a broadcasting implementation of the Observer protocol. Other concrete observers may be registered and named with this broadcast observer (registerObserver method), retrieved (findObserver method), and unregistered (deregisterObserver method). The publish method of this class forwards the log records that it receives to the publish method of each registered observer.

See ball_broadcastobserver

Member Typedef Documentation

◆ ObserverRegistry

This typedef is an alias for the type of the registry maintained by this observer.

Constructor & Destructor Documentation

◆ BroadcastObserver()

ball::BroadcastObserver::BroadcastObserver ( bslma::Allocator basicAllocator = 0)
inlineexplicit

Create a broadcast observer having no registered observers. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~BroadcastObserver()

ball::BroadcastObserver::~BroadcastObserver ( )

Destroy this broadcast observer. Note that this method has no effect on the lifetime of observers registered with this observer, if any.

Member Function Documentation

◆ deregisterAllObservers()

void ball::BroadcastObserver::deregisterAllObservers ( )

◆ deregisterObserver()

int ball::BroadcastObserver::deregisterObserver ( const bsl::string_view observerName)

Remove the observer having the specified observerName from the registry of this broadcast observer. Return 0 if the observer having observerName was successfully deregistered, and a non-zero value (with no effect) otherwise. Henceforth, the observer that had observerName will no longer receive log records from this observer.

◆ findObserver() [1/4]

template<class t_OBSERVER >
int ball::BroadcastObserver::findObserver ( bsl::shared_ptr< const t_OBSERVER > *  result,
const bsl::string_view observerName,
typename bsl::enable_if< bsl::is_convertible< const t_OBSERVER *, const ball::Observer * >::value, void * >::type  = 0 
) const
inline

Load into the specified result a shared pointer to the observer of (template parameter) t_OBSERVER type having the specified observerName in the registry of this broadcast observer, and an empty shared pointer if there is no such observer otherwise. Return 0 if a non-empty shared pointer was loaded, and a non-zero value otherwise. Note that an empty shared pointer will be loaded if either no observer having observerName is in the registry or the observer registered with that name is not of t_OBSERVER type.

The implementation is placed here in the class definition to work around a Microsoft C++ compiler (version 16) bug where the definition cannot be matched to the declaration when an enable_if is used.

◆ findObserver() [2/4]

template<class t_OBSERVER >
int ball::BroadcastObserver::findObserver ( bsl::shared_ptr< t_OBSERVER > *  result,
const bsl::string_view observerName,
typename bsl::enable_if< bsl::is_convertible< t_OBSERVER *, ball::Observer * >::value, void * >::type  = 0 
)
inline

Load into the specified result a shared pointer to the observer of (template parameter) t_OBSERVER type having the specified observerName in the registry of this broadcast observer, and an empty shared pointer if there is no such observer otherwise. Return 0 if a non-empty shared pointer was loaded, and a non-zero value otherwise. Note that an empty shared pointer will be loaded if either no observer having observerName is in the registry or the observer registered with that name is not of t_OBSERVER type.

The implementation is placed here in the class definition to work around a Microsoft C++ compiler (version 16) bug where the definition cannot be matched to the declaration when an enable_if is used.

◆ findObserver() [3/4]

bsl::shared_ptr< Observer > ball::BroadcastObserver::findObserver ( const bsl::string_view observerName)

Return a shared pointer to the observer having the specified observerName in the registry of this broadcast observer, and an empty shared pointer if there is no such observer otherwise.

◆ findObserver() [4/4]

bsl::shared_ptr< const Observer > ball::BroadcastObserver::findObserver ( const bsl::string_view observerName) const

Return a shared pointer to the observer having the specified observerName in the registry of this broadcast observer, and an empty shared pointer if there is no such observer otherwise.

◆ numRegisteredObservers()

int ball::BroadcastObserver::numRegisteredObservers ( ) const
inline

Return the number of observers registered with this broadcast observer.

◆ publish() [1/3]

virtual void ball::Observer::publish ( const bsl::shared_ptr< const Record > &  record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context. The exact definition of publish depends on the implementing class, though the intention is that the log record (whose publication has occurred according to context) be distributed in a human or machine readable form.

Reimplemented from ball::Observer.

◆ publish() [2/3]

void ball::BroadcastObserver::publish ( const bsl::shared_ptr< const Record > &  record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context by forwarding record and context to each of the observers registered with this broadcast observer.

Reimplemented from ball::Observer.

◆ publish() [3/3]

virtual void ball::Observer::publish ( const Record record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context.

Deprecated:
Use the alternative publish overload instead.

Reimplemented from ball::Observer.

◆ registerObserver()

int ball::BroadcastObserver::registerObserver ( const bsl::shared_ptr< Observer > &  observer,
const bsl::string_view observerName 
)

Add the specified observer with the specified observerName to the registry of this broadcast observer. Return 0 if observer was successfully registered, and a non-zero value (with no effect) otherwise. Henceforth, this observer will forward each record it receives through its publish method, including the record's context, to the publish method of observer, until observer is deregistered. The behavior is undefined if a cyclic reference is created among registered observers. Note that this method will fail if an observer having observerName is already registered.

◆ releaseRecords()

void ball::BroadcastObserver::releaseRecords ( )
virtual

Discard any shared reference to a Record object that was supplied to the publish method, and is held by this observer. This implementation processes releaseRecords by calling releaseRecords on each of the registered observers. Note that this operation should be called if resources underlying the previously provided shared pointers must be released.

Reimplemented from ball::Observer.

◆ visitObservers() [1/2]

template<class t_VISITOR >
void ball::BroadcastObserver::visitObservers ( const t_VISITOR &  visitor) const
inline

Invoke the specified visitor functor of (template parameter) t_VISITOR type on each element in the registry of this broadcast observer, supplying that functor modifiable access to each observer. visitor must be a functor that can be called as if it had the following signature:

void operator()(const bsl::shared_ptr<Observer>& observer,
const bsl::string_view& observerName);
Definition bslstl_stringview.h:441
Definition bslstl_sharedptr.h:1830

◆ visitObservers() [2/2]

template<class t_VISITOR >
void ball::BroadcastObserver::visitObservers ( t_VISITOR &  visitor)
inline

Invoke the specified visitor functor of (template parameter) t_VISITOR type on each element in the registry of this broadcast observer, supplying that functor modifiable access to each observer. visitor must be a functor that can be called as if it had the following signature:

void operator()(const bsl::shared_ptr<Observer>& observer,
const bsl::string_view& observerName);

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