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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

92.8
/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())
1✔
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())
8✔
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;
77

78
    qDebug() << "InputPatch::set - plugin:" << ((plugin == NULL)?"None":plugin->name())
79
             << ", line:" << input
80
             << ", profile:" << ((profile == NULL)?"None":profile->name());
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;
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
            foreach (QString par, m_parametersCache.keys())
2✔
144
            {
145
                qDebug() << "[InputPatch] restoring parameter:" << par << m_parametersCache[par];
146
                m_plugin->setParameter(m_universe, m_pluginLine, QLCIOPlugin::Input, par, m_parametersCache[par]);
×
147
            }
×
148
        }
149
        return ret;
1✔
150
    }
151
    return false;
152
}
153

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

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

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

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

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

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

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

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

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

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

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

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

282
void InputPatch::flush(quint32 universe)
5✔
283
{
284
    if (universe == UINT_MAX || universe == m_universe)
5✔
285
    {
286
        QMutexLocker inputBufferLocker(&m_inputBufferMutex);
5✔
287
        for (QHash<quint32, InputValue>::const_iterator it = m_inputBuffer.begin(); it != m_inputBuffer.end(); ++it)
13✔
288
        {
289
            emit inputValueChanged(m_universe, it.key(), it.value().value, it.value().key);
3✔
290
        }
291
        m_inputBuffer.clear();
5✔
292
    }
293
}
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

© 2025 Coveralls, Inc