OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
WPropertyObserver Class Reference

This class can observe properties inside a property group. More...

#include <WPropertyObserver.h>

+ Inheritance diagram for WPropertyObserver:
+ Collaboration diagram for WPropertyObserver:

Public Types

typedef std::map< std::string, std::shared_ptr< WPropertyBase > > PropertyNameMap
 Convenience type for a set of property instances. More...
 
typedef std::shared_ptr< WPropertyObserverSPtr
 Convenience type for a shared pointer on property observers. More...
 
- Public Types inherited from WCondition
typedef std::shared_ptr< WConditionSPtr
 Shared pointer type for WCondition. More...
 
typedef std::shared_ptr< const WConditionConstSPtr
 Const shared pointer type for WCondition. More...
 
typedef boost::function0< void > t_ConditionNotifierType
 Type used for signalling condition changes. More...
 

Public Member Functions

 WPropertyObserver ()
 Default constructor. More...
 
virtual ~WPropertyObserver ()
 Destructor. More...
 
void observe (std::shared_ptr< WProperties > properties, std::set< std::string > names=std::set< std::string >())
 Defines the property group whose children should be watched. More...
 
bool updated () const
 Is true if one observed property fired. More...
 
PropertyNameMap handled ()
 Resets the update flag and the list of fired properties. More...
 
- Public Member Functions inherited from WCondition
 WCondition ()
 Default constructor. More...
 
virtual ~WCondition ()
 Destructor. More...
 
virtual void wait () const
 Wait for the condition. More...
 
virtual void notify ()
 Notifies all waiting threads. More...
 
boost::signals2::connection subscribeSignal (t_ConditionNotifierType notifier) const
 Subscribes a specified function to be notified on condition change. More...
 

Static Public Member Functions

static std::shared_ptr< WPropertyObservercreate ()
 Creates a new instance of WPropertyObserver. More...
 

Private Types

typedef WSharedAssociativeContainer< std::map< std::shared_ptr< WPropertyBase >, boost::signals2::connection > > Subscriptions
 Type for shared container with signal connections. More...
 
typedef WSharedAssociativeContainer< PropertyNameMapLastUpdated
 Type of shared container for the list of last updated properties. More...
 

Private Member Functions

 WPropertyObserver (const WPropertyObserver &rhs)
 Disallow copy construction. More...
 
WPropertyObserveroperator= (const WPropertyObserver &rhs)
 Disallow copy assignment. More...
 
void cancelSubscriptions ()
 Cancels all current subscriptions and cleans m_subscriptions. More...
 
void updateSubscriptions ()
 Subscribes each property update condition which matches an entry in m_propNames. More...
 
void propertyUpdated (std::shared_ptr< WPropertyBase > property)
 Gets called by the update callback of the property. More...
 

Private Attributes

Subscriptions m_subscriptions
 The subscription to each property which was subscribed. More...
 
bool m_updated
 True if a property fired. More...
 
std::shared_ptr< WPropertiesm_properties
 The properties handled by this observer. More...
 
std::set< std::string > m_propNames
 The names of the properties which shall be observed if they are or become available. More...
 
boost::signals2::scoped_connection m_updateConditionConnection
 The connection used to get notified about m_properties updates. More...
 
LastUpdated m_lastUpdated
 The queue of properties that fired before handled() is called. More...
 

Additional Inherited Members

- Protected Types inherited from WCondition
typedef boost::signals2::signal< void(void)> t_ConditionSignalType
 Type used for condition notification. More...
 
- Protected Attributes inherited from WCondition
t_ConditionSignalType signal_ConditionFired
 Signal getting fired whenever the condition fires. More...
 
boost::condition_variable_any m_condition
 The condition. More...
 
std::shared_mutex m_mutex
 The mutex used for the condition. More...
 

Detailed Description

This class can observe properties inside a property group.

The property group to observer can simply be set and replaced comfortably. Whenever one of the child properties updates, the observer fires too. If the observed property group itself changes (added properties, removed properties and so on), the observer gets updated automatically.

Definition at line 45 of file WPropertyObserver.h.

Member Typedef Documentation

◆ LastUpdated

Type of shared container for the list of last updated properties.

Definition at line 166 of file WPropertyObserver.h.

◆ PropertyNameMap

typedef std::map< std::string, std::shared_ptr< WPropertyBase > > WPropertyObserver::PropertyNameMap

Convenience type for a set of property instances.

Definition at line 51 of file WPropertyObserver.h.

◆ SPtr

typedef std::shared_ptr< WPropertyObserver > WPropertyObserver::SPtr

Convenience type for a shared pointer on property observers.

Definition at line 56 of file WPropertyObserver.h.

◆ Subscriptions

typedef WSharedAssociativeContainer< std::map< std::shared_ptr< WPropertyBase >, boost::signals2::connection > > WPropertyObserver::Subscriptions
private

