-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnectioncheck.cpp
59 lines (47 loc) · 1.24 KB
/
connectioncheck.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
#include "connectioncheck.h"
#include <QDebug>
#include <QTime>
#include <MultiWidgets/Widget.hpp>
#include <QTextStream>
ConnectionCheck::ConnectionCheck(MultiWidgets::Widget * widget, QFile * logfile)
{
this->canvas = widget;
this->maxFingers = 0;
this->log = logfile;
}
void ConnectionCheck::run() {
this->runs = true;
if( ! this->log->isOpen() ) {
this->log->open( QIODevice::WriteOnly );
}
QTextStream out( this->log );
while( this->runs ) {
// qDebug() << QTime().currentTime().toString("hh:mm:ss:zzz");
MultiWidgets::Widget * w = canvas;
int fingers = w->grabFingerCount();
if( fingers > this->maxFingers ) {
this->maxFingers = fingers;
}
if( fingers < this->maxFingers ) {
out << QTime().currentTime().toString("hh:mm:ss:zzz");
out << " connection lost!\n";
out.flush();
this->maxFingers = fingers;
}
this->msleep(2);
}
this->log->close();
}
int ConnectionCheck::exit(int retcode)
{
this->runs = false;
return retcode;
}
ConnectionCheck::~ConnectionCheck()
{
// close thread
this->runs = false;
// make sure log is close
log->close();
delete log;
}