forked from raspberrypi/rpi-imager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrivelistmodelpollthread.cpp
47 lines (40 loc) · 1.01 KB
/
drivelistmodelpollthread.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
#include "drivelistmodelpollthread.h"
#include <QElapsedTimer>
#include <QDebug>
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2020 Raspberry Pi (Trading) Limited
*/
DriveListModelPollThread::DriveListModelPollThread(QObject *parent)
: QThread(parent), _terminate(false)
{
qRegisterMetaType< std::vector<Drivelist::DeviceDescriptor> >( "std::vector<Drivelist::DeviceDescriptor>" );
}
DriveListModelPollThread::~DriveListModelPollThread()
{
_terminate = true;
if (!wait(2000)) {
terminate();
}
}
void DriveListModelPollThread::stop()
{
_terminate = true;
}
void DriveListModelPollThread::start()
{
_terminate = false;
QThread::start();
}
void DriveListModelPollThread::run()
{
QElapsedTimer t1;
while (!_terminate)
{
t1.start();
emit newDriveList( Drivelist::ListStorageDevices() );
if (t1.elapsed() > 1000)
qDebug() << "Enumerating drives took a long time:" << t1.elapsed()/1000.0 << "seconds";
QThread::sleep(1);
}
}