Commit 07c0eb51 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IMediaLibrary: Remove parse() method.

Let the media library parse any new file it finds
parent 44dbe0e4
......@@ -30,7 +30,7 @@ class IMediaLibrary
/// \param dbPath Path to the database
/// \return true in case of success, false otherwise
///
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory ) = 0;
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory, IMetadataCb* metadataCb ) = 0;
/// Adds a stand alone file
virtual FilePtr addFile( const std::string& path ) = 0;
virtual FilePtr file( const std::string& path ) = 0;
......@@ -61,7 +61,6 @@ class IMediaLibrary
* is expected to be uninitialized.
*/
virtual void addMetadataService( std::unique_ptr<IMetadataService> service ) = 0;
virtual void parse( FilePtr file, IMetadataCb* cb ) = 0;
/**
* @brief discover Launch a discovery on the provided entry point.
......
......@@ -59,13 +59,14 @@ MediaLibrary::~MediaLibrary()
AudioTrack::clear();
}
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory )
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory, IMetadataCb* metadataCb )
{
if ( fsFactory != nullptr )
m_fsFactory = fsFactory;
else
m_fsFactory.reset( new factory::FileSystemDefaultFactory );
m_snapshotPath = snapshotPath;
m_metadataCb = metadataCb;
m_discoverers.emplace_back( new FsDiscoverer( m_fsFactory, this ) );
......@@ -339,6 +340,7 @@ FilePtr MediaLibrary::addFile( const fs::IFile* file, unsigned int folderId )
std::cerr << "Failed to add file " << file->fullPath() << " to the media library" << std::endl;
return nullptr;
}
m_parser->parse( fptr, m_metadataCb );
return fptr;
}
......@@ -13,7 +13,7 @@ class MediaLibrary : public IMediaLibrary, public IDiscovererCb
public:
MediaLibrary();
~MediaLibrary();
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory );
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory, IMetadataCb* metadataCb );
virtual std::vector<FilePtr> files();
virtual FilePtr file( const std::string& path );
......@@ -61,6 +61,7 @@ class MediaLibrary : public IMediaLibrary, public IDiscovererCb
std::shared_ptr<factory::IFileSystem> m_fsFactory;
std::vector<std::unique_ptr<IDiscoverer>> m_discoverers;
std::string m_snapshotPath;
IMetadataCb* m_metadataCb;
// Keep the parser as last field.
// The parser holds a (raw) pointer to the media library. When MediaLibrary's destructor gets called
......
......@@ -33,7 +33,7 @@ public:
virtual void SetUp() override
{
Tests::SetUp();
Tests::Reload( nullptr, cb.get() );
auto emotionService = std::unique_ptr<EmotionMetadataService>( new EmotionMetadataService );
ml->addMetadataService( std::move( emotionService ) );
}
......@@ -44,9 +44,8 @@ std::unique_ptr<EmotionMetadataServiceCb> EmotionMetadataService_Tests::cb;
TEST_F( EmotionMetadataService_Tests, ParseAudio )
{
auto file = ml->addFile( "mr-zebra.mp3" );
std::unique_lock<std::mutex> lock( cb->mutex );
ml->parse( file, cb.get() );
auto file = ml->addFile( "mr-zebra.mp3" );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return file->audioTracks().size() > 0;
} );
......
......@@ -25,14 +25,14 @@ void Tests::TearDown()
}
void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /* = nullptr */ )
void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /*= nullptr*/, IMetadataCb* metadataCb /*= nullptr*/ )
{
ml.reset( MediaLibraryFactory::create() );
if ( fs == nullptr )
{
fs = std::shared_ptr<factory::IFileSystem>( new mock::NoopFsFactory );
}
bool res = ml->initialize( "test.db", "/tmp", fs );
bool res = ml->initialize( "test.db", "/tmp", fs, metadataCb );
ASSERT_TRUE( res );
}
......
......@@ -10,6 +10,6 @@ protected:
std::shared_ptr<factory::IFileSystem> defaultFs;
virtual void SetUp() override;
void Reload( std::shared_ptr<factory::IFileSystem> fs = nullptr );
void Reload( std::shared_ptr<factory::IFileSystem> fs = nullptr, IMetadataCb* metadataCb = nullptr );
virtual void TearDown() override;
};
......@@ -37,7 +37,7 @@ class VLCMetadataServices : public Tests
virtual void SetUp() override
{
Tests::SetUp();
Tests::Reload( nullptr, cb.get() );
const char* args[] = {
"-vv",
......@@ -58,7 +58,6 @@ TEST_F( VLCMetadataServices, ParseAudio )
{
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mr-zebra.mp3" );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return file->audioTracks().size() > 0;
} );
......@@ -77,9 +76,8 @@ TEST_F( VLCMetadataServices, ParseAudio )
TEST_F( VLCMetadataServices, ParseAlbum )
{
auto file = ml->addFile( "mr-zebra.mp3" );
std::unique_lock<std::mutex> lock( cb->mutex );
ml->parse( file, cb.get() );
auto file = ml->addFile( "mr-zebra.mp3" );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return file->albumTrack() != nullptr;
} );
......@@ -107,7 +105,6 @@ TEST_F( VLCMetadataServices, ParseVideo )
{
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mrmssmith.mp4" );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [file]{
return file->videoTracks().size() != 0;
} );
......
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