Menu

[r2007]: / framework / trunk / cppcms / session_storage.h  Maximize  Restore  History

Download this file

113 lines (94 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_SESSION_STORAGE_H
#define CPPCMS_SESSION_STORAGE_H
#include <cppcms/defs.h>
#include <booster/noncopyable.h>
#include <booster/shared_ptr.h>
#include <string>
namespace cppcms {
namespace json {
class value;
}
namespace sessions {
///
/// \a session_server_storage is an abstract class that allows user to implements
/// custom session storage device like, database storage device
///
/// Note: if the member functions save/load/remove are thread safe -- can be called
/// from different threads, than you may create a single session and return \a shared_ptr
/// to a single instance, otherwise you have to create multiple instances of object
///
class session_storage : public booster::noncopyable
{
public:
///
/// Save session with end of life time at \a timeout using session id \a sid and content \a in
///
virtual void save(std::string const &sid,time_t timeout,std::string const &in) = 0;
///
/// Load session with \a sid, put its end of life time to \a timeout and return its
/// value to \a out
///
virtual bool load(std::string const &sid,time_t &timeout,std::string &out) = 0;
///
/// Remove a session with id \a sid from the storage
///
virtual void remove(std::string const &sid) = 0;
///
/// Return true of the save or load operations can be blocking
///
virtual bool is_blocking() = 0;
///
/// Destroy an object
///
virtual ~session_storage()
{
}
};
///
/// \brief The factory is an interface to a factory that creates session_storage objects, it should be thread safe.
///
class session_storage_factory {
public:
///
/// Get a pointer to session_storage. Note if the returned pointer is same for different calls
/// session_storage implementation should be thread safe.
///
virtual booster::shared_ptr<session_storage> get() = 0;
///
/// Return true if session_storage requires garbage collection - removal of expired session time-to-time
///
virtual bool requires_gc() = 0;
///
/// Actual garbage collection job (if required). If requires_gc returns true it will be called once-in-a-while to remove
/// all expired objects from the DB.
///
virtual void gc_job() {}
///
/// Delete the object, cleanup
///
virtual ~session_storage_factory() {}
};
extern "C" {
typedef session_storage_factory *(*cppcms_session_storage_generator_type)(cppcms::json::value const &options);
}
} // sessions
} // cppcms
#endif
MongoDB Logo MongoDB