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

parser: Handle IParserService result from the worker

It has a direct access to the IParserService, which will ease up
handling all results from the Worker, instead of having the parser
services managing the task states themselves
parent b3052d79
......@@ -150,15 +150,6 @@ void Parser::done( std::shared_ptr<parser::Task> t, parser::Task::Status status
auto serviceIdx = ++t->currentService;
if ( status == parser::Task::Status::Completed )
{
t->markStepCompleted( parser::Task::ParserStep::Completed );
t->saveParserStep();
}
else if ( status == parser::Task::Status::Discarded )
{
parser::Task::destroy( m_ml, t->id() );
}
if ( status == parser::Task::Status::TemporaryUnavailable ||
status == parser::Task::Status::Fatal ||
status == parser::Task::Status::Discarded ||
......
......@@ -100,6 +100,7 @@ void ParserWorker::parse( std::shared_ptr<parser::Task> t )
bool ParserWorker::initialize( MediaLibrary* ml, IParserCb* parserCb, std::unique_ptr<IParserService> service )
{
m_ml = ml;
m_service = std::move( service );
m_parserCb = parserCb;
// Run the service specific initializer
......@@ -190,6 +191,8 @@ void ParserWorker::mainloop()
LOG_ERROR( "Caught an exception during ", task->item().mrl(), " [", serviceName, "] parsing: ", ex.what() );
status = parser::Task::Status::Fatal;
}
if ( handleServiceResult( *task, status ) == false )
status = parser::Task::Status::Fatal;
m_parserCb->done( std::move( task ), status );
}
LOG_INFO("Exiting ParserService [", serviceName, "] thread");
......@@ -204,4 +207,18 @@ void ParserWorker::setIdle(bool isIdle)
m_parserCb->onIdleChanged( isIdle );
}
bool ParserWorker::handleServiceResult( parser::Task& task, parser::Task::Status status )
{
if ( status == parser::Task::Status::Completed )
{
task.markStepCompleted( parser::Task::ParserStep::Completed );
return task.saveParserStep();
}
else if ( status == parser::Task::Status::Discarded )
{
return parser::Task::destroy( m_ml, task.id() );
}
return true;
}
}
......@@ -80,8 +80,10 @@ private:
void start();
void mainloop();
void setIdle( bool isIdle );
bool handleServiceResult( parser::Task& task, parser::Task::Status status );
private:
MediaLibrary* m_ml;
std::unique_ptr<IParserService> m_service;
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