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 @@ ...@@ -30,6 +30,7 @@
#include "Folder.h" #include "Folder.h"
#include "MediaLibrary.h" #include "MediaLibrary.h"
#include "Device.h" #include "Device.h"
#include "Media.h"
#include "utils/Filename.h" #include "utils/Filename.h"
#include "medialibrary/filesystem/Errors.h" #include "medialibrary/filesystem/Errors.h"
#include <cassert> #include <cassert>
...@@ -107,6 +108,11 @@ void DiscovererWorker::reloadDevice(int64_t deviceId) ...@@ -107,6 +108,11 @@ void DiscovererWorker::reloadDevice(int64_t deviceId)
enqueue( deviceId, Task::Type::ReloadDevice ); enqueue( deviceId, Task::Type::ReloadDevice );
} }
void DiscovererWorker::reloadAllDevices()
{
enqueue( 0, Task::Type::ReloadAllDevices );
}
void DiscovererWorker::enqueue( const std::string& entryPoint, Task::Type type ) void DiscovererWorker::enqueue( const std::string& entryPoint, Task::Type type )
{ {
std::unique_lock<compat::Mutex> lock( m_mutex ); std::unique_lock<compat::Mutex> lock( m_mutex );
...@@ -190,6 +196,9 @@ void DiscovererWorker::run() ...@@ -190,6 +196,9 @@ void DiscovererWorker::run()
case Task::Type::ReloadDevice: case Task::Type::ReloadDevice:
runReloadDevice( task.entityId ); runReloadDevice( task.entityId );
break; break;
case Task::Type::ReloadAllDevices:
runReloadAllDevices();
break;
default: default:
assert(false); assert(false);
} }
...@@ -305,6 +314,13 @@ void DiscovererWorker::runReloadDevice( int64_t deviceId ) ...@@ -305,6 +314,13 @@ void DiscovererWorker::runReloadDevice( int64_t deviceId )
} }
} }
void DiscovererWorker::runReloadAllDevices()
{
m_ml->refreshDevices();
MediaLibrary::removeOldEntities( m_ml );
}
bool DiscovererWorker::isInterrupted() const bool DiscovererWorker::isInterrupted() const
{ {
return m_run.load() == false; return m_run.load() == false;
......
...@@ -48,6 +48,12 @@ class DiscovererWorker : public IInterruptProbe ...@@ -48,6 +48,12 @@ class DiscovererWorker : public IInterruptProbe
Ban, Ban,
Unban, Unban,
ReloadDevice, 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; Task() = default;
...@@ -73,6 +79,7 @@ public: ...@@ -73,6 +79,7 @@ public:
void ban( const std::string& entryPoint ); void ban( const std::string& entryPoint );
void unban( const std::string& entryPoint ); void unban( const std::string& entryPoint );
void reloadDevice( int64_t deviceId ); void reloadDevice( int64_t deviceId );
void reloadAllDevices();
private: private:
void enqueue( const std::string& entryPoint, Task::Type type ); void enqueue( const std::string& entryPoint, Task::Type type );
...@@ -85,6 +92,7 @@ private: ...@@ -85,6 +92,7 @@ private:
void runBan( const std::string& entryPoint ); void runBan( const std::string& entryPoint );
void runUnban( const std::string& entryPoint ); void runUnban( const std::string& entryPoint );
void runReloadDevice( int64_t deviceId ); void runReloadDevice( int64_t deviceId );
void runReloadAllDevices();
private: private:
virtual bool isInterrupted() const override; 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