Message.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 #ifndef _MESSAGE_
47 #define _MESSAGE_
48 
49 #include <rok4/datastream/DataStream.h>
50 #include <rok4/datasource/DataSource.h>
51 #include <string.h> // Pour memcpy
52 #include "ServiceException.h"
53 #include <vector>
54 
67 class MessageDataSource : public DataSource {
68 private:
73  std::string type;
74 protected:
79  std::string message;
80 public:
90  MessageDataSource ( std::string message, std::string type ) : message ( message ), type ( type ) {}
91  const uint8_t* getData ( size_t& size ) {
92  size=message.length();
93  return ( const uint8_t* ) message.data();
94  }
104  return 200;
105  }
114  std::string getType() {
115  return type.c_str();
116  }
125  std::string getEncoding() {
126  return "";
127  }
137  bool releaseData() {return true;}
138 
139  unsigned int getLength(){
140  return message.length();
141  }
142 };
143 
149 private:
150  int httpStatus ;
151 public:
160  std::string getMessage() {
161  return this->message;
162  } ;
167  return this->httpStatus;
168  }
169 };
170 
171 
183 class EmptyResponseDataStream : public DataStream {
184 private:
189  std::string type;
190 
195  uint32_t pos;
196 protected:
201  std::string message;
202 
203 public:
205 
206  size_t read ( uint8_t *buffer, size_t size ) {
207  return 0;
208  }
209  bool eof() {
210  return true;
211  }
212  std::string getType() {
213  return "";
214  }
215  std::string getEncoding() {
216  return "";
217  }
218  int getHttpStatus() {
219  return 204;
220  }
221  unsigned int getLength(){
222  return 0;
223  }
224 };
225 
237 class MessageDataStream : public DataStream {
238 private:
243  std::string type;
244 
249  uint32_t pos;
250 protected:
255  std::string message;
256 
257 public:
258  MessageDataStream ( std::string message, std::string type ) : message ( message ), type ( type ), pos ( 0 ) {}
259 
260  size_t read ( uint8_t *buffer, size_t size ) {
261  if ( size > message.length() - pos ) size = message.length() - pos;
262  memcpy ( buffer, ( uint8_t* ) ( message.data() +pos ),size );
263  pos+=size;
264  return size;
265  }
266  bool eof() {
267  return ( pos==message.length() );
268  }
269  std::string getType() {
270  return type.c_str();
271  }
272  std::string getEncoding() {
273  return "";
274  }
275  int getHttpStatus() {
276  return 200;
277  }
278  unsigned int getLength(){
279  return message.length();
280  }
281 };
282 
288 private:
289  int httpStatus ;
290 public:
299  std::string getMessage() {
300  return this->message;
301  } ;
306  return this->httpStatus;
307  }
308 };
309 
310 #endif
SERDataSource::getMessage
std::string getMessage()
Definition: Message.h:160
SERDataSource
Definition: Message.h:148
SERDataStream::getHttpStatus
int getHttpStatus()
Definition: Message.h:305
MessageDataStream
Gestion des messages sous forme de flux.
Definition: Message.h:237
MessageDataSource::getHttpStatus
int getHttpStatus()
Retourne le code de retour HTTP associé au message.
Definition: Message.h:103
SERDataSource::getHttpStatus
int getHttpStatus()
Definition: Message.h:166
SERDataSource::SERDataSource
SERDataSource(ServiceException *sex)
Definition: Message.cpp:80
EmptyResponseDataStream
Gestion des messages sous forme de flux.
Definition: Message.h:183
ServiceException
Gestion des exceptions de service.
Definition: ServiceException.h:188
MessageDataSource::getEncoding
std::string getEncoding()
Retourne l'encodage message.
Definition: Message.h:125
SERDataStream
Definition: Message.h:287
EmptyResponseDataStream::message
std::string message
Definition: Message.h:201
MessageDataSource::MessageDataSource
MessageDataSource(std::string message, std::string type)
Crée un MessageDataSource à partir de ses éléments constitutifs.
Definition: Message.h:90
MessageDataSource::message
std::string message
Definition: Message.h:79
SERDataStream::getMessage
std::string getMessage()
Definition: Message.h:299
MessageDataSource
Gestion des messages sous forme de fichier.
Definition: Message.h:67
SERDataStream::SERDataStream
SERDataStream(ServiceException *sex)
Definition: Message.cpp:86
ServiceException.h
Définition de la gestion des exceptions des services.
MessageDataStream::message
std::string message
Definition: Message.h:255
MessageDataSource::getType
std::string getType()
Retourne le type MIME du message.
Definition: Message.h:114
MessageDataSource::releaseData
bool releaseData()
Libère les données mémoire allouées.
Definition: Message.h:137