Kstars

clientmanager.h
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QPointer>
10 
11 #ifdef USE_QT5_INDI
12 #include <baseclientqt.h>
13 #else
14 #include <baseclient.h>
15 #include <QObject>
16 #endif
17 
18 #include "blobmanager.h"
19 
20 class DeviceInfo;
21 class DriverInfo;
22 class ServerManager;
23 
24 /**
25  * @class ClientManager
26  * ClientManager manages connection to INDI server, creation of devices, and receiving/sending properties.
27  *
28  * ClientManager is a subclass of INDI::BaseClient class part of the INDI Library.
29  * This enables the class to communicate with INDI server and to receive notification of devices, properties, and messages.
30  *
31  * @author Jasem Mutlaq
32  * @version 1.3
33  */
34 #ifdef USE_QT5_INDI
35 class ClientManager : public INDI::BaseClientQt
36 #else
37 class ClientManager : public QObject, public INDI::BaseClient
38 #endif
39 {
40  Q_OBJECT
41 
42  public:
43  ClientManager();
44  virtual ~ClientManager() override = default;
45 
46  /**
47  * @brief appendManagedDriver Add driver to pool of managed drivers by this client manager.
48  * @param dv pointer to driver info instance.
49  * @note This function is ALWAYS called from the main KStars thread.
50  */
52 
53  /**
54  * @brief removeManagedDriver Remove managed driver from pool of drivers managed by this client manager.
55  * @param dv pointer to driver info instance.
56  * @note This function is ALWAYS called from the main KStars thread.
57  */
59 
60  /**
61  * @brief disconnectAll Disconnect from server and disconnect all BLOB Managers.
62  */
63  void disconnectAll();
64 
65  int count()
66  {
67  return m_ManagedDrivers.count();
68  }
69 
70  bool isBLOBEnabled(const QString &device, const QString &property);
71  void setBLOBEnabled(bool enabled, const QString &device, const QString &property);
72 
73  ServerManager *getServerManager()
74  {
75  return sManager;
76  }
77 
78  DriverInfo *findDriverInfoByName(const QString &name);
79  DriverInfo *findDriverInfoByLabel(const QString &label);
80 
81  bool isDriverManaged(DriverInfo *);
82 
83  QList<DriverInfo *> getManagedDrivers() const;
84 
85  void establishConnection();
86 
87  protected:
88  virtual void newDevice(INDI::BaseDevice *dp) override;
89  virtual void newProperty(INDI::Property *prop) override;
90  virtual void removeProperty(INDI::Property *prop) override;
91  virtual void removeDevice(INDI::BaseDevice *dp) override;
92  virtual void newBLOB(IBLOB *bp) override;
93  virtual void newSwitch(ISwitchVectorProperty *svp) override;
94  virtual void newNumber(INumberVectorProperty *) override;
95  virtual void newText(ITextVectorProperty *) override;
96  virtual void newLight(ILightVectorProperty *) override;
97  virtual void newMessage(INDI::BaseDevice *dp, int messageID) override;
98 
99 #if INDI_VERSION_MAJOR >= 1 && INDI_VERSION_MINOR >= 5
100  virtual void newUniversalMessage(std::string message) override;
101 #endif
102 
103  virtual void serverConnected() override;
104  virtual void serverDisconnected(int exitCode) override;
105 
106  private:
107  void processNewProperty(INDI::Property prop);
108  void processRemoveBLOBManager(const QString &device, const QString &property);
109  QList<DriverInfo *> m_ManagedDrivers;
110  QList<BlobManager *> blobManagers;
111  ServerManager *sManager { nullptr };
112 
113  signals:
114  // Client successfully connected to the server.
115  void started();
116  // Client failed to connect to the server.
117  void failed(const QString &message);
118  // Running client was abnormally disconnected from server.
119  void terminated(const QString &message);
120 
121  // @note If using INDI Posix client, the following newINDIDevice/Property and removeINDIDevice/Property signals
122  // must be connected to slots using Qt::BlockingQueuedConnection to ensure operation is fully completed before
123  // resuming the INDI client thread. For Qt Based INDI client, Qt::DirectConnection should be used.
124 
125  void newINDIDevice(DeviceInfo *dv);
126  void removeINDIDevice(const QString &name);
127 
128  void newINDIProperty(INDI::Property prop);
129  void removeINDIProperty(const QString &device, const QString &name);
130 
131  void newBLOBManager(const char *device, INDI::Property prop);
132  void removeBLOBManager(const QString &device, const QString &property);
133 
134  void newINDIBLOB(IBLOB *bp);
135  void newINDISwitch(ISwitchVectorProperty *svp);
136  void newINDINumber(INumberVectorProperty *nvp);
137  void newINDIText(ITextVectorProperty *tvp);
138  void newINDILight(ILightVectorProperty *lvp);
139  void newINDIMessage(INDI::BaseDevice *dp, int messageID);
140 #if INDI_VERSION_MAJOR >= 1 && INDI_VERSION_MINOR >= 5
141  void newINDIUniversalMessage(const QString &message);
142 #endif
143 
144  private:
145  static constexpr uint8_t MAX_RETRIES {2};
146  uint8_t m_ConnectionRetries {MAX_RETRIES};
147  bool m_PendingConnection {false};
148 };
Q_OBJECTQ_OBJECT
int count(const T &value) const const
void removeManagedDriver(DriverInfo *dv)
removeManagedDriver Remove managed driver from pool of drivers managed by this client manager.
void appendManagedDriver(DriverInfo *dv)
appendManagedDriver Add driver to pool of managed drivers by this client manager.
QString message
void disconnectAll()
disconnectAll Disconnect from server and disconnect all BLOB Managers.
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Aug 14 2022 04:13:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.