CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Observable< ParamT > Class Template Reference

#include <util_concurrency.h>

Inheritance diagram for Observable< ParamT >:
Collaboration diagram for Observable< ParamT >:

Public Types

typedef Callbackable< ParamT >
::CallbackTN
CallbackPtr
 
- Public Types inherited from Callbackable< ParamT >
typedef CallbackBase< ParamT > CallbackTN
 

Public Member Functions

virtual ~Observable ()
 
template<class DelegateT , class ClosureDataT >
CallbackPtr RegisterListener (typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, ClosureDataT data)
 
template<class DelegateT >
CallbackPtr RegisterListener (typename BoundCallback< ParamT, DelegateT >::CallbackMethod method, DelegateT *delegate)
 
CallbackPtr RegisterListener (typename Callback< ParamT >::CallbackFunction fn)
 
void UnregisterListener (CallbackPtr callback_object)
 
void UnregisterListeners ()
 
template<class DelegateT , class ClosureDataT >
Observable< ParamT >::CallbackPtr RegisterListener (typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, ClosureDataT data)
 
template<class DelegateT >
Observable< ParamT >::CallbackPtr RegisterListener (typename BoundCallback< ParamT, DelegateT >::CallbackMethod method, DelegateT *delegate)
 
template<typename ParamT>
void RegisterListener (Observable< ParamT >::CallbackPtr callback_object)
 

Protected Types

typedef std::set< CallbackPtrCallbacks
 

Protected Member Functions

 Observable ()
 
void RegisterListener (CallbackPtr callback_object)
 
void NotifyListeners (const ParamT &parameter)
 

Private Attributes

Callbacks listeners_
 
pthread_rwlock_t listeners_rw_lock_
 

Additional Inherited Members

- Static Public Member Functions inherited from Callbackable< ParamT >
template<class DelegateT , typename ClosureDataT >
static CallbackTNMakeClosure (typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, const ClosureDataT &closure_data)
 
template<class DelegateT >
static CallbackTNMakeCallback (typename BoundCallback< ParamT, DelegateT >::CallbackMethod method, DelegateT *delegate)
 
static CallbackTNMakeCallback (typename Callback< ParamT >::CallbackFunction function)
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Detailed Description

template<typename ParamT>
class Observable< ParamT >

This is a base class for classes that need to expose a callback interface for asynchronous callback methods. One can register an arbitrary number of observers on an Observable that get notified when the method NotifyListeners() is invoked.

Note: the registration and invocation of callbacks in Observable is thread- safe, but be aware that the callbacks of observing classes might run in arbitrary threads. When using these classes, you should take extra care for thread-safety.

Note: The RegisterListener() methods return a pointer to a CallbackBase. You MUST NOT free these objects, they are managed by the Observable class. Use them only as handles to unregister specific callbacks.

Parameters
ParamTthe type of the parameter that is passed to every callback invocation.

Definition at line 288 of file util_concurrency.h.

Member Typedef Documentation

template<typename ParamT>
typedef Callbackable<ParamT>::CallbackTN* Observable< ParamT >::CallbackPtr

Definition at line 313 of file util_concurrency.h.

template<typename ParamT>
typedef std::set<CallbackPtr> Observable< ParamT >::Callbacks
protected

Definition at line 315 of file util_concurrency.h.

Constructor & Destructor Documentation

template<typename ParamT >
Observable< ParamT >::~Observable ( )
virtual

Definition at line 134 of file util_concurrency_impl.h.

template<typename ParamT >
Observable< ParamT >::Observable ( )
protected

Definition at line 127 of file util_concurrency_impl.h.

Here is the call graph for this function:

Member Function Documentation

template<typename ParamT>
void Observable< ParamT >::NotifyListeners ( const ParamT &  parameter)
protected

Notifies all registered listeners and passes them the provided argument This method should be called by a derived class to send out asynchronous messages to registered observers.

Parameters
parameterthe data to be passed to the observers

Definition at line 216 of file util_concurrency_impl.h.

