rcpp_framework/core/application.h

56 lines
1.3 KiB
C
Raw Normal View History

2020-11-25 00:20:41 +01:00
#ifndef APPLICATION_H
#define APPLICATION_H
#include "object.h"
2020-11-25 00:20:41 +01:00
#include <functional>
#include <map>
#include <string>
#include <vector>
#include "mutex"
#include "handler_instance.h"
2020-11-25 00:20:41 +01:00
class Request;
class Application {
public:
static std::string default_error_404_body;
static std::string default_generic_error_body;
void handle_request(Request *request);
void send_error(int error_code, Request *request);
void send_file(const std::string &path, Request *request);
2020-11-25 00:20:41 +01:00
static void default_fallback_error_handler(int error_code, Request *request);
static void default_404_error_handler(int error_code, Request *request);
2020-11-25 00:20:41 +01:00
2020-12-08 16:22:18 +01:00
virtual void load_settings();
2020-11-25 00:20:41 +01:00
virtual void setup_routes();
virtual void setup_middleware();
2020-11-25 00:20:41 +01:00
void default_routing_middleware(Object *instance, Request *request);
virtual void migrate();
void register_request_update(Request *request);
void unregister_request_update(Request *request);
void update();
2020-11-25 00:20:41 +01:00
Application();
virtual ~Application();
public:
HandlerInstance index_func;
std::map<std::string, HandlerInstance> main_route_map;
std::vector<HandlerInstance> middlewares;
2020-11-25 00:20:41 +01:00
std::map<int, std::function<void(int, Request *)> > error_handler_map;
std::function<void(int, Request *)> default_error_handler_func;
2020-11-25 00:20:41 +01:00
protected:
std::mutex _update_registered_requests_mutex;
std::vector<Request *> _update_registered_requests;
2020-11-25 00:20:41 +01:00
};
#endif