2016-02-16 14:59:31 +01:00
|
|
|
// STL includes
|
2016-02-16 15:56:20 +01:00
|
|
|
#include <stdexcept>
|
2016-02-16 14:59:31 +01:00
|
|
|
|
2016-02-15 18:25:18 +01:00
|
|
|
#include <hyperion/MessageForwarder.h>
|
|
|
|
|
|
|
|
|
2016-02-15 20:53:03 +01:00
|
|
|
MessageForwarder::MessageForwarder()
|
2016-02-15 18:25:18 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageForwarder::~MessageForwarder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MessageForwarder::addJsonSlave(std::string slave)
|
|
|
|
{
|
2016-02-15 20:53:03 +01:00
|
|
|
QStringList parts = QString(slave.c_str()).split(":");
|
|
|
|
if (parts.size() != 2)
|
|
|
|
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(slave.c_str()).toStdString());
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
quint16 port = parts[1].toUShort(&ok);
|
|
|
|
if (!ok)
|
|
|
|
throw std::runtime_error(QString("Wrong address: Unable to parse the port number (%1)").arg(parts[1]).toStdString());
|
|
|
|
|
|
|
|
JsonSlaveAddress c;
|
|
|
|
c.addr = QHostAddress(parts[0]);
|
|
|
|
c.port = port;
|
|
|
|
_jsonSlaves << c;
|
2016-02-15 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageForwarder::addProtoSlave(std::string slave)
|
|
|
|
{
|
|
|
|
_protoSlaves << QString(slave.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MessageForwarder::getProtoSlaves()
|
|
|
|
{
|
|
|
|
return _protoSlaves;
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
|
|
|
|
QList<MessageForwarder::JsonSlaveAddress> MessageForwarder::getJsonSlaves()
|
|
|
|
{
|
|
|
|
return _jsonSlaves;
|
|
|
|
}
|
2016-02-19 13:31:08 +01:00
|
|
|
|
|
|
|
bool MessageForwarder::protoForwardingEnabled()
|
|
|
|
{
|
|
|
|
return ! _protoSlaves.empty();
|
|
|
|
}
|