TKN Logo SelfSoft Logo

Total Knowledge

SelfSoft, Inc.

CPPSERV

[CPPSERV] [Documentation] [Download] [Contact] [Bug tracker] [News] [RSS Feed] [gitweb]

App.h

Go to the documentation of this file.
00001 
00002 #ifndef _CONTAINER_APP_H_
00003 #define _CONTAINER_APP_H_
00004 
00005 #include <servletcontainer.h>
00006 #include "ServletConfigImpl.h"
00007 
00008 #include <servlet/ServletContext.h>
00009 #include <HttpSessionImpl.h>
00010 #include <map>
00011 #include <util.h>
00012 #include <time.h>
00013 #include <sptk3/CThread.h>
00014 #include <sptk3/CWaiter.h>
00015 #include "ServletMap.h"
00016 
00017 namespace container
00018 {
00019 class ServerConfig;
00020 class App: public servlet::ServletContext
00021 {
00022 private:
00023         typedef servlet::Servlet* (*servletcreatefunc_t)();
00024         struct ServletDesc
00025         {
00026                 ServletDesc(servlet::Servlet* serv,container::ServletConfigImpl* conf,void* handle, const std::string& path):
00027                         cont(serv,conf,path),h(handle){}
00028                 ServletContainer cont;
00029                 void* h;
00030         };
00031 public:
00032         friend class ServerConfig;
00033         typedef ServletMap<ServletDesc> servletmap_t;
00034 private:
00035         servletmap_t maptop;
00036         ServerConfig& cfg;
00037 
00038         void splitServPath(const std::string& path, std::string& dir, std::string& name);
00039         void unloadServlet(const std::string& path);
00040         bool addServlet(const std::string& path,ServletDesc* d);
00041         ServletDesc* getDesc(const std::string& path);
00042         void initServlet(const std::string& path);
00043         void destroyServlet(const std::string& path);
00044 public:
00045         App(ServerConfig& cfg, time_t sessionTimeout,const std::string& name, const std::string& fileSaveDir, const std::string& uribase);
00046         virtual ~App();
00047         ServletConfigImpl* addServlet(const std::string& path, const std::string& name, const std::string& dso, bool hidden);
00048         void delServlet(const std::string& path);
00049         ServletContainer* getServletContainer(const std::string& path);
00050         void* getDso(const std::string& path);
00051         void initServlets();
00052         void destroyServlets();
00053 
00054 private:
00055         class SessionCleaner: public sptk::CThread
00056         {
00057         private:
00058                 bool running;
00059                 int freq;
00060                 App* ctx;
00062                 int trigger[2];
00063         public:
00064                 SessionCleaner(App* ctx,int freq);
00065                 ~SessionCleaner();
00066                 void stop();
00067                 virtual void threadFunction();
00068                 void wakeUp();
00069         };
00070         SessionCleaner *cleaner;
00071 private:
00072         typedef std::map<std::string, HttpSessionImpl*> sessionlist_t;
00073         sessionlist_t sessions;
00074         std::string sessionCookieName;
00075         time_t sessionTimeout;
00076         std::string fileSaveTemplate;
00077         sptk::CWaiter sessionLock; //Used for locking session list for modification
00078         std::string name;
00079         typedef std::map<std::string,boost::shared_ptr<void> > attr_t;
00080         attr_t m_attrs;
00081         typedef std::map<std::string,std::string> param_t;
00082         param_t m_params;
00083         std::string m_uribase;
00084 public:
00085         HttpSessionImpl* getSession(const std::string& sid, bool create);
00086 
00090         const std::string& getSessionCookieName()
00091         {
00092                 return sessionCookieName;
00093         }
00094         void killSession(const std::string& sid);
00095         void cleanSessions();
00096         bool isSessionValid(const std::string& sid);
00097         void addInitParam(const std::string& name, const std::string& value);
00098 
00099         void killAllSessions();
00100         const std::string& getFileSaveTemplate() const {return fileSaveTemplate;}
00101         const std::string& getUriBase() const { return m_uribase;}
00102 public:
00104         virtual servlet::ServletContext* getContext(const std::string& uripath);
00105         virtual int  getMajorVersion();
00106         virtual int  getMinorVersion();
00107         virtual std::string  getMimeType(const std::string& file);
00108         virtual std::auto_ptr< std::set<std::string> >  getResourcePaths(const std::string& path);
00109         virtual std::string getResource(const std::string& path);
00110         virtual std::istream& getResourceAsStream(const std::string& path);
00111         virtual servlet::RequestDispatcher* getRequestDispatcher(const std::string& path);
00112         virtual servlet::RequestDispatcher* getNamedDispatcher(const std::string& name);
00113         virtual void  log(const std::string& msg) const ;
00114         virtual void  log(const std::string& message, const std::exception& e) const ;
00115         virtual std::string  getRealPath(const std::string& path);
00116         virtual std::string  getServerInfo();
00117         virtual std::string  getInitParameter(const std::string& name);
00118         virtual std::auto_ptr< std::vector<std::string> > getInitParameterNames();
00119         virtual boost::shared_ptr<void> getAttribute(const std::string& name);
00120         virtual std::auto_ptr< std::vector<std::string> > getAttributeNames();
00121         virtual void setAttribute(const std::string& name, boost::shared_ptr<void> object);
00122         virtual void  removeAttribute(const std::string& name);
00123         virtual bool hasAttribute(const std::string& name) const;
00124         virtual std::string  getServletContextName() const;
00125 
00126 private:
00127         HttpSessionImpl* newSession();
00128         static std::string makeSName(const std::string& name);
00129 
00130 };
00131 }
00132 #endif

SourceForge.net Logo

Authoright © Total Knowledge: 2001-2004