BDE 4.14.0 Production release
|
#include <ball_broadcastobserver.h>
Public Types | |
typedef bsl::unordered_map< bsl::string, bsl::shared_ptr< Observer >, bdlb::TransparentHash, bdlb::TransparentEqualTo > | ObserverRegistry |
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< Observer > | findObserver (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 Observer > | findObserver (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. | |
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.
typedef bsl::unordered_map<bsl::string, bsl::shared_ptr<Observer>, bdlb::TransparentHash, bdlb::TransparentEqualTo> ball::BroadcastObserver::ObserverRegistry |
This typedef
is an alias for the type of the registry maintained by this observer.
|
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.
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.
void ball::BroadcastObserver::deregisterAllObservers | ( | ) |
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.
|
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.
|
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.
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.
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.
|
inline |
Return the number of observers registered with this broadcast observer.
|
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.
|
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.
Process the specified log record
having the specified publishing context
.
publish
overload instead. Reimplemented from ball::Observer.
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.
|
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.
|
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:
|
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: