sic/src/Routerin.H

80 lines
2.1 KiB
C++

#pragma once
#include <memory>
#include <mongoose.h>
#include "StaticFileHandler.H"
//#include "DynamicObjects.H"
class DynamicObjects;
class Routerin
{
public:
//Routerin(StaticFileHandler &sfh);
~Routerin();
// const ???
static Routerin * get_instance()
{
static Routerin * me = nullptr;
if (!me)
return me = new Routerin();
return me;
}
static int event_route(struct mg_event *event)
{
// Foohash fh;
Routerin *rouri = Routerin::get_instance();
switch (event->type) {
case MG_REQUEST_BEGIN:
return rouri->event_request_route(event);
case MG_THREAD_BEGIN:
return rouri->event_newthread_route(event);
case MG_REQUEST_END:
return rouri->event_requend_route(event);
case MG_HTTP_ERROR:
case MG_EVENT_LOG:
case MG_THREAD_END:
default:
return rouri->event_fallback_route(event);
}
}
std::string const & get_baseurl()const{return baseurl;}
void set_baseurl(std::string baseurl);
std::string const & get_file_path()const{return file_path;}
void set_file_path(std::string file_path);
std::string const & get_json_path()const{return json_path;}
void set_json_path(std::string json_path);
std::string const & get_persist_path() const { return perists_path;}
private:
explicit Routerin();
std::unique_ptr<StaticFileHandler> sfh;
DynamicObjects * _dyn_obs;
std::string baseurl;
std::string file_path;
std::string json_path;
bool hasInstance = false;
int event_request_route ( struct mg_event *event);
int event_newthread_route ( struct mg_event *event);
int event_fallback_route ( struct mg_event *event);
int event_requend_route ( struct mg_event *event);
int rq_static(char const * const restrstr , struct mg_event *event);
int rq_file(char const * const reststr , struct mg_event *event);
int rq_date(char const * const reststr , struct mg_event *event);
int rq_upload(char const * const reststr , struct mg_event *event);
int rq_render_mainpage(struct mg_event *event);
};