MetriVis Overview | Download | User Manual | Development
Reference Overview | Design Documentation | Reference Backend | Reference Frontend

src/HTTPDriver.h

Go to the documentation of this file.
00001 /*
00002  *   MetriVis - Metrics Visualization Application
00003  *
00004  *
00005  *   License notice:
00006  *
00007  *   This program is free software: you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation, either version 3 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  */
00021 
00022 #ifndef _METRIVIS_HTTP_DRIVER__
00023 #define _METRIVIS_HTTP_DRIVER__
00024 
00032 #include <map>
00033 #include "BaseClass.h"
00034 #include "pattern/Thread.h"
00035 #include "pattern/Singleton.h"
00036 #include "lib/easyhttpd/connection.h"
00037 #include "lib/easyhttpd/embedhttp.h"
00038 #include "RequestDescription.h"
00039 
00040 
00041 namespace metrivis {
00042 
00043 // Prototype class declarations.
00044 class RequestHandlerBase;
00045 
00046 
00070 class HTTPDriver : public Thread, public BaseClass {
00071 
00072 public:
00076   HTTPDriver(int port_number = 8080);
00077 
00081   virtual ~HTTPDriver();
00082 
00089   virtual int Init();
00090 
00101   int StartListening();
00102 
00103 
00110   int StopListening();
00111 
00112 
00119   virtual int Uninit();
00120 
00121 
00126   inline void set_port_number(int port_number) {
00127     port_number_ = port_number;
00128   }
00129 
00134   inline int port_number() const {
00135     return port_number_;
00136   }
00137 
00147   inline void set_number_parallelism(int number_parallelism) {
00148     number_parallelism_ = number_parallelism;
00149   }
00150 
00157   inline int number_parallelism() const {
00158     return number_parallelism_;
00159   }
00160 
00161 
00162 protected:
00163 
00171   virtual void Run();
00172 
00173 
00174 
00185   void RegisterRequestHandler(const std::string& id, RequestHandlerBase*
00186                               handler);
00187 
00188 
00195   void RegisterRequestHandlers();
00196 
00197 
00204   void UnregisterRequestHandlers();
00205 
00206 
00207 private:
00208 
00213   void AssignRequestToHandler(RequestDescription& request_description);
00214 
00215 
00216 
00217 private:
00218   int port_number_;                    
00219 
00220   http::Connection connection_;        
00221 
00223   std::map<std::string, RequestHandlerBase*> request_handlers_;
00224 
00225   int number_parallelism_;            
00226 
00227   http::ehttp http_parser_;           
00228 
00229 };
00230 
00232 typedef Singleton<HTTPDriver> HTTP;
00233 
00234 } //  namespace metrivis
00235 
00236 #endif // _METRIVIS_HTTP_DRIVER__

Generated on Fri Feb 29 16:47:19 2008 for MetriVis by  doxygen 1.5.3