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

Add the foundations for IMetadataService

parent c89a3e8a
......@@ -7,6 +7,7 @@
class IFile;
class ILabel;
class IMetadataService;
typedef std::shared_ptr<IFile> FilePtr;
typedef std::shared_ptr<ILabel> LabelPtr;
......@@ -24,6 +25,7 @@ class IMediaLibrary
virtual bool deleteLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual bool files( std::vector<FilePtr>& res ) = 0;
virtual void addMetadataService( IMetadataService* service ) = 0;
};
class MediaLibraryFactory
......
#ifndef IMETADATASERVICE_H
#define IMETADATASERVICE_H
#include "IMediaLibrary.h"
class IMetadataService
{
public:
enum Result
{
Success,
Failure,
NotApplicable // If trying to fetch the tv show summary of an album, for instance
};
virtual ~IMetadataService() {}
virtual unsigned int priority() = 0;
virtual Result run( FilePtr file ) = 0;
};
#endif // IMETADATASERVICE_H
#include <algorithm>
#include <functional>
#include "MediaLibrary.h"
#include "IMetadataService.h"
#include "SqliteTools.h"
#include "File.h"
#include "Label.h"
......@@ -77,3 +81,15 @@ bool MediaLibrary::deleteLabel( LabelPtr label )
{
return Label::destroy( m_dbConnection, std::static_pointer_cast<Label>( label ) );
}
void MediaLibrary::addMetadataService(IMetadataService* service)
{
typedef std::unique_ptr<IMetadataService> MdsPtr;
std::function<bool(const MdsPtr&, const MdsPtr&)> comp = []( const MdsPtr& a, const MdsPtr& b )
{
// We want higher priority first
return a->priority() > b->priority();
};
m_mdServices.push_back( MdsPtr( service ) );
std::push_heap( m_mdServices.begin(), m_mdServices.end(), comp );
}
......@@ -19,7 +19,9 @@ class MediaLibrary : public IMediaLibrary
virtual LabelPtr createLabel( const std::string& label );
virtual bool deleteLabel(const std::string& text );
virtual bool deleteLabel( LabelPtr label );
virtual void addMetadataService( IMetadataService* service );
private:
sqlite3* m_dbConnection;
std::vector<std::unique_ptr<IMetadataService>> m_mdServices;
};
#endif // MEDIALIBRARY_H
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