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

parser: Split restart/flush handling out of ParserService

parent a709a981
......@@ -54,7 +54,7 @@ MetadataParser::MetadataParser()
{
}
bool MetadataParser::initialize()
bool MetadataParser::cacheUnknownArtist()
{
m_unknownArtist = Artist::fetch( m_ml, UnknownArtistID );
if ( m_unknownArtist == nullptr )
......@@ -66,7 +66,7 @@ bool MetadataParser::initialize( MediaLibrary* ml)
{
m_ml = ml;
m_notifier = ml->getNotifier();
return initialize();
return cacheUnknownArtist();
}
int MetadataParser::toInt( VLC::Media& vlcMedia, libvlc_meta_t meta, const char* name )
......@@ -832,18 +832,17 @@ uint8_t MetadataParser::nbThreads() const
return 1;
}
void MetadataParser::flush()
void MetadataParser::onFlushing()
{
ParserService::flush();
m_variousArtists = nullptr;
m_previousAlbum = nullptr;
m_previousFolderId = 0;
}
void MetadataParser::restart()
void MetadataParser::onRestarted()
{
// Reset locally cached entities
initialize();
cacheUnknownArtist();
}
bool MetadataParser::isCompleted( const parser::Task& task ) const
......
......@@ -36,13 +36,13 @@ public:
MetadataParser();
protected:
bool initialize();
bool cacheUnknownArtist();
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 void flush() override;
virtual void restart() override;
virtual void onFlushing() override;
virtual void onRestarted() override;
bool isCompleted( const parser::Task& task ) const override;
bool addPlaylistMedias( parser::Task& task, int nbSubitem ) const;
......
......@@ -113,4 +113,12 @@ bool VLCMetadataService::isCompleted( const parser::Task& task ) const
return task.vlcMedia.isValid() == true;
}
void VLCMetadataService::onFlushing()
{
}
void VLCMetadataService::onRestarted()
{
}
}
......@@ -47,6 +47,8 @@ private:
virtual const char* name() const override;
virtual uint8_t nbThreads() const override;
virtual bool isCompleted( const parser::Task& task ) const override;
virtual void onFlushing() override;
virtual void onRestarted() override;
private:
MediaLibrary* m_ml;
......
......@@ -69,6 +69,25 @@ public:
* If false is returned, the service will be released and won't be used.
*/
virtual bool initialize( MediaLibrary* ml ) = 0;
/**
* @brief onFlushing will be invoked prior to restarting/flushing the service
*
* A service must release any database entity it might hold.
* The service will be paused or unstarted when this method gets called.
*/
virtual void onFlushing() = 0;
/**
* @brief onRestarted will be invoked prior to a service restart.
*
* A restart will always occur after a flush. Once this function gets called,
* the service is free to cache some database entities, or interact with the
* medialibrary again.
* The thread(s) running the service itself won't have been restarted when this
* function gets called.
*/
virtual void onRestarted() = 0;
};
}
......@@ -119,10 +119,12 @@ void ParserService::flush()
});
while ( m_tasks.empty() == false )
m_tasks.pop();
onFlushing();
}
void ParserService::restart()
{
onRestarted();
}
void ParserService::mainloop()
......
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