Commit 3807a79f authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

parser: Move service specific variables to the service implementations

parent 69a830d1
......@@ -49,7 +49,8 @@ namespace medialibrary
{
MetadataParser::MetadataParser()
: m_previousFolderId( 0 )
: m_ml( nullptr )
, m_previousFolderId( 0 )
{
}
......@@ -61,6 +62,13 @@ bool MetadataParser::initialize()
return m_unknownArtist != nullptr;
}
bool MetadataParser::initialize( MediaLibrary* ml)
{
m_ml = ml;
m_notifier = ml->getNotifier();
return initialize();
}
int MetadataParser::toInt( VLC::Media& vlcMedia, libvlc_meta_t meta, const char* name )
{
auto str = vlcMedia.meta( meta );
......
......@@ -36,7 +36,8 @@ public:
MetadataParser();
protected:
virtual bool initialize() override;
bool initialize();
virtual bool initialize( MediaLibrary* ml ) override;
virtual parser::Task::Status run( parser::Task& task ) override;
virtual const char* name() const override;
virtual uint8_t nbThreads() const override;
......@@ -61,6 +62,9 @@ private:
static int toInt( VLC::Media& vlcMedia, libvlc_meta_t meta, const char* name );
private:
MediaLibrary* m_ml;
std::shared_ptr<ModificationNotifier> m_notifier;
std::shared_ptr<Artist> m_unknownArtist;
std::shared_ptr<Artist> m_variousArtists;
std::shared_ptr<Album> m_previousAlbum;
......
......@@ -36,10 +36,17 @@ namespace medialibrary
{
VLCMetadataService::VLCMetadataService()
: m_instance( VLCInstance::get() )
: m_ml( nullptr )
, m_instance( VLCInstance::get() )
{
}
bool VLCMetadataService::initialize( MediaLibrary* ml )
{
m_ml = ml;
return true;
}
parser::Task::Status VLCMetadataService::run( parser::Task& task )
{
auto mrl = task.mrl;
......
......@@ -34,18 +34,23 @@
namespace medialibrary
{
class IParserCb;
class VLCMetadataService : public ParserService
{
public:
explicit VLCMetadataService();
private:
virtual bool initialize( MediaLibrary* ml ) override;
virtual parser::Task::Status run( parser::Task& task ) override;
virtual const char* name() const override;
virtual uint8_t nbThreads() const override;
virtual bool isCompleted( const parser::Task& task ) const override;
private:
MediaLibrary* m_ml;
VLC::Instance m_instance;
compat::Mutex m_mutex;
compat::ConditionVariable m_cond;
......
......@@ -63,10 +63,12 @@ public:
*
* By the time this function is called, the database is fully initialized and
* can be used.
* A pointer the the medialibrary is provided to allow the service to
* create/fetch entities.
*
* If false is returned, the service will be released and won't be used.
*/
virtual bool initialize() = 0;
virtual bool initialize( MediaLibrary* ml ) = 0;
};
}
......@@ -53,7 +53,7 @@ Parser::~Parser()
void Parser::addService( ServicePtr service )
{
service->initialize( m_ml, this );
service->initialize2( m_ml, this );
m_services.push_back( std::move( service ) );
}
......
......@@ -32,9 +32,7 @@ namespace medialibrary
{
ParserService::ParserService()
: m_ml( nullptr )
, m_cb( nullptr )
, m_parserCb( nullptr )
: m_parserCb( nullptr )
, m_stopParser( false )
, m_paused( false )
, m_idle( true )
......@@ -102,14 +100,11 @@ void ParserService::parse( std::shared_ptr<parser::Task> t )
}
}
void ParserService::initialize( MediaLibrary* ml, IParserCb* parserCb )
void ParserService::initialize2( MediaLibrary* ml, IParserCb* parserCb )
{
m_ml = ml;
m_cb = ml->getCb();
m_notifier = ml->getNotifier();
m_parserCb = parserCb;
// Run the service specific initializer
initialize();
initialize( ml );
}
bool ParserService::isIdle() const
......@@ -132,11 +127,6 @@ void ParserService::restart()
{
}
bool ParserService::initialize()
{
return true;
}
void ParserService::mainloop()
{
// It would be unsafe to call name() at the end of this function, since
......
......@@ -61,7 +61,8 @@ public:
///
void stop();
void parse( std::shared_ptr<parser::Task> t );
void initialize( MediaLibrary* mediaLibrary, IParserCb* parserCb );
// temporary name to avoid shadowing IParserService::initialize
void initialize2( MediaLibrary* ml, IParserCb* parserCb );
bool isIdle() const;
///
/// \brief flush flush every currently scheduled tasks
......@@ -76,21 +77,12 @@ public:
///
virtual void restart();
protected:
/// Can be overriden to run service dependent initializations
virtual bool initialize() override;
private:
// Thread(s) entry point
void start();
void mainloop();
void setIdle( bool isIdle );
protected:
MediaLibrary* m_ml;
IMediaLibraryCb* m_cb;
std::shared_ptr<ModificationNotifier> m_notifier;
private:
IParserCb* m_parserCb;
bool m_stopParser;
......
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