some fixes [multithreading,..]

needed interface changes [new options]
logger for android
wifi-ap-optimization
new test-cases
This commit is contained in:
2016-09-28 12:19:14 +02:00
parent 91e3367372
commit 4f511d907e
62 changed files with 1418 additions and 175 deletions

View File

@@ -6,6 +6,8 @@
#include <iomanip>
#include "Time.h"
#include "log/LoggerCOUT.h"
/** quick and dirty workaround */
static decltype(Time::tick()) LogLastTick;
@@ -13,18 +15,36 @@ static decltype(Time::tick()) LogLastTick;
class Log {
private:
static Logger** getLoggerPtr() {
static Logger* logger = new LoggerCOUT();
return &logger;
}
static Logger* getLogger() {
return *getLoggerPtr();
}
public:
/** set the to-be-used logger */
static void setLogger(Logger* logger) {
*getLoggerPtr() = logger;
}
static void add(const char* comp, const std::string what, const bool nl = true) {
addComp(comp);
std::cout << what;
if (nl) {std::cout << std::endl;} else {std::cout << std::flush;}
std::stringstream out;
addComp(out, comp);
out << what;
getLogger()->add(out.str(), nl);
}
static void add(const std::string& component, const std::string what, const bool nl = true) {
addComp(component.c_str());
std::cout << what;
if (nl) {std::cout << std::endl;} else {std::cout << std::flush;}
std::stringstream out;
addComp(out, component.c_str());
out << what;
getLogger()->add(out.str(), nl);
}
@@ -37,15 +57,17 @@ public:
const auto cur = Time::tick();
const int diff_ms = Time::diffMS(LogLastTick, cur);
LogLastTick = cur;
std::cout << " (took: " << diff_ms << "ms)" << std::endl;
std::stringstream out;
out << " (took: " << diff_ms << "ms)";
getLogger()->add(out.str(), true);
}
private:
static void addComp(const char* component) {
std::cout << "[" << std::setw(12) << std::setfill(' ') << component << "] ";
static void addComp(std::ostream& out, const char* component) {
out << "[" << std::setw(12) << std::setfill(' ') << component << "] ";
}
};

17
misc/log/Logger.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <string>
/** base-class for all loggers */
class Logger {
public:
virtual ~Logger() {;}
virtual void add(const std::string& str, const bool nl) = 0;
};
#endif // LOGGER_H

19
misc/log/LoggerAndroid.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef LOGGERANDROID_H
#define LOGGERANDROID_H
#include "Logger.h"
class LoggerAndroid : public Logger {
public:
virtual void add(const std::string& str, const bool nl) override {
(void) nl;
#ifdef ANDROID
QMessageLogger().info(str.c_str());
#endif
}
};
#endif // LOGGERANDROID_H

18
misc/log/LoggerCOUT.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef LOGGERCOUT_H
#define LOGGERCOUT_H
#include "Logger.h"
#include <iostream>
class LoggerCOUT : public Logger {
public:
virtual void add(const std::string& str, const bool nl) override {
std::cout << str;
if (nl) {std::cout << std::endl;} else {std::cout << std::flush;}
}
};
#endif // LOGGERCOUT_H

View File

@@ -0,0 +1,30 @@
#ifndef LOGGERCOMPOSITE_H
#define LOGGERCOMPOSITE_H
#include "Logger.h"
#include <vector>
class LoggerComposite : public Logger {
private:
/** all contained loggers */
std::vector<Logger*> loggers;
public:
/** add a new logger to this composite */
void addLogger(Logger* l) {
loggers.push_back(l);
}
virtual void add(const std::string& str, const bool nl) override {
for (Logger* l : loggers) {l->add(str, nl);}
}
};
#endif // LOGGERCOMPOSITE_H