code format
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
#include "dispatcherclient.h"
|
||||
|
||||
#include "picloudtcp.h"
|
||||
|
||||
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : authorised(false), eth(eth_), streampacker(eth_), tcp(&streampacker), client_id(id) {
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id)
|
||||
: authorised(false)
|
||||
, eth(eth_)
|
||||
, streampacker(eth_)
|
||||
, tcp(&streampacker)
|
||||
, client_id(id) {
|
||||
eth->setName(PIString::fromNumber(id));
|
||||
CONNECTU(&streampacker, packetReceiveEvent, this, readed);
|
||||
CONNECTU(eth, disconnected, this, disconnected);
|
||||
@@ -43,14 +49,18 @@ void DispatcherClient::sendDisconnected(uint client_id) {
|
||||
|
||||
|
||||
void DispatcherClient::sendData(const PIByteArray & data) {
|
||||
if (tcp.role() == PICloud::TCP::Client) tcp.sendData(data);
|
||||
else piCoutObj << "error sendData, invalid role";
|
||||
if (tcp.role() == PICloud::TCP::Client)
|
||||
tcp.sendData(data);
|
||||
else
|
||||
piCoutObj << "error sendData, invalid role";
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id) {
|
||||
if (tcp.role() == PICloud::TCP::Server) tcp.sendData(data, client_id);
|
||||
else piCoutObj << "error sendDataToClient, invalid role";
|
||||
if (tcp.role() == PICloud::TCP::Server)
|
||||
tcp.sendData(data, client_id);
|
||||
else
|
||||
piCoutObj << "error sendDataToClient, invalid role";
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +77,7 @@ void DispatcherClient::disconnected(bool withError) {
|
||||
|
||||
void DispatcherClient::readed(PIByteArray & ba) {
|
||||
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
||||
// piCoutObj << "readed" << hdr.first << hdr.second;
|
||||
// piCoutObj << "readed" << hdr.first << hdr.second;
|
||||
if (hdr.first == PICloud::TCP::InvalidType) {
|
||||
piCoutObj << "invalid message";
|
||||
disconnected(true);
|
||||
@@ -76,34 +86,35 @@ void DispatcherClient::readed(PIByteArray & ba) {
|
||||
if (authorised) {
|
||||
if (hdr.second == tcp.role()) {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect:
|
||||
piCoutObj << "PICloud::TCP::Connect";
|
||||
return;
|
||||
case PICloud::TCP::Connect: piCoutObj << "PICloud::TCP::Connect"; return;
|
||||
case PICloud::TCP::Disconnect:
|
||||
piCoutObj << "PICloud::TCP::Disconnect";
|
||||
disconnected(false);
|
||||
return;
|
||||
return;
|
||||
case PICloud::TCP::Data:
|
||||
//piCoutObj << "TCP::Data" << tcp.role();
|
||||
// piCoutObj << "TCP::Data" << tcp.role();
|
||||
if (tcp.role() == PICloud::TCP::Client) {
|
||||
if (tcp.canParseData(ba)) dataReaded(ba);
|
||||
else piCoutObj << "invalid data from client";
|
||||
if (tcp.canParseData(ba))
|
||||
dataReaded(ba);
|
||||
else
|
||||
piCoutObj << "invalid data from client";
|
||||
}
|
||||
if (tcp.role() == PICloud::TCP::Server) {
|
||||
PIPair<uint, PIByteArray> dp = tcp.parseDataServer(ba);
|
||||
if (!dp.second.isEmpty()) dataReadedServer(dp.first, dp.second);
|
||||
else piCoutObj << "invalid data from server";
|
||||
if (!dp.second.isEmpty())
|
||||
dataReadedServer(dp.first, dp.second);
|
||||
else
|
||||
piCoutObj << "invalid data from server";
|
||||
}
|
||||
return;
|
||||
case PICloud::TCP::Ping:
|
||||
pingReceived();
|
||||
return;
|
||||
case PICloud::TCP::Ping: pingReceived(); return;
|
||||
default:
|
||||
piCoutObj << "unknown data";
|
||||
//disconnected(true);
|
||||
return;
|
||||
// disconnected(true);
|
||||
return;
|
||||
}
|
||||
} else piCoutObj << "invalid role";
|
||||
} else
|
||||
piCoutObj << "invalid role";
|
||||
} else {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect: {
|
||||
@@ -116,12 +127,11 @@ void DispatcherClient::readed(PIByteArray & ba) {
|
||||
case PICloud::TCP::Disconnect:
|
||||
piCoutObj << "unauthorised PICloud::TCP::Disconnect";
|
||||
disconnected(false);
|
||||
return;
|
||||
return;
|
||||
default:
|
||||
piCoutObj << "authorised invalid message";
|
||||
disconnected(true);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user