ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_SESSION_STORAGE_H
  9. #define CPPCMS_SESSION_STORAGE_H
  10. #include <cppcms/defs.h>
  11. #include <booster/noncopyable.h>
  12. #include <booster/shared_ptr.h>
  13. #include <string>
  14. namespace cppcms {
  15. namespace json {
  16. class value;
  17. }
  18. namespace sessions {
  19. ///
  20. /// \brief session_server_storage is an abstract class that allows user to implements
  21. /// custom session storage device like, database storage device
  22. ///
  23. /// Note: if the member functions save/load/remove are thread safe -- can be called
  24. /// from different threads, than you may create a single session and return \a shared_ptr
  25. /// to a single instance, otherwise you have to create multiple instances of object
  26. ///
  27. class session_storage : public booster::noncopyable
  28. {
  29. public:
  30. ///
  31. /// Save session with end of life time at \a timeout using session id \a sid and content \a in
  32. ///
  33. virtual void save(std::string const &sid,time_t timeout,std::string const &in) = 0;
  34. ///
  35. /// Load session with \a sid, put its end of life time to \a timeout and return its
  36. /// value to \a out
  37. ///
  38. virtual bool load(std::string const &sid,time_t &timeout,std::string &out) = 0;
  39. ///
  40. /// Remove a session with id \a sid from the storage
  41. ///
  42. virtual void remove(std::string const &sid) = 0;
  43. ///
  44. /// Return true of the save or load operations can be blocking
  45. ///
  46. virtual bool is_blocking() = 0;
  47. ///
  48. /// Destroy an object
  49. ///
  50. virtual ~session_storage()
  51. {
  52. }
  53. };
  54. ///
  55. /// \brief The factory is an interface to a factory that creates session_storage objects, it should be thread safe.
  56. ///
  57. class session_storage_factory {
  58. public:
  59. ///
  60. /// Get a pointer to session_storage. Note if the returned pointer is same for different calls
  61. /// session_storage implementation should be thread safe.
  62. ///
  63. virtual booster::shared_ptr<session_storage> get() = 0;
  64. ///
  65. /// Return true if session_storage requires garbage collection - removal of expired session time-to-time
  66. ///
  67. virtual bool requires_gc() = 0;
  68. ///
  69. /// Actual garbage collection job (if required). If requires_gc returns true it will be called once-in-a-while to remove
  70. /// all expired objects from the DB.
  71. ///
  72. virtual void gc_job() {}
  73. ///
  74. /// Delete the object, cleanup
  75. ///
  76. virtual ~session_storage_factory() {}
  77. };
  78. extern "C" {
  79. typedef session_storage_factory *(*cppcms_session_storage_generator_type)(cppcms::json::value const &options);
  80. }
  81. } // sessions
  82. } // cppcms
  83. #endif