Rok4Server.h
Aller à la documentation de ce fichier.
1 /*
2  * Copyright © (2011-2013) Institut national de l'information
3  * géographique et forestière
4  *
5  * Géoportail SAV <contact.geoservices@ign.fr>
6  *
7  * This software is a computer program whose purpose is to publish geographic
8  * data using OGC WMS and WMTS protocol.
9  *
10  * This software is governed by the CeCILL-C license under French law and
11  * abiding by the rules of distribution of free software. You can use,
12  * modify and/ or redistribute the software under the terms of the CeCILL-C
13  * license as circulated by CEA, CNRS and INRIA at the following URL
14  * "http://www.cecill.info".
15  *
16  * As a counterpart to the access to the source code and rights to copy,
17  * modify and redistribute granted by the license, users are provided only
18  * with a limited warranty and the software's author, the holder of the
19  * economic rights, and the successive licensors have only limited
20  * liability.
21  *
22  * In this respect, the user's attention is drawn to the risks associated
23  * with loading, using, modifying and/or developing or reproducing the
24  * software by the user in light of its specific status of free software,
25  * that may mean that it is complicated to manipulate, and that also
26  * therefore means that it is reserved for developers and experienced
27  * professionals having in-depth computer knowledge. Users are therefore
28  * encouraged to load and test the software's suitability as regards their
29  * requirements in conditions enabling the security of their systems and/or
30  * data to be ensured and, more generally, to use and operate it in the
31  * same conditions as regards security.
32  *
33  * The fact that you are presently reading this means that you have had
34  *
35  * knowledge of the CeCILL-C license and that you accept its terms.
36  */
37 
46 class Rok4Server;
47 
48 #ifndef _ROK4SERVER_
49 #define _ROK4SERVER_
50 
51 #include "config.h"
52 #include <rok4/datasource/DataSource.h>
53 #include "Request.h"
54 #include <pthread.h>
55 #include <map>
56 #include <vector>
57 #include "Layer.h"
58 #include <stdio.h>
59 #include <rok4/utils/TileMatrixSet.h>
60 #include "fcgiapp.h"
61 #include <csignal>
62 #include "ServerConf.h"
63 #include "ServicesConf.h"
64 #include "GetFeatureInfoEncoder.h"
65 #include <rok4/utils/BoundingBox.h>
66 
78 class Rok4Server {
79 private:
84  std::vector<pthread_t> threads;
85 
90  volatile bool running;
91 
96  int sock;
97 
102  int pid;
103 
108  long time;
109 
114  ServicesConf* servicesConf;
115 
120  ServerConf* serverConf;
121 
126  std::string wmsCapabilities;
127 
132  std::string wmtsCapabilities;
133 
138  std::string tmsCapabilities;
139 
144  std::map<std::string, std::string> ogctilesCapabilities;
145 
156  static void* thread_loop ( void* arg );
157 
158 
165  void buildWMSCapabilities();
166 
173  void buildWMTSCapabilities();
174 
181  void buildTMSCapabilities();
182 
189  void buildOGCTILESCapabilities();
190 
199  DataSource* getTileParamWMTS ( Request* request, Layer*& layer, TileMatrixSet*& tms, TileMatrix*& tm, int& tileCol, int& tileRow, std::string& format, Style*& style);
200 
209  DataSource* getTileParamTMS ( Request* request, Layer*& layer, TileMatrixSet*& tms, TileMatrix*& tm, int& tileCol, int& tileRow, std::string& format, Style*& style);
210 
219  DataSource* getTileParamOGCTILES ( Request* request, Layer*& layer, TileMatrixSet*& tms, TileMatrix*& tm, int& tileCol, int& tileRow, std::string& format, Style*& style);
220 
229  DataStream* getMapParamWMS ( Request* request, std::vector<Layer*>& layers, BoundingBox< double >& bbox, int& width, int& height, CRS*& crs, std::string& format, std::vector<Style*>& styles, std::map< std::string, std::string >& format_option,int& dpi);
230 
239  DataStream* getCapParamWMS ( Request* request, std::string& version );
240 
249  DataStream* getCapParamWMTS ( Request* request, std::string& version );
250 
259  DataStream* getLayerParamTMS ( Request* request, Layer*& layer );
260 
269  DataStream* getFeatureInfoParamWMS (
270  Request* request, std::vector<Layer*>& layers, std::vector<Layer*>& query_layers,
271  BoundingBox< double >& bbox, int& width, int& height, CRS*& crs, std::string& format,
272  std::vector<Style*>& styles, std::string& info_format, int& X, int& Y, int& feature_count,std::map <std::string, std::string >& format_option
273  );
274 
283  DataStream* getFeatureInfoParamWMTS ( Request* request, Layer*& layer, TileMatrixSet*& tms, TileMatrix*& tm, int &tileCol, int &tileRow, std::string &format, Style* &style, std::string& info_format, int& X, int& Y);
284 
303  Image *styleImage(Image *curImage, Rok4Format::eformat_data pyrType, Style *style, std::string format, int size, Pyramid *pyr);
304 
323  Image *mergeImages(std::vector<Image*> images, Rok4Format::eformat_data &pyrType, Style *style, CRS* crs, BoundingBox<double> bbox);
324 
345  DataStream *formatImage(Image *image, std::string format, Rok4Format::eformat_data pyrType, std::map<std::string, std::string> format_option, int size, Style *style);
346 
357  DataStream* WMSGetCapabilities ( Request* request );
358 
369  DataStream* WMTSGetCapabilities ( Request* request );
370 
381  DataStream* TMSGetCapabilities ( Request* request );
382 
393  DataStream* OGCTILESGetCapabilities ( Request* request );
394 
405  DataStream* GlobalGetServices ( Request* request );
406 
417  DataStream* TMSGetLayer ( Request* request );
418 
429  DataStream* TMSGetLayerMetadata ( Request* request );
430 
441  DataStream* TMSGetLayerGDAL ( Request* request );
442 
453  DataStream* AdminCreateLayer ( Request* request );
454 
465  DataStream* AdminBuildCapabilities ( Request* request );
466 
477  DataStream* AdminDeleteLayer ( Request* request );
478 
489  DataStream* AdminUpdateLayer ( Request* request );
490 
501  DataStream* getMap ( Request* request );
502 
513  DataSource* getTile ( Request* request );
514 
525  DataStream* WMSGetFeatureInfo ( Request* request );
526 
537  DataStream* WMTSGetFeatureInfo ( Request* request );
538 
549  DataStream* OGCTILESGetFeatureInfo ( Request* request );
550 
551  DataStream* CommonGetFeatureInfo ( std::string service, Layer* layer, BoundingBox<double> bbox, int width, int height, CRS* crs, std::string info_format , int X, int Y, std::string format, int feature_count);
552 
557  void processWMS ( Request *request, FCGX_Request& fcgxRequest );
562  void processWMTS ( Request *request, FCGX_Request& fcgxRequest );
567  void processTMS ( Request *request, FCGX_Request& fcgxRequest );
572  void processOGCTILES ( Request *request, FCGX_Request& fcgxRequest );
577  void processAdmin ( Request *request, FCGX_Request& fcgxRequest );
582  void processHealthCheck ( Request *request, FCGX_Request& fcgxRequest );
587  void processGlobal ( Request *request, FCGX_Request& fcgxRequest );
592  void processRequest ( Request *request, FCGX_Request& fcgxRequest );
593 
606  static std::vector<std::string> split ( const std::string &s, char delim ) {
607  std::vector<std::string> elems;
608  std::stringstream ss ( s );
609  std::string item;
610  while ( std::getline ( ss, item, delim ) ) {
611  elems.push_back ( item );
612  }
613  return elems;
614  }
615 
620  static std::string numToStr ( long int i ) {
621  std::ostringstream strstr;
622  strstr << i;
623  return strstr.str();
624  }
625 
630  static std::string doubleToStr ( long double d ) {
631  std::ostringstream strstr;
632  strstr.setf ( std::ios::fixed,std::ios::floatfield );
633  strstr.precision ( 16 );
634  strstr << d;
635  return strstr.str();
636  }
637 
650  static std::string getParam ( std::map<std::string, std::string>& option, std::string paramName ) {
651  std::map<std::string, std::string>::iterator it = option.find ( paramName );
652  if ( it == option.end() ) {
653  return "";
654  }
655  return it->second;
656  }
657 public:
668 
673  std::map<std::string, Layer*>& getLayerList() ;
674 
681  void run(sig_atomic_t signal_pending = 0);
688  void initFCGI();
698  int getFCGISocket() ;
699 
710  void setFCGISocket ( int sockFCGI ) ;
711 
718  void setPID ( int processID );
719 
726  int getPID();
727 
734  void setTime ( long processTime );
735 
742  long getTime();
743 
750  void terminate();
751 
760  bool isRunning() ;
761 
765  Rok4Server ( ServerConf* svr, ServicesConf* svc);
772  virtual ~Rok4Server ();
773 
774 };
775 
776 #endif
777 
Rok4Server::getPID
int getPID()
Obtient le PID du process principal.
Definition: Rok4Server.cpp:985
Rok4Server::getLayerList
std::map< std::string, Layer * > & getLayerList()
Definition: Rok4Server.cpp:981
Rok4Server::terminate
void terminate()
Demande l'arrêt du serveur.
Definition: Rok4Server.cpp:201
Rok4Server::getServerConf
ServerConf * getServerConf()
Definition: Rok4Server.cpp:980
Layer.h
Définition de la classe Layer modélisant les couches de données.
Rok4Server::run
void run(sig_atomic_t signal_pending=0)
Lancement des threads du serveur.
Definition: Rok4Server.cpp:185
Rok4Server::initFCGI
void initFCGI()
Initialise le socket FastCGI.
Definition: Rok4Server.cpp:179
Layer
Gestion des couches.
Definition: Layer.h:95
Rok4Server::Rok4Server
Rok4Server(ServerConf *svr, ServicesConf *svc)
Construction du serveur.
Definition: Rok4Server.cpp:140
Request.h
Définition de la classe Request, analysant les requêtes HTTP.
Rok4Server::getServicesConf
ServicesConf * getServicesConf()
Definition: Rok4Server.cpp:979
ServicesConf
Definition: ServicesConf.h:54
ServerConf
Definition: ServerConf.h:55
Rok4Server::isRunning
bool isRunning()
Retourne l'état du serveur.
Definition: Rok4Server.cpp:989
Request
Gestion des requêtes HTTP.
Definition: Request.h:176
Rok4Server::setTime
void setTime(long processTime)
Stocke la date du process principal.
Definition: Rok4Server.cpp:988
Rok4Server::getFCGISocket
int getFCGISocket()
Retourne la représentation interne du socket FastCGI.
Definition: Rok4Server.cpp:983
Rok4Server::~Rok4Server
virtual ~Rok4Server()
Destructeur par défaut.
Definition: Rok4Server.cpp:174
Rok4Server::setFCGISocket
void setFCGISocket(int sockFCGI)
Restaure le socket FastCGI.
Definition: Rok4Server.cpp:984
Rok4Server
Gestion du programme principal, lien entre les modules.
Definition: Rok4Server.h:78
Rok4Server::getTime
long getTime()
Obtient la date du process principal.
Definition: Rok4Server.cpp:987
Rok4Server::setPID
void setPID(int processID)
Stocke le PId du process principal.
Definition: Rok4Server.cpp:986