Commit 8c635e8e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IMediaLibrary: Split discoverers/parser startup out of initialize()

parent 395dfc8c
......@@ -195,6 +195,23 @@ class IMediaLibrary
* If it returns true the first time, calling this method again is a no-op
*/
virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback ) = 0;
/**
* @brief start Starts the background thread and reload the medialibrary content
* This *MUST* be called after initialize.
*
* The user is expected to populate its device lister between a call to initialize() and a
* call to start().
* Once this method has been called, the medialibrary will know all the device known to the
* device lister, and it become impossible to know wether a removable storage device has been
* inserted for the first time or not.
*
* @return true in case of success, false otherwise.
* * If start returns false, this medialibrary must not be used anymore, and should be
* disposed off.
* If it returns true the first time, calling this method again is a no-op
*/
virtual bool start() = 0;
virtual void setVerbosity( LogLevel v ) = 0;
virtual LabelPtr createLabel( const std::string& label ) = 0;
......@@ -262,6 +279,7 @@ class IMediaLibrary
* @brief discover Launch a discovery on the provided entry point.
* The actuall discovery will run asynchronously, meaning this method will immediatly return.
* Depending on which discoverer modules where provided, this might or might not work
* \note This must be called after start()
* @param entryPoint What to discover.
*/
virtual void discover( const std::string& entryPoint ) = 0;
......
......@@ -274,12 +274,20 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
return false;
}
}
m_initialized = true;
LOG_INFO( "Successfuly initialized" );
return true;
}
bool MediaLibrary::start()
{
if ( m_parser != nullptr )
return false;
for ( auto& fsFactory : m_fsFactories )
refreshDevices( *fsFactory );
startDiscoverer();
startParser();
m_initialized = true;
LOG_INFO( "Successfuly initialized" );
return true;
}
......
......@@ -63,6 +63,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
MediaLibrary();
~MediaLibrary();
virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback ) override;
virtual bool start() override;
virtual void setVerbosity( LogLevel v ) override;
virtual MediaPtr media( int64_t mediaId ) const override;
......
......@@ -78,6 +78,7 @@ void Tests::SetUp()
m_ml->setVerbosity( LogLevel::Info );
ASSERT_TRUE( m_ml->initialize( "test.db", "/tmp", m_cb.get() ) );
ASSERT_TRUE( m_ml->start() );
}
void Tests::checkVideoTracks( const rapidjson::Value& expectedTracks, const std::vector<VideoTrackPtr>& tracks )
......
......@@ -65,6 +65,8 @@ void Tests::Reload( std::shared_ptr<factory::IFileSystem> fs /*= nullptr*/, IMed
ml->setVerbosity( LogLevel::Error );
bool res = ml->initialize( "test.db", "/tmp", metadataCb );
ASSERT_TRUE( res );
res = ml->start();
ASSERT_TRUE( res );
}
......
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