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)
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error(QString("HYPERION (forwarder) ERROR: Wrong address: unable to parse address (%1)").arg(slave.c_str()).toStdString());
|
2016-02-15 20:53:03 +01:00
|
|
|
|
|
|
|
bool ok;
|
|
|
|
quint16 port = parts[1].toUShort(&ok);
|
|
|
|
if (!ok)
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error(QString("HYPERION (forwarder) ERROR: Wrong address: Unable to parse the port number (%1)").arg(parts[1]).toStdString());
|
2016-02-15 20:53:03 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|