-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestcontroller.cpp
87 lines (75 loc) · 2.58 KB
/
requestcontroller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "requestcontroller.h"
#include "clientsocket.h"
#include "matrixstorage.h"
#include "screenpacket.h"
#include <QMutexLocker>
#include "updatethread.h"
#include <QApplication>
#include <QDebug>
using namespace DG;
RequestController::RequestController(DG::ClientSocket* socket, DG::MatrixStorage* storage): _socket(socket), _storage(storage), requestCount(0), packetC(0), ackC(0){
connect(_storage, SIGNAL(enqueued()), this, SLOT(rectAdded()));
}
void RequestController::rectAdded(){
qDebug() << "rectQueueSize: " << packetCount();
_send();
}
void RequestController::request(){
++requestCount;
qDebug() << "Requested " << requestCount;
if(requestCount >= 0)
_send();
}
int RequestController::packetCount() const{
return _storage->queueSize();
}
void RequestController::_send(){
QMutexLocker locker(&mutex);
qDebug() << "requestCount" << requestCount << "packetCount(): " << packetCount();
if(requestCount > 0 && packetCount() > 0){
qDebug() << "requestCount" << requestCount;
while(requestCount-- > 0){
DG::ScreenPacket* packet = _storage->next(10);
if(packet->pixmap().toImage().save("C:\\scan\\"+QString("%1x%2.jpg").arg(packet->rect().left).arg(packet->rect().top), "JPEG")){
_socket->send(packet);
QApplication::beep();
}
packetSent();
delete packet;
}
requestCount = 0;
}
//if(requestCount >= 0){
qDebug() << "packetCount(): " << packetCount();
//if(packetCount() >= RequestController::maxQueueSize){
while(packetCount() >= RequestController::minQueueSize){
DG::ScreenPacket* packet = _storage->next(10);
if(packet->pixmap().toImage().save("C:\\scan\\"+QString("%1x%2.jpg").arg(packet->rect().left).arg(packet->rect().top), "JPEG")){
_socket->send(packet);
QApplication::beep();
}
delete packet;
--requestCount;
qDebug() << "Forcing " << requestCount;
}
//}
//}
}
void RequestController::addThread(DG::UpdateThread* thread){
threads << thread;
if(threads.count() > 1){
threads.at(threads.count()-2)->setNext(thread);
qDebug() << "RequestController::addThread()" << threads.at(threads.count()-2) << thread;
}
}
void RequestController::allThreadsAdded(){
threads.at(threads.count()-1)->setNext(threads.at(0));
}
void RequestController::packetSent(){
++packetC;
}
void RequestController::acknowledged(){
++ackC;
}
const quint8 RequestController::minQueueSize = 4;
const quint8 RequestController::maxQueueSize = 1;