pandemonium_engine/modules/web/http/web_server.cpp

102 lines
3.0 KiB
C++
Raw Normal View History

#include "web_server.h"
2022-06-26 21:34:29 +02:00
#include "web_node.h"
#include "web_server_request.h"
2022-06-27 14:16:23 +02:00
#include "http_session_manager.h"
2022-06-26 21:34:29 +02:00
NodePath WebServer::get_web_root_path() const {
return _web_root_path;
}
void WebServer::set_web_root_path(const NodePath &path) {
_web_root_path = path;
}
WebNode *WebServer::get_web_root() {
return _web_root;
}
2022-06-26 21:34:29 +02:00
void WebServer::set_web_root(WebNode *root) {
_web_root = root;
}
2022-06-26 21:34:29 +02:00
Node *WebServer::get_web_root_bind() {
return _web_root;
}
void WebServer::set_web_root_bind(Node *root) {
WebNode *web_root = Object::cast_to<WebNode>(root);
_web_root = web_root;
}
2022-06-27 14:16:23 +02:00
HTTPSessionManager *WebServer::get_session_manager() {
return _session_manager;
}
void WebServer::set_session_manager(HTTPSessionManager *sess_man) {
_session_manager = sess_man;
}
Node *WebServer::get_session_manager_bind() {
return _session_manager;
}
void WebServer::set_session_manager_bind(Node *sess_man) {
_session_manager = Object::cast_to<HTTPSessionManager>(sess_man);
}
2022-06-27 01:03:01 +02:00
void WebServer::server_handle_request(Ref<WebServerRequest> request) {
ERR_FAIL_COND(!_web_root);
2022-06-27 14:16:23 +02:00
request->server = this;
2022-06-27 01:03:01 +02:00
request->web_root = _web_root;
_rw_lock.read_lock();
_web_root->handle_request_main(request);
_rw_lock.read_unlock();
}
2022-06-27 14:16:23 +02:00
void WebServer::start() {
call("_start");
}
void WebServer::stop() {
call("_stop");
}
void WebServer::_start() {
//look up root node, and sessionmanager, if not set.
}
void WebServer::_stop() {
}
2022-06-26 21:34:29 +02:00
WebServer::WebServer() {
_web_root = nullptr;
2022-06-26 21:34:29 +02:00
_write_lock_requested = false;
}
WebServer::~WebServer() {
}
2022-06-26 21:34:29 +02:00
void WebServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_web_root_path"), &WebServer::get_web_root_path);
ClassDB::bind_method(D_METHOD("set_web_root_path", "val"), &WebServer::set_web_root_path);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "web_root_path"), "set_web_root_path", "get_web_root_path");
2022-06-27 14:16:23 +02:00
ClassDB::bind_method(D_METHOD("get_web_root"), &WebServer::get_web_root_bind);
ClassDB::bind_method(D_METHOD("set_web_root", "val"), &WebServer::set_web_root_bind);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "web_root", PROPERTY_HINT_RESOURCE_TYPE, "WebRoot"), "set_web_root", "get_web_root");
ClassDB::bind_method(D_METHOD("get_session_manager"), &WebServer::get_session_manager_bind);
ClassDB::bind_method(D_METHOD("set_session_manager", "val"), &WebServer::set_session_manager_bind);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "session_manager", PROPERTY_HINT_RESOURCE_TYPE, "HTTPSessionManager"), "set_session_manager", "get_session_manager");
2022-06-26 21:34:29 +02:00
2022-06-27 01:03:01 +02:00
ClassDB::bind_method(D_METHOD("server_handle_request", "request"), &WebServer::server_handle_request);
2022-06-26 21:34:29 +02:00
ClassDB::bind_method(D_METHOD("request_write_lock"), &WebServer::request_write_lock);
2022-06-27 14:16:23 +02:00
BIND_VMETHOD(MethodInfo("_start"));
BIND_VMETHOD(MethodInfo("_stop"));
ClassDB::bind_method(D_METHOD("start"), &WebServer::start);
ClassDB::bind_method(D_METHOD("stop"), &WebServer::stop);
ClassDB::bind_method(D_METHOD("_start"), &WebServer::_start);
ClassDB::bind_method(D_METHOD("_stop"), &WebServer::_stop);
2022-06-26 21:34:29 +02:00
}