diff --git a/core/http/http_session.cpp b/core/http/http_session.cpp new file mode 100644 index 0000000..6c65714 --- /dev/null +++ b/core/http/http_session.cpp @@ -0,0 +1,51 @@ + +#include "http_session.h" + +void HTTPSession::add_object(const std::string &key, Object *obj) { + std::lock_guard lock(_mutex); + + _data[key] = obj; +} +void HTTPSession::remove_object(const std::string &key) { + std::lock_guard lock(_mutex); + + _data.erase(key); +} +Object *HTTPSession::get_object(const std::string &key) { + //don't lock here + + return _data[key]; +} + +void HTTPSession::add_int(const std::string &key, const int val) { + std::lock_guard lock(_mutex); + + _int_data[key] = val; +} +void HTTPSession::remove_int(const std::string &key) { + std::lock_guard lock(_mutex); + + _int_data.erase(key); +} +int HTTPSession::get_int(const std::string &key) { + //don't lock here + + return _int_data[key]; +} + +void HTTPSession::clear() { + _data.clear(); + _int_data.clear(); +} + +void HTTPSession::reset() { + clear(); + session_id = ""; +} + +HTTPSession::HTTPSession() { +} + +HTTPSession::~HTTPSession() { + clear(); +} \ No newline at end of file diff --git a/core/http/http_session.h b/core/http/http_session.h new file mode 100644 index 0000000..f113c8f --- /dev/null +++ b/core/http/http_session.h @@ -0,0 +1,35 @@ +#ifndef HTTP_SESSION_H +#define HTTP_SESSION_H + +#include "core/object.h" +#include +#include +#include + +class HTTPSession : public Object { +public: + void add_object(const std::string &key,Object *obj); + void remove_object(const std::string &key); + Object *get_object(const std::string &key); + + void add_int(const std::string &key, const int val); + void remove_int(const std::string &key); + int get_int(const std::string &key); + + std::string session_id; + + void clear(); + void reset(); + + HTTPSession(); + ~HTTPSession(); + +protected: + std::mutex _mutex; + + //todo make something similar to godot's variant. (Or get godot's variant lol) + std::map _data; + std::map _int_data; +}; + +#endif \ No newline at end of file