diff --git a/server/guhcore.cpp b/server/guhcore.cpp index a3206788..4e68db20 100644 --- a/server/guhcore.cpp +++ b/server/guhcore.cpp @@ -27,6 +27,13 @@ instantiate, set up and connect all the other components. */ +/*! \enum GuhCore::RunningMode + \value RunningModeApplication + Guh runns as application. + \value RunningModeService + Guh is started as service (daemon). +*/ + /*! \fn void GuhCore::eventTriggered(const Event &event); This signal is emitted when an \a event happend. */ @@ -92,6 +99,18 @@ void GuhCore::destroy() s_instance = 0; } +/*! Returns the runningMode of this instance. */ +GuhCore::RunningMode GuhCore::runningMode() const +{ + return m_runningMode; +} + +/*! Set the \a runningMode of this instance. */ +void GuhCore::setRunningMode(const GuhCore::RunningMode &runningMode) +{ + m_runningMode = runningMode; +} + /*! Calls the metheod DeviceManager::plugins(). * \sa DeviceManager::plugins(), */ QList GuhCore::plugins() const diff --git a/server/guhcore.h b/server/guhcore.h index 233c7cdc..3828d010 100644 --- a/server/guhcore.h +++ b/server/guhcore.h @@ -37,12 +37,20 @@ class GuhCore : public QObject { Q_OBJECT public: + enum RunningMode { + RunningModeApplication, + RunningModeService + }; + static GuhCore* instance(); ~GuhCore(); // Used for testing void destroy(); + RunningMode runningMode() const; + void setRunningMode(const RunningMode &runningMode); + QList plugins() const; DeviceManager::DeviceError setPluginConfig(const PluginId &pluginId, const ParamList ¶ms); @@ -89,6 +97,7 @@ private: DeviceManager* deviceManager() const; explicit GuhCore(QObject *parent = 0); static GuhCore *s_instance; + RunningMode m_runningMode; JsonRPCServer *m_jsonServer; DeviceManager *m_deviceManager; diff --git a/server/guhservice.cpp b/server/guhservice.cpp index 7f02a351..13540ae6 100644 --- a/server/guhservice.cpp +++ b/server/guhservice.cpp @@ -1,8 +1,34 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh 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, version 2 of the License. * + * * + * Guh 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 guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include #include "guhservice.h" GuhService::GuhService(int argc, char **argv): QtService(argc, argv, "guh daemon") { + qDebug() << "guhd started as daemon."; + application()->setOrganizationName("guh"); + application()->setApplicationName("guhd"); + application()->setApplicationVersion(GUH_VERSION_STRING); + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); setServiceDescription("guh daemon"); setServiceFlags(QtServiceBase::CanBeSuspended); } @@ -13,5 +39,5 @@ GuhService::~GuhService() void GuhService::start() { - GuhCore::instance(); + GuhCore::instance()->setRunningMode(GuhCore::RunningModeService); } diff --git a/server/guhservice.h b/server/guhservice.h index ba369a1b..6ef1ec59 100644 --- a/server/guhservice.h +++ b/server/guhservice.h @@ -1,3 +1,21 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh 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, version 2 of the License. * + * * + * Guh 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 guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef GUHSERVICE_H #define GUHSERVICE_H diff --git a/server/main.cpp b/server/main.cpp index b4e1dcec..a092fbc1 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -17,53 +17,40 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include +#include #include -#include #include "guhcore.h" #include "guhservice.h" int main(int argc, char *argv[]) { - QStringList arguments; - for (int i = 0; i < argc; ++i) { - arguments.append(QString(argv[i])); + QCoreApplication application(argc, argv); + application.setOrganizationName("guh"); + application.setApplicationName("guhd"); + application.setApplicationVersion(GUH_VERSION_STRING); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + QString description = QString("\nguh ( /[guːh]/ ) is an open source home automation server, which allows to\n" + "control a lot of different devices from many different manufacturers.\n" + "guhd %1 (C) 2014-2015 guh\n" + "Released under the GNU GENERAL PUBLIC LICENSE Version 2.").arg(GUH_VERSION_STRING); + + parser.setApplicationDescription(description); + + QCommandLineOption foregroundOption(QStringList() << "n" << "no-daemon", QCoreApplication::translate("main", "Run guhd in the foreground, not as daemon.")); + parser.addOption(foregroundOption); + + parser.process(application); + + bool startForeground = parser.isSet(foregroundOption); + if (startForeground) { + GuhCore::instance()->setRunningMode(GuhCore::RunningModeApplication); + return application.exec(); } - if (arguments.contains("-h") || arguments.contains("--help")) { - qDebug() << "guhd" << GUH_VERSION_STRING << "(C) 2014-2015 guh" ; - qDebug() << "Released under the GNU GENERAL PUBLIC LICENSE Version 2"; - qDebug() << ""; - qDebug() << "guh (/[guːh]/ - pronounced German and sounds like \"goo\") is an open source"; - qDebug() << "home automation server, which allows to control a lot of different devices "; - qDebug() << "from many different manufacturers."; - qDebug() << ""; - qDebug() << "options:"; - qDebug() << " -h, --help print this help message"; - qDebug() << " -v, --version print version"; - qDebug() << " -e, --executable start guh as application, not as daemon"; - qDebug() << ""; - exit(0); - } - - if (arguments.contains("-v") || arguments.contains("--version")) { - qDebug() << "guhd" << GUH_VERSION_STRING; - exit(0); - } - - if (!arguments.contains("-e") && !arguments.contains("--executable")) { - qDebug() << "guhd started as daemon."; - GuhService service(argc, argv); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - return service.exec(); - } - - QCoreApplication a(argc, argv); - qDebug() << "guhd started as executable."; - a.setOrganizationName("guh"); - a.setApplicationName("guhd"); - GuhCore::instance(); - return a.exec(); + GuhService service(argc, argv); + return service.exec(); } diff --git a/server/qtservice/qtservice.cpp b/server/qtservice/qtservice.cpp index 4d46dd97..20c54151 100644 --- a/server/qtservice/qtservice.cpp +++ b/server/qtservice/qtservice.cpp @@ -1005,7 +1005,7 @@ void QtServiceBase::processCommand(int /*code*/) \b{Note:} On Unix systems, this class relies on facilities provided by the QtNetwork module, provided as part of the - \l{Qt Open Source Edition} and certain \l{Qt Commercial Editions}. + Qt Open Source Edition and certain Qt Commercial Editions. The QtService class functionality is inherited from QtServiceBase, but in addition the QtService class binds an instance of diff --git a/server/tcpserver.cpp b/server/tcpserver.cpp index 4162e9f6..db09981a 100644 --- a/server/tcpserver.cpp +++ b/server/tcpserver.cpp @@ -39,7 +39,9 @@ TcpServer::TcpServer(QObject *parent) : // load settings bool ok; QSettings settings("/etc/guh/guhd.conf"); - settings.beginGroup("JSON-RPC Server"); + settings.beginGroup("JSONRPC"); + + // TODO: handle interfaces in settings (enable just localhost ecc...) uint port = settings.value("port", 1234).toUInt(&ok); settings.endGroup(); diff --git a/tests/auto/checklicenseheaders.sh b/tests/auto/checklicenseheaders.sh index 7abccf77..802f02b3 100755 --- a/tests/auto/checklicenseheaders.sh +++ b/tests/auto/checklicenseheaders.sh @@ -3,7 +3,7 @@ if test -z "$results"; then exit 0 else echo "*** License check failed. Offending files:" - licensecheck -r -c '\.(cpp|h)$' $1 | grep -v "GPL (v2)" | grep -v "GENERATED" + licensecheck -r -c '\.(cpp|h)$' $1 | grep -v "GPL (v2)" | grep -v "BSD" | grep -v "GENERATED" exit 1 fi