mirror of https://github.com/nymea/nymea.git
fixed main and added RunningMode
parent
1529706561
commit
8eaa447cb1
|
|
@ -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<DevicePlugin *> GuhCore::plugins() const
|
||||
|
|
|
|||
|
|
@ -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<DevicePlugin *> 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;
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "guhservice.h"
|
||||
|
||||
GuhService::GuhService(int argc, char **argv):
|
||||
QtService<QCoreApplication>(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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef GUHSERVICE_H
|
||||
#define GUHSERVICE_H
|
||||
|
||||
|
|
|
|||
|
|
@ -17,53 +17,40 @@
|
|||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QtPlugin>
|
||||
#include <unistd.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue