Commit e9406493 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

FsHolder: Add a onDeviceDiappearing callback

Which allows the parser to get that information without the FsHolder
going through the media library instance, locking it to get the parser
instance, and invoking the callback manually
Fix #362
parent bfe122a9
......@@ -290,6 +290,14 @@ void DiscovererWorker::onDeviceReappearing( int64_t deviceId )
reloadDevice( deviceId );
}
void DiscovererWorker::onDeviceDisappearing( int64_t )
{
/*
* The FsDiscoverer will abort the discovery itself if the device can't be
* read from anymore
*/
}
void DiscovererWorker::enqueue( DiscovererWorker::Task t )
{
std::unique_lock<compat::Mutex> lock( m_mutex );
......
......@@ -110,6 +110,7 @@ private:
void runAddEntryPoint( const std::string& entryPoint );
bool filter( const Task& newTask );
virtual void onDeviceReappearing( int64_t deviceId ) override;
virtual void onDeviceDisappearing( int64_t deviceId ) override;
protected:
std::list<Task> m_tasks;
......
......@@ -334,13 +334,12 @@ void FsHolder::onDeviceUnmounted( const fs::IDevice& deviceFs,
device->isPresent() ? "1" : "0", " -> ",
deviceFs.isPresent() ? "1" : "0" );
device->setPresent( deviceFs.isPresent() );
if ( deviceFs.isPresent() == false && m_ml->tryGetParser() != nullptr )
if ( deviceFs.isPresent() == false )
{
/*
* The device went away, let's ensure we're not still trying to
* analyze its content
*/
m_ml->tryGetParser()->refreshTaskList();
std::lock_guard<compat::Mutex> lock{ m_mutex };
assert( deviceFs.isPresent() == false );
for ( const auto cb : m_callbacks )
cb->onDeviceReappearing( device->id() );
}
}
......
......@@ -43,6 +43,7 @@ class IFsHolderCb
public:
virtual ~IFsHolderCb() = default;
virtual void onDeviceReappearing( int64_t deviceId ) = 0;
virtual void onDeviceDisappearing( int64_t deviceId ) = 0;
};
class FsHolder : public fs::IFileSystemFactoryCb
......
......@@ -147,6 +147,17 @@ void Parser::onDeviceReappearing( int64_t )
refreshTaskList();
}
void Parser::onDeviceDisappearing( int64_t )
{
/*
* If a device went away, let's ensure we're not still trying to
* analyze its content.
* By the time this callback is called, the database has been updated so
* the tasks associated with it will be filtered out due to `is_present = 0`
*/
refreshTaskList();
}
void Parser::refreshTaskList()
{
/*
......
......@@ -97,6 +97,7 @@ private:
// Queues all unparsed files for parsing.
void restore();
virtual void onDeviceReappearing( int64_t deviceId ) override;
virtual void onDeviceDisappearing( int64_t deviceId ) override;
private:
std::vector<std::unique_ptr<Worker>> m_serviceWorkers;
......
Supports Markdown
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