• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.61
/engine/src/inputpatch.cpp
1
/*
2
  Q Light Controller
3
  inputpatch.cpp
4

5
  Copyright (c) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#if defined(WIN32) || defined(Q_OS_WIN)
21
#   include <Windows.h>
22
#else
23
#   include <unistd.h>
24
#endif
25

26
#include <QDebug>
27

28
#include "qlcinputchannel.h"
29
#include "qlcioplugin.h"
30
#include "inputpatch.h"
31

32
#define GRACE_MS 1
33

34
/*****************************************************************************
35
 * Initialization
36
 *****************************************************************************/
37

38
InputPatch::InputPatch(QObject *parent)
1✔
39
    : QObject(parent)
40
    , m_universe(UINT_MAX)
1✔
41
    , m_plugin(NULL)
1✔
42
    , m_pluginLine(QLCIOPlugin::invalidLine())
2✔
43
    , m_profile(NULL)
1✔
44
    , m_nextPageCh(USHRT_MAX)
1✔
45
    , m_prevPageCh(USHRT_MAX)
1✔
46
    , m_pageSetCh(USHRT_MAX)
1✔
47
{
48

49
}
1✔
50

51
InputPatch::InputPatch(quint32 inputUniverse, QObject* parent)
8✔
52
    : QObject(parent)
53
    , m_universe(inputUniverse)
8✔
54
    , m_plugin(NULL)
8✔
55
    , m_pluginLine(QLCIOPlugin::invalidLine())
16✔
56
    , m_profile(NULL)
8✔
57
    , m_nextPageCh(USHRT_MAX)
8✔
58
    , m_prevPageCh(USHRT_MAX)
8✔
59
    , m_pageSetCh(USHRT_MAX)
8✔
60
{
61

62
}
8✔
63

64
InputPatch::~InputPatch()
16✔
65
{
66
    if (m_plugin != NULL)
9✔
67
        m_plugin->closeInput(m_pluginLine, m_universe);
6✔
68
}
16✔
69

70
/*****************************************************************************
71
 * Properties
72
 *****************************************************************************/
73

74
bool InputPatch::set(QLCIOPlugin* plugin, quint32 input, QLCInputProfile* profile)
8✔
75
{
76
    bool result = false;
8✔
77

78
    qDebug() << "InputPatch::set - plugin:" << ((plugin == NULL)?"None":plugin->name())
16✔
79
             << ", line:" << input
8✔
80
             << ", profile:" << ((profile == NULL)?"None":profile->name());
8✔
81

82
    if (m_plugin != NULL && m_pluginLine != QLCIOPlugin::invalidLine())
8✔
83
    {
84
        disconnect(m_plugin, SIGNAL(valueChanged(quint32,quint32,quint32,uchar,QString)),
2✔
85
                   this, SLOT(slotValueChanged(quint32,quint32,quint32,uchar,QString)));
86
        m_plugin->closeInput(m_pluginLine, m_universe);
2✔
87
    }
88

89
    m_plugin = plugin;
8✔
90
    m_pluginLine = input;
8✔
91
    m_profile = profile;
8✔
92

93
    if (m_plugin != NULL)
8✔
94
    {
95
        emit pluginNameChanged();
8✔
96
        if (m_pluginLine != QLCIOPlugin::invalidLine())
8✔
97
            emit inputNameChanged();
8✔
98
        if (m_profile != NULL)
8✔
99
            emit profileNameChanged();
4✔
100
    }
101

102
    /* Open the assigned plugin input */
103
    if (m_plugin != NULL && m_pluginLine != QLCIOPlugin::invalidLine())
8✔
104
    {
105
        connect(m_plugin, SIGNAL(valueChanged(quint32,quint32,quint32,uchar,QString)),
8✔
106
                this, SLOT(slotValueChanged(quint32,quint32,quint32,uchar,QString)));
107
        result = m_plugin->openInput(m_pluginLine, m_universe);
8✔
108

109
        if (m_profile != NULL)
8✔
110
            setProfilePageControls();
4✔
111
    }
112
    return result;
8✔
113
}
114

115
bool InputPatch::set(QLCInputProfile *profile)
2✔
116
{
117
    if (m_plugin == NULL || m_pluginLine == QLCIOPlugin::invalidLine())
2✔
118
        return false;
1✔
119

120
    m_profile = profile;
1✔
121

122
    if (m_profile != NULL)
1✔
123
        setProfilePageControls();
1✔
124

125
    emit profileNameChanged();
1✔
126

127
    return true;
1✔
128
}
129

130
bool InputPatch::reconnect()
1✔
131
{
132
    if (m_plugin != NULL && m_pluginLine != QLCIOPlugin::invalidLine())
1✔
133
    {
134
        m_plugin->closeInput(m_pluginLine, m_universe);
1✔
135
#if defined(WIN32) || defined(Q_OS_WIN)
136
        Sleep(GRACE_MS);
137
#else
138
        usleep(GRACE_MS * 1000);
1✔
139
#endif
140
        bool ret = m_plugin->openInput(m_pluginLine, m_universe);
1✔
141
        if (ret == true)
1✔
142
        {
143
            QMap<QString, QVariant>::iterator it = m_parametersCache.begin();
1✔
144
            for (; it != m_parametersCache.end(); it++)
1✔
145
            {
146
                qDebug() << "[InputPatch] restoring parameter:" << it.key() << it.value();
×
147
                m_plugin->setParameter(m_universe, m_pluginLine, QLCIOPlugin::Input, it.key(), it.value());
×
148
            }
149
        }
150
        return ret;
1✔
151
    }
152
    return false;
×
153
}
154

