OpenWalnut
1.5.0dev
|
This class can observe properties inside a property group. More...
#include <WPropertyObserver.h>
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< WPropertyObserver > | SPtr |
Convenience type for a shared pointer on property observers. More... | |
Public Types inherited from WCondition | |
typedef std::shared_ptr< WCondition > | SPtr |
Shared pointer type for WCondition. More... | |
typedef std::shared_ptr< const WCondition > | ConstSPtr |
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< WPropertyObserver > | create () |
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< PropertyNameMap > | LastUpdated |
Type of shared container for the list of last updated properties. More... | |
Private Member Functions | |
WPropertyObserver (const WPropertyObserver &rhs) | |
Disallow copy construction. More... | |
WPropertyObserver & | operator= (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< WProperties > | m_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... | |
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.
|
private |
Type of shared container for the list of last updated properties.
Definition at line 166 of file WPropertyObserver.h.
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.
typedef std::shared_ptr< WPropertyObserver > WPropertyObserver::SPtr |
Convenience type for a shared pointer on property observers.
Definition at line 56 of file WPropertyObserver.h.
|
private |
Type for shared container with signal connections.
Definition at line 136 of file WPropertyObserver.h.
WPropertyObserver::WPropertyObserver | ( | ) |
Default constructor.
Definition at line 32 of file WPropertyObserver.cpp.
Referenced by create().
|
virtual |
Destructor.
Definition at line 43 of file WPropertyObserver.cpp.
|
private |
Disallow copy construction.
rhs | the other threaded runner. |
|
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().
|
static |
Creates a new instance of WPropertyObserver.
Useful to save some typing as it creates an shared pointer for you.
Definition at line 140 of file WPropertyObserver.cpp.
References WPropertyObserver().
Referenced by WMFiberDisplay::moduleMain().
WPropertyObserver::PropertyNameMap WPropertyObserver::handled | ( | ) |
Resets the update flag and the list of fired properties.
Definition at line 53 of file WPropertyObserver.cpp.
References WSharedObject< T >::getWriteTicket(), m_lastUpdated, and m_updated.
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.
properties | the group whose children should be watched. |
names | list 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().
|
private |
Disallow copy assignment.
rhs | the other threaded runner. |
|
private |
Gets called by the update callback of the property.
The property given as parameter was the property that fired.
property | the 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().
bool WPropertyObserver::updated | ( | ) | const |
Is true if one observed property fired.
This is reset by the handled method.
Definition at line 48 of file WPropertyObserver.cpp.
References m_updated.
|
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().
|
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().
|
private |
The properties handled by this observer.
Definition at line 151 of file WPropertyObserver.h.
Referenced by observe(), and updateSubscriptions().
|
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().
|
private |
The subscription to each property which was subscribed.
Definition at line 141 of file WPropertyObserver.h.
Referenced by cancelSubscriptions(), and updateSubscriptions().
|
private |
The connection used to get notified about m_properties updates.
Definition at line 161 of file WPropertyObserver.h.
Referenced by observe().
|
private |
True if a property fired.
Definition at line 146 of file WPropertyObserver.h.
Referenced by handled(), observe(), propertyUpdated(), and updated().