24
24
#include <qwaitcondition.h>
27
#include "configobject.h"
29
class ControlDoublePrivate;
27
30
class ControlObject;
31
*@author Tue Haste Andersen
33
* This class is used to store a control value as used by an EngineObject.
34
* ControlEngine is thread safe, and sends a user event to a ControlObject
35
* whenever it's value is changed. setExtern is used for external threads
39
class ControlObjectThread : public QObject
32
class ControlObjectThread : public QObject {
43
35
ControlObjectThread(ControlObject *pControlObject, QObject* pParent=NULL);
44
36
virtual ~ControlObjectThread();
45
/** Returns the value of the object */
47
/** Setting the value from an external controller. This happen when a ControlObject has
48
* changed and its value is syncronized with this object. Thread safe, non blocking. Returns
49
* true if successful, otherwise false. Thread safe, non blocking. */
50
virtual bool setExtern(double v);
51
/** Adds a value to the value property of the ControlEngine. Notification in a similar way
52
* to set. Thread safe, blocking. */
54
/** Subtracts a value to the value property. Notification in a similar way
55
* to set. Thread safe, blocking. */
57
/** Updates the object with changes from the corresponding ControlObject, and emits
58
* valueChagned signal. Returns true if this it was updated*/
60
38
/** Called from update(); */
61
39
void emitValueChanged();
64
// FIXME: Dangerous GED hack
65
ControlObject* getControlObject();
68
/** The value is changed by the engine, and the corresponding ControlObject is updated.
69
* Thread safe, blocking. */
70
void slotSet(double v);
72
// The danger signal! This is for safety in wierd shutdown scenarios where the
73
// ControlObject dies to avoid segfaults.
74
void slotParentDead();
41
inline ConfigKey getKey() const {
45
// Returns the value of the object. Thread safe, non-blocking.
51
// Set the control to a new value. Non-blocking.
52
virtual void slotSet(double v);
53
// Sets the control value to v. Thread safe, non-blocking.
54
virtual void set(double v);
55
// Resets the control to its default value. Thread safe, non-blocking.
77
59
void valueChanged(double);
80
/** The actual value of the object */
82
/** Mutex controlling access to static members*/
83
static QMutex m_sqMutex;
84
/** Mutex controlling access to non-static members*/
86
/** Pointer to corresponding ControlObject */
87
ControlObject *m_pControlObject;
90
/** Update corresponding ControlObject */
91
virtual void updateControlObject();
93
/** Wait condition, used to wait for changes */
94
static QWaitCondition m_sqWait;
95
/** Queue used to keep changes */
96
static QQueue<ControlObjectThread*> m_sqQueue;
60
// This means that the control value has changed as a result of a mutation
61
// (set/add/sub/reset) originating from this object.
62
void valueChangedByThis(double);
65
// Receives the value from the master control and re-emits either
66
// valueChanged(double) or valueChangedByThis(double) based on pSetter.
67
virtual void slotValueChanged(double v, QObject* pSetter);
71
// Pointer to connected control.
72
ControlDoublePrivate* m_pControl;