diff --git a/modules/web/http/http_session.cpp b/modules/web/http/http_session.cpp index fccc5db21..8f8739531 100644 --- a/modules/web/http/http_session.cpp +++ b/modules/web/http/http_session.cpp @@ -1,6 +1,20 @@ #include "http_session.h" +String HTTPSession::get_session_id() { + return session_id; +} +void HTTPSession::set_session_id(const String &val) { + session_id = val; +} + +int HTTPSession::get_id() { + return id; +} +void HTTPSession::set_id(const int val) { + id = val; +} + void HTTPSession::add(const String &key, const Variant &value) { _mutex.lock(); @@ -19,7 +33,7 @@ bool HTTPSession::has(const String &key) { return !_data[key].is_null(); } -Variant HTTPSession::get(const String &key) { +Variant HTTPSession::get_value(const String &key) { return _data[key]; } const Variant &HTTPSession::get_const(const String &key) { @@ -29,19 +43,19 @@ const Variant &HTTPSession::get_const(const String &key) { Object *HTTPSession::get_object(const String &key) { // don't lock here - return _data[key].to_object(); + return _data[key]; } Ref HTTPSession::get_reference(const String &key) { // don't lock here - return _data[key].to_reference(); + return Ref(_data[key]); } int HTTPSession::get_int(const String &key) { // don't lock here - return _data[key].to_int(); + return _data[key]; } void HTTPSession::clear() { @@ -53,7 +67,7 @@ void HTTPSession::reset() { session_id = ""; } -std::map *HTTPSession::get_data() { +HashMap *HTTPSession::get_data() { return &_data; } @@ -63,4 +77,22 @@ HTTPSession::HTTPSession() { HTTPSession::~HTTPSession() { clear(); -} \ No newline at end of file +} + +void HTTPSession::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_session_id"), &HTTPSession::get_session_id); + ClassDB::bind_method(D_METHOD("set_session_id", "val"), &HTTPSession::set_session_id); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "session_id"), "set_session_id", "get_session_id"); + + ClassDB::bind_method(D_METHOD("get_id"), &HTTPSession::get_id); + ClassDB::bind_method(D_METHOD("set_id", "val"), &HTTPSession::set_id); + ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); + + ClassDB::bind_method(D_METHOD("add", "key", "value"), &HTTPSession::add); + ClassDB::bind_method(D_METHOD("remove", "key"), &HTTPSession::remove); + ClassDB::bind_method(D_METHOD("has", "key"), &HTTPSession::has); + ClassDB::bind_method(D_METHOD("get_value", "key"), &HTTPSession::get_value); + + ClassDB::bind_method(D_METHOD("clear"), &HTTPSession::clear); + ClassDB::bind_method(D_METHOD("reset"), &HTTPSession::reset); +} diff --git a/modules/web/http/http_session.h b/modules/web/http/http_session.h index 1837eeedf..6ed0e7269 100644 --- a/modules/web/http/http_session.h +++ b/modules/web/http/http_session.h @@ -1,44 +1,51 @@ #ifndef HTTP_SESSION_H #define HTTP_SESSION_H -#include +#include "core/hash_map.h" #include "core/reference.h" -#include "core/string.h" +#include "core/os/mutex.h" +#include "core/ustring.h" #include "core/variant.h" -#include "core/threading/mutex.h" - class HTTPSession : public Reference { - RCPP_OBJECT(HTTPSession, Reference); + GDCLASS(HTTPSession, Reference); public: + String get_session_id(); + void set_session_id(const String &val); + + int get_id(); + void set_id(const int val); + void add(const String &key, const Variant &value); void remove(const String &key); bool has(const String &key); + Variant get_value(const String &key); - Variant get(const String &key); const Variant &get_const(const String &key); Object *get_object(const String &key); Ref get_reference(const String &key); int get_int(const String &key); - String session_id; - int id; - void clear(); void reset(); - std::map *get_data(); + HashMap *get_data(); HTTPSession(); ~HTTPSession(); + String session_id; + int id; + protected: + static void _bind_methods(); + Mutex _mutex; - std::map _data; + HashMap _data; }; -#endif \ No newline at end of file +#endif