template<typename ParamT>
template<class DelegateT , class ClosureDataT >
Observable<ParamT>::CallbackPtr Observable< ParamT >::RegisterListener ( typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod  method,
DelegateT *  delegate,
ClosureDataT  data 
)

Definition at line 142 of file util_concurrency_impl.h.

Here is the call graph for this function:

template<typename ParamT>
template<class DelegateT >
Observable<ParamT>::CallbackPtr Observable< ParamT >::RegisterListener ( typename BoundCallback< ParamT, DelegateT >::CallbackMethod  method,
DelegateT *  delegate 
)

Definition at line 158 of file util_concurrency_impl.h.

Here is the call graph for this function:

template<typename ParamT>
template<typename ParamT>
void Observable< ParamT >::RegisterListener ( Observable< ParamT >::CallbackPtr  callback_object)

Definition at line 181 of file util_concurrency_impl.h.

template<typename ParamT>
template<class DelegateT , class ClosureDataT >
CallbackPtr Observable< ParamT >::RegisterListener ( typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod  method,
DelegateT *  delegate,
ClosureDataT  data 
)

Registers a method of a specific object as a listener to the Observable object. The method is invoked on the given delegate when the callback is fired by the observed object using NotifyListeners(). Since this is meant to be a closure, it also passes the third argument to the method being in- voked by the Observable object.

Parameters
DelegateTthe type of the delegate object
methoda pointer to the method to be invoked by the callback
delegatea pointer to the object to invoke the callback on
closuresomething to be passed to method
Returns
a handle to the registered callback

Referenced by IngestionPipeline::IngestionPipeline(), swissknife::CommandScrub::Main(), receiver::PayloadProcessor::Process(), swissknife::CatalogTraversalParallel< ObjectFetcherT >::PushNestedCatalogs(), swissknife::CatalogTraversalParallel< ObjectFetcherT >::PushPreviousRevision(), and ScrubbingPipeline::ScrubbingPipeline().

Here is the caller graph for this function:

template<typename ParamT>
template<class DelegateT >
CallbackPtr Observable< ParamT >::RegisterListener ( typename BoundCallback< ParamT, DelegateT >::CallbackMethod  method,
DelegateT *  delegate 
)

Registers a method of a specific object as a listener to the Observable object. The method is invoked on the given delegate when the callback is fired by the observed object using NotifyListeners().

Parameters
DelegateTthe type of the delegate object
methoda pointer to the method to be invoked by the callback
delegatea pointer to the object to invoke the callback on
Returns
a handle to the registered callback
template<typename ParamT>
Observable< ParamT >::CallbackPtr Observable< ParamT >::RegisterListener ( typename Callback< ParamT >::CallbackFunction  fn)

Registers a static class member or a C-like function as a callback to the Observable object. The function is invoked when the callback is fired by the observed object using NotifyListeners().

Parameters
fna pointer to the function to be called by the callback
Returns
a handle to the registered callback

Definition at line 170 of file util_concurrency_impl.h.

Here is the call graph for this function:

template<typename ParamT>
void Observable< ParamT >::RegisterListener ( CallbackPtr  callback_object)
protected
template<typename ParamT>
void Observable< ParamT >::UnregisterListener ( CallbackPtr  callback_object)

Removes the given callback from the listeners group of this Observable.

Parameters
callback_objecta callback handle that was returned by RegisterListener() before.

Definition at line 190 of file util_concurrency_impl.h.

Here is the call graph for this function:

template<typename ParamT >
void Observable< ParamT >::UnregisterListeners ( )

Removes all listeners from the Observable

Definition at line 202 of file util_concurrency_impl.h.

Referenced by receiver::PayloadProcessor::Process().

Here is the caller graph for this function:

Member Data Documentation

template<typename ParamT>
Callbacks Observable< ParamT >::listeners_
private

the set of registered callback objects

Definition at line 394 of file util_concurrency.h.

template<typename ParamT>
pthread_rwlock_t Observable< ParamT >::listeners_rw_lock_
mutableprivate

Definition at line 396 of file util_concurrency.h.


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