-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #87
- Loading branch information
Showing
8 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef DRIVELISTMODELPOLLTHREAD_H | ||
#define DRIVELISTMODELPOLLTHREAD_H | ||
|
||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (C) 2020 Raspberry Pi (Trading) Limited | ||
*/ | ||
|
||
#include <QThread> | ||
#include "dependencies/drivelist/src/drivelist.hpp" | ||
|
||
class DriveListModelPollThread : public QThread | ||
{ | ||
Q_OBJECT | ||
public: | ||
DriveListModelPollThread(QObject *parent = nullptr); | ||
~DriveListModelPollThread(); | ||
void start(); | ||
void stop(); | ||
|
||
protected: | ||
bool _terminate; | ||
virtual void run() override; | ||
|
||
signals: | ||
void newDriveList(std::vector<Drivelist::DeviceDescriptor> list); | ||
}; | ||
|
||
#endif // DRIVELISTMODELPOLLTHREAD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters