Commit bd2445f5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Hugo Beauzée-Luyssen

DiscovererWorker: Add a refreshAllDevice task

Which will... refresh all devices, but from a background thread
parent 22b4d070
......@@ -30,6 +30,7 @@
#include "Folder.h"
#include "MediaLibrary.h"
#include "Device.h"
#include "Media.h"
#include "utils/Filename.h"
#include "medialibrary/filesystem/Errors.h"
#include <cassert>
......@@ -107,6 +108,11 @@ void DiscovererWorker::reloadDevice(int64_t deviceId)
enqueue( deviceId, Task::Type::ReloadDevice );
}
void DiscovererWorker::reloadAllDevices()
{
enqueue( 0, Task::Type::ReloadAllDevices );
}
void DiscovererWorker::enqueue( const std::string& entryPoint, Task::Type type )
{
std::unique_lock<compat::Mutex> lock( m_mutex );
......@@ -190,6 +196,9 @@ void DiscovererWorker::run()
case Task::Type::ReloadDevice:
runReloadDevice( task.entityId );
break;
case Task::Type::ReloadAllDevices:
runReloadAllDevices();
break;
default:
assert(false);
}
......@@ -305,6 +314,13 @@ void DiscovererWorker::runReloadDevice( int64_t deviceId )
}
}
void DiscovererWorker::runReloadAllDevices()
{
m_ml->refreshDevices();
MediaLibrary::removeOldEntities( m_ml );
}
bool DiscovererWorker::isInterrupted() const
{
return m_run.load() == false;
......
......@@ -48,6 +48,12 @@ class DiscovererWorker : public IInterruptProbe
Ban,
Unban,
ReloadDevice,
/*
* Checks the presence of all devices in database
* This is expected to be run as the first task, before any other
* subsequent discovery requests.
*/
ReloadAllDevices,
};
Task() = default;
......@@ -73,6 +79,7 @@ public:
void ban( const std::string& entryPoint );
void unban( const std::string& entryPoint );
void reloadDevice( int64_t deviceId );
void reloadAllDevices();
private:
void enqueue( const std::string& entryPoint, Task::Type type );
......@@ -85,6 +92,7 @@ private:
void runBan( const std::string& entryPoint );
void runUnban( const std::string& entryPoint );
void runReloadDevice( int64_t deviceId );
void runReloadAllDevices();
private:
virtual bool isInterrupted() const override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment