platform/services/ConfigService.hpp

00001 // ------------------------------------------------------------------------
00002 // Pion is a development platform for building Reactors that process Events
00003 // ------------------------------------------------------------------------
00004 // Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
00005 //
00006 // Pion is free software: you can redistribute it and/or modify it under the
00007 // terms of the GNU Affero General Public License as published by the Free
00008 // Software Foundation, either version 3 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Pion is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Affero General Public License
00017 // along with Pion.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef __PION_CONFIGSERVICE_HEADER__
00021 #define __PION_CONFIGSERVICE_HEADER__
00022 
00023 #include <pion/PionConfig.hpp>
00024 #include "PlatformService.hpp"
00025 
00026 
00027 namespace pion {        // begin namespace pion
00028 namespace plugins {     // begin namespace plugins
00029 
00030 
00034 class ConfigService
00035     : public pion::server::PlatformService
00036 {
00037 public:
00038     
00040     class MissingUIDirectoryException : public PionException {
00041     public:
00042         MissingUIDirectoryException()
00043             : PionException("The ConfigService configuration is missing a UIDirectory parameter") {}
00044     };
00045 
00046 
00048     ConfigService(void) : PlatformService("pion.ConfigService"), m_config_logger(PION_GET_LOGGER("config")) {}
00049 
00051     virtual ~ConfigService() {}
00052 
00060     virtual void setConfig(const pion::platform::Vocabulary& v,
00061                            const xmlNodePtr config_ptr);
00062 
00069     virtual void operator()(pion::net::HTTPRequestPtr& request,
00070                             pion::net::TCPConnectionPtr& tcp_conn);
00071 
00072 protected:
00073 
00074     // Handles logging and sends a 400 (Bad Request) response.
00075     virtual void handleBadRequest(pion::net::HTTPRequestPtr& request, pion::net::TCPConnectionPtr& tcp_conn, const std::string& error_msg);
00076 
00077     // Handles logging and sends a 403 (Forbidden) response.
00078     virtual void handleForbiddenRequest(pion::net::HTTPRequestPtr& request, pion::net::TCPConnectionPtr& tcp_conn, const std::string& error_msg);
00079 
00080     // Handles logging and sends a 404 (Not Found) response.
00081     virtual void handleNotFoundRequest(pion::net::HTTPRequestPtr& request, pion::net::TCPConnectionPtr& tcp_conn);
00082 
00083     // Handles logging and sends a 405 (Method Not Allowed) response.
00084     virtual void handleMethodNotAllowed(pion::net::HTTPRequestPtr& request, pion::net::TCPConnectionPtr& tcp_conn, const std::string& allowed_methods);
00085 
00086     // Logs the request if it resulted in or might have been intended to result in a configuration change.
00087     void logRequestIfPotentialConfigChange(pion::net::HTTPRequestPtr& request, unsigned int status);
00088 
00089 private:
00090 
00092     PionLogger                      m_config_logger;
00093 
00095     static const std::string        UI_DIRECTORY_ELEMENT_NAME;
00096 
00098     std::string                     m_ui_directory;
00099 };
00100 
00101     
00102 }   // end namespace plugins
00103 }   // end namespace pion
00104 
00105 #endif

Generated on Wed Apr 13 16:38:34 2011 for pion-platform by  doxygen 1.4.7