73 lines
1.9 KiB
C++
73 lines
1.9 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_persist_path() const { return perists_path;}
|
|
private:
|
|
explicit Routerin();
|
|
std::unique_ptr<StaticFileHandler> sfh;
|
|
DynamicObjects * _dyn_obs;
|
|
std::string _baseurl;
|
|
|
|
std::string perists_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);
|
|
|
|
};
|