mainapp.h
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MAINAPP_H
#define MAINAPP_H
#include <iostream>
#include <sys/socket.h>
#include <stdexcept>
#include <netinet/in.h>
#include <fcntl.h>
#include <thread>
#include <vector>
#include <functional>
#include <forward_list>
#include "forward_declarations.h"
#include "utils.h"
#include "threaddata.h"
#include "client.h"
#include "mqttpacket.h"
#include "subscriptionstore.h"
#include "configfileparser.h"
#include "timer.h"
class MainApp
{
static MainApp *instance;
int num_threads = 0;
bool started = false;
bool running = true;
std::vector<std::shared_ptr<ThreadData>> threads;
std::shared_ptr<SubscriptionStore> subscriptionStore;
std::unique_ptr<ConfigFileParser> confFileParser;
std::forward_list<std::function<void()>> taskQueue;
int epollFdAccept = -1;
int taskEventFd = -1;
std::mutex eventMutex;
Timer timer;
uint listenPort = 0;
uint sslListenPort = 0;
SSL_CTX *sslctx = nullptr;
Logger *logger = Logger::getInstance();
void loadConfig();
void reloadConfig();
static void doHelp(const char *arg);
static void showLicense();
void setCertAndKeyFromConfig();
int createListenSocket(int portNr, bool ssl);
void wakeUpThread();
MainApp(const std::string &configFilePath);
public:
MainApp(const MainApp &rhs) = delete;
MainApp(MainApp &&rhs) = delete;
~MainApp();
static MainApp *getMainApp();
static void initMainApp(int argc, char *argv[]);
void start();
void quit();
bool getStarted() const {return started;}
static void testConfig();
void queueConfigReload();
void queueCleanup();
};
#endif // MAINAPP_H