2 #include "NetworkReceiver.h"
3 #include "NetworkReceiver.moc"
4 #include "storage/AllocEvent.h"
5 #include "storage/FreeEvent.h"
7 NetworkReceiver::NetworkReceiver(DataThread
*data_thread
, QString host
, quint16 port
) : DataReceiver(data_thread
), host(host
), port(port
) {
8 tcp_socket
= new QTcpSocket(this);
9 tcp_socket
->connectToHost(host
, port
);
10 connect(tcp_socket
, SIGNAL(readyRead()), this, SLOT(data_received()));
11 connect(tcp_socket
, SIGNAL(disconnected()), this, SLOT(disconnected()));
12 connect(tcp_socket
, SIGNAL(connected()), SLOT(connected()));
15 NetworkReceiver::~NetworkReceiver() {
18 quint64
NetworkReceiver::pop_quint64() {
20 ret
|= unprocessed
.at(0);
21 ret
|= quint64(quint8(unprocessed
.at(1))) << 8;
22 ret
|= quint64(quint8(unprocessed
.at(2))) << 16;
23 ret
|= quint64(quint8(unprocessed
.at(3))) << 24;
24 ret
|= quint64(quint8(unprocessed
.at(4))) << 32;
25 ret
|= quint64(quint8(unprocessed
.at(5))) << 40;
26 ret
|= quint64(quint8(unprocessed
.at(6))) << 48;
27 ret
|= quint64(quint8(unprocessed
.at(7))) << 56;
28 unprocessed
.remove(0, 8);
32 void NetworkReceiver::data_received() {
33 QByteArray received
= tcp_socket
->readAll();
34 unprocessed
+= received
;
35 while(unprocessed
.size()) {
36 quint8 type_byte
= unprocessed
.at(0);
37 unprocessed
.remove(0, 1);
38 /* If the first bit is set, then it's a block event . . . */
39 if(type_byte
& 0x01) {
40 quint8 block_type
= (type_byte
& 0x06) >> 1;
41 quint64 address
= pop_quint64();
43 emit
event_received(new AllocEvent(address
, pop_quint64()));
45 else if(block_type
== 1) {
46 emit
event_received(new FreeEvent(address
));
47 emit
event_received(new AllocEvent(pop_quint64(), pop_quint64()));
49 else if(block_type
== 2) {
50 emit
event_received(new FreeEvent(address
));
56 void NetworkReceiver::connected() {
60 void NetworkReceiver::disconnected() {