CPPSERV


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

HttpSessionImpl.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 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 #ifndef CSERVIMPLSESSIONIMPL_H
00021 #define CSERVIMPLSESSIONIMPL_H
00022 
00023 #include <servlet/HttpSession.h>
00024 #include <time.h>
00025 #include <map>
00026 #include <boost/shared_ptr.hpp>
00027 #include <string>
00028 
00029 namespace container {
00030 
00034 class HttpSessionImpl : public servlet::HttpSession
00035 {
00036 private:
00037     typedef std::map<std::string,boost::shared_ptr<void> > attr_t;
00038     attr_t m_attrs;
00039     int m_maxInactiveInterval;
00040     time_t m_creationTime, m_lastAccessTime;
00041     servlet::ServletContext& m_servletContext;
00042     std::string m_id;
00043     bool m_isNew;
00044     bool m_isValid;
00045 
00046 public:
00047     HttpSessionImpl(servlet::ServletContext& ctx, const std::string& id,time_t timeout);
00048     virtual ~HttpSessionImpl();
00049 
00055     void notNew()
00056     {
00057         m_isNew=false;
00058         m_lastAccessTime=::time(0);
00059     }
00060 
00064     bool validP() const
00065     {
00066         return m_isValid && ::time(0) - m_lastAccessTime < m_maxInactiveInterval;
00067     }
00068 
00069         virtual long  getCreationTime() const;
00070         virtual long  getLastAccessedTime() const;
00071         virtual const servlet::ServletContext&  getServletContext() const;
00072         virtual void  setMaxInactiveInterval(int interval);
00073         virtual int  getMaxInactiveInterval() const;
00074         virtual boost::shared_ptr<void> getAttribute(const std::string& name);
00075         virtual std::auto_ptr< std::vector<std::string> > getAttributeNames() const;
00076         virtual void setAttribute(const std::string& name, boost::shared_ptr<void> value);
00077         virtual bool hasAttribute(const std::string& name) const;
00078         virtual void  removeAttribute(const std::string& name);
00079         virtual void  invalidate();
00080         virtual bool  isNew() const;
00081         virtual std::string getId() const;
00082 };
00083 
00084 }
00085 
00086 #endif

SourceForge.net Logo