Type for shared container with signal connections.

Definition at line 136 of file WPropertyObserver.h.

Constructor & Destructor Documentation

◆ WPropertyObserver() [1/2]

WPropertyObserver::WPropertyObserver ( )

Default constructor.

Definition at line 32 of file WPropertyObserver.cpp.

Referenced by create().

+ Here is the caller graph for this function:

◆ ~WPropertyObserver()

WPropertyObserver::~WPropertyObserver ( )
virtual

Destructor.

Definition at line 43 of file WPropertyObserver.cpp.

◆ WPropertyObserver() [2/2]

WPropertyObserver::WPropertyObserver ( const WPropertyObserver rhs)
private

Disallow copy construction.

Parameters
rhsthe other threaded runner.

Member Function Documentation

◆ cancelSubscriptions()

void WPropertyObserver::cancelSubscriptions ( )
private

Cancels all current subscriptions and cleans m_subscriptions.

Definition at line 96 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), and m_subscriptions.

Referenced by observe().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

std::shared_ptr< WPropertyObserver > WPropertyObserver::create ( )
static

Creates a new instance of WPropertyObserver.

Useful to save some typing as it creates an shared pointer for you.

Returns
the new instance.

Definition at line 140 of file WPropertyObserver.cpp.

References WPropertyObserver().

Referenced by WMFiberDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handled()

WPropertyObserver::PropertyNameMap WPropertyObserver::handled ( )

Resets the update flag and the list of fired properties.

Returns
the set of properties fired until the last call of handled.

Definition at line 53 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_lastUpdated, and m_updated.

+ Here is the call graph for this function:

◆ observe()

void WPropertyObserver::observe ( std::shared_ptr< WProperties properties,
std::set< std::string >  names = std::set< std::string >() 
)

Defines the property group whose children should be watched.

You can define a list of names manually if you are not interested in updates of ALL properties.

Note
this also resets the updated flag and the list of the last fired properties.
Parameters
propertiesthe group whose children should be watched.
nameslist of names. If specified, only these properties are observed.

Definition at line 67 of file WPropertyObserver.cpp.

References cancelSubscriptions(), WSharedObject< T >::getWriteTicket(), m_lastUpdated, m_properties, m_propNames, m_updateConditionConnection, m_updated, and updateSubscriptions().

+ Here is the call graph for this function:

◆ operator=()

WPropertyObserver& WPropertyObserver::operator= ( const WPropertyObserver rhs)
private

Disallow copy assignment.

Parameters
rhsthe other threaded runner.
Returns
this.

◆ propertyUpdated()

void WPropertyObserver::propertyUpdated ( std::shared_ptr< WPropertyBase property)
private

Gets called by the update callback of the property.

The property given as parameter was the property that fired.

Parameters
propertythe property that fired.

Definition at line 131 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_lastUpdated, m_updated, and WCondition::notify().

Referenced by updateSubscriptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updated()

bool WPropertyObserver::updated ( ) const

Is true if one observed property fired.

This is reset by the handled method.

Returns
true if one property fired.

Definition at line 48 of file WPropertyObserver.cpp.

References m_updated.

◆ updateSubscriptions()

void WPropertyObserver::updateSubscriptions ( )
private

Subscribes each property update condition which matches an entry in m_propNames.

Definition at line 111 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_properties, m_propNames, m_subscriptions, and propertyUpdated().

Referenced by observe().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_lastUpdated

LastUpdated WPropertyObserver::m_lastUpdated
private

The queue of properties that fired before handled() is called.

Definition at line 171 of file WPropertyObserver.h.

Referenced by handled(), observe(), and propertyUpdated().

◆ m_properties

std::shared_ptr< WProperties > WPropertyObserver::m_properties
private

The properties handled by this observer.

Definition at line 151 of file WPropertyObserver.h.

Referenced by observe(), and updateSubscriptions().

◆ m_propNames

std::set< std::string > WPropertyObserver::m_propNames
private

The names of the properties which shall be observed if they are or become available.

Definition at line 156 of file WPropertyObserver.h.

Referenced by observe(), and updateSubscriptions().

◆ m_subscriptions

Subscriptions WPropertyObserver::m_subscriptions
private

The subscription to each property which was subscribed.

Definition at line 141 of file WPropertyObserver.h.

Referenced by cancelSubscriptions(), and updateSubscriptions().

◆ m_updateConditionConnection

boost::signals2::scoped_connection WPropertyObserver::m_updateConditionConnection
private

The connection used to get notified about m_properties updates.

Definition at line 161 of file WPropertyObserver.h.

Referenced by observe().

◆ m_updated

bool WPropertyObserver::m_updated
private

True if a property fired.

Definition at line 146 of file WPropertyObserver.h.

Referenced by handled(), observe(), propertyUpdated(), and updated().


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