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

Rename & simplify IParserCb to IMetadataCb

parent 279b6f9f
......@@ -8,25 +8,15 @@
#include "factory/IFileSystem.h"
#include "IDiscoverer.h"
class IParserCb
class IMetadataCb
{
public:
virtual ~IParserCb() = default;
/**
* @brief onServiceDone will be called after each MetadataService completes
* @param file The file being parsed
* @param status A flag describing the parsing outcome
*/
virtual void onServiceDone( FilePtr file, ServiceStatus status ) = 0;
/**
* @brief onFileDone will be called when all parsing operations on a given file have been completed
*
* This doesn't imply all modules have succeeded
*/
//FIXME: We should probably expose some way of telling if the user should retry later in
// case of tmeporary failure
virtual void onFileDone( FilePtr file ) = 0;
public:
virtual ~IMetadataCb() = default;
/**
* @brief onMetadataUpdated Will be called when a file gets some updated metadata
* @param file The updated file.
*/
virtual void onMetadataUpdated( FilePtr file ) = 0;
};
class IMediaLibrary
......@@ -71,7 +61,7 @@ class IMediaLibrary
* is expected to be uninitialized.
*/
virtual void addMetadataService( std::unique_ptr<IMetadataService> service ) = 0;
virtual void parse( FilePtr file, IParserCb* cb ) = 0;
virtual void parse( FilePtr file, IMetadataCb* cb ) = 0;
/**
* @brief discover Launch a discovery on the provided entry point.
......
......@@ -197,7 +197,7 @@ void MediaLibrary::addMetadataService(std::unique_ptr<IMetadataService> service)
m_parser->addService( std::move( service ) );
}
void MediaLibrary::parse(FilePtr file , IParserCb* cb)
void MediaLibrary::parse(FilePtr file , IMetadataCb *cb)
{
m_parser->parse( file, cb );
}
......
......@@ -38,7 +38,7 @@ class MediaLibrary : public IMediaLibrary, public IDiscovererCb
virtual MoviePtr createMovie( const std::string& title );
virtual void addMetadataService( std::unique_ptr<IMetadataService> service );
virtual void parse( FilePtr file, IParserCb* cb );
virtual void parse( FilePtr file, IMetadataCb* cb );
virtual void discover( const std::string& entryPoint ) override;
// IDiscovererCb implementation
......
......@@ -31,7 +31,7 @@ void Parser::addService(std::unique_ptr<IMetadataService> service)
});
}
void Parser::parse(FilePtr file, IParserCb* cb)
void Parser::parse(FilePtr file, IMetadataCb* cb)
{
std::lock_guard<std::mutex> lock( m_lock );
......@@ -63,11 +63,11 @@ void Parser::run()
}
Parser::Task::Task( FilePtr file, Parser::ServiceList& serviceList, IParserCb* parserCb )
Parser::Task::Task( FilePtr file, Parser::ServiceList& serviceList, IMetadataCb* metadataCb )
: file(file)
, it( serviceList.begin() )
, end( serviceList.end() )
, cb( parserCb )
, cb( metadataCb )
{
}
......@@ -75,7 +75,6 @@ Parser::Task::Task( FilePtr file, Parser::ServiceList& serviceList, IParserCb* p
void Parser::done( FilePtr file, ServiceStatus status, void* data )
{
Task *t = reinterpret_cast<Task*>( data );
t->cb->onServiceDone( file, status );
if ( status == StatusTemporaryUnavailable || status == StatusFatal )
{
delete t;
......@@ -84,7 +83,7 @@ void Parser::done( FilePtr file, ServiceStatus status, void* data )
++t->it;
if (t->it == t->end)
{
t->cb->onFileDone( file );
t->cb->onMetadataUpdated( file );
delete t;
return;
}
......
......@@ -19,8 +19,7 @@ class Parser : public IMetadataServiceCb
Parser();
~Parser();
void addService(std::unique_ptr<IMetadataService> service );
void parse( FilePtr file, IParserCb* cb );
void parse( FilePtr file, IMetadataCb* cb );
private:
virtual void done( FilePtr file, ServiceStatus status, void* data );
......@@ -31,11 +30,11 @@ class Parser : public IMetadataServiceCb
typedef std::vector<ServicePtr> ServiceList;
struct Task
{
Task(FilePtr file, ServiceList& serviceList , IParserCb* parserCb);
Task(FilePtr file, ServiceList& serviceList , IMetadataCb* metadataCb);
FilePtr file;
ServiceList::iterator it;
ServiceList::iterator end;
IParserCb* cb;
IMetadataCb* cb;
};
private:
......
......@@ -3,27 +3,21 @@
#include <condition_variable>
#include <mutex>
#include "IFile.h"
#include "IMediaLibrary.h"
#include "metadata_services/emotion/Emotion.h"
class EmotionMetadataServiceCb : public IParserCb
class EmotionMetadataServiceCb : public IMetadataCb
{
public:
bool failed;
std::condition_variable waitCond;
std::mutex mutex;
virtual void onServiceDone( FilePtr, ServiceStatus status ) override
virtual void onMetadataUpdated( FilePtr )
{
std::unique_lock<std::mutex> lock( mutex );
if ( status == StatusSuccess )
failed = false;
waitCond.notify_all();
}
virtual void onFileDone( FilePtr ) override
{
}
};
class EmotionMetadataService_Tests : public Tests
......@@ -40,7 +34,6 @@ public:
virtual void SetUp() override
{
Tests::SetUp();
cb->failed = true;
auto emotionService = std::unique_ptr<EmotionMetadataService>( new EmotionMetadataService );
ml->addMetadataService( std::move( emotionService ) );
}
......@@ -55,7 +48,7 @@ TEST_F( EmotionMetadataService_Tests, ParseAudio )
std::unique_lock<std::mutex> lock( cb->mutex );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return cb->failed == true || ( file->audioTracks().size() > 0 );
return file->audioTracks().size() > 0;
} );
ASSERT_TRUE( res );
}
......@@ -12,32 +12,16 @@
#include "metadata_services/vlc/VLCMetadataService.h"
#include "metadata_services/vlc/VLCThumbnailer.h"
class ServiceCb : public IParserCb
class ServiceCb : public IMetadataCb
{
public:
std::condition_variable waitCond;
std::mutex mutex;
volatile bool failed;
ServiceCb()
: failed(false)
virtual void onMetadataUpdated( FilePtr )
{
}
~ServiceCb()
{
}
virtual void onServiceDone( FilePtr, ServiceStatus status )
{
if ( status != StatusSuccess )
failed = true;
waitCond.notify_all();
}
virtual void onFileDone( FilePtr )
{
}
};
class VLCMetadataServices : public Tests
......@@ -55,7 +39,6 @@ class VLCMetadataServices : public Tests
{
Tests::SetUp();
cb->failed = false;
const char* args[] = {
"-vv",
"--vout=dummy",
......@@ -77,11 +60,10 @@ TEST_F( VLCMetadataServices, ParseAudio )
auto file = ml->addFile( "mr-zebra.mp3" );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return cb->failed == true || ( file->audioTracks().size() > 0 );
return file->audioTracks().size() > 0;
} );
ASSERT_TRUE( res );
ASSERT_FALSE( cb->failed );
Reload();
file = ml->file( "mr-zebra.mp3" );
auto tracks = file->audioTracks();
......@@ -99,7 +81,7 @@ TEST_F( VLCMetadataServices, ParseAlbum )
std::unique_lock<std::mutex> lock( cb->mutex );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return cb->failed == true || file->albumTrack() != nullptr;
return file->albumTrack() != nullptr;
} );
ASSERT_TRUE( res );
......@@ -127,7 +109,7 @@ TEST_F( VLCMetadataServices, ParseVideo )
auto file = ml->addFile( "mrmssmith.mp4" );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [file]{
return cb->failed == true || (file->videoTracks().size() != 0);
return file->videoTracks().size() != 0;
} );
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