From 0c0123889b067043a46bc3bafedb36dd17d05714 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 27 May 2021 16:52:53 +0200 Subject: [PATCH] Renamed the Application class to BryWebApplication. --- ...pplication.cpp => bry_web_application.cpp} | 42 +++++++++---------- core/{application.h => bry_web_application.h} | 10 ++--- core/http/http_server.cpp | 2 +- core/http/http_server.h | 4 +- core/request.cpp | 2 +- core/request.h | 4 +- modules/paged_article/paged_article.cpp | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) rename core/{application.cpp => bry_web_application.cpp} (61%) rename core/{application.h => bry_web_application.h} (90%) diff --git a/core/application.cpp b/core/bry_web_application.cpp similarity index 61% rename from core/application.cpp rename to core/bry_web_application.cpp index 3a16c54..e8943c7 100644 --- a/core/application.cpp +++ b/core/bry_web_application.cpp @@ -1,4 +1,4 @@ -#include "application.h" +#include "bry_web_application.h" #include #include @@ -12,20 +12,20 @@ #include #include -void Application::load_settings() { +void BryWebApplication::load_settings() { } -void Application::setup_routes() { - default_error_handler_func = Application::default_fallback_error_handler; +void BryWebApplication::setup_routes() { + default_error_handler_func = BryWebApplication::default_fallback_error_handler; - error_handler_map[404] = Application::default_404_error_handler; + error_handler_map[404] = BryWebApplication::default_404_error_handler; } -void Application::setup_middleware() { +void BryWebApplication::setup_middleware() { middlewares.push_back(HandlerInstance([this](Object *instance, Request *request){ this->default_routing_middleware(instance, request); })); } -void Application::default_routing_middleware(Object *instance, Request *request) { +void BryWebApplication::default_routing_middleware(Object *instance, Request *request) { std::string path = request->http_parser->getPath(); if (FileCache::get_singleton()->wwwroot_has_file(path)) { @@ -60,24 +60,24 @@ void Application::default_routing_middleware(Object *instance, Request *request) request->next_stage(); } -void Application::default_fallback_error_handler(int error_code, Request *request) { +void BryWebApplication::default_fallback_error_handler(int error_code, Request *request) { request->response->setBody(default_generic_error_body); request->send(); } -void Application::default_404_error_handler(int error_code, Request *request) { +void BryWebApplication::default_404_error_handler(int error_code, Request *request) { request->response->setBody(default_error_404_body); request->send(); } -void Application::handle_request(Request *request) { +void BryWebApplication::handle_request(Request *request) { request->middleware_stack = &middlewares; - //note that middlewares handle the routing -> Application::default_routing_middleware by default + //note that middlewares handle the routing -> BryWebApplication::default_routing_middleware by default request->next_stage(); } -void Application::send_error(int error_code, Request *request) { +void BryWebApplication::send_error(int error_code, Request *request) { std::function func = error_handler_map[error_code]; if (!func) { @@ -88,21 +88,21 @@ void Application::send_error(int error_code, Request *request) { func(error_code, request); } -void Application::send_file(const std::string &path, Request *request) { +void BryWebApplication::send_file(const std::string &path, Request *request) { std::string fp = FileCache::get_singleton()->wwwroot + path; request->send_file(fp); } -void Application::migrate() { +void BryWebApplication::migrate() { } -void Application::register_request_update(Request *request) { +void BryWebApplication::register_request_update(Request *request) { std::lock_guard lock(_update_registered_requests_mutex); _update_registered_requests.push_back(request); } -void Application::unregister_request_update(Request *request) { +void BryWebApplication::unregister_request_update(Request *request) { std::lock_guard lock(_update_registered_requests_mutex); std::size_t s = _update_registered_requests.size(); @@ -119,7 +119,7 @@ void Application::unregister_request_update(Request *request) { } } -void Application::update() { +void BryWebApplication::update() { for (std::size_t i = 0; i < _update_registered_requests.size(); ++i) { Request *r = _update_registered_requests[i]; @@ -127,14 +127,14 @@ void Application::update() { } } -Application::Application() { +BryWebApplication::BryWebApplication() { } -Application::~Application() { +BryWebApplication::~BryWebApplication() { main_route_map.clear(); error_handler_map.clear(); middlewares.clear(); } -std::string Application::default_error_404_body = "404 :("; -std::string Application::default_generic_error_body = "Internal server error! :("; +std::string BryWebApplication::default_error_404_body = "404 :("; +std::string BryWebApplication::default_generic_error_body = "Internal server error! :("; diff --git a/core/application.h b/core/bry_web_application.h similarity index 90% rename from core/application.h rename to core/bry_web_application.h index 108969b..1b0c4f3 100644 --- a/core/application.h +++ b/core/bry_web_application.h @@ -1,5 +1,5 @@ -#ifndef APPLICATION_H -#define APPLICATION_H +#ifndef BRY_WEB_APPLICATION_H +#define BRY_WEB_APPLICATION_H #include "object.h" #include @@ -13,7 +13,7 @@ class Request; -class Application { +class BryWebApplication { public: static std::string default_error_404_body; static std::string default_generic_error_body; @@ -37,8 +37,8 @@ public: void unregister_request_update(Request *request); void update(); - Application(); - virtual ~Application(); + BryWebApplication(); + virtual ~BryWebApplication(); public: HandlerInstance index_func; diff --git a/core/http/http_server.cpp b/core/http/http_server.cpp index 3736155..7ab1653 100644 --- a/core/http/http_server.cpp +++ b/core/http/http_server.cpp @@ -1,6 +1,6 @@ #include "http_server.h" -#include "core/application.h" +#include "core/bry_web_application.h" #include "core/request.h" #define LOG_VERBOSE 0 diff --git a/core/http/http_server.h b/core/http/http_server.h index d78256d..5dd39a4 100644 --- a/core/http/http_server.h +++ b/core/http/http_server.h @@ -15,7 +15,7 @@ #include class Request; -class Application; +class BryWebApplication; class HTTPServer { public: @@ -40,7 +40,7 @@ public: virtual ~HTTPServer(); //move this to a sublcass - Application *application; + BryWebApplication *application; protected: std::map _request_map; diff --git a/core/request.cpp b/core/request.cpp index 639ccc7..80368e2 100644 --- a/core/request.cpp +++ b/core/request.cpp @@ -1,6 +1,6 @@ #include "request.h" -#include "application.h" +#include "bry_web_application.h" void Request::compile_body() { compiled_body.reserve(body.size() + head.size() + 13 + 14 + 15); diff --git a/core/request.h b/core/request.h index c3b5e6e..99c00cb 100644 --- a/core/request.h +++ b/core/request.h @@ -9,14 +9,14 @@ #include "handler_instance.h" -class Application; +class BryWebApplication; class Request { public: HTTPParser::Ptr http_parser; HttpSession::Ptr session; HttpResponse *response; - Application *application; + BryWebApplication *application; uint32_t current_middleware_index; HandlerInstance handler_instance; diff --git a/modules/paged_article/paged_article.cpp b/modules/paged_article/paged_article.cpp index 28175b5..e8bf701 100644 --- a/modules/paged_article/paged_article.cpp +++ b/modules/paged_article/paged_article.cpp @@ -8,7 +8,7 @@ #include #include -#include "core/application.h" +#include "core/bry_web_application.h" void PagedArticle::index(Request *request) { const std::string r = request->get_current_path_segment();