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

#include <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 147 of file concurrency.h.

Member Typedef Documentation

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

Definition at line 172 of file concurrency.h.

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

Definition at line 174 of file concurrency.h.

Constructor & Destructor Documentation

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

Definition at line 79 of file concurrency_impl.h.

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

Definition at line 72 of file 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 161 of file 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 87 of file 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 103 of file 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 126 of file 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 115 of file 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 135 of file 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 147 of file 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 253 of file concurrency.h.

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

Definition at line 255 of file concurrency.h.


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