Enroute Flight Navigation
A navigation app for VFR pilots
TileServer.h
1/***************************************************************************
2 * Copyright (C) 2019-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include "fileFormats/MBTILES.h"
24#include "geomaps/TileHandler.h"
25
26#include <QAbstractHttpServer>
27#include <QCoreApplication>
28#include <QSharedPointer>
29
30
31namespace GeoMaps {
32
69
70class TileServer : public QAbstractHttpServer
71{
72 Q_OBJECT
73
74public:
83 explicit TileServer(QObject* parent = nullptr);
84
85 // Standard destructor
86 ~TileServer() override = default;
87
88
89
90 //
91 // Properties
92 //
93
102 Q_PROPERTY(QString serverUrl READ serverUrl NOTIFY serverUrlChanged)
103
104
105
106 //
107 // Getter Methods
108 //
109
110
114 [[nodiscard]] QString serverUrl();
115
116
117public slots:
138 void addMbtilesFileSet(const QString& baseName, const QVector<QSharedPointer<FileFormats::MBTILES>>& MBTilesFiles);
139
144 void removeMbtilesFileSet(const QString& baseName) {m_tileHandlers.take(baseName);}
145
150 void removeMbtilesFileSets() {m_tileHandlers.clear();}
151
152
153signals:
156
157
158private:
159 Q_DISABLE_COPY_MOVE(TileServer)
160
161 // Implemented pure virtual method from QAbstractHttpServer
162 bool handleRequest(const QHttpServerRequest& request, QHttpServerResponder& responder) override;
163
164 // Implemented pure virtual method from QAbstractHttpServer
165 void missingHandler(const QHttpServerRequest& request, QHttpServerResponder& responder) override;
166
167#if defined(Q_OS_IOS)
179 void restart();
180#endif
181
182#if defined(Q_OS_ANDROID)
183 // Name of the local socket. QLocalServer places simple names in the
184 // temporary directory; the PID keeps parallel instances apart. Lowercase
185 // letters, digits and hyphens only, because the name doubles as the host
186 // part of the server URL.
187 const QString m_socketName {QStringLiteral("enroute-tiles-%1").arg(QCoreApplication::applicationPid())};
188#endif
189
190 // List of tile handlers
191 QMap<QString, QSharedPointer<GeoMaps::TileHandler>> m_tileHandlers;
192
193 // Night-mode sprite sheets, keyed by resource file name of the day-mode
194 // original. Computing the recolored PNGs is not free, so they are cached
195 // here after the first request. The transform is deterministic, so entries
196 // never need to be invalidated.
197 QMap<QString, QByteArray> m_nightSprites;
198
199 // Internal variable. Indicates if the app has been suspended.
200 // This is used on changes of QGuiApplication::applicationState,
201 // to check if the application is currently awaking from sleep,
202 // so that the server needs to be restarted (if on iOS).
203#if defined(Q_OS_IOS)
204 bool suspended = false;
205#endif
206};
207
208} // namespace GeoMaps
TileServer(QObject *parent=nullptr)
Create a new tile server.
void serverUrlChanged()
Notification signal for the property with the same name.
void removeMbtilesFileSet(const QString &baseName)
Removes a set of tile files.
Definition TileServer.h:144
QString serverUrl
URL under which this server is presently reachable.
Definition TileServer.h:102
void removeMbtilesFileSets()
Removes a set of tile files.
Definition TileServer.h:150
void addMbtilesFileSet(const QString &baseName, const QVector< QSharedPointer< FileFormats::MBTILES > > &MBTilesFiles)
Add a new set of tile files.
QString serverUrl()
Getter function for the property with the same name.