mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
Same legal entity, just a company name change. https://find-and-update.company-information.service.gov.uk/company/08207441/filing-history
47 lines
1 KiB
C++
47 lines
1 KiB
C++
#include "drivelistmodelpollthread.h"
|
|
#include <QElapsedTimer>
|
|
#include <QDebug>
|
|
|
|
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
* Copyright (C) 2020 Raspberry Pi Ltd
|
|
*/
|
|
|
|
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);
|
|
}
|
|
}
|