QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
server
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
"
26
#include "
qgsfcgiserverrequest.h
"
27
#include "
qgsfcgiserverresponse.h
"
28
#include "
qgsserver.h
"
29
30
#include <QFontDatabase>
31
#include <QString>
32
33
#include <fcgi_stdio.h>
34
35
using namespace
Qt::StringLiterals;
36
37
int
fcgi_accept
()
38
{
39
#ifdef Q_OS_WIN
40
if
( FCGX_IsCGI() )
41
return
FCGI_Accept();
42
else
43
return
FCGX_Accept( &FCGI_stdin->fcgx_stream, &FCGI_stdout->fcgx_stream, &FCGI_stderr->fcgx_stream, &environ );
44
#else
45
return
FCGI_Accept();
46
#endif
47
}
48
49
int
main
(
int
argc,
char
*argv[] )
50
{
51
if
( argc >= 2 )
52
{
53
if
( argv[1] ==
"--version"
_L1 || argv[1] ==
"-v"
_L1 )
54
{
55
std::cout <<
QgsCommandLineUtils::allVersions
().toStdString();
56
return
0;
57
}
58
}
59
60
// Test if the environ variable DISPLAY is defined
61
// if it's not, the server is running in offscreen mode
62
// Qt supports using various QPA (Qt Platform Abstraction) back ends
63
// for rendering. You can specify the back end to use with the environment
64
// variable QT_QPA_PLATFORM when invoking a Qt-based application.
65
// Available platform plugins are: directfbegl, directfb, eglfs, linuxfb,
66
// minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
67
// https://www.ics.com/blog/qt-tips-and-tricks-part-1
68
// http://doc.qt.io/qt-5/qpa.html
69
const
char
*display = getenv(
"DISPLAY"
);
70
bool
withDisplay =
true
;
71
if
( !display )
72
{
73
withDisplay =
false
;
74
qputenv(
"QT_QPA_PLATFORM"
,
"offscreen"
);
75
QgsMessageLog::logMessage
(
"DISPLAY not set, running in offscreen mode, all printing capabilities will not be available."
,
"Server"
,
Qgis::MessageLevel::Info
);
76
}
77
// since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
78
const
QgsApplication
app( argc, argv, withDisplay, QString(), u
"server"
_s );
79
QgsServer
server;
80
#ifdef HAVE_SERVER_PYTHON_PLUGINS
81
server.initPython();
82
#endif
83
84
#ifdef Q_OS_WIN
85
// Initialize font database before fcgi_accept.
86
// When using FCGI with IIS, environment variables (QT_QPA_FONTDIR in this case) are lost after fcgi_accept().
87
QFontDatabase fontDB;
88
#endif
89
90
// Starts FCGI loop
91
while
(
fcgi_accept
() >= 0 )
92
{
93
QgsFcgiServerRequest
request;
94
QgsFcgiServerResponse
response( request.
method
() );
95
if
( !request.
hasError
() )
96
{
97
server.
handleRequest
( request, response );
98
}
99
else
100
{
101
response.
sendError
( 400,
"Bad request"
);
102
}
103
}
104
QgsApplication::exitQgis
();
105
return
0;
106
}
Qgis::Info
@ Info
Information message.
Definition
qgis.h:161
QgsApplication
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
Definition
qgsapplication.h:107
QgsApplication::exitQgis
static void exitQgis()
deletes provider registry and map layer registry
Definition
qgsapplication.cpp:1677
QgsCommandLineUtils::allVersions
static QString allVersions()
Display all versions in the standard output stream.
Definition
qgscommandlineutils.cpp:44
QgsFcgiServerRequest
Defines fcgi requests.
Definition
qgsfcgiserverrequest.h:31
QgsFcgiServerRequest::hasError
bool hasError() const
Returns true if an error occurred during initialization.
Definition
qgsfcgiserverrequest.h:40
QgsFcgiServerResponse
Defines fcgi responses.
Definition
qgsfcgiserverresponse.h:73
QgsFcgiServerResponse::sendError
void sendError(int code, const QString &message) override
Send error This method delegates error handling at the server level.
Definition
qgsfcgiserverresponse.cpp:295
QgsMessageLog::logMessage
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Definition
qgsmessagelog.cpp:35
QgsServerRequest::method
QgsServerRequest::Method method() const
Returns the request method.
Definition
qgsserverrequest.cpp:113
QgsServer
A server which provides OGC web services.
Definition
qgsserver.h:50
QgsServer::handleRequest
void handleRequest(QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project=nullptr)
Handles the request.
Definition
qgsserver.cpp:405
main
int main(int argc, char *argv[])
Definition
qgis_map_serv.cpp:49
fcgi_accept
int fcgi_accept()
Definition
qgis_map_serv.cpp:37
qgsapplication.h
qgscommandlineutils.h
qgsfcgiserverrequest.h
qgsfcgiserverresponse.h
qgsserver.h
Generated on
for QGIS API Documentation by
1.17.0