Skip to content
Permalink
Browse files

Renamed static members and moved init into ctor

  • Loading branch information
elpaso committed Feb 23, 2016
1 parent 1c177d0 commit d2665826a1fae146b4f8703f3e259076a580ee33
Showing with 89 additions and 76 deletions.
  1. +1 −2 src/server/qgis_map_serv.cpp
  2. +52 −45 src/server/qgsserver.cpp
  3. +23 −16 src/server/qgsserver.h
  4. +11 −11 src/server/qgsserverplugins.cpp
  5. +2 −2 src/server/qgsserverplugins.h
@@ -36,8 +36,7 @@ int fcgi_accept()

int main( int argc, char * argv[] )
{
QgsServer server;
server.init( argc, argv );
QgsServer server( argc, argv );
// Starts FCGI loop
while ( fcgi_accept() >= 0 )
{
@@ -54,24 +54,36 @@
#include <stdlib.h>


// Static initialisers, default values for fcgi server
QgsApplication* QgsServer::mQgsApplication = nullptr;
bool QgsServer::mInitialised = false;
bool QgsServer::mCaptureOutput = false;
char* QgsServer::mArgv[1];
int QgsServer::mArgc = 1;
QString QgsServer::mConfigFilePath;
QgsMapRenderer* QgsServer::mMapRenderer = nullptr;
QgsCapabilitiesCache* QgsServer::mCapabilitiesCache;

// Server status static initialisers.
// Default values are for C++, SIP bindings will override their
// options in in init()

QString QgsServer::sConfigFilePath = QString();
QgsCapabilitiesCache* QgsServer::sCapabilitiesCache = nullptr;
QgsMapRenderer* QgsServer::sMapRenderer = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
bool QgsServer::mInitPython = true;
QgsServerInterfaceImpl* QgsServer::mServerInterface = nullptr;
QgsServerInterfaceImpl*QgsServer::sServerInterface = nullptr;
bool QgsServer::sInitPython = true;
#endif
// Initialization must run once for all servers
bool QgsServer::sInitialised = false;
char* QgsServer::sArgv[1];
int QgsServer::sArgc;
QgsApplication* QgsServer::sQgsApplication = nullptr;
bool QgsServer::sCaptureOutput = false;



QgsServer::QgsServer( int &argc, char **argv )
{
init( argc, argv );
}


QgsServer::QgsServer()
{
init();
}


@@ -298,17 +310,18 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
*/
bool QgsServer::init()
{
if ( mInitialised )
if ( sInitialised )
{
return false;
}
mArgv[0] = serverName().toUtf8().data();
mArgc = 1;
mCaptureOutput = true;

sArgv[0] = serverName().toUtf8().data();
sArgc = 1;
sCaptureOutput = true;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mInitPython = false;
sInitPython = false;
#endif
return init( mArgc , mArgv );
return init( sArgc , sArgv );
}


@@ -317,7 +330,7 @@ bool QgsServer::init()
*/
bool QgsServer::init( int & argc, char ** argv )
{
if ( mInitialised )
if ( sInitialised )
{
return false;
}
@@ -336,7 +349,7 @@ bool QgsServer::init( int & argc, char ** argv )
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath );
}

mQgsApplication = new QgsApplication( argc, argv, getenv( "DISPLAY" ), QString(), "server" );
sQgsApplication = new QgsApplication( argc, argv, getenv( "DISPLAY" ), QString(), "server" );

QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME );
QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN );
@@ -392,24 +405,24 @@ bool QgsServer::init( int & argc, char ** argv )
}
if ( !defaultConfigFilePath.isEmpty() )
{
mConfigFilePath = defaultConfigFilePath;
sConfigFilePath = defaultConfigFilePath;
}

//create cache for capabilities XML
mCapabilitiesCache = new QgsCapabilitiesCache();
mMapRenderer = new QgsMapRenderer;
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
sCapabilitiesCache = new QgsCapabilitiesCache();
sMapRenderer = new QgsMapRenderer;
sMapRenderer->setLabelingEngine( new QgsPalLabeling() );

#ifdef ENABLE_MS_TESTS
QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" );
#endif

