Kstars

servermanager.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 "indicommon.h"
10 
11 #include <QFile>
12 #include <QObject>
13 #include <QProcess>
14 #include <QTcpSocket>
15 #include <QTemporaryFile>
16 #include <QFuture>
17 
18 #include <memory>
19 
20 class DriverInfo;
21 
22 /**
23  * @class ServerManager
24  * ServerManager is responsible for starting and shutting local INDI servers.
25  *
26  * @author Jasem Mutlaq
27  */
28 class ServerManager : public QObject
29 {
30  Q_OBJECT
31 
32  public:
33  ServerManager(const QString &inHost, int inPort);
34  ~ServerManager() override;
35 
36  bool start();
37  void stop();
38 
39  QString getLogBuffer();
40  const QString &getHost() const
41  {
42  return host;
43  }
44  int getPort() const
45  {
46  return port;
47  }
48 
49  void setPendingDrivers(QList<DriverInfo *> drivers)
50  {
51  m_PendingDrivers = drivers;
52  }
53  const QList<DriverInfo *> &pendingDrivers() const
54  {
55  return m_PendingDrivers;
56  }
57 
58  void startDriver(DriverInfo *dv);
59  void stopDriver(DriverInfo *dv);
60  bool restartDriver(DriverInfo *dv);
61 
62  const QList<DriverInfo *> &managedDrivers() const
63  {
64  return m_ManagedDrivers;
65  }
66  bool contains(DriverInfo *dv)
67  {
68  return m_ManagedDrivers.contains(dv);
69  }
70 
71  void setMode(ServerMode inMode)
72  {
73  mode = inMode;
74  }
75  ServerMode getMode()
76  {
77  return mode;
78  }
79 
80  QString errorString();
81 
82  int size()
83  {
84  return m_ManagedDrivers.size();
85  }
86 
87  public slots:
88  void processServerError(QProcess::ProcessError);
89  void processStandardError();
90 
91  private:
92  QTcpSocket serverSocket;
93  QString host;
94  int port;
95  QTemporaryFile serverBuffer;
96  std::unique_ptr<QProcess> serverProcess;
97 
98  void insertEnvironmentPath(QProcessEnvironment *env, const QString &variable, const QString &relativePath);
99 
100  ServerMode mode { SERVER_CLIENT };
101 
102  QList<DriverInfo *> m_ManagedDrivers;
103 
104  QList<DriverInfo *> m_PendingDrivers;
105 
106  QFile indiFIFO;
107 
108  signals:
109  void started();
110  void stopped();
111  void failed(const QString &message);
112  void terminated(const QString &message);
113 
114 
115  void newServerLog();
116 
117  // Driver Signals
118  void driverStarted(DriverInfo *driver);
119  void driverStopped(DriverInfo *driver);
120  void driverRestarted(DriverInfo *driver);
121  void driverFailed(DriverInfo *driver, const QString &message);
122 };
Q_OBJECTQ_OBJECT
bool contains(const T &value) const const
int size() const const
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.