2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This 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/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drone.h"
|
|
|
|
|
|
|
|
#include "myservice.h"
|
2019-07-02 07:45:26 -05:00
|
|
|
#include "params.h"
|
2015-11-06 07:27:07 -06:00
|
|
|
#include "rpcserver.h"
|
|
|
|
#include "settings.h"
|
2016-06-07 10:41:38 -05:00
|
|
|
#include "../common/updater.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2015-04-28 08:15:35 -05:00
|
|
|
#include <QMetaType>
|
|
|
|
|
2019-07-02 07:45:26 -05:00
|
|
|
extern Params appParams;
|
2015-04-16 11:50:07 -05:00
|
|
|
extern const char* version;
|
|
|
|
extern const char* revision;
|
|
|
|
|
|
|
|
Drone::Drone(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
2016-06-07 10:41:38 -05:00
|
|
|
Updater *updater = new Updater();
|
|
|
|
|
2019-07-02 07:45:26 -05:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
bool enableLogs = true;
|
|
|
|
#else
|
|
|
|
bool enableLogs = !appParams.optLogsDisabled();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rpcServer = new RpcServer(enableLogs);
|
2015-04-16 11:50:07 -05:00
|
|
|
service = new MyService();
|
2016-06-07 10:41:38 -05:00
|
|
|
|
|
|
|
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
|
|
|
this, SLOT(onNewVersion(QString)));
|
|
|
|
updater->checkForNewVersion();
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Drone::~Drone()
|
|
|
|
{
|
|
|
|
delete rpcServer;
|
|
|
|
delete service;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Drone::init()
|
|
|
|
{
|
2015-11-06 07:27:07 -06:00
|
|
|
QString addr = appSettings->value(kRpcServerAddress).toString();
|
|
|
|
QHostAddress address = addr.isEmpty() ?
|
|
|
|
QHostAddress::Any : QHostAddress(addr);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(rpcServer);
|
|
|
|
|
2015-04-28 08:15:35 -05:00
|
|
|
qRegisterMetaType<SharedProtobufMessage>("SharedProtobufMessage");
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
if (address.isNull()) {
|
|
|
|
qWarning("Invalid RpcServer Address <%s> specified. Using 'Any'",
|
|
|
|
qPrintable(addr));
|
|
|
|
address = QHostAddress::Any;
|
|
|
|
}
|
|
|
|
|
2019-07-02 07:45:26 -05:00
|
|
|
if (!rpcServer->registerService(service, address, appParams.servicePortNumber()))
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
//qCritical(qPrintable(rpcServer->errorString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:15:35 -05:00
|
|
|
connect(service, SIGNAL(notification(int, SharedProtobufMessage)),
|
|
|
|
rpcServer, SIGNAL(notifyClients(int, SharedProtobufMessage)));
|
2015-04-24 10:23:00 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-10 08:10:32 -06:00
|
|
|
|
|
|
|
MyService* Drone::rpcService()
|
|
|
|
{
|
|
|
|
return service;
|
|
|
|
}
|
2016-06-07 10:41:38 -05:00
|
|
|
|
|
|
|
void Drone::onNewVersion(QString newVersion)
|
|
|
|
{
|
|
|
|
qWarning("%s", qPrintable(QString("New Ostinato version %1 available. "
|
|
|
|
"Visit http://ostinato.org to download").arg(newVersion)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|