Kstars

indiconcretedevice.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5
6 Handle INDI Standard properties.
7*/
8
9#include "indiconcretedevice.h"
10#include "clientmanager.h"
11
12namespace ISD
13{
14
15uint8_t ConcreteDevice::m_ID = 1;
16
17ConcreteDevice::ConcreteDevice(ISD::GenericDevice *parent) : GDInterface(parent), m_Parent(parent),
18 m_Name(parent->getDeviceName())
19{
20 // Signal --> Signal
21 connect(parent, &GenericDevice::Connected, this, [this]()
22 {
23 m_ReadyTimer.reset(new QTimer(this));
24 m_ReadyTimer->setInterval(250);
25 m_ReadyTimer->setSingleShot(true);
26 connect(m_ReadyTimer.get(), &QTimer::timeout, this, &ConcreteDevice::ready);
27 emit Connected();
28 });
29 connect(parent, &GenericDevice::Disconnected, this, &ConcreteDevice::Disconnected);
30
31 // Signal --> Slots
32 connect(parent, &GenericDevice::propertyDefined, this, [this](INDI::Property value)
33 {
34 if (m_ReadyTimer)
35 m_ReadyTimer->start();
36 registerProperty(value);
37 });
38 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::removeProperty);
39 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::updateProperty);
40
41 // N.B. JM 2024.04.09: Better move signals to bottom to allow internal update slots above to run first
42 // and update any status variables before informing the outside world.
43 // Signal --> Signal
44 connect(parent, &GenericDevice::propertyDefined, this, &ConcreteDevice::propertyDefined);
45 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::propertyDeleted);
46 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::propertyUpdated);
47}
48
49void ConcreteDevice::registeProperties()
50{
51 // Register all properties first
52 for (auto &oneProperty : m_Parent->getProperties())
53 registerProperty(oneProperty);
54}
55
56void ConcreteDevice::updateProperty(INDI::Property prop)
57{
58 switch (prop.getType())
59 {
60 case INDI_SWITCH:
61 processSwitch(prop);
62 break;
63 case INDI_NUMBER:
64 processNumber(prop);
65 break;
66 case INDI_TEXT:
67 processText(prop);
68 break;
69 case INDI_LIGHT:
70 processLight(prop);
71 break;
72 case INDI_BLOB:
73 processBLOB(prop);
74 default:
75 break;
76 }
77}
78
79void ConcreteDevice::processProperties()
80{
81 // Register all properties first
82 for (auto &oneProperty : m_Parent->getProperties())
83 {
84 switch (oneProperty.getType())
85 {
86 case INDI_SWITCH:
87 processSwitch(oneProperty);
88 break;
89 case INDI_NUMBER:
90 processNumber(oneProperty);
91 break;
92 case INDI_TEXT:
93 processText(oneProperty);
94 break;
95 case INDI_LIGHT:
96 processLight(oneProperty);
97 break;
98 case INDI_BLOB:
99 processBLOB(oneProperty);
100 break;
101 default:
102 break;
103 }
104 }
105}
106
107INDI::PropertyView<INumber> *ConcreteDevice::getNumber(const QString &name) const
108{
109 return m_Parent->getBaseDevice().getNumber(name.toLatin1().constData());
110}
111
112INDI::PropertyView<IText> *ConcreteDevice::getText(const QString &name) const
113{
114 return m_Parent->getBaseDevice().getText(name.toLatin1().constData());
115}
116
117INDI::PropertyView<ISwitch> *ConcreteDevice::getSwitch(const QString &name) const
118{
119 return m_Parent->getBaseDevice().getSwitch(name.toLatin1().constData());
120}
121
122INDI::PropertyView<ILight> *ConcreteDevice::getLight(const QString &name) const
123{
124 return m_Parent->getBaseDevice().getLight(name.toLatin1().constData());
125}
126
127INDI::PropertyView<IBLOB> *ConcreteDevice::getBLOB(const QString &name) const
128{
129 return m_Parent->getBaseDevice().getBLOB(name.toLatin1().constData());
130}
131
132void ConcreteDevice::sendNewProperty(INDI::Property prop)
133{
134 m_Parent->sendNewProperty(prop);
135}
136
137QString ConcreteDevice::getMessage(int id) const
138{
139 return QString::fromStdString(m_Parent->getBaseDevice().messageQueue(id));
140}
141
142INDI::Property ConcreteDevice::getProperty(const QString &name) const
143{
144 return m_Parent->getProperty(name);
145}
146
147const QSharedPointer<DriverInfo> &ConcreteDevice::getDriverInfo() const
148{
149 return m_Parent->getDriverInfo();
150}
151
152bool ConcreteDevice::setConfig(INDIConfig tConfig)
153{
154 return m_Parent->setConfig(tConfig);
155}
156
157Properties ConcreteDevice::getProperties() const
158{
159 return m_Parent->getProperties();
160}
161
162bool ConcreteDevice::getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
163 double *step) const
164{
165 return m_Parent->getMinMaxStep(propName, elementName, min, max, step);
166}
167
168IPState ConcreteDevice::getState(const QString &propName) const
169{
170 return m_Parent->getState(propName);
171}
172
173IPerm ConcreteDevice::getPermission(const QString &propName) const
174{
175 return m_Parent->getPermission(propName);
176}
177
178}
GenericDevice is the Generic Device for INDI devices.
Definition indistd.h:117
ISD is a collection of INDI Standard Devices.
const char * constData() const const
QString fromStdString(const std::string &str)
QByteArray toLatin1() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:59:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.