Files
thehub/libs/server/Application.h
T

96 lines
2.6 KiB
C++
Raw Permalink Normal View History

2016-08-16 16:51:22 +02:00
/*
2017-11-13 23:09:33 +01:00
* This file is part of the Flowee project
* Copyright (C) 2016-2021 Tom Zander <tom@flowee.org>
2016-08-16 16:51:22 +02:00
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef APPLICATION_H
#define APPLICATION_H
#include "DiskSpaceChecker.h"
#include <WorkerThreads.h>
2016-08-16 16:51:22 +02:00
#include <boost/asio/io_service.hpp>
#include <boost/thread.hpp>
#include <memory>
2018-01-15 15:26:12 +00:00
namespace Validation {
class Engine;
}
class CTxMemPool;
2016-08-16 16:51:22 +02:00
2018-01-16 16:40:34 +00:00
#define flApp Application::instance()
2016-08-16 16:51:22 +02:00
/**
* An application singleton that manages some application specific data.
* The Application singleton can be used to have a single place that owns a threadpool
* which becomes easy to reach from all your classes and thus avoids cross-dependencies.
* The IoService is lazy-initialized on first call to IoService() and as such you
* won't have any negative side-effects if the application does not use them (yet).
*/
class Application : public WorkerThreads
2016-08-16 16:51:22 +02:00
{
public:
Application();
2017-02-18 15:31:38 +01:00
~Application();
2016-08-16 16:51:22 +02:00
/// returns (and optionally creates) an instance
static Application *instance();
static int exec();
static void quit(int rc = 0);
2018-01-15 15:26:12 +00:00
Validation::Engine* validation();
CTxMemPool* mempool();
2016-12-28 13:20:24 +01:00
/**
* @brief userAgent creates the user-agent string as it is send over the wire.
* This includes the client name, the version number and any parameters
* like -uacomments (user-agent-comments)
*/
static std::string userAgent();
/**
2017-11-13 23:09:33 +01:00
* @returns the name of the client, in this case "Flowee".
2016-12-28 13:20:24 +01:00
*/
static const char * clientName();
2017-02-21 13:44:48 +01:00
/**
* Wrapper function that allows users to create a thread on our global thread-group.
*/
template<typename F>
static boost::thread* createThread(F threadfunc) {
return instance()->createNewThread(threadfunc);
2017-02-21 13:44:48 +01:00
}
2020-05-21 19:33:13 +02:00
static bool isClosingDown();
2017-02-24 14:34:35 +01:00
DiskSpaceChecker& diskSpaceChecker();
2017-07-23 12:37:49 +02:00
protected:
void init();
2018-01-15 15:26:12 +00:00
std::unique_ptr<Validation::Engine> m_validationEngine;
2017-07-23 12:37:49 +02:00
2016-08-16 16:51:22 +02:00
private:
int m_returnCode;
2020-05-21 19:33:13 +02:00
std::atomic_bool m_closingDown;
2021-04-05 11:36:31 +02:00
std::unique_ptr<DiskSpaceChecker> m_diskSpaceChecker;
2016-08-16 16:51:22 +02:00
};
#endif