Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

ball::BroadcastObserver Class Reference

#include <ball_broadcastobserver.h>

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

List of all members.

Public Types

typedef bsl::unordered_map
< bsl::string, bsl::shared_ptr
< Observer > > 
ObserverRegistry

Public Member Functions

 BroadcastObserver (bslma::Allocator *basicAllocator=0)
virtual ~BroadcastObserver ()
void deregisterAllObservers ()
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)
virtual void publish (const bsl::shared_ptr< const Record > &record, const Context &context)
int registerObserver (const bsl::shared_ptr< Observer > &observer, const bsl::string_view &observerName)
virtual void releaseRecords ()
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)

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 Component ball_broadcastobserver


Member Typedef Documentation


Constructor & Destructor Documentation

ball::BroadcastObserver::BroadcastObserver ( bslma::Allocator basicAllocator = 0  )  [explicit]

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.

virtual ball::BroadcastObserver::~BroadcastObserver (  )  [virtual]

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

void ball::BroadcastObserver::deregisterAllObservers (  ) 

Remove all observers from the registry of this broadcast observer.

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.

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.

Referenced by findObserver().

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]
virtual 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.

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 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.

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

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);
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.

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.

References bslstl::SharedPtrUtil::dynamicCast(), and findObserver().

int ball::BroadcastObserver::numRegisteredObservers (  )  const

Return the number of observers registered with this broadcast observer.

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

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);
virtual void ball::Observer::publish ( const Record record,
const Context context 
) [virtual, inherited]

Process the specified log record having the specified publishing context.

DEPRECATED: Use the alternative publish overload instead.

Reimplemented in ball::FileObserver, ball::FileObserver2, ball::MultiplexObserver, ball::ObserverAdapter, and ball::TestObserver.


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