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#include <QMutex>
18
19#include <memory>
20
21class DriverInfo;
22
23/**
24 * @class ServerManager
25 * ServerManager is responsible for starting and shutting local INDI servers.
26 *
27 * @author Jasem Mutlaq
28 */
29class ServerManager : public QObject
30{
32
33 public:
34 ServerManager(const QString &inHost, int inPort);
35 ~ServerManager() override;
36
37 bool start();
38 void stop();
39
40 QString getLogBuffer();
41 const QString &getHost() const
42 {
43 return host;
44 }
45 int getPort() const
46 {
47 return port;
48 }
49
50 void setPendingDrivers(QList<QSharedPointer<DriverInfo>> drivers)
51 {
52 QMutexLocker locker(&m_PendingMutex);
53 m_PendingDrivers = drivers;
54 }
55 QList<QSharedPointer<DriverInfo>> pendingDrivers() const
56 {
57 QMutexLocker locker(&m_PendingMutex);
58 return m_PendingDrivers;
59 }
60
61 void startDriver(const QSharedPointer<DriverInfo> &driver);
62 void stopDriver(const QSharedPointer<DriverInfo> &driver);
63 bool restartDriver(const QSharedPointer<DriverInfo> &driver);
64
65 QList<QSharedPointer<DriverInfo>> managedDrivers() const
66 {
67 QMutexLocker locker(&m_DriverMutex);
68 return m_ManagedDrivers;
69 }
70 bool contains(const QSharedPointer<DriverInfo> &driver)
71 {
72 QMutexLocker locker(&m_DriverMutex);
73 return m_ManagedDrivers.contains(driver);
74 }
75
76 void setMode(ServerMode inMode)
77 {
78 mode = inMode;
79 }
80 ServerMode getMode()
81 {
82 return mode;
83 }
84
85 QString errorString();
86
87 int size()
88 {
89 QMutexLocker locker(&m_DriverMutex);
90 return m_ManagedDrivers.size();
91 }
92
93 public slots:
94 void processServerError(QProcess::ProcessError);
95 void processStandardError();
96 void connectScriptDriver(const QSharedPointer<DriverInfo> &driver);
97
98 private:
99 QTcpSocket serverSocket;
100 QString host;
101 int port;
102 QTemporaryFile serverBuffer;
103 std::unique_ptr<QProcess> serverProcess;
104
105 void insertEnvironmentPath(QProcessEnvironment *env, const QString &variable, const QString &relativePath);
106
107 ServerMode mode { SERVER_CLIENT };
108
109 // Protected by m_DriverMutex for concurrent access from main thread and QtConcurrent thread
110 QList<QSharedPointer<DriverInfo>> m_ManagedDrivers;
111 QList<QSharedPointer<DriverInfo>> m_PendingDrivers;
112
113 mutable QMutex m_DriverMutex;
114 mutable QMutex m_PendingMutex;
115
116
117 QFile indiFIFO;
118
119 signals:
120 void started();
121 void stopped();
122 void failed(const QString &message);
123 void terminated(const QString &message);
124 void newServerLog();
125
126 // Driver Signals
127 void driverStarted(const QSharedPointer<DriverInfo> &driver);
128 void driverStopped(const QSharedPointer<DriverInfo> &driver);
129 void driverRestarted(const QSharedPointer<DriverInfo> &driver);
130 void scriptDriverStarted(const QSharedPointer<DriverInfo> &driver);
131 void driverFailed(const QSharedPointer<DriverInfo> &driver, const QString &message);
132};
DriverInfo holds all metadata associated with a particular INDI driver.
Definition driverinfo.h:46
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:56:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.