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 removeDevice(INDI::BaseDevice dp) override;
90 
91  virtual void newProperty(INDI::Property prop) override;
92  virtual void updateProperty(INDI::Property prop) override;
93  virtual void removeProperty(INDI::Property prop) override;
94 
95  virtual void newMessage(INDI::BaseDevice dp, int messageID) override;
96  virtual void newUniversalMessage(std::string message) override;
97 
98  virtual void serverConnected() override;
99  virtual void serverDisconnected(int exitCode) override;
100 
101  private:
102  void processNewProperty(INDI::Property prop);
103  void processRemoveBLOBManager(const QString &device, const QString &property);
104  QList<DriverInfo *> m_ManagedDrivers;
105  QList<BlobManager *> blobManagers;
106  ServerManager *sManager { nullptr };
107 
108  signals:
109  // Client successfully connected to the server.
110  void started();
111  // Client failed to connect to the server.
112  void failed(const QString &message);
113  // Running client was abnormally disconnected from server.
114  void terminated(const QString &message);
115 
116  // @note If using INDI Posix client, the following newINDIDevice/Property and removeINDIDevice/Property signals
117  // must be connected to slots using Qt::BlockingQueuedConnection to ensure operation is fully completed before
118  // resuming the INDI client thread. For Qt Based INDI client, Qt::DirectConnection should be used.
119 
120  void newINDIDevice(DeviceInfo *dv);
121  void removeINDIDevice(const QString &name);
122 
123  void newINDIProperty(INDI::Property prop);
124  void updateINDIProperty(INDI::Property prop);
125  void removeINDIProperty(INDI::Property prop);
126 
127  void newBLOBManager(const char *device, INDI::Property prop);
128  void removeBLOBManager(const QString &device, const QString &property);
129 
130  void newINDIMessage(INDI::BaseDevice dp, int messageID);
131  void newINDIUniversalMessage(const QString &message);
132 
133  private:
134  static constexpr uint8_t MAX_RETRIES {2};
135  uint8_t m_ConnectionRetries {MAX_RETRIES};
136  bool m_PendingConnection {false};
137 };
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-2023 The KDE developers.
Generated on Mon May 8 2023 03:57:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.