CPPSERV


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

HttpSessionImpl.cpp

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 #include <HttpSessionImpl.h>
00021 #include <iostream>
00022 #include <util.h>
00023 
00024 namespace container {
00025 
00026 HttpSessionImpl::HttpSessionImpl(servlet::ServletContext& ctx, const std::string& id, time_t timeout)
00027  : m_maxInactiveInterval(timeout)
00028  , m_creationTime (time(0))
00029  , m_servletContext(ctx)
00030  , m_id(id)
00031  , m_isNew(true)
00032  , m_isValid(true)
00033 {
00034     this->m_lastAccessTime = this->m_creationTime;
00035 }
00036 
00037 
00038 HttpSessionImpl::~HttpSessionImpl()
00039 {
00040 }
00041 
00042 long HttpSessionImpl::getCreationTime() const
00043 {
00044     return m_creationTime;
00045 }
00046 
00047 long HttpSessionImpl::getLastAccessedTime() const
00048 {
00049     return m_lastAccessTime;
00050 }
00051 
00052 const servlet::ServletContext& HttpSessionImpl::getServletContext() const
00053 {
00054     return m_servletContext;
00055 }
00056 
00057 int HttpSessionImpl::getMaxInactiveInterval() const
00058 {
00059     return m_maxInactiveInterval;
00060 }
00061 
00062 boost::shared_ptr<void> HttpSessionImpl::getAttribute(const std::string& name)
00063 {
00064     attr_t::iterator iRet = m_attrs.find(name);
00065     if(iRet == m_attrs.end())
00066         return boost::shared_ptr<void>();
00067     return iRet->second;
00068 }
00069 
00070 std::auto_ptr<std::vector<std::string> > HttpSessionImpl::getAttributeNames() const
00071 {
00072     return container::util::getMapKeyNames(m_attrs);
00073 }
00074 
00075 void HttpSessionImpl::setAttribute(const std::string& name, boost::shared_ptr<void> value)
00076 {
00077     m_attrs[name] = value;
00078 }
00079 
00080 void HttpSessionImpl::removeAttribute(const std::string& name)
00081 {
00082     attr_t::iterator it = m_attrs.find(name);
00083     if(it == m_attrs.end())
00084         return;
00085     m_attrs.erase(it);
00086 }
00087 
00088 void HttpSessionImpl::invalidate()
00089 {
00090     m_isValid = false;
00091 }
00092 
00093 bool HttpSessionImpl::isNew() const
00094 {
00095     return m_isNew;
00096 }
00097 
00098 std::string HttpSessionImpl::getId() const
00099 {
00100     return m_id;
00101 }
00102 
00103 void  HttpSessionImpl::setMaxInactiveInterval(int interval)
00104 {
00105     m_maxInactiveInterval = interval;
00106 }
00107 
00108 bool HttpSessionImpl::hasAttribute(const std::string& name) const
00109 {
00110     return m_attrs.find(name) != m_attrs.end();
00111 }
00112 
00113 }

SourceForge.net Logo