Kstars

driverinfo.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 "indicommon.h"
10
11#include <QObject>
12#include <QVariantMap>
13#include <QJsonObject>
14
15class ClientManager;
16class DeviceInfo;
17class ServerManager;
18
19/**
20 * @class DriverInfo
21 * DriverInfo holds all metadata associated with a particular INDI driver.
22 * An INDI drivers holds both static and dynamic information. Example for static information:
23 * <ul>
24 * <li>Device name.</li>
25 * <li>Device label.</li>
26 * <li>Driver version.</li>
27 * <li>Device Family: Telescope, CCD, Focuser...etc</li>
28 * </ul>
29 *
30 * Dynamic information include associated Server and Client managers, port in use, associated devices...etc.
31 * Most INDI drivers operate only one device, but some driver can present multiple devices simultaneously.
32 *
33 * Driver information are obtained from multiple sources:
34 * <ol>
35 * <li>INDI driver XML file: All INDI driver install an XML file (usually to /usr/share/indi) that contains information
36 * on the driver and device or devices it is capabale of running.</li>
37 * <li>Client DriverInfos: Users can add a new host/port combo in the Device Manager in order to connect to
38 * to local or remote INDI servers.</li>
39 * <li>Generated DriverInfos: DriverInfo can be created programatically to connect to local or remote INDI server with unknown
40 * number of actual drivers/devices at the server side.</li>
41 * </ol>
42 *
43 * @author Jasem Mutlaq
44 */
45class DriverInfo : public QObject
46{
47 Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer)
49
50 public:
51 explicit DriverInfo(const QString &inName);
52 explicit DriverInfo(DriverInfo *driver);
53 ~DriverInfo() override;
54
55 QSharedPointer<DriverInfo> clone(bool resetClone = true);
56
57 QJsonObject toJson() const
58 {
59 return
60 {
61 {"name", name},
62 {"label", label},
63 {"binary", exec},
64 {"version", version},
65 {"manufacturer", m_Manufacturer},
66 {"skel", skelFile},
67 {"family", DeviceFamilyLabels[type]},
68 };
69 }
70
71 void reset();
72 void resetDevices()
73 {
74 devices.clear();
75 }
76 QString getServerBuffer() const;
77
78 bool isEmpty() const
79 {
80 return devices.isEmpty();
81 }
82
83 // Actual name of the driver
84 // i.e. what getDefaultName() returns
85 const QString &getName() const
86 {
87 return name;
88 }
89 void setName(const QString &newName)
90 {
91 name = newName;
92 }
93
94 // Driver executable
95 void setExecutable(const QString &newDriver)
96 {
97 exec = newDriver;
98 }
99 const QString &getExecutable() const
100 {
101 return exec;
102 }
103
104 // Driver Label/Alias. We _rename_ the INDI driver in _runtime_ to the label
105 // Internally INDI server changes the actual driver "name" above to the label value
106 // It's a method of running multiple instances of the same driver with multiple names.
107 void setLabel(const QString &inlabel)
108 {
109 label = inlabel;
110 }
111 const QString &getLabel() const
112 {
113 return label;
114 }
115
116 void setUniqueLabel(const QString &inUniqueLabel);
117 const QString &getUniqueLabel() const
118 {
119 return uniqueLabel;
120 }
121
122 void setVersion(const QString &newVersion)
123 {
124 version = newVersion;
125 }
126 const QString &getVersion() const
127 {
128 return version;
129 }
130
131 void setType(DeviceFamily newType)
132 {
133 type = newType;
134 }
135 DeviceFamily getType() const
136 {
137 return type;
138 }
139
140 void setDriverSource(DriverSource newDriverSource)
141 {
142 driverSource = newDriverSource;
143 }
144 DriverSource getDriverSource() const
145 {
146 return driverSource;
147 }
148
149 void setServerManager(ServerManager *newServerManager)
150 {
151 serverManager = newServerManager;
152 }
153 ServerManager *getServerManager() const
154 {
155 return serverManager;
156 }
157
158 void setClientManager(ClientManager *newClientManager)
159 {
160 clientManager = newClientManager;
161 }
162 ClientManager *getClientManager() const
163 {
164 return clientManager;
165 }
166
167 void setUserPort(int inUserPort)
168 {
169 userPort = inUserPort;
170 }
171 int getUserPort() const
172 {
173 return userPort;
174 }
175
176 void setSkeletonFile(const QString &inSkeleton)
177 {
178 skelFile = inSkeleton;
179 }
180 const QString &getSkeletonFile() const
181 {
182 return skelFile;
183 }
184
185 void setServerState(bool inState);
186 bool getServerState() const
187 {
188 return serverState;
189 }
190
191 void setClientState(bool inState);
192 bool getClientState() const
193 {
194 return clientState;
195 }
196
197 void setHostParameters(const QString &inHost, int inPort)
198 {
199 hostname = inHost;
200 port = inPort;
201 }
202 void setPort(int inPort)
203 {
204 port = inPort;
205 }
206 void setHost(const QString &inHost)
207 {
208 hostname = inHost;
209 }
210 const QString &getHost() const
211 {
212 return hostname;
213 }
214 int getPort() const
215 {
216 return port;
217 }
218
219 void setRemotePort(const QString &inPort)
220 {
221 remotePort = inPort;
222 }
223 void setRemoteHost(const QString &inHost)
224 {
225 remoteHostname = inHost;
226 }
227 const QString &getRemoteHost() const
228 {
229 return remoteHostname;
230 }
231 const QString &getRemotePort() const
232 {
233 return remotePort;
234 }
235
236 //void setBaseDevice(INDI::BaseDevice *idv) { baseDevice = idv;}
237 //INDI::BaseDevice* getBaseDevice() { return baseDevice; }
238
239 void addDevice(DeviceInfo *idv);
240 void removeDevice(DeviceInfo *idv);
241 DeviceInfo *getDevice(const QString &deviceName) const;
242 QList<DeviceInfo *> getDevices() const
243 {
244 return devices;
245 }
246
247 QVariantMap getAuxInfo() const;
248 void setAuxInfo(const QVariantMap &value);
249 void addAuxInfo(const QString &key, const QVariant &value);
250
251 QString manufacturer() const;
252 void setManufacturer(const QString &Manufacturer);
253
254 QJsonObject startupRule() const;
255 void setStartupRule(const QJsonObject &value);
256
257 private:
258 /// Actual device name as defined by INDI server
259 QString name;
260 /// How it appears in the GUI initially as read from source
261 QString label;
262 /// How it appears in INDI Menu in case tree_label above is taken by another device
263 QString uniqueLabel;
264 /// Exec for the driver
265 QString exec;
266 /// Version of the driver (optional)
267 QString version;
268 /// INDI server port as the user wants it.
269 int userPort;
270 /// Skeleton file, if any;
271 QString skelFile;
272 /// INDI Host port
273 int port;
274 /// INDI Host hostname
275 QString hostname;
276 // INDI Remote Hostname (for remote drivers)
277 QString remoteHostname;
278 // INDI remote port (for remote drivers)
279 QString remotePort;
280 // Manufacturer
281 QString m_Manufacturer;
282 /// Device type (Telescope, CCD..etc), if known (optional)
283 DeviceFamily type { KSTARS_UNKNOWN };
284 /// Is the driver in the server running?
285 bool serverState { false };
286 /// Is the client connected to the server running the desired driver?
287 bool clientState { false };
288 /// How did we read the driver information? From XML file? From 3rd party file? ..etc.
289 DriverSource driverSource { PRIMARY_XML };
290 /// Who is managing this device?
291 ServerManager *serverManager { nullptr };
292 /// Any GUI client handling this device?
293 ClientManager *clientManager { nullptr };
294 /// Any additional properties in key, value pairs
295 QVariantMap auxInfo;
296 QList<DeviceInfo *> devices;
297 QJsonObject m_StartupRule;
298
299 signals:
300 void deviceStateChanged();
301};
ClientManager manages connection to INDI server, creation of devices, and receiving/sending propertie...
DeviceInfo is simple class to hold DriverInfo and INDI::BaseDevice associated with a particular devic...
Definition deviceinfo.h:21
DriverInfo holds all metadata associated with a particular INDI driver.
Definition driverinfo.h:46
ServerManager is responsible for starting and shutting local INDI servers.
void clear()
bool isEmpty() const const
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:15:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.