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
|
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>
Public Types | |
typedef QPair< QString, bool > | proxy |
propertyName/value More... | |
typedef QMultiMap< QObject *, proxy > | propMap |
A map of object/propertyName/value triplets. More... | |
typedef QMutableMapIterator< QObject *, proxy > | propIterator |
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... | |
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.
typedef QMutableMapIterator<QObject*, proxy> Zbl::ZAndGate::propIterator |
iterator for object/propertyName/value triplet maps
Definition at line 73 of file ZAndGate.h.
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.
typedef QPair<QString,bool> Zbl::ZAndGate::proxy |
propertyName/value
Definition at line 58 of file ZAndGate.h.
|
explicit |
Definition at line 8 of file ZAndGate.cpp.
bool Zbl::ZAndGate::addInputProperty | ( | QObject * | targetObject, |
const QString & | propertyName, | ||
const QString & | signalName = QString() |
||
) |
Adds a property to the watched properties list.
targetObject | The object to watch |
propertyName | Name of the property on targetObject to watch |
signalName | Name 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.
|
protected |
Definition at line 196 of file ZAndGate.cpp.
Referenced by addInputProperty(), and onPropChanged().
bool Zbl::ZAndGate::getValue | ( | ) |
Definition at line 22 of file ZAndGate.cpp.
|
slot |
Definition at line 103 of file ZAndGate.cpp.
|
signal |
Referenced by evaluate(), onPropChanged(), and removeAllProperties().
|
static |
Registers ZAndGate as a QML type.
Definition at line 14 of file ZAndGate.cpp.
Referenced by Zbl::Zblcore::registerTypes().
void Zbl::ZAndGate::removeAllProperties | ( | ) |
Removes all properties from the watched properties list.
Definition at line 91 of file ZAndGate.cpp.
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.
|
protected |
Definition at line 174 of file ZAndGate.cpp.
Referenced by onPropChanged().
|
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().
|
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().
|
read |
Output value of "anded" input property values.
Definition at line 89 of file ZAndGate.h.
Zuble documentation copyright © 2019 Bob Dinitto. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Zuble is a derivative work of Qt version 5. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.