Kstars

drivermanager.h
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "indi/indidbus.h"
10#include "indicommon.h"
11#include "customdrivers.h"
12#include "ui_drivermanager.h"
13
14#include <QDialog>
15#include <QFrame>
16#include <QIcon>
17#include <QString>
18#include <QPointer>
19#include <QJsonArray>
20
21#include <lilxml.h>
22
23//class QStringList;
24class QTreeWidgetItem;
25
26class DriverManager;
27class ServerManager;
28class ClientManager;
29class DriverInfo;
30
31class DriverManagerUI : public QFrame, public Ui::DriverManager
32{
34
35 public:
36 explicit DriverManagerUI(QWidget *parent = nullptr);
37
38 public slots:
39 void makePortEditable(QTreeWidgetItem *selectedItem, int column);
40
41 public:
42 QIcon runningPix;
43 QIcon stopPix;
44 QIcon connected;
45 QIcon disconnected;
46 QIcon localMode;
47 QIcon serverMode;
48};
49
50/**
51 * @brief DriverManager is the primary class to handle all operations related to starting and stopping INDI drivers.
52 *
53 * INDI drivers can be local or remote drivers. For remote hosts, driver information is not known and devices are built
54 * as they arrive dynamically. The class parses INDI primary devices XML file (drivers.xml) and any 3rd party INDI Driver
55 * XML file to build a tree of devices grouped by driver family type.
56 *
57 * When starting local drivers, DriverManager also establishes an INDI server with the requested drivers and then connect to
58 * the local server to receive the devices dynamically.
59 *
60 * The class also handles INDI hosts which can be added in order to connect to a local or remote INDI server.
61 *
62 * @author Jasem Mutlaq
63 */
64class DriverManager : public QDialog
65{
67
68 public:
69 static DriverManager *Instance();
70 static void release();
71
72 enum
73 {
74 LOCAL_NAME_COLUMN = 0,
75 LOCAL_STATUS_COLUMN,
76 LOCAL_MODE_COLUMN,
77 LOCAL_VERSION_COLUMN,
78 LOCAL_PORT_COLUMN
79 };
80 enum
81 {
82 HOST_STATUS_COLUMN = 0,
83 HOST_NAME_COLUMN,
84 HOST_PORT_COLUMN
85 };
86
87 bool readXMLDrivers();
88 bool readINDIHosts();
89 void processXMLDriver(const QString &driverName);
90 bool buildDeviceGroup(XMLEle *root, char errmsg[]);
91 bool buildDriverElement(XMLEle *root, QTreeWidgetItem *DGroup, DeviceFamily groupType, char errmsg[]);
92
93 int getINDIPort(int customPort);
94 bool isDeviceRunning(const QString &deviceLabel);
95
96 void saveHosts();
97
98 void processLocalTree(bool dState);
99 void processRemoteTree(bool dState);
100
101 QSharedPointer<DriverInfo> findDriverByName(const QString &name);
102 QSharedPointer<DriverInfo> findDriverByLabel(const QString &label);
103 QSharedPointer<DriverInfo> findDriverByExec(const QString &exec);
104
105 ClientManager *getClientManager(const QSharedPointer<DriverInfo> &driver);
106
107 const QList<QSharedPointer<DriverInfo>> &getDrivers() const
108 {
109 return driversList;
110 }
111 const QList<QVariantMap> &getCustomDrivers() const
112 {
113 return m_CustomDrivers->customDrivers();
114 }
115 QJsonArray getDriverList() const;
116
117 const QStringList &getDriversStringList()
118 {
119 return driversStringList;
120 }
121
122 /**
123 * @brief getUniqueHosts Given a list of DriverInfos, extract all the host:port information from all the drivers.
124 * and then consolidate each groups of drivers that belong to the same server & port to a specific list
125 * e.g. If we have driver1 (localhost:7624), driver2(192.168.1.90:7624), driver3(localhost:7624) then this would create
126 * two lists. First list contains [driver1,driver3] and second list contains [driver2] making each list _unique_ in terms of host params.
127 * @param dList list of driver to examine
128 * @param uHosts List of unique hosts, each with a group of drivers that belong to it.
129 */
131
132 void addDriver(const QSharedPointer<DriverInfo> &driver)
133 {
134 driversList.append(driver);
135 }
136 void removeDriver(const QSharedPointer<DriverInfo> &driver)
137 {
138 driversList.removeOne(driver);
139 }
140
141 void startDevices(const QList<QSharedPointer<DriverInfo> > &dList);
142 void stopDevices(const QList<QSharedPointer<DriverInfo>> &dList);
143 void stopAllDevices()
144 {
145 stopDevices(driversList);
146 }
147 bool restartDriver(const QSharedPointer<DriverInfo> &driver);
148
149 void connectRemoteHost(const QSharedPointer<DriverInfo> &driver);
150 bool disconnectRemoteHost(const QSharedPointer<DriverInfo> &driver);
151
152 QString getUniqueDeviceLabel(const QString &label);
153
154 void startClientManager(const QList<QSharedPointer<DriverInfo>> &qdv, const QString &host, int port);
155 void startLocalDrivers(ServerManager *serverManager);
156 void processDriverStartup(const QSharedPointer<DriverInfo> &driver);
157 void processDriverFailure(const QSharedPointer<DriverInfo> &driver, const QString &message);
158
159 void disconnectClients();
160 void clearServers();
161
162 private:
164 ~DriverManager() override;
165
166 bool checkDriverAvailability(const QString &driver);
167
168 static DriverManager *_DriverManager;
169 static INDIDBus *_INDIDBus;
170
171 ServerMode connectionMode { SERVER_CLIENT };
172 QTreeWidgetItem *lastGroup { nullptr };
173 int currentPort;
174 //DriverInfo::XMLSource xmlSource;
175 DriverSource driverSource;
176 DriverManagerUI *ui { nullptr };
180 QStringList driversStringList;
181 QPointer<CustomDrivers> m_CustomDrivers;
182
183 public slots:
184 void resizeDeviceColumn();
185 void updateLocalTab();
186 void updateClientTab();
187
188 void updateMenuActions();
189
190 void addINDIHost();
191 void modifyINDIHost();
192 void removeINDIHost();
193 void activateRunService();
194 void activateStopService();
195 void activateHostConnection();
196 void activateHostDisconnection();
197
198 void updateCustomDrivers();
199
200 void setClientStarted();
201 void setClientFailed(const QString &message);
202 void setClientTerminated(const QString &message);
203
204 void setServerStarted();
205 void setServerFailed(const QString &message);
206 void setServerTerminated(const QString &message);
207
208 void processDeviceStatus(const QSharedPointer<DriverInfo> &driver);
209
210 void showCustomDrivers()
211 {
212 m_CustomDrivers->show();
213 }
214
215 signals:
216
217 // Server Signals
218
219 // Server started successfully
220 void serverStarted(const QString &host, int port);
221 // Server failed to start.
222 void serverFailed(const QString &host, int port, const QString &message);
223 // Running server was abruptly terminated.
224 void serverTerminated(const QString &host, int port, const QString &message);
225
226 // Client Signals
227 // Client connected to server successfully.
228 void clientStarted(const QString &host, int port);
229 // Client failed to connect to server.
230 void clientFailed(const QString &host, int port, const QString &message);
231 // Running server lost connection to server.
232 void clientTerminated(const QString &host, int port, const QString &message);
233
234 // Driver Signals
235 void driverStarted(const QSharedPointer<DriverInfo> &driver);
236 void driverFailed(const QSharedPointer<DriverInfo> &driver, const QString &message);
237 void driverStopped(const QSharedPointer<DriverInfo> &driver);
238 void driverRestarted(const QSharedPointer<DriverInfo> &driver);
239};
ClientManager manages connection to INDI server, creation of devices, and receiving/sending propertie...
DriverInfo holds all metadata associated with a particular INDI driver.
Definition driverinfo.h:46
DriverManager is the primary class to handle all operations related to starting and stopping INDI dri...
void getUniqueHosts(const QList< QSharedPointer< DriverInfo > > &dList, QList< QList< QSharedPointer< DriverInfo > > > &uHosts)
getUniqueHosts Given a list of DriverInfos, extract all the host:port information from all the driver...
Collection of INDI DBus functions.
Definition indidbus.h:19
ServerManager is responsible for starting and shutting local INDI servers.
virtual int exec()
void append(QList< T > &&value)
bool removeOne(const AT &t)
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.