WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
Zbl::ZAndGate Class Reference

A software AND gate that monitors an arbitrary number of input properties from multiple objects and produces a single AND-ed output. When all inputs are true output is true. If any input is false output is false. More...

#include <ZAndGate.h>

Inheritance diagram for Zbl::ZAndGate:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZAndGate:
Collaboration graph
[legend]

Public Types

typedef QPair< QString, bool > proxy
 propertyName/value More...
 
typedef QMultiMap< QObject *, proxypropMap
 A map of object/propertyName/value triplets. More...
 
typedef QMutableMapIterator< QObject *, proxypropIterator
 iterator for object/propertyName/value triplet maps More...
 

Public Slots

void onPropChanged ()
 

Signals

void outputChanged ()
 

Public Member Functions

 ZAndGate (QObject *parent=nullptr)
 
bool getValue ()
 
Q_INVOKABLE bool addInputProperty (QObject *targetObject, const QString &propertyName, const QString &signalName=QString())
 Adds a property to the watched properties list. More...
 
Q_INVOKABLE bool removeInputProperty (QObject *targetObject, const QString &propertyName)
 Removes a property from the watched properties list. More...
 
Q_INVOKABLE void removeAllProperties ()
 Removes all properties from the watched properties list. More...
 

Static Public Member Functions

static void registerType ()
 Registers ZAndGate as a QML type. More...
 

Protected Member Functions

void evaluate ()
 
QVariant waitGetProperty (QObject *targetObj, const QString &name)
 

Protected Attributes

propMap m_props
 A map of object property proxies, by object pointer. Each proxy identifies one property. Multiple proxies may exist per input object. More...
 
bool m_value
 Current output value of the AND gate. True if all input properties are true, false otherwise. More...
 

Properties

bool output
 Output value of "anded" input property values. More...
 

Detailed Description

A software AND gate that monitors an arbitrary number of input properties from multiple objects and produces a single AND-ed output. When all inputs are true output is true. If any input is false output is false.

This object is reentrant. It can be instanciated in multiple threads concurrently but each instance can only be used in its own thread. Input objects passed to addInputProperty() must be in the same thread as the ZAndGate object on which the method is called.

The purpose of this object is to synchronize multiple control and configuration input sequences that can occur concurrently to determine when all have completed initialization. Although this problem is typically solved through QML property bindings, that solution isn't practical when the number of inputs isn't known till run time and that number may change over the course of the running program, as with Zuble control modules, which can be loaded and unloaded arbitrarily over time.

Caveat 1: To simplify the data structures and memory footprint of ZAndGate the algorithm will poll all properties of a target object whenever any of them change. This means if many input properties are connected from the same target object ZAndGate will poll each property of the object each time ANY of the properties change.

This is because the design connects all watched property change signals to a single slot on ZAndGate that can determine which object sent the property change signal but not which property of the object caused the signal to be sent. We poll to determine which property has changed. This should not be a big problem for a small number of properties per input object or if properties change infrequently. However for a large number of properties per input object that change frequently this design aspect could introduce significant performance degradation.

Work around this problem by calling addInputProperty() for only one property per input object and then use standard QML property binding to bind that input property to other properties of the input object.

Caveat 2: ZAndGate DOES NOT support connections from objects in other threads. This is because the QObject::property(name) method isn't thread safe.

Definition at line 50 of file ZAndGate.h.

Member Typedef Documentation

◆ propIterator

typedef QMutableMapIterator<QObject*, proxy> Zbl::ZAndGate::propIterator

iterator for object/propertyName/value triplet maps

Definition at line 73 of file ZAndGate.h.

◆ propMap

typedef QMultiMap<QObject*, proxy> Zbl::ZAndGate::propMap

A map of object/propertyName/value triplets.

ZAndGate stores these in order to poll their properties when a value change occurs.

Definition at line 67 of file ZAndGate.h.

◆ proxy

typedef QPair<QString,bool> Zbl::ZAndGate::proxy

propertyName/value

Definition at line 58 of file ZAndGate.h.

Constructor & Destructor Documentation

◆ ZAndGate()

Zbl::ZAndGate::ZAndGate ( QObject *  parent = nullptr)
explicit

Definition at line 8 of file ZAndGate.cpp.

Member Function Documentation

◆ addInputProperty()

bool Zbl::ZAndGate::addInputProperty ( QObject *  targetObject,
const QString &  propertyName,
const QString &  signalName = QString() 
)

Adds a property to the watched properties list.

Parameters
targetObjectThe object to watch
propertyNameName of the property on targetObject to watch
signalNameName of the signal on targetObject to watch for changes to propertyName. Defaults to <propertyName>Changed(). Example: 'ready' propertyName defaults to 'readyChanged()' signalName.

Definition at line 27 of file ZAndGate.cpp.

◆ evaluate()

void Zbl::ZAndGate::evaluate ( )
protected

Definition at line 196 of file ZAndGate.cpp.

Referenced by addInputProperty(), and onPropChanged().

◆ getValue()

bool Zbl::ZAndGate::getValue ( )

Definition at line 22 of file ZAndGate.cpp.

◆ onPropChanged

void Zbl::ZAndGate::onPropChanged ( )
slot

Definition at line 103 of file ZAndGate.cpp.

◆ outputChanged

void Zbl::ZAndGate::outputChanged ( )
signal

◆ registerType()

void Zbl::ZAndGate::registerType ( )
static

Registers ZAndGate as a QML type.

Definition at line 14 of file ZAndGate.cpp.

Referenced by Zbl::Zblcore::registerTypes().

◆ removeAllProperties()

void Zbl::ZAndGate::removeAllProperties ( )

Removes all properties from the watched properties list.

Definition at line 91 of file ZAndGate.cpp.

◆ removeInputProperty()

bool Zbl::ZAndGate::removeInputProperty ( QObject *  targetObject,
const QString &  propertyName 
)

Removes a property from the watched properties list.

Definition at line 85 of file ZAndGate.cpp.

◆ waitGetProperty()

QVariant Zbl::ZAndGate::waitGetProperty ( QObject *  targetObj,
const QString &  name 
)
protected

Definition at line 174 of file ZAndGate.cpp.

Referenced by onPropChanged().

Member Data Documentation

◆ m_props

propMap Zbl::ZAndGate::m_props
protected

A map of object property proxies, by object pointer. Each proxy identifies one property. Multiple proxies may exist per input object.

Definition at line 139 of file ZAndGate.h.

Referenced by addInputProperty(), evaluate(), onPropChanged(), and removeAllProperties().

◆ m_value

bool Zbl::ZAndGate::m_value
protected

Current output value of the AND gate. True if all input properties are true, false otherwise.

Definition at line 146 of file ZAndGate.h.

Referenced by evaluate(), getValue(), onPropChanged(), and removeAllProperties().

Property Documentation

◆ output

bool Zbl::ZAndGate::output
read

Output value of "anded" input property values.

Definition at line 89 of file ZAndGate.h.


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