File indexing completed on 2024-12-08 06:30:13
0001 /* 0002 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "indicommon.h" 0010 0011 #include <QObject> 0012 #include <QVariantMap> 0013 #include <QJsonObject> 0014 0015 class ClientManager; 0016 class DeviceInfo; 0017 class ServerManager; 0018 0019 /** 0020 * @class DriverInfo 0021 * DriverInfo holds all metadata associated with a particular INDI driver. 0022 * An INDI drivers holds both static and dynamic information. Example for static information: 0023 * <ul> 0024 * <li>Device name.</li> 0025 * <li>Device label.</li> 0026 * <li>Driver version.</li> 0027 * <li>Device Family: Telescope, CCD, Focuser...etc</li> 0028 * </ul> 0029 * 0030 * Dynamic information include associated Server and Client managers, port in use, associated devices...etc. 0031 * Most INDI drivers operate only one device, but some driver can present multiple devices simultaneously. 0032 * 0033 * Driver information are obtained from multiple sources: 0034 * <ol> 0035 * <li>INDI driver XML file: All INDI driver install an XML file (usually to /usr/share/indi) that contains information 0036 * on the driver and device or devices it is capabale of running.</li> 0037 * <li>Client DriverInfos: Users can add a new host/port combo in the Device Manager in order to connect to 0038 * to local or remote INDI servers.</li> 0039 * <li>Generated DriverInfos: DriverInfo can be created programatically to connect to local or remote INDI server with unknown 0040 * number of actual drivers/devices at the server side.</li> 0041 * </ol> 0042 * 0043 * @author Jasem Mutlaq 0044 */ 0045 class DriverInfo : public QObject 0046 { 0047 Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer) 0048 Q_OBJECT 0049 0050 public: 0051 explicit DriverInfo(const QString &inName); 0052 explicit DriverInfo(DriverInfo *driver); 0053 ~DriverInfo() override; 0054 0055 QSharedPointer<DriverInfo> clone(bool resetClone = true); 0056 0057 QJsonObject toJson() const 0058 { 0059 return 0060 { 0061 {"name", name}, 0062 {"label", label}, 0063 {"binary", exec}, 0064 {"version", version}, 0065 {"manufacturer", m_Manufacturer}, 0066 {"skel", skelFile}, 0067 {"family", DeviceFamilyLabels[type]}, 0068 }; 0069 } 0070 0071 void reset(); 0072 void resetDevices() 0073 { 0074 devices.clear(); 0075 } 0076 QString getServerBuffer() const; 0077 0078 bool isEmpty() const 0079 { 0080 return devices.isEmpty(); 0081 } 0082 0083 // Actual name of the driver 0084 // i.e. what getDefaultName() returns 0085 const QString &getName() const 0086 { 0087 return name; 0088 } 0089 void setName(const QString &newName) 0090 { 0091 name = newName; 0092 } 0093 0094 // Driver executable 0095 void setExecutable(const QString &newDriver) 0096 { 0097 exec = newDriver; 0098 } 0099 const QString &getExecutable() const 0100 { 0101 return exec; 0102 } 0103 0104 // Driver Label/Alias. We _rename_ the INDI driver in _runtime_ to the label 0105 // Internally INDI server changes the actual driver "name" above to the label value 0106 // It's a method of running multiple instances of the same driver with multiple names. 0107 void setLabel(const QString &inlabel) 0108 { 0109 label = inlabel; 0110 } 0111 const QString &getLabel() const 0112 { 0113 return label; 0114 } 0115 0116 void setUniqueLabel(const QString &inUniqueLabel); 0117 const QString &getUniqueLabel() const 0118 { 0119 return uniqueLabel; 0120 } 0121 0122 void setVersion(const QString &newVersion) 0123 { 0124 version = newVersion; 0125 } 0126 const QString &getVersion() const 0127 { 0128 return version; 0129 } 0130 0131 void setType(DeviceFamily newType) 0132 { 0133 type = newType; 0134 } 0135 DeviceFamily getType() const 0136 { 0137 return type; 0138 } 0139 0140 void setDriverSource(DriverSource newDriverSource) 0141 { 0142 driverSource = newDriverSource; 0143 } 0144 DriverSource getDriverSource() const 0145 { 0146 return driverSource; 0147 } 0148 0149 void setServerManager(ServerManager *newServerManager) 0150 { 0151 serverManager = newServerManager; 0152 } 0153 ServerManager *getServerManager() const 0154 { 0155 return serverManager; 0156 } 0157 0158 void setClientManager(ClientManager *newClientManager) 0159 { 0160 clientManager = newClientManager; 0161 } 0162 ClientManager *getClientManager() const 0163 { 0164 return clientManager; 0165 } 0166 0167 void setUserPort(int inUserPort) 0168 { 0169 userPort = inUserPort; 0170 } 0171 int getUserPort() const 0172 { 0173 return userPort; 0174 } 0175 0176 void setSkeletonFile(const QString &inSkeleton) 0177 { 0178 skelFile = inSkeleton; 0179 } 0180 const QString &getSkeletonFile() const 0181 { 0182 return skelFile; 0183 } 0184 0185 void setServerState(bool inState); 0186 bool getServerState() const 0187 { 0188 return serverState; 0189 } 0190 0191 void setClientState(bool inState); 0192 bool getClientState() const 0193 { 0194 return clientState; 0195 } 0196 0197 void setHostParameters(const QString &inHost, int inPort) 0198 { 0199 hostname = inHost; 0200 port = inPort; 0201 } 0202 void setPort(int inPort) 0203 { 0204 port = inPort; 0205 } 0206 void setHost(const QString &inHost) 0207 { 0208 hostname = inHost; 0209 } 0210 const QString &getHost() const 0211 { 0212 return hostname; 0213 } 0214 int getPort() const 0215 { 0216 return port; 0217 } 0218 0219 void setRemotePort(const QString &inPort) 0220 { 0221 remotePort = inPort; 0222 } 0223 void setRemoteHost(const QString &inHost) 0224 { 0225 remoteHostname = inHost; 0226 } 0227 const QString &getRemoteHost() const 0228 { 0229 return remoteHostname; 0230 } 0231 const QString &getRemotePort() const 0232 { 0233 return remotePort; 0234 } 0235 0236 //void setBaseDevice(INDI::BaseDevice *idv) { baseDevice = idv;} 0237 //INDI::BaseDevice* getBaseDevice() { return baseDevice; } 0238 0239 void addDevice(DeviceInfo *idv); 0240 void removeDevice(DeviceInfo *idv); 0241 DeviceInfo *getDevice(const QString &deviceName) const; 0242 QList<DeviceInfo *> getDevices() const 0243 { 0244 return devices; 0245 } 0246 0247 QVariantMap getAuxInfo() const; 0248 void setAuxInfo(const QVariantMap &value); 0249 void addAuxInfo(const QString &key, const QVariant &value); 0250 0251 QString manufacturer() const; 0252 void setManufacturer(const QString &Manufacturer); 0253 0254 QJsonObject startupRule() const; 0255 void setStartupRule(const QJsonObject &value); 0256 0257 private: 0258 /// Actual device name as defined by INDI server 0259 QString name; 0260 /// How it appears in the GUI initially as read from source 0261 QString label; 0262 /// How it appears in INDI Menu in case tree_label above is taken by another device 0263 QString uniqueLabel; 0264 /// Exec for the driver 0265 QString exec; 0266 /// Version of the driver (optional) 0267 QString version; 0268 /// INDI server port as the user wants it. 0269 int userPort; 0270 /// Skeleton file, if any; 0271 QString skelFile; 0272 /// INDI Host port 0273 int port; 0274 /// INDI Host hostname 0275 QString hostname; 0276 // INDI Remote Hostname (for remote drivers) 0277 QString remoteHostname; 0278 // INDI remote port (for remote drivers) 0279 QString remotePort; 0280 // Manufacturer 0281 QString m_Manufacturer; 0282 /// Device type (Telescope, CCD..etc), if known (optional) 0283 DeviceFamily type { KSTARS_UNKNOWN }; 0284 /// Is the driver in the server running? 0285 bool serverState { false }; 0286 /// Is the client connected to the server running the desired driver? 0287 bool clientState { false }; 0288 /// How did we read the driver information? From XML file? From 3rd party file? ..etc. 0289 DriverSource driverSource { PRIMARY_XML }; 0290 /// Who is managing this device? 0291 ServerManager *serverManager { nullptr }; 0292 /// Any GUI client handling this device? 0293 ClientManager *clientManager { nullptr }; 0294 /// Any additional properties in key, value pairs 0295 QVariantMap auxInfo; 0296 QList<DeviceInfo *> devices; 0297 QJsonObject m_StartupRule; 0298 0299 signals: 0300 void deviceStateChanged(); 0301 };