summaryrefslogtreecommitdiffstats
path: root/src/controlobjectslave.cpp
blob: 293d9c183b5c2dbc056d57e4561cbe4af18f87bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <QApplication>
#include <QtDebug>

#include "controlobjectslave.h"
#include "control/control.h"

ControlObjectSlave::ControlObjectSlave(QObject* pParent)
        : QObject(pParent),
          m_pControl(NULL) {
}

ControlObjectSlave::ControlObjectSlave(const QString& g, const QString& i, QObject* pParent)
        : QObject(pParent) {
    initialize(ConfigKey(g, i));
}

ControlObjectSlave::ControlObjectSlave(const char* g, const char* i, QObject* pParent)
        : QObject(pParent) {
    initialize(ConfigKey(g, i));
}

ControlObjectSlave::ControlObjectSlave(const ConfigKey& key, QObject* pParent)
        : QObject(pParent) {
    initialize(key);
}

void ControlObjectSlave::initialize(const ConfigKey& key) {
    m_key = key;
    // Don't bother looking up the control if key is NULL. Prevents log spew.
    if (!key.isNull()) {
        m_pControl = ControlDoublePrivate::getControl(key);
    }
}

ControlObjectSlave::~ControlObjectSlave() {
}

bool ControlObjectSlave::connectValueChanged(const QObject* receiver,
        const char* method, Qt::ConnectionType requestedConnectionType) {

    // We connect to the
    // ControlObjectPrivate only once and in a way that
    // the requested ConnectionType is working as desired.
    // We try to avoid direct connections if not requested
    // since you cannot safely delete an object with a pending
    // direct connection. This fixes bug Bug #1406124
    // requested: Auto -> COP = Auto / SCO = Auto
    // requested: Direct -> COP = Direct / SCO = Direct
    // requested: Queued -> COP = Auto / SCO = Queued
    // requested: BlockingQueued -> Assert(false)


    bool ret = false;
    if (m_pControl) {
        // We must not block the signal source by a blocking connection
        DEBUG_ASSERT(requestedConnectionType != Qt::BlockingQueuedConnection);
        ret = connect((QObject*)this, SIGNAL(valueChanged(double)),
                      receiver, method, requestedConnectionType);
        if (ret) {
            // Connect to ControlObjectPrivate only if required. Do not allow
            // duplicate connections.
            if (requestedConnectionType == Qt::DirectConnection) {
                // use only explicit direct connection if requested
                // the caller must not delete this until the all signals are
                // processed to avoid segfaults
                connect(m_pControl.data(), SIGNAL(valueChanged(double, QObject*)),
                         this, SLOT(slotValueChangedDirect(double, QObject*)),
                         static_cast<Qt::ConnectionType>(Qt::DirectConnection |
                                                         Qt::UniqueConnection));
            } else {
                connect(m_pControl.data(), SIGNAL(valueChanged(double, QObject*)),
                        this, SLOT(slotValueChangedAuto(double, QObject*)),
                        static_cast<Qt::ConnectionType>(Qt::AutoConnection |
                                                        Qt::UniqueConnection));
            }
        }
    }
    return ret;
}

// connect to parent object
bool ControlObjectSlave::connectValueChanged(
        const char* method, Qt::ConnectionType type) {
    DEBUG_ASSERT(parent() != NULL);
    return connectValueChanged(parent(), method, type);
}