mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
- prepare general way to send (proto) messages. currently only incomming protomessages are forwarded
- begin impl. of json server Former-commit-id: 8f9237cd57ada1e84dc05e60b9ad723e47fd57b1
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
// project includes
|
||||
#include "ProtoClientConnection.h"
|
||||
|
||||
ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket, Hyperion * hyperion, QStringList forwardClientList) :
|
||||
ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket, Hyperion * hyperion) :
|
||||
QObject(),
|
||||
_socket(socket),
|
||||
_imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
@@ -30,22 +30,11 @@ ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket, Hyperion * hype
|
||||
// connect internal signals and slots
|
||||
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
|
||||
connect(_socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
for (int i = 0; i < forwardClientList.size(); ++i) {
|
||||
std::cout << "Proto forward to " << forwardClientList.at(i).toLocal8Bit().constData() << std::endl;
|
||||
ProtoConnection* p = new ProtoConnection("127.0.0.1:19445");
|
||||
p->setSkipReply(true);
|
||||
_proxy_connections << p;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ProtoClientConnection::~ProtoClientConnection()
|
||||
{
|
||||
delete _socket;
|
||||
|
||||
while (!_proxy_connections.isEmpty())
|
||||
delete _proxy_connections.takeFirst();
|
||||
}
|
||||
|
||||
void ProtoClientConnection::readData()
|
||||
@@ -93,8 +82,7 @@ void ProtoClientConnection::socketClosed()
|
||||
void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message)
|
||||
{
|
||||
// forward messages
|
||||
for (int i = 0; i < _proxy_connections.size(); ++i)
|
||||
_proxy_connections.at(i)->sendMessage(message);
|
||||
emit newMessage(&message);
|
||||
|
||||
switch (message.command())
|
||||
{
|
||||
|
@@ -30,7 +30,7 @@ public:
|
||||
/// @param socket The Socket object for this connection
|
||||
/// @param hyperion The Hyperion server
|
||||
///
|
||||
ProtoClientConnection(QTcpSocket * socket, Hyperion * hyperion, QStringList forwardClientList);
|
||||
ProtoClientConnection(QTcpSocket * socket, Hyperion * hyperion);
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
@@ -43,6 +43,7 @@ signals:
|
||||
/// @param connection This connection object
|
||||
///
|
||||
void connectionClosed(ProtoClientConnection * connection);
|
||||
void newMessage(const proto::HyperionRequest * message);
|
||||
|
||||
private slots:
|
||||
///
|
||||
@@ -125,8 +126,4 @@ private:
|
||||
|
||||
/// The buffer used for reading data from the socket
|
||||
QByteArray _receiveBuffer;
|
||||
|
||||
/// Hyperion proto connection object for forwarding
|
||||
QList<ProtoConnection*> _proxy_connections;
|
||||
|
||||
};
|
||||
|
@@ -2,17 +2,27 @@
|
||||
#include <stdexcept>
|
||||
|
||||
// project includes
|
||||
#include <hyperion/MessageForwarder.h>
|
||||
#include <protoserver/ProtoServer.h>
|
||||
#include "protoserver/ProtoConnection.h"
|
||||
#include "ProtoClientConnection.h"
|
||||
|
||||
ProtoServer::ProtoServer(Hyperion *hyperion, uint16_t port, QStringList * forwardClientList) :
|
||||
ProtoServer::ProtoServer(Hyperion *hyperion, uint16_t port) :
|
||||
QObject(),
|
||||
_hyperion(hyperion),
|
||||
_server(),
|
||||
_openConnections()
|
||||
{
|
||||
for (int i = 0; i < forwardClientList->size(); ++i)
|
||||
_forwardClients << forwardClientList->at(i);
|
||||
|
||||
MessageForwarder * forwarder = hyperion->getForwarder();
|
||||
QStringList slaves = forwarder->getProtoSlaves();
|
||||
|
||||
for (int i = 0; i < slaves.size(); ++i) {
|
||||
std::cout << "Proto forward to " << slaves.at(i).toLocal8Bit().constData() << std::endl;
|
||||
ProtoConnection* p = new ProtoConnection(slaves.at(i).toLocal8Bit().constData());
|
||||
p->setSkipReply(true);
|
||||
_proxy_connections << p;
|
||||
}
|
||||
|
||||
if (!_server.listen(QHostAddress::Any, port))
|
||||
{
|
||||
@@ -28,6 +38,9 @@ ProtoServer::~ProtoServer()
|
||||
foreach (ProtoClientConnection * connection, _openConnections) {
|
||||
delete connection;
|
||||
}
|
||||
|
||||
while (!_proxy_connections.isEmpty())
|
||||
delete _proxy_connections.takeFirst();
|
||||
}
|
||||
|
||||
uint16_t ProtoServer::getPort() const
|
||||
@@ -42,14 +55,22 @@ void ProtoServer::newConnection()
|
||||
if (socket != nullptr)
|
||||
{
|
||||
std::cout << "New proto connection" << std::endl;
|
||||
ProtoClientConnection * connection = new ProtoClientConnection(socket, _hyperion, _forwardClients);
|
||||
ProtoClientConnection * connection = new ProtoClientConnection(socket, _hyperion);
|
||||
_openConnections.insert(connection);
|
||||
|
||||
// register slot for cleaning up after the connection closed
|
||||
connect(connection, SIGNAL(connectionClosed(ProtoClientConnection*)), this, SLOT(closedConnection(ProtoClientConnection*)));
|
||||
connect(connection, SIGNAL(newMessage(const proto::HyperionRequest*)), this, SLOT(newMessage(const proto::HyperionRequest*)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ProtoServer::newMessage(const proto::HyperionRequest * message)
|
||||
{
|
||||
for (int i = 0; i < _proxy_connections.size(); ++i)
|
||||
_proxy_connections.at(i)->sendMessage(*message);
|
||||
}
|
||||
|
||||
void ProtoServer::closedConnection(ProtoClientConnection *connection)
|
||||
{
|
||||
std::cout << "Proto connection closed" << std::endl;
|
||||
|
Reference in New Issue
Block a user