9#include "indilistener.h"
11#include "clientmanager.h"
12#include "deviceinfo.h"
16#include "auxiliary/ksnotification.h"
18#include <knotification.h>
20#include <basedevice.h>
21#include <indi_debug.h>
27 if (_INDIListener ==
nullptr)
30 qRegisterMetaType<INDI::BaseDevice>(
"INDI::BaseDevice");
39 auto it = std::find_if(all.begin(), all.end(), [name](
auto & oneDevice)
41 return oneDevice->getDeviceName() == name;
54 for (
auto &oneDevice : m_Devices)
56 if (oneDevice->getDeviceName() == name)
68 <<
"INDIListener: Adding a new client manager to INDI listener..";
72 connect(cm, &ClientManager::newINDIDevice,
this, &INDIListener::processDevice);
73 connect(cm, &ClientManager::removeINDIDevice,
this, &INDIListener::removeDevice);
75 connect(cm, &ClientManager::newINDIProperty,
this, &INDIListener::registerProperty);
76 connect(cm, &ClientManager::updateINDIProperty,
this, &INDIListener::updateProperty);
77 connect(cm, &ClientManager::removeINDIProperty,
this, &INDIListener::removeProperty);
79 connect(cm, &ClientManager::newINDIMessage,
this,
80 &INDIListener::processMessage);
81 connect(cm, &ClientManager::newINDIUniversalMessage,
this,
82 &INDIListener::processUniversalMessage);
87 qCDebug(KSTARS_INDI) <<
"INDIListener: Removing client manager for server"
88 << cm->getHost() <<
"@" << cm->getPort();
93 auto managedDrivers = cm->getManagedDrivers();
94 for (
auto &oneDriverInfo : managedDrivers)
98void INDIListener::processDevice(
DeviceInfo *dv)
101 Q_ASSERT_X(cm, __FUNCTION__,
"Client manager is not valid.");
103 qCDebug(KSTARS_INDI) <<
"INDIListener: New device" << dv->getDeviceName();
108 auto isConnected = gd->isConnected();
111 for (
auto &oneProperty : dv->getBaseDevice().getProperties())
113 gd->registerProperty(oneProperty);
116 switch (oneProperty.getType())
119 gd->processSwitch(oneProperty.getSwitch());
122 gd->processNumber(oneProperty.getNumber());
125 gd->processText(oneProperty.getText());
128 gd->processLight(oneProperty.getLight());
136 m_Devices.append(std::move(gd));
141void INDIListener::removeDevice(
const QString &deviceName)
143 qCDebug(KSTARS_INDI) <<
"INDIListener: Removing device" << deviceName;
145 for (
auto oneDevice : qAsConst(m_Devices))
147 if (oneDevice->getDeviceName() == deviceName)
150 m_Devices.removeOne(oneDevice);
152 emit deviceRemoved(oneDevice);
154 oneDevice->deleteLater();
160void INDIListener::registerProperty(INDI::Property prop)
162 if (!prop.getRegistered())
165 qCDebug(KSTARS_INDI) <<
"<" << prop.getDeviceName() <<
">: <" << prop.getName()
168 for (
auto &oneDevice : m_Devices)
170 if (oneDevice->getDeviceName() == prop.getDeviceName())
172 oneDevice->registerProperty(prop);
178void INDIListener::removeProperty(INDI::Property prop)
180 for (
auto &oneDevice : m_Devices)
182 if (oneDevice->getDeviceName() == prop.getDeviceName())
184 oneDevice->removeProperty(prop);
190void INDIListener::updateProperty(INDI::Property prop)
192 for (
auto &oneDevice : m_Devices)
194 if (oneDevice->getDeviceName() == prop.getDeviceName())
196 oneDevice->updateProperty(prop);
202void INDIListener::processMessage(INDI::BaseDevice dp,
int messageID)
204 for (
auto &oneDevice : m_Devices)
206 if (oneDevice->getDeviceName() == dp.getDeviceName())
208 oneDevice->processMessage(messageID);
214void INDIListener::processUniversalMessage(
const QString &message)
216 QString displayMessage = message;
218 int colonIndex = displayMessage.
indexOf(
": ");
220 displayMessage = displayMessage.
mid(colonIndex + 2);
225 qCDebug(KSTARS_INDI) <<
"AlignmentSubSystem:" << displayMessage;
229 if (Options::messageNotificationINDI())
231 KSNotification::event(
QLatin1String(
"IndiServerMessage"), displayMessage,
232 KSNotification::INDI, KSNotification::Warn);
ClientManager manages connection to INDI server, creation of devices, and receiving/sending propertie...
void removeManagedDriver(const QSharedPointer< DriverInfo > &driver)
removeManagedDriver Remove managed driver from pool of drivers managed by this client manager.
DeviceInfo is simple class to hold DriverInfo and INDI::BaseDevice associated with a particular devic...
INDIListener is responsible for creating ISD::GDInterface generic devices as new devices arrive from ...
GenericDevice is the Generic Device for INDI devices.
static KStars * Instance()
QString i18n(const char *text, const TYPE &arg...)
void transient(const QString &message, const QString &title)
transient Non modal message box that gets deleted on close.
void append(QList< T > &&value)
bool removeOne(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
T qobject_cast(QObject *object)
QObject * sender() const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const