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, [this]()
30 {
31 // Invalidate dispatched.
32 setProperty("dispatched", QVariant());
33 emit Disconnected();
34 });
35
36 // Signal --> Slots
37 connect(parent, &GenericDevice::propertyDefined, this, [this](INDI::Property value)
38 {
39 if (m_ReadyTimer)
40 m_ReadyTimer->start();
41 registerProperty(value);
42 });
43 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::removeProperty);
44 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::updateProperty);
45
46 // N.B. JM 2024.04.09: Better move signals to bottom to allow internal update slots above to run first
47 // and update any status variables before informing the outside world.
48 // Signal --> Signal
49 connect(parent, &GenericDevice::propertyDefined, this, &ConcreteDevice::propertyDefined);
50 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::propertyDeleted);
51 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::propertyUpdated);
52}
53
54void ConcreteDevice::registeProperties()
55{
56 // Register all properties first
57 for (auto &oneProperty : m_Parent->getProperties())
58 registerProperty(oneProperty);
59}
60
61void ConcreteDevice::updateProperty(INDI::Property prop)
62{
63 switch (prop.getType())
64 {
65 case INDI_SWITCH:
66 processSwitch(prop);
67 break;
68 case INDI_NUMBER:
69 processNumber(prop);
70 break;
71 case INDI_TEXT:
72 processText(prop);
73 break;
74 case INDI_LIGHT:
75 processLight(prop);
76 break;
77 case INDI_BLOB:
78 processBLOB(prop);
79 default:
80 break;
81 }
82}
83
84void ConcreteDevice::processProperties()
85{
86 // Register all properties first
87 for (auto &oneProperty : m_Parent->getProperties())
88 {
89 switch (oneProperty.getType())
90 {
91 case INDI_SWITCH:
92 processSwitch(oneProperty);
93 break;
94 case INDI_NUMBER:
95 processNumber(oneProperty);
96 break;
97 case INDI_TEXT:
98 processText(oneProperty);
99 break;
100 case INDI_LIGHT:
101 processLight(oneProperty);
102 break;
103 case INDI_BLOB:
104 processBLOB(oneProperty);
105 break;
106 default:
107 break;
108 }
109 }
110}
111
112INDI::PropertyView<INumber> *ConcreteDevice::getNumber(const QString &name) const
113{
114 return m_Parent->getBaseDevice().getNumber(name.toLatin1().constData());
115}
116
117INDI::PropertyView<IText> *ConcreteDevice::getText(const QString &name) const
118{
119 return m_Parent->getBaseDevice().getText(name.toLatin1().constData());
120}
121
122INDI::PropertyView<ISwitch> *ConcreteDevice::getSwitch(const QString &name) const
123{
124 return m_Parent->getBaseDevice().getSwitch(name.toLatin1().constData());
125}
126
127INDI::PropertyView<ILight> *ConcreteDevice::getLight(const QString &name) const
128{
129 return m_Parent->getBaseDevice().getLight(name.toLatin1().constData());
130}
131
132INDI::PropertyView<IBLOB> *ConcreteDevice::getBLOB(const QString &name) const
133{
134 return m_Parent->getBaseDevice().getBLOB(name.toLatin1().constData());
135}
136
137void ConcreteDevice::sendNewProperty(INDI::Property prop)
138{
139 m_Parent->sendNewProperty(prop);
140}
141
142QString ConcreteDevice::getMessage(int id) const
143{
144 return QString::fromStdString(m_Parent->getBaseDevice().messageQueue(id));
145}
146
147INDI::Property ConcreteDevice::getProperty(const QString &name) const
148{
149 return m_Parent->getProperty(name);
150}
151
152const QSharedPointer<DriverInfo> &ConcreteDevice::getDriverInfo() const
153{
154 return m_Parent->getDriverInfo();
155}
156
157bool ConcreteDevice::setConfig(INDIConfig tConfig)
158{
159 return m_Parent->setConfig(tConfig);
160}
161
162Properties ConcreteDevice::getProperties() const
163{
164 return m_Parent->getProperties();
165}
166
167bool ConcreteDevice::getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
168 double *step) const
169{
170 return m_Parent->getMinMaxStep(propName, elementName, min, max, step);
171}
172
173IPState ConcreteDevice::getState(const QString &propName) const
174{
175 return m_Parent->getState(propName);
176}
177
178IPerm ConcreteDevice::getPermission(const QString &propName) const
179{
180 return m_Parent->getPermission(propName);
181}
182
183}
GenericDevice is the Generic Device for INDI devices.
Definition indistd.h:117
ISD is a collection of INDI Standard Devices.
QCA_EXPORT void setProperty(const QString &name, const QVariant &value)
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 Dec 20 2024 11:53:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.