mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Added a http session class.
This commit is contained in:
parent
3f6752ed20
commit
2521c28a9a
51
core/http/http_session.cpp
Normal file
51
core/http/http_session.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
#include "http_session.h"
|
||||
|
||||
void HTTPSession::add_object(const std::string &key, Object *obj) {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
_data[key] = obj;
|
||||
}
|
||||
void HTTPSession::remove_object(const std::string &key) {
|
||||
std::lock_guard<std::mutex> 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<std::mutex> lock(_mutex);
|
||||
|
||||
_int_data[key] = val;
|
||||
}
|
||||
void HTTPSession::remove_int(const std::string &key) {
|
||||
std::lock_guard<std::mutex> 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();
|
||||
}
|
35
core/http/http_session.h
Normal file
35
core/http/http_session.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef HTTP_SESSION_H
|
||||
#define HTTP_SESSION_H
|
||||
|
||||
#include "core/object.h"
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
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<std::string, Object *> _data;
|
||||
std::map<std::string, int> _int_data;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user