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

MediaLibrary: Simplify network discovery enabling/disabling

Instead of relying on the content of m_fsFactories, just use a boolean
This also fix a few thread unsafe accesses
parent 9ddc11ef
......@@ -594,8 +594,7 @@ public:
virtual void discover( const std::string& entryPoint ) = 0;
/**
* @brief setDiscoverNetworkEnabled Enable discovery of network shares
* @return true if some IFileSystemFactory able of handling network
* discovery were installed prior to calling this.
* @return true In case of success, false otherwise.
*
* This can be called at any time, but won't have any effect before
* initialize() has been called.
......@@ -606,8 +605,12 @@ public:
* a USB drive, in the sense that the medialibrary will still store
* information about network content and won't have to discover/parse it
* again.
* When enabling, this method will consider the lack of network enabled
* IFsFactory implementation a failure.
* Setting the same state twice is considered as a success, regardless of
* the previous call status.
*/
virtual bool setDiscoverNetworkEnabled( bool enable ) = 0;
virtual bool setDiscoverNetworkEnabled( bool enabled ) = 0;
/**
* @brief entryPoints List the entrypoints that are managed by the medialibrary
*
......
......@@ -134,6 +134,7 @@ MediaLibrary::MediaLibrary()
, m_settings( this )
, m_initialized( false )
, m_started( false )
, m_networkDiscoveryEnabled( false )
, m_discovererIdle( true )
, m_parserIdle( true )
, m_fsFactoryCb( this )
......@@ -1926,21 +1927,20 @@ bool MediaLibrary::addNetworkFileSystemFactory( std::shared_ptr<fs::IFileSystemF
bool MediaLibrary::setDiscoverNetworkEnabled( bool enabled )
{
std::lock_guard<compat::Mutex> lock( m_mutex );
if ( enabled == m_networkDiscoveryEnabled )
return true;
if ( enabled )
{
auto it = std::find_if( begin( m_fsFactories ),
end( m_fsFactories ),
[]( const std::shared_ptr<fs::IFileSystemFactory> fs ) {
return fs->isNetworkFileSystem();
});
if ( it != end( m_fsFactories ) )
return true;
auto previousSize = m_fsFactories.size();
for ( auto fsFactory : m_externalNetworkFsFactories )
{
if ( fsFactory->start( &m_fsFactoryCb ) == true )
m_fsFactories.push_back( std::move( fsFactory ) );
}
m_networkDiscoveryEnabled = true;
return m_fsFactories.size() != previousSize;
}
......@@ -1958,6 +1958,7 @@ bool MediaLibrary::setDiscoverNetworkEnabled( bool enabled )
fsFactory->stop();
});
m_fsFactories.erase( it, end( m_fsFactories ) );
m_networkDiscoveryEnabled = false;
return true;
}
......
......@@ -317,6 +317,7 @@ protected:
Settings m_settings;
bool m_initialized;
bool m_started;
bool m_networkDiscoveryEnabled;
std::atomic_bool m_discovererIdle;
std::atomic_bool m_parserIdle;
......
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