CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

globalcontext.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Ilya A. Volynets-Evenbakh                       *
00003  *   ilya@total-knowledge.com                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef _SERVERCONFIG_GLOBALCONTEXT_H_
00022 #define _SERVERCONFIG_GLOBALCONTEXT_H_
00023 
00024 #include "context.h"
00025 #include "contextregistry.h"
00026 #include "paramregistry.h"
00027 #include <requestlistener.h>
00028 
00029 // Forward declarations
00030 namespace sptk {
00031 class CThreadPool;
00032 }
00033 namespace container {
00034 
00035 namespace serverconfig {
00036 
00037 class AppContext;
00038 
00040 
00048 class GlobalContext:
00049     public Context
00050 {
00051     static ContextRegistry m_contextregistry;
00052     static ParamRegistry<GlobalContext> m_paramregistry;
00053     static void registerParams(ParamRegistry<GlobalContext>&);
00054     class GlobalConfigNode:
00055         public ConfigNode
00056     {
00057     public:
00058         GlobalConfigNode(const std::string& type, const std::string& value)
00059             : ConfigNode()
00060         {
00061             this->m_type=type;
00062             m_attrs["value"]=value;
00063         }
00064     };
00065     std::list<GlobalConfigNode*> m_globalNodes;
00066     std::list<container::RequestListener::Acceptor*> m_acceptors;
00067     std::map<std::string, AppContext*> m_apps;
00068 private: // command line-aware stuff
00075     int m_nThreads;
00082     int m_queueDepth;
00083 
00084     container::RequestListener* m_listener;
00085     sptk::CThreadPool* m_pool;
00086 private:
00087     static void registerContexts(ContextRegistry&);
00088 protected:
00089     virtual bool onSetParam(const ConfigNode&);
00090     virtual Context* getContext(const ConfigNode& node)
00091     { return m_contextregistry.getContext(node, this); }
00092     bool setListener(const ConfigNode&);
00093     bool setNumThreads(const ConfigNode&);
00094     bool setQueueDepth(const ConfigNode&);
00095     bool onPostComplete();
00096 public:
00097     GlobalContext(ServerConfig& cfg);
00098     ~GlobalContext();
00099     bool setGlobalParam(const std::string&, const std::string&);
00100     container::RequestListener* getListener(){return m_listener;}
00101     void registerApp(const std::string& name, AppContext* app) { m_apps[name] = app; }
00102     AppContext* getApp(const std::string& name)
00103     {
00104         std::map<std::string, AppContext*>::iterator it = m_apps.find(name);
00105         if( m_apps.end() == it )
00106             return 0;
00107         return it->second;
00108     }
00109 };
00110 
00111 }
00112 }
00113 #endif //_SERVERCONFIG_GLOBALCONTEXT_H_

SourceForge.net Logo