QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgis_map_serv.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs_map_serv.cpp
3 A server application supporting WMS / WFS / WCS
4 -------------------
5 begin : July 04, 2006
6 copyright : (C) 2006 by Marco Hugentobler & Ionut Iosifescu Enescu
7 email : marco dot hugentobler at karto dot baug dot ethz dot ch
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19//for CMAKE_INSTALL_PREFIX
20#include "qgsconfig.h"
21
22#include <cstdlib>
23
24#include "qgsapplication.h"
25#include "qgscommandlineutils.h"
28#include "qgsserver.h"
29
30#include <QFontDatabase>
31#include <QString>
32
33#include <fcgi_stdio.h>
34
36{
37#ifdef Q_OS_WIN
38 if ( FCGX_IsCGI() )
39 return FCGI_Accept();
40 else
41 return FCGX_Accept( &FCGI_stdin->fcgx_stream, &FCGI_stdout->fcgx_stream, &FCGI_stderr->fcgx_stream, &environ );
42#else
43 return FCGI_Accept();
44#endif
45}
46
47int main( int argc, char *argv[] )
48{
49 if ( argc >= 2 )
50 {
51 if ( argv[1] == QLatin1String( "--version" ) || argv[1] == QLatin1String( "-v" ) )
52 {
53 std::cout << QgsCommandLineUtils::allVersions().toStdString();
54 return 0;
55 }
56 }
57
58 // Test if the environ variable DISPLAY is defined
59 // if it's not, the server is running in offscreen mode
60 // Qt supports using various QPA (Qt Platform Abstraction) back ends
61 // for rendering. You can specify the back end to use with the environment
62 // variable QT_QPA_PLATFORM when invoking a Qt-based application.
63 // Available platform plugins are: directfbegl, directfb, eglfs, linuxfb,
64 // minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
65 // https://www.ics.com/blog/qt-tips-and-tricks-part-1
66 // http://doc.qt.io/qt-5/qpa.html
67 const char *display = getenv( "DISPLAY" );
68 bool withDisplay = true;
69 if ( !display )
70 {
71 withDisplay = false;
72 qputenv( "QT_QPA_PLATFORM", "offscreen" );
73 QgsMessageLog::logMessage( "DISPLAY not set, running in offscreen mode, all printing capabilities will not be available.", "Server", Qgis::MessageLevel::Info );
74 }
75 // since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
76 const QgsApplication app( argc, argv, withDisplay, QString(), QStringLiteral( "server" ) );
77 QgsServer server;
78#ifdef HAVE_SERVER_PYTHON_PLUGINS
79 server.initPython();
80#endif
81
82#ifdef Q_OS_WIN
83 // Initialize font database before fcgi_accept.
84 // When using FCGI with IIS, environment variables (QT_QPA_FONTDIR in this case) are lost after fcgi_accept().
85 QFontDatabase fontDB;
86#endif
87
88 // Starts FCGI loop
89 while ( fcgi_accept() >= 0 )
90 {
92 QgsFcgiServerResponse response( request.method() );
93 if ( !request.hasError() )
94 {
95 server.handleRequest( request, response );
96 }
97 else
98 {
99 response.sendError( 400, "Bad request" );
100 }
101 }
103 return 0;
104}
@ Info
Information message.
Definition qgis.h:157
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
static void exitQgis()
deletes provider registry and map layer registry
static QString allVersions()
Display all versions in the standard output stream.
Defines fcgi requests.
bool hasError() const
Returns true if an error occurred during initialization.
Defines fcgi responses.
void sendError(int code, const QString &message) override
Send error This method delegates error handling at the server level.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
QgsServerRequest::Method method() const
Returns the request method.
A server which provides OGC web services.
Definition qgsserver.h:50
void handleRequest(QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project=nullptr)
Handles the request.
int main(int argc, char *argv[])
int fcgi_accept()