gespielt mit std::unique_ptr und so...
This commit is contained in:
parent
7b64cb5b76
commit
b4337f73b2
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
#include "StaticFileHandler.H"
|
#include "StaticFileHandler.H"
|
||||||
|
|
||||||
|
@ -12,8 +14,8 @@ public:
|
||||||
// const ???
|
// const ???
|
||||||
static Routerin * get_instance()
|
static Routerin * get_instance()
|
||||||
{
|
{
|
||||||
static Routerin * me;
|
static Routerin * me = nullptr;
|
||||||
if ( ! me->hasInstance )
|
if (!me)
|
||||||
return me = new Routerin();
|
return me = new Routerin();
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
|
@ -38,8 +40,8 @@ public:
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
explicit Routerin();
|
explicit Routerin();
|
||||||
StaticFileHandler && sfh;
|
std::unique_ptr<StaticFileHandler> sfh;
|
||||||
bool hasInstance = false;
|
//bool hasInstance = false;
|
||||||
|
|
||||||
int event_request_route ( struct mg_event *event);
|
int event_request_route ( struct mg_event *event);
|
||||||
int event_newthread_route ( struct mg_event *event);
|
int event_newthread_route ( struct mg_event *event);
|
||||||
|
|
|
@ -14,17 +14,11 @@ using std::endl;
|
||||||
|
|
||||||
|
|
||||||
Routerin::Routerin():
|
Routerin::Routerin():
|
||||||
sfh( UltraSimpleStaticFileHandler())
|
sfh( new UltraSimpleStaticFileHandler())
|
||||||
{
|
{
|
||||||
cout << "Konstr Routering" << std::endl;
|
cout << "Konstr Routering" << std::endl;
|
||||||
Routerin::hasInstance = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Routerin::~Routerin()
|
|
||||||
{
|
|
||||||
Routerin::hasInstance = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int Routerin::event_request_route(struct mg_event *event){
|
int Routerin::event_request_route(struct mg_event *event){
|
||||||
const RouterOp *blub=0;
|
const RouterOp *blub=0;
|
||||||
|
@ -85,7 +79,7 @@ int Routerin::rq_static(char const * const reststr , struct mg_event *event)
|
||||||
{
|
{
|
||||||
std::cerr << " a static file is reqested!" << endl;
|
std::cerr << " a static file is reqested!" << endl;
|
||||||
std::cerr << " path: " << reststr << endl;
|
std::cerr << " path: " << reststr << endl;
|
||||||
sfh.answer_pathreq(reststr,event->conn);
|
sfh->answer_pathreq(reststr,event->conn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ class UltraSimpleStaticFileHandler :public StaticFileHandler
|
||||||
public:
|
public:
|
||||||
virtual ~UltraSimpleStaticFileHandler();
|
virtual ~UltraSimpleStaticFileHandler();
|
||||||
virtual int answer_pathreq(const char * const path, struct mg_connection *conn) override;
|
virtual int answer_pathreq(const char * const path, struct mg_connection *conn) override;
|
||||||
|
UltraSimpleStaticFileHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,19 @@ static const char * hello_world_html = u8R"HERE(
|
||||||
</body>
|
</body>
|
||||||
</html>)HERE";
|
</html>)HERE";
|
||||||
|
|
||||||
UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler(){};
|
#include <iostream>
|
||||||
|
|
||||||
|
UltraSimpleStaticFileHandler::UltraSimpleStaticFileHandler()
|
||||||
|
{
|
||||||
|
std::cout << "hallo ausm construktor von USSFH [" << this << "] "
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler(){
|
||||||
|
std::cout << "Arrrr aus destruktor! und (∀Gute) zum Pinguintag!!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
int UltraSimpleStaticFileHandler::answer_pathreq(const char * const path,
|
int UltraSimpleStaticFileHandler::answer_pathreq(const char * const path __attribute__((unused)),
|
||||||
struct mg_connection *conn)
|
struct mg_connection *conn)
|
||||||
{
|
{
|
||||||
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
|
|
||||||
|
@ -81,43 +82,65 @@ bool configfile_parsing_action(int& argc, char **argv)
|
||||||
//initialize the parameters structure
|
//initialize the parameters structure
|
||||||
params = cmd_parser_params_create();
|
params = cmd_parser_params_create();
|
||||||
|
|
||||||
params->check_required = 0;
|
params->check_required = 0;
|
||||||
|
|
||||||
if (cmd_parser_config_file("./siccc.conf", &args_info, params) != 0) {
|
if (cmd_parser_config_file("./siccc.conf", &args_info, params) != 0) {
|
||||||
cmd_parser_free(&args_info);
|
cmd_parser_free(&args_info);
|
||||||
free(params);
|
free(params);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
params->initialize = 0;
|
params->initialize = 0;
|
||||||
params->override = 1;
|
params->override = 1;
|
||||||
params->check_required = 1;
|
params->check_required = 1;
|
||||||
|
|
||||||
//call the command line parser
|
//call the command line parser
|
||||||
if (cmd_parser(argc, argv, &args_info) != 0) {
|
if (cmd_parser(argc, argv, &args_info) != 0) {
|
||||||
cmd_parser_free(&args_info);
|
cmd_parser_free(&args_info);
|
||||||
free(params);
|
free(params);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void signalhandler(int signum){
|
||||||
|
switch(signum){
|
||||||
|
case SIGINT:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cout << "called sighandler with signal " << signum << " FUPP! " << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exithandlerfunc(){
|
||||||
|
std::cout << "alles hat ein ende" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( !configfile_parsing_action(argc, argv) ) {
|
if ( !configfile_parsing_action(argc, argv) ) {
|
||||||
std::cerr << "ERROR ERROR BEEP" << std::endl;
|
std::cerr << "ERROR ERROR BEEP" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
dump_args();
|
dump_args();
|
||||||
|
if (std::atexit(&exithandlerfunc))
|
||||||
|
exit(-4);
|
||||||
#endif
|
#endif
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = signalhandler;
|
||||||
|
sigaction(SIGINT, &sa ,nullptr);
|
||||||
|
|
||||||
MongooseHandler m(args_info.port_arg);
|
MongooseHandler m(args_info.port_arg);
|
||||||
if (!args_info.daemonize_flag) {
|
|
||||||
while(1)
|
|
||||||
getchar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
if (!args_info.daemonize_flag) {
|
||||||
|
while(1)
|
||||||
|
getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue