Files
thehub/libs/apputils/FloweeServiceApplication.h
T

89 lines
2.9 KiB
C++
Raw Permalink Normal View History

2019-04-01 10:53:46 +02:00
/*
* This file is part of the Flowee project
* Copyright (C) 2019 Tom Zander <tomz@freedommail.ch>
*
* 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 FLOWEESERVICEAPPLICATION_H
#define FLOWEESERVICEAPPLICATION_H
#include <QCoreApplication>
#include <QCommandLineParser>
2019-04-09 19:34:55 +02:00
#include <QList>
2019-04-01 10:53:46 +02:00
#include <Logger.h>
#include <NetworkEndPoint.h>
2019-04-09 19:34:55 +02:00
#include <boost/asio/ip/tcp.hpp>
2019-04-01 10:53:46 +02:00
void HandleSIGTERM(int);
void HandleSIGHUP(int);
class FloweeServiceApplication : public QCoreApplication {
Q_OBJECT
public:
2019-09-12 15:23:30 +02:00
FloweeServiceApplication(int &argc, char **argv, short appLogSection = LOG_DEFAULT_SECTION);
2019-04-01 10:53:46 +02:00
~FloweeServiceApplication();
enum Option {
NoOptions = 0,
NoConnect = 1,
NoVerbosity = 2
};
Q_DECLARE_FLAGS(Options, Option)
void addServerOptions(QCommandLineParser &parser, Options options = NoOptions);
void addClientOptions(QCommandLineParser &parser, Options options = NoOptions);
2019-05-09 12:15:34 +02:00
void setup(const char *logFilename = nullptr, const QString &configFilePath = QString());
2019-04-01 10:53:46 +02:00
2019-09-12 15:23:30 +02:00
EndPoint serverAddressFromArguments(uint16_t defaultPort) const;
2019-08-24 15:36:17 +02:00
enum DefaultBindOption {
UserSupplied, ///< If the user doesn't supply a bind option, we don't bind.
LocalhostAsDefault, ///< If no user supplied bind was found, we bind to localhost (ipv4 and ipv6)
AllInterfacesAsDefault ///< If no user supplied bind was found, we bind to all found interfaces.
};
/**
* Return all end points based on the command line arguments.
* We accept "localhost" as a string to bind to that.
*
* We accept "0.0.0.0" as a wildcard to all local interfaces. Please note this requires QtNetworkLib.
*/
2019-09-12 15:23:30 +02:00
QList<boost::asio::ip::tcp::endpoint> bindingEndPoints(QCommandLineParser &parser, uint16_t defaultPort, DefaultBindOption defaultBind = UserSupplied) const;
2019-04-01 10:53:46 +02:00
void handleSigHub() const;
signals:
void reparseConfig() const;
2019-04-01 10:53:46 +02:00
private:
QCommandLineOption m_debug;
2019-05-13 18:27:09 +02:00
QCommandLineOption m_verbose;
QCommandLineOption m_quiet;
2019-04-13 16:23:02 +02:00
QCommandLineOption m_version;
2019-04-09 19:34:55 +02:00
QCommandLineOption m_bindAddress;
2019-05-09 12:15:34 +02:00
QCommandLineOption m_connect;
2019-04-01 10:53:46 +02:00
QString m_logsconf;
QString m_logFile;
2019-09-12 15:23:30 +02:00
short m_appLogSection = -1;
2019-05-13 18:27:09 +02:00
bool m_isServer = false;
QCommandLineParser *m_parser = nullptr;
2019-04-01 10:53:46 +02:00
};
Q_DECLARE_OPERATORS_FOR_FLAGS(FloweeServiceApplication::Options)
2019-04-01 10:53:46 +02:00
#endif