1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*
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"
#include "params.h"
#include "rpcserver.h"
#include "settings.h"
#include "../common/updater.h"
#include <QMetaType>
extern Params appParams;
extern const char* version;
extern const char* revision;
Drone::Drone(QObject *parent)
: QObject(parent)
{
Updater *updater = new Updater();
#ifdef QT_DEBUG
bool enableLogs = true;
#else
bool enableLogs = !appParams.optLogsDisabled();
#endif
rpcServer = new RpcServer(enableLogs);
service = new MyService();
connect(updater, SIGNAL(newVersionAvailable(QString)),
this, SLOT(onNewVersion(QString)));
updater->checkForNewVersion();
}
Drone::~Drone()
{
delete rpcServer;
delete service;
}
bool Drone::init()
{
QString addr = appSettings->value(kRpcServerAddress).toString();
QHostAddress address = addr.isEmpty() ?
QHostAddress::Any : QHostAddress(addr);
Q_ASSERT(rpcServer);
qRegisterMetaType<SharedProtobufMessage>("SharedProtobufMessage");
if (address.isNull()) {
qWarning("Invalid RpcServer Address <%s> specified. Using 'Any'",
qPrintable(addr));
address = QHostAddress::Any;
}
if (!rpcServer->registerService(service, address, appParams.servicePortNumber()))
{
//qCritical(qPrintable(rpcServer->errorString()));
return false;
}
connect(service, SIGNAL(notification(int, SharedProtobufMessage)),
rpcServer, SIGNAL(notifyClients(int, SharedProtobufMessage)));
return true;
}
MyService* Drone::rpcService()
{
return service;
}
void Drone::onNewVersion(QString newVersion)
{
qWarning("%s", qPrintable(QString("New Ostinato version %1 available. "
"Visit http://ostinato.org to download").arg(newVersion)));
}
|