forked from artyom-beilis/cppcms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_storage.h
More file actions
102 lines (84 loc) · 2.89 KB
/
Copy pathsession_storage.h
File metadata and controls
102 lines (84 loc) · 2.89 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
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <[email protected]>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#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>
#include <time.h>
namespace cppcms {
namespace json {
class value;
}
namespace sessions {
///
/// \brief 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