mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-10 12:59:40 +01:00
Cleaned up WebServer.
This commit is contained in:
parent
47ee34044a
commit
633acfcd54
@ -16,6 +16,24 @@
|
||||
#include "database/table_builder.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
void WebNode::update() {
|
||||
if (!_root_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
_root_node->notification(Node::NOTIFICATION_UPDATE);
|
||||
|
||||
if (_write_lock_requested) {
|
||||
_rw_lock.write_lock();
|
||||
_root_node->notification(Node::NOTIFICATION_TREE_WRITE_LOCKED);
|
||||
_rw_lock.write_unlock();
|
||||
|
||||
_write_lock_requested = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
String WebNode::get_uri_segment() {
|
||||
return _uri_segment;
|
||||
}
|
||||
@ -342,4 +360,4 @@ WebNode::WebNode() :
|
||||
}
|
||||
|
||||
WebNode::~WebNode() {
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,17 @@ class TableBuilder;
|
||||
class QueryBuilder;
|
||||
#endif
|
||||
|
||||
//note add an alterative queue_delete() -> (with different name) -> if called node stops getting routed to, and when rwlock can be locked gets queue_deleted.
|
||||
|
||||
class WebNode : public Node {
|
||||
RCPP_OBJECT(WebNode, Node);
|
||||
|
||||
public:
|
||||
enum {
|
||||
//todo likely needs a different constant number
|
||||
NOTIFICATION_SERVER_TREE_WRITE_LOCKED = 2000,
|
||||
};
|
||||
|
||||
String get_uri_segment();
|
||||
void set_uri_segment(const String &val);
|
||||
|
||||
@ -49,7 +56,7 @@ public:
|
||||
|
||||
virtual void render_index(Request *request);
|
||||
virtual void render_preview(Request *request);
|
||||
|
||||
|
||||
virtual void render_menu(Request *request);
|
||||
virtual void _render_menu(Request *request);
|
||||
|
||||
@ -93,4 +100,4 @@ protected:
|
||||
Ref<WebPermission> _web_permission;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,23 +1,33 @@
|
||||
#include "web_server.h"
|
||||
|
||||
#include "request.h"
|
||||
#include "web/http/web_node.h"
|
||||
#include "web_node.h"
|
||||
#include "web_server_request.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void WebServer::set_root(Node *root) {
|
||||
WebNode *web_root = Object::cast_to<WebNode>(root);
|
||||
|
||||
ERR_FAIL_COND(!web_root);
|
||||
|
||||
_web_root = web_root;
|
||||
|
||||
NodeTree::set_root(root);
|
||||
void WebServer::set_web_root(WebNode *root) {
|
||||
_web_root = root;
|
||||
}
|
||||
|
||||
void WebServer::handle_request(Request *request) {
|
||||
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;
|
||||
}
|
||||
|
||||
void WebServer::handle_request(Ref<WebServerRequest> request) {
|
||||
ERR_FAIL_COND(!_web_root);
|
||||
|
||||
_rw_lock.read_lock();
|
||||
@ -25,14 +35,24 @@ void WebServer::handle_request(Request *request) {
|
||||
_rw_lock.read_unlock();
|
||||
}
|
||||
|
||||
float WebServer::get_update_delta_time() {
|
||||
return _update_interval;
|
||||
}
|
||||
|
||||
WebServer::WebServer() : NodeTree() {
|
||||
WebServer::WebServer() {
|
||||
_web_root = nullptr;
|
||||
_update_interval = 0.5;
|
||||
|
||||
_write_lock_requested = false;
|
||||
}
|
||||
|
||||
WebServer::~WebServer() {
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_web_root_bind"), &WebServer::get_web_root_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_web_root_bind", "val"), &WebServer::set_web_root_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "web_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"), "set_web_root_bind", "get_web_root_bind");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("handle_request", "request"), &WebServer::handle_request);
|
||||
ClassDB::bind_method(D_METHOD("request_write_lock"), &WebServer::request_write_lock);
|
||||
}
|
||||
|
@ -1,29 +1,40 @@
|
||||
#ifndef WEB_SERVER_H
|
||||
#define WEB_SERVER_H
|
||||
|
||||
#include "core/nodes/node_tree.h"
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
class Request;
|
||||
class WebServerRequest;
|
||||
class WebNode;
|
||||
|
||||
class WebServer : public NodeTree {
|
||||
RCPP_OBJECT(WebServer, NodeTree);
|
||||
class WebServer : public Node {
|
||||
GDCLASS(WebServer, Node);
|
||||
|
||||
public:
|
||||
NodePath get_web_root_path() const;
|
||||
void set_web_root_path(const NodePath &path);
|
||||
|
||||
WebNode *get_web_root();
|
||||
void set_web_root(WebNode *root);
|
||||
|
||||
void set_root(Node *root);
|
||||
Node *get_web_root_bind();
|
||||
void set_web_root_bind(Node *root);
|
||||
|
||||
void handle_request(Request *request);
|
||||
void handle_request(Ref<WebServerRequest> request);
|
||||
|
||||
float get_update_delta_time();
|
||||
void request_write_lock();
|
||||
|
||||
WebServer();
|
||||
virtual ~WebServer();
|
||||
~WebServer();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
NodePath _web_root_path;
|
||||
WebNode *_web_root;
|
||||
float _update_interval;
|
||||
|
||||
bool _write_lock_requested;
|
||||
RWLock _rw_lock;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user