sic/src/Routerin.H

98 lines
2.6 KiB
C++
Raw Normal View History

2014-01-17 23:47:14 +01:00
#pragma once
2014-01-25 23:32:02 +01:00
#include <memory>
2014-01-17 23:47:14 +01:00
#include <mongoose.h>
2014-05-02 00:01:01 +02:00
#include "StaticFileHandler.H"
2014-05-02 00:01:01 +02:00
//#include "DynamicObjects.H"
class DynamicObjects;
2014-01-17 23:47:14 +01:00
int event_route_wrap(struct mg_connection *conn, mg_event ev);
2014-01-17 23:47:14 +01:00
class Routerin
{
2014-01-23 02:22:06 +01:00
public:
2014-01-18 14:48:52 +01:00
//Routerin(StaticFileHandler &sfh);
2014-01-17 23:47:14 +01:00
2014-01-23 02:22:06 +01:00
~Routerin();
// const ???
static Routerin * get_instance()
{
2014-01-25 23:32:02 +01:00
static Routerin * me = nullptr;
if (!me)
2014-01-23 02:22:06 +01:00
return me = new Routerin();
return me;
}
2014-05-02 01:15:14 +02:00
//after configuration:
void start(void);
2014-05-29 18:58:20 +02:00
void function_name()
{
}
2014-05-01 23:39:14 +02:00
/*enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };*/
//enum mg_event {
//MG_POLL = 100, // Callback return value is ignored
//MG_CONNECT, // If callback returns MG_FALSE, connect fails
//MG_AUTH, // If callback returns MG_FALSE, authentication fails
//MG_REQUEST, // If callback returns MG_FALSE, Mongoose continues with req
//MG_REPLY, // If callback returns MG_FALSE, Mongoose closes connection
//MG_CLOSE, // Connection is closed, callback return value is ignored
//MG_WS_HANDSHAKE, // New websocket connection, handshake request
//MG_HTTP_ERROR // If callback returns MG_FALSE, Mongoose continues with err
//};
2014-05-01 23:39:14 +02:00
int event_route(struct mg_connection *conn, enum mg_event event)
2014-01-23 02:22:06 +01:00
{
// Foohash fh;
switch (event) {
case MG_REQUEST:
return event_request_route(conn);
case MG_AUTH:
return MG_TRUE;
2014-01-23 02:22:06 +01:00
default:
return event_fallback_route(event, conn);
2014-01-23 02:22:06 +01:00
}
}
2014-05-02 00:54:08 +02:00
std::string const & get_baseurl()const{return baseurl;}
void set_baseurl(std::string baseurl);
2014-05-01 23:39:14 +02:00
2014-05-02 00:54:08 +02:00
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);
2014-01-17 23:47:14 +01:00
private:
2014-01-23 02:22:06 +01:00
explicit Routerin();
std::unique_ptr<StaticFileHandler> sfh;
DynamicObjects * _dyn_obs;
2014-05-02 00:54:08 +02:00
std::string baseurl;
2014-05-02 00:54:08 +02:00
std::string file_path;
std::string json_path;
2014-05-01 23:39:14 +02:00
// bool hasInstance = false;
2014-01-17 23:47:14 +01:00
int event_request_route ( struct mg_connection *conn);
// int event_newthread_route ( struct mg_event *event);
int event_fallback_route ( enum mg_event event, struct mg_connection *conn );
// int event_requend_route ( struct mg_event *event);
2014-01-17 23:47:14 +01:00
int rq_static(char const * const restrstr , struct mg_connection *conn);
int rq_file(char const * const reststr , struct mg_connection *conn);
int rq_date(char const * const reststr , struct mg_connection *conn);
int rq_upload(char const * const reststr , struct mg_connection *conn);
int rq_render_mainpage(struct mg_connection *conn);
int handle_upload(struct mg_connection *conn);
2014-01-17 23:47:14 +01:00
};