mainapp.h
2.64 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3.
FlashMQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.
*/
#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 <list>
#include <sys/resource.h>
#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"
#include "scopedsocket.h"
#include "oneinstancelock.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;
std::shared_ptr<Settings> settings;
std::list<std::shared_ptr<Listener>> listeners;
std::mutex quitMutex;
std::string fuzzFilePath;
OneInstanceLock oneInstanceLock;
Logger *logger = Logger::getInstance();
void setlimits(rlim_t nofile);
void loadConfig();
void reloadConfig();
static void doHelp(const char *arg);
static void showLicense();
std::list<ScopedSocket> createListenSocket(const std::shared_ptr<Listener> &listener);
void wakeUpThread();
void queueKeepAliveCheckAtAllThreads();
void queuePasswordFileReloadAllThreads();
void setFuzzFile(const std::string &fuzzFilePath);
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