picloud
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include "dispatcherclient.h"
|
||||
#include "picloudtcp.h"
|
||||
|
||||
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_) {
|
||||
eth = eth_;
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_) : eth(eth_), authorised(false) {
|
||||
CONNECTU(&disconnect_tm, tickEvent, eth, close);
|
||||
eth->startThreadedRead();
|
||||
CONNECTU(eth, threadedReadEvent, this, readed);
|
||||
@@ -21,6 +21,10 @@ PIString DispatcherClient::address() {
|
||||
return eth->path();
|
||||
}
|
||||
|
||||
void DispatcherClient::close() {
|
||||
eth->close();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::disconnected(bool withError) {
|
||||
piCoutObj << "client disconnected" << eth->sendAddress();
|
||||
@@ -30,7 +34,18 @@ void DispatcherClient::disconnected(bool withError) {
|
||||
|
||||
void DispatcherClient::readed(uchar *data, int size) {
|
||||
PIByteArray ba(data, size);
|
||||
piCoutObj << "readed" << ba.toHex();
|
||||
eth->write(ba);
|
||||
if (authorised) {
|
||||
dataReaded(ba);
|
||||
} else {
|
||||
if (ba.size() < 4) return;
|
||||
PICloud::Header hdr;
|
||||
ba >> hdr;
|
||||
if ((PICloud::HeaderType)hdr.type == PICloud::Server) {
|
||||
registerServer(hdr.sname, this);
|
||||
}
|
||||
if ((PICloud::HeaderType)hdr.type == PICloud::Client) {
|
||||
registerClient(hdr.sname, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user