#ifndef JSON_ADAPTER_SESSION_REGISTRY_HH #define JSON_ADAPTER_SESSION_REGISTRY_HH #include #include #include #include #include #include #include "logger.hh" class SessionRegistry { public: SessionRegistry(messageToSend_t _mts, inject_sync_event_t _ise, int _client_timeout) : mts{_mts} , ise{_ise} , Log{"SR"} , client_timeout{_client_timeout} // in seconds {} // calls "init" for the given thread if no PEP_SESSION exists, yet for the given thread PEP_SESSION get(std::thread::id tid, const std::string& client_id); void remove(std::thread::id tid = std::this_thread::get_id()); std::size_t size() const { return m.size(); } bool empty() const { return m.empty(); } // calls the given function (which might be a lambda or std::function<> or std::bind thingy) // on each stored session. void for_each(void(*function)(PEP_SESSION)); void add_to_cache(const std::string& client_id, const std::string& fn_name, const std::function& func); std::string to_string() const; private: std::map m; messageToSend_t mts; inject_sync_event_t ise; Logger Log; int client_timeout; // in seconds // function name -> functor typedef std::map> cache_per_client_t; // key=client_id std::map cache; std::map > last_use; typedef std::recursive_mutex Mutex; typedef std::unique_lock Lock; mutable Mutex _mtx; void update_last_use(const std::string& client_id); }; #endif // JSON_ADAPTER_SESSION_REGISTRY_HH