#ifdef HAVE_SERVER_PYTHON_PLUGINS
mServerInterface = new QgsServerInterfaceImpl( mCapabilitiesCache );
if ( mInitPython )
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache );
if ( sInitPython )
{
// Init plugins
if ( ! QgsServerPlugins::initPlugins( mServerInterface ) )
if ( ! QgsServerPlugins::initPlugins( sServerInterface ) )
{
QgsMessageLog::logMessage( "No server python plugins are available", "Server", QgsMessageLog::INFO );
}
@@ -421,7 +434,7 @@ bool QgsServer::init( int & argc, char ** argv )
#endif

QgsEditorWidgetRegistry::initEditors();
mInitialised = true;
sInitialised = true;
QgsMessageLog::logMessage( "Server initialized", "Server", QgsMessageLog::INFO );
return true;
}
@@ -442,12 +455,6 @@ void QgsServer::putenv( const QString &var, const QString &val )
*/
QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryString )
{
// Run init if handleRequest was called without previously initialising
// the server
if ( ! mInitialised )
{
init();
}

/*
* This is mainly for python bindings, passing QUERY_STRING
@@ -459,15 +466,15 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
int logLevel = QgsServerLogger::instance()->logLevel();
QTime time; //used for measuring request time if loglevel < 1
QgsMapLayerRegistry::instance()->removeAllMapLayers();
mQgsApplication->processEvents();
sQgsApplication->processEvents();
if ( logLevel < 1 )
{
time.start();
printRequestInfos();
}

//Request handler
QScopedPointer<QgsRequestHandler> theRequestHandler( createRequestHandler( mCaptureOutput ) );
QScopedPointer<QgsRequestHandler> theRequestHandler( createRequestHandler( sCaptureOutput ) );

try
{
@@ -482,10 +489,10 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri

#ifdef HAVE_SERVER_PYTHON_PLUGINS
// Set the request handler into the interface for plugins to manipulate it
mServerInterface->setRequestHandler( theRequestHandler.data() );
sServerInterface->setRequestHandler( theRequestHandler.data() );
// Iterate filters and call their requestReady() method
QgsServerFiltersMap::const_iterator filtersIterator;
QgsServerFiltersMap filters = mServerInterface->filters();
QgsServerFiltersMap filters = sServerInterface->filters();
for ( filtersIterator = filters.constBegin(); filtersIterator != filters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->requestReady();
@@ -494,22 +501,22 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
//Pass the filters to the requestHandler, this is needed for the following reasons:
// 1. allow core services to access plugin filters and implement thir own plugin hooks
// 2. allow requestHandler to call sendResponse plugin hook
theRequestHandler->setPluginFilters( mServerInterface->filters() );
theRequestHandler->setPluginFilters( sServerInterface->filters() );
#endif

// Copy the parameters map
QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() );
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* accessControl = nullptr;
accessControl = mServerInterface->accessControls();
accessControl = sServerInterface->accessControls();
#endif

printRequestParameters( parameterMap, logLevel );
QMap<QString, QString>::const_iterator paramIt;
//Config file path
QString configFilePath = configPath( mConfigFilePath, parameterMap );
QString configFilePath = configPath( sConfigFilePath, parameterMap );
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mServerInterface->setConfigFilePath( configFilePath );
sServerInterface->setConfigFilePath( configFilePath );
#endif
//Service parameter
QString serviceString = theRequestHandler->parameter( "SERVICE" );
@@ -606,8 +613,8 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
, parameterMap
, p
, theRequestHandler.data()
, mMapRenderer
, mCapabilitiesCache
, sMapRenderer
, sCapabilitiesCache
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, accessControl
#endif
@@ -623,14 +630,14 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri

#ifdef HAVE_SERVER_PYTHON_PLUGINS
// Iterate filters and call their responseComplete() method
filters = mServerInterface->filters();
filters = sServerInterface->filters();
for ( filtersIterator = filters.constBegin(); filtersIterator != filters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->responseComplete();
}
// We are done using theRequestHandler in plugins, make sure we don't access
// to a deleted request handler from Python bindings
mServerInterface->clearRequestHandler();
sServerInterface->clearRequestHandler();
#endif

theRequestHandler->sendResponse();
@@ -47,11 +47,16 @@
class SERVER_EXPORT QgsServer
{
public:
/**
* Standard ctor for CGI/FCGI
* @note Not available in Python bindings
*/
QgsServer( int & argc, char ** argv );
//! The following is mainly for python bindings, that do not pass argc/argv
QgsServer();
~QgsServer();

/** Server initialization: intialise QGIS ang QT core application.
* This method is automatically called by handleRequest if it wasn't
* explicitly called before
* @note Not available in Python bindings
*/
static bool init( int & argc, char ** argv );
@@ -84,7 +89,7 @@ class SERVER_EXPORT QgsServer

/** Returns a pointer to the server interface */
#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsServerInterfaceImpl* serverInterface() { return mServerInterface; }
QgsServerInterfaceImpl* serverInterface() { return sServerInterface; }
#endif

private:
@@ -106,21 +111,23 @@ class SERVER_EXPORT QgsServer
//! Create and return a request handler instance
static QgsRequestHandler* createRequestHandler( const bool captureOutput = false );

// Server status
static QString mConfigFilePath;
static QgsCapabilitiesCache* mCapabilitiesCache;
static QgsMapRenderer* mMapRenderer;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
static QgsServerInterfaceImpl* mServerInterface;
static bool mInitPython;
#endif
static bool mInitialised;
static char* mArgv[1];
static int mArgc;
static QgsApplication* mQgsApplication;
static bool mCaptureOutput;
// Return the server name
static QString &serverName();

// Status
static QString sConfigFilePath;
static QgsCapabilitiesCache* sCapabilitiesCache;
static QgsMapRenderer* sMapRenderer;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
static QgsServerInterfaceImpl* sServerInterface;
static bool sInitPython;
#endif
//! Initialization must run once for all servers
static bool sInitialised;
static char* sArgv[1];
static int sArgc;
static QgsApplication* sQgsApplication;
static bool sCaptureOutput;
};
#endif // QGSSERVER_H

