QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgsserver.h"
22 #include "qgslogger.h"
23 #include "qgsserverlogger.h"
24 #include "qgsfcgiserverresponse.h"
25 #include "qgsfcgiserverrequest.h"
26 
27 #include <fcgi_stdio.h>
28 #include <cstdlib>
29 
31 {
32 #ifdef Q_OS_WIN
33  if ( FCGX_IsCGI() )
34  return FCGI_Accept();
35  else
36  return FCGX_Accept( &FCGI_stdin->fcgx_stream, &FCGI_stdout->fcgx_stream, &FCGI_stderr->fcgx_stream, &environ );
37 #else
38  return FCGI_Accept();
39 #endif
40 }
41 
42 int main( int argc, char *argv[] )
43 {
44  // Test if the environ variable DISPLAY is defined
45  // if it's not, the server is running in offscreen mode
46  // Qt supports using various QPA (Qt Platform Abstraction) back ends
47  // for rendering. You can specify the back end to use with the environment
48  // variable QT_QPA_PLATFORM when invoking a Qt-based application.
49  // Available platform plugins are: directfbegl, directfb, eglfs, linuxfb,
50  // minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
51  // https://www.ics.com/blog/qt-tips-and-tricks-part-1
52  // http://doc.qt.io/qt-5/qpa.html
53  const char *display = getenv( "DISPLAY" );
54  bool withDisplay = true;
55  if ( !display )
56  {
57  withDisplay = false;
58  qputenv( "QT_QPA_PLATFORM", "offscreen" );
59  QgsMessageLog::logMessage( "DISPLAY not set, running in offscreen mode, all printing capabilities will not be available.", "Server", Qgis::Info );
60  }
61  // since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
62  QgsApplication app( argc, argv, withDisplay, QString(), QStringLiteral( "server" ) );
63  QgsServer server;
64 #ifdef HAVE_SERVER_PYTHON_PLUGINS
65  server.initPython();
66 #endif
67  // Starts FCGI loop
68  while ( fcgi_accept() >= 0 )
69  {
70  QgsFcgiServerRequest request;
71  QgsFcgiServerResponse response( request.method() );
72  if ( ! request.hasError() )
73  {
74  server.handleRequest( request, response );
75  }
76  else
77  {
78  response.sendError( 400, "Bad request" );
79  }
80  }
81  app.exitQgis();
82  return 0;
83 }
84 
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
int fcgi_accept()
int main(int argc, char *argv[])
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Class defining fcgi response.
The QgsServer class provides OGC web services.
Definition: qgsserver.h:52
bool hasError() const
Returns true if an error occurred during initialization.
QgsServerRequest::Method method() const
Class defining fcgi request.
static void exitQgis()
deletes provider registry and map layer registry
void handleRequest(QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project=nullptr)
Handles the request.
Definition: qgsserver.cpp:297