gespielt mit std::unique_ptr und so...

master
john stone 9 years ago
parent 7b64cb5b76
commit b4337f73b2

@ -1,5 +1,7 @@
#pragma once
#include <memory>
#include <mongoose.h>
#include "StaticFileHandler.H"
@ -12,8 +14,8 @@ public:
// const ???
static Routerin * get_instance()
{
static Routerin * me;
if ( ! me->hasInstance )
static Routerin * me = nullptr;
if (!me)
return me = new Routerin();
return me;
}
@ -38,8 +40,8 @@ public:
}
private:
explicit Routerin();
StaticFileHandler && sfh;
bool hasInstance = false;
std::unique_ptr<StaticFileHandler> sfh;
//bool hasInstance = false;
int event_request_route ( struct mg_event *event);
int event_newthread_route ( struct mg_event *event);

@ -14,17 +14,11 @@ using std::endl;
Routerin::Routerin():
sfh( UltraSimpleStaticFileHandler())
sfh( new UltraSimpleStaticFileHandler())
{
cout << "Konstr Routering" << std::endl;
Routerin::hasInstance = true;
}
Routerin::~Routerin()
{
Routerin::hasInstance = false;
}
int Routerin::event_request_route(struct mg_event *event){
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 << " path: " << reststr << endl;
sfh.answer_pathreq(reststr,event->conn);
sfh->answer_pathreq(reststr,event->conn);
return 1;
}

@ -6,6 +6,7 @@ class UltraSimpleStaticFileHandler :public StaticFileHandler
public:
virtual ~UltraSimpleStaticFileHandler();
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>
</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)
{
mg_printf(conn, "HTTP/1.0 200 OK\r\n"

@ -2,6 +2,7 @@
#include <cstdio>
#include <cstring>
#include <iostream>
#include <signal.h>
#include <mongoose.h>
@ -81,43 +82,65 @@ bool configfile_parsing_action(int& argc, char **argv)
//initialize the parameters structure
params = cmd_parser_params_create();
params->check_required = 0;
params->check_required = 0;
if (cmd_parser_config_file("./siccc.conf", &args_info, params) != 0) {
cmd_parser_free(&args_info);
free(params);
return false;
cmd_parser_free(&args_info);
free(params);
return false;
}
params->initialize = 0;
params->override = 1;
params->check_required = 1;
params->check_required = 1;
//call the command line parser
if (cmd_parser(argc, argv, &args_info) != 0) {
cmd_parser_free(&args_info);
free(params);
return false;
cmd_parser_free(&args_info);
free(params);
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)
{
if ( !configfile_parsing_action(argc, argv) ) {
std::cerr << "ERROR ERROR BEEP" << std::endl;
exit(1);
}
if ( !configfile_parsing_action(argc, argv) ) {
std::cerr << "ERROR ERROR BEEP" << std::endl;
exit(1);
}
#ifdef DEBUG
dump_args();
dump_args();
if (std::atexit(&exithandlerfunc))
exit(-4);
#endif
struct sigaction sa;
sa.sa_handler = signalhandler;
sigaction(SIGINT, &sa ,nullptr);
MongooseHandler m(args_info.port_arg);
if (!args_info.daemonize_flag) {
while(1)
getchar();
}
MongooseHandler m(args_info.port_arg);
if (!args_info.daemonize_flag) {
while(1)
getchar();
}
return 0;
return 0;
}

Loading…
Cancel
Save