155
QLCIOPlugin* InputPatch::plugin() const
12✔
156
{
157
    return m_plugin;
12✔
158
}
159

160
QString InputPatch::pluginName() const
17✔
161
{
162
    if (m_plugin != NULL)
17✔
163
        return m_plugin->name();
15✔
164
    else
165
        return KInputNone;
2✔
166
}
167

168
quint32 InputPatch::input() const
20✔
169
{
170
    return m_pluginLine;
20✔
171
}
172

173
QString InputPatch::inputName() const
6✔
174
{
175
    if (m_plugin != NULL && m_pluginLine != QLCIOPlugin::invalidLine() &&
10✔
176
            m_pluginLine < quint32(m_plugin->inputs().count()))
10✔
177
        return m_plugin->inputs()[m_pluginLine];
4✔
178
    else
179
        return KInputNone;
2✔
180
}
181

182
QLCInputProfile* InputPatch::profile() const
12✔
183
{
184
    return m_profile;
12✔
185
}
186

187
QString InputPatch::profileName() const
9✔
188
{
189
    if (m_profile != NULL)
9✔
190
        return m_profile->name();
6✔
191
    else
192
        return KInputNone;
3✔
193
}
194

195
bool InputPatch::isPatched() const
3✔
196
{
197
    return input() != QLCIOPlugin::invalidLine();
3✔
198
}
199

200
void InputPatch::setPluginParameter(QString prop, QVariant value)
1✔
201
{
202
    qDebug() << "[InputPatch] caching parameter:" << prop << value;
1✔
203
    m_parametersCache[prop] = value;
1✔
204
    if (m_plugin != NULL)
1✔
205
        m_plugin->setParameter(m_universe, m_pluginLine, QLCIOPlugin::Input, prop, value);
1✔
206
}
1✔
207

208
QMap<QString, QVariant> InputPatch::getPluginParameters()
3✔
209
{
210
    if (m_plugin != NULL)
3✔
211
        return m_plugin->getParameters(m_universe, m_pluginLine, QLCIOPlugin::Input);
3✔
212

213
    return QMap<QString, QVariant>();
×
214
}
215

216
void InputPatch::slotValueChanged(quint32 universe, quint32 input, quint32 channel,
6✔
217
                                  uchar value, const QString& key)
218
{
219
    // In case we have several lines connected to the same plugin, emit only
220
    // such values that belong to this particular patch.
221
    if (input == m_pluginLine)
6✔
222
    {
223
        if (universe == UINT_MAX || universe == m_universe)
4✔
224
        {
225
            QMutexLocker inputBufferLocker(&m_inputBufferMutex);
4✔
226
            InputValue val(value, key);
4✔
227
            if (m_inputBuffer.contains(channel))
4✔
228
            {
229
                InputValue const& curVal = m_inputBuffer.value(channel);
1✔
230
                if (curVal.value != val.value)
1✔
231
                {
232
                    // Every ON/OFF changes must pass through
233
                    if (curVal.value == 0 || val.value == 0)
1✔
234
                    {
235
                        emit inputValueChanged(m_universe, channel, curVal.value, curVal.key);
1✔
236
                    }
237
                    m_inputBuffer.insert(channel, val);
1✔
238
                }
239
            }
1✔
240
            else
241
            {
242
                m_inputBuffer.insert(channel, val);
3✔
243
            }
244
        }
4✔
245
    }
246
}
6✔
247

248
void InputPatch::setProfilePageControls()
5✔
249
{
250
    if (m_profile != NULL)
5✔
251
    {
252
        if (m_plugin != NULL)
5✔
253
        {
254
            QMap<QString, QVariant> settings = m_profile->globalSettings();
5✔
255
            if (settings.isEmpty() == false)
5✔
256
            {
257
                QMapIterator <QString,QVariant> it(settings);
×
258
                while (it.hasNext() == true)
×
259
                {
260
                    it.next();
×
261
                    m_plugin->setParameter(m_universe, m_pluginLine, QLCIOPlugin::Input, it.key(), it.value());
×
262
                }
263
            }
×
264
        }
5✔
265
        QMapIterator <quint32,QLCInputChannel*> it(m_profile->channels());
5✔
266
        while (it.hasNext() == true)
261✔
267
        {
268
            it.next();
256✔
269
            QLCInputChannel *ch = it.value();
256✔
270
            if (ch != NULL)
256✔
271
            {
272
                if (m_nextPageCh == USHRT_MAX && ch->type() == QLCInputChannel::NextPage)
256✔
273
                    m_nextPageCh = m_profile->channelNumber(ch);
×
274
                else if (m_prevPageCh == USHRT_MAX && ch->type() == QLCInputChannel::PrevPage)
256✔
275
                    m_prevPageCh = m_profile->channelNumber(ch);
×
276
                else if (m_pageSetCh == USHRT_MAX && ch->type() == QLCInputChannel::PageSet)
256✔
277
                    m_pageSetCh = m_profile->channelNumber(ch);
×
278
            }
279
        }
280
    }
5✔
281
}
5✔
282

283
void InputPatch::flush(quint32 universe)
5✔
284
{
285
    if (universe == UINT_MAX || universe == m_universe)
5✔
286
    {
287
        QMutexLocker inputBufferLocker(&m_inputBufferMutex);
5✔
288
        for (QHash<quint32, InputValue>::const_iterator it = m_inputBuffer.begin(); it != m_inputBuffer.end(); ++it)
8✔
289
        {
290
            emit inputValueChanged(m_universe, it.key(), it.value().value, it.value().key);
3✔
291
        }
292
        m_inputBuffer.clear();
5✔
293
    }
5✔
294
}
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc