Kstars

servermanager.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 <QFile>
12#include <QObject>
13#include <QProcess>
14#include <QTcpSocket>
15#include <QTemporaryFile>
16#include <QFuture>
17
18#include <memory>
19
20class DriverInfo;
21
22/**
23 * @class ServerManager
24 * ServerManager is responsible for starting and shutting local INDI servers.
25 *
26 * @author Jasem Mutlaq
27 */
28class ServerManager : public QObject
29{
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<QSharedPointer<DriverInfo>> drivers)
50 {
51 m_PendingDrivers = drivers;
52 }
53 const QList<QSharedPointer<DriverInfo>> &pendingDrivers() const
54 {
55 return m_PendingDrivers;
56 }
57
58 void startDriver(const QSharedPointer<DriverInfo> &driver);
59 void stopDriver(const QSharedPointer<DriverInfo> &driver);
60 bool restartDriver(const QSharedPointer<DriverInfo> &driver);
61
62 const QList<QSharedPointer<DriverInfo>> &managedDrivers() const
63 {
64 return m_ManagedDrivers;
65 }
66 bool contains(const QSharedPointer<DriverInfo> &driver)
67 {
68 return m_ManagedDrivers.contains(driver);
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 void connectScriptDriver(const QSharedPointer<DriverInfo> &driver);
91
92 private:
93 QTcpSocket serverSocket;
94 QString host;
95 int port;
96 QTemporaryFile serverBuffer;
97 std::unique_ptr<QProcess> serverProcess;
98
99 void insertEnvironmentPath(QProcessEnvironment *env, const QString &variable, const QString &relativePath);
100
101 ServerMode mode { SERVER_CLIENT };
102
103 QList<QSharedPointer<DriverInfo>> m_ManagedDrivers;
104
105 QList<QSharedPointer<DriverInfo>> m_PendingDrivers;
106
107 QFile indiFIFO;
108
109 signals:
110 void started();
111 void stopped();
112 void failed(const QString &message);
113 void terminated(const QString &message);
114 void newServerLog();
115
116 // Driver Signals
117 void driverStarted(const QSharedPointer<DriverInfo> &driver);
118 void driverStopped(const QSharedPointer<DriverInfo> &driver);
119 void driverRestarted(const QSharedPointer<DriverInfo> &driver);
120 void scriptDriverStarted(const QSharedPointer<DriverInfo> &driver);
121 void driverFailed(const QSharedPointer<DriverInfo> &driver, const QString &message);
122};
DriverInfo holds all metadata associated with a particular INDI driver.
Definition driverinfo.h:46
ServerManager is responsible for starting and shutting local INDI servers.
bool contains(const AT &value) const const
qsizetype size() const const
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:53:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.