forked from cculianu/Fulcrum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.h
75 lines (57 loc) · 2.13 KB
/
App.h
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
//
// Fulcrum - A fast & nimble SPV Server for Bitcoin Cash
// Copyright (C) 2019-2020 Calin A. Culianu <calin.culianu@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program (see LICENSE.txt). If not, see
// <https://www.gnu.org/licenses/>.
//
#pragma once
#include <QCoreApplication>
#include <atomic>
#include <memory>
#include "Mixins.h"
#include "Options.h"
class Controller;
class Logger;
class SimpleHttpServer;
class App final : public QCoreApplication, public TimersByNameMixin
{
Q_OBJECT
public:
explicit App(int argc, char *argv[]);
~App() override;
static void miscPreAppFixups();
Logger *logger() { return _logger.get(); }
std::shared_ptr<Options> options;
/// app-global ids used for JSON-RPC 'id', as well as app-level objects we wish to track by id rather than pointer
inline quint64 newId() { return ++globalId; }
/// This is only ever true if the aboutToQuit signal has fired (as a result of this->exit() or this->quit())
inline bool isQuitting() const { return quitting; }
signals:
public slots:
private:
std::atomic<quint64> globalId = 0;
std::unique_ptr<Logger> _logger;
std::unique_ptr<Controller> controller;
QList<std::shared_ptr<SimpleHttpServer> > httpServers;
std::atomic_bool quitting = false;
void startup();
void cleanup();
void cleanup_WaitForThreadPoolWorkers();
void parseArgs();
/// This is defined in register_MetaTypes.cpp
void register_MetaTypes();
void start_httpServer(const Options::Interface &iface); // may throw
};
inline App *app() { return dynamic_cast<App *>(qApp); }