@@ -28,21 +28,21 @@


// Initialize static members
QgsPythonUtils* QgsServerPlugins::mPythonUtils;
QgsPythonUtils* QgsServerPlugins::sPythonUtils;


QgsServerPlugins::QgsServerPlugins()
{
}


// Initialize static members
// Construct on first use
QStringList &QgsServerPlugins::serverPlugins()
{
static QStringList* pluginList = new QStringList();
return *pluginList;
}


// This code is mainly borrowed from QGIS desktop Python plugin initialization
bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
{
@@ -81,10 +81,10 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
}

QgsDebugMsg( "Python support library's instance() symbol resolved." );
mPythonUtils = pythonlib_inst();
mPythonUtils->initServerPython( interface );
sPythonUtils = pythonlib_inst();
sPythonUtils->initServerPython( interface );

if ( mPythonUtils && mPythonUtils->isEnabled() )
if ( sPythonUtils && sPythonUtils->isEnabled() )
{
QgsDebugMsg( "Python support ENABLED :-)" );
}
@@ -96,17 +96,17 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )

//Init plugins: loads a list of installed plugins and filter them
//for "server" metadata
QListIterator<QString> plugins( mPythonUtils->pluginList() );
QListIterator<QString> plugins( sPythonUtils->pluginList() );
bool atLeastOneEnabled = false;
while ( plugins.hasNext() )
{
QString pluginName = plugins.next();
QString pluginService = mPythonUtils->getPluginMetadata( pluginName, "server" );
QString pluginService = sPythonUtils->getPluginMetadata( pluginName, "server" );
if ( pluginService == "True" )
{
if ( mPythonUtils->loadPlugin( pluginName ) )
if ( sPythonUtils->loadPlugin( pluginName ) )
{
if ( mPythonUtils->startServerPlugin( pluginName ) )
if ( sPythonUtils->startServerPlugin( pluginName ) )
{
atLeastOneEnabled = true;
serverPlugins().append( pluginName );
@@ -123,7 +123,7 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
}
}
}
return mPythonUtils && mPythonUtils->isEnabled() && atLeastOneEnabled;
return sPythonUtils && sPythonUtils->isEnabled() && atLeastOneEnabled;
}


@@ -37,10 +37,10 @@ class SERVER_EXPORT QgsServerPlugins
* @return bool true on success
*/
static bool initPlugins( QgsServerInterface* interface );
//! Pointer to QgsPythonUtils
static QgsPythonUtils* mPythonUtils;
//! List of available server plugin names
static QStringList& serverPlugins();
//! Pointer to QgsPythonUtils
static QgsPythonUtils* sPythonUtils;
};

#endif // QGSSERVERPLUGINS_H

0 comments on commit d266582

Please sign in to comment.
You can’t perform that action at this time.