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

Move Parser class in parser namespace

parent 584bda0b
......@@ -713,7 +713,7 @@ SearchAggregate MediaLibrary::search( const std::string& pattern,
void MediaLibrary::startParser()
{
m_parser.reset( new Parser( this ) );
m_parser.reset( new parser::Parser( this ) );
auto vlcService = std::unique_ptr<VLCMetadataService>( new VLCMetadataService );
auto metadataService = std::unique_ptr<MetadataParser>( new MetadataParser );
......
......@@ -34,7 +34,6 @@ namespace medialibrary
class ModificationNotifier;
class DiscovererWorker;
class Parser;
class ParserWorker;
class VLCThumbnailer;
......@@ -52,12 +51,18 @@ namespace factory
{
class IFileSystem;
}
namespace fs
{
class IFile;
class IDirectory;
}
namespace parser
{
class Parser;
}
class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
{
public:
......@@ -217,7 +222,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
// it might still finish a few operations before exiting the parser thread. Those operations are
// likely to require a valid MediaLibrary, which would be compromised if some fields have already been
// deleted/destroyed.
std::unique_ptr<Parser> m_parser;
std::unique_ptr<parser::Parser> m_parser;
// Same reasoning applies here.
//FIXME: Having to maintain a specific ordering sucks, let's use shared_ptr or something
std::unique_ptr<DiscovererWorker> m_discovererWorker;
......
......@@ -36,6 +36,8 @@
namespace medialibrary
{
namespace parser
{
Parser::Parser( MediaLibrary* ml )
: m_ml( ml )
......@@ -59,7 +61,7 @@ void Parser::addService( ServicePtr service )
m_services.push_back( std::move( worker ) );
}
void Parser::parse( std::shared_ptr<parser::Task> task )
void Parser::parse( std::shared_ptr<Task> task )
{
if ( m_services.empty() == true )
return;
......@@ -114,7 +116,7 @@ void Parser::restore()
if ( m_services.empty() == true )
return;
auto tasks = parser::Task::fetchUncompleted( m_ml );
auto tasks = Task::fetchUncompleted( m_ml );
LOG_INFO( "Resuming parsing on ", tasks.size(), " tasks" );
for ( auto& t : tasks )
{
......@@ -144,15 +146,15 @@ void Parser::updateStats()
}
}
void Parser::done( std::shared_ptr<parser::Task> t, parser::Status status )
void Parser::done( std::shared_ptr<Task> t, Status status )
{
++m_opDone;
auto serviceIdx = ++t->currentService;
if ( status == parser::Status::TemporaryUnavailable ||
status == parser::Status::Fatal ||
status == parser::Status::Discarded ||
if ( status == Status::TemporaryUnavailable ||
status == Status::Fatal ||
status == Status::Discarded ||
t->isCompleted() )
{
if ( serviceIdx < m_services.size() )
......@@ -191,3 +193,4 @@ void Parser::onIdleChanged( bool idle )
}
}
}
......@@ -33,15 +33,18 @@
namespace medialibrary
{
class IParserService;
class ParserWorker;
class IParserService;
namespace parser
{
// Use an interface to expose only the "done" method
class IParserCb
{
public:
virtual ~IParserCb() = default;
virtual void done( std::shared_ptr<parser::Task> task, parser::Status status ) = 0;
virtual void done( std::shared_ptr<Task> task, Status status ) = 0;
virtual void onIdleChanged( bool isIdle ) = 0;
};
......@@ -54,7 +57,7 @@ public:
Parser( MediaLibrary* ml );
virtual ~Parser();
void addService( ServicePtr service );
void parse( std::shared_ptr<parser::Task> task );
void parse( std::shared_ptr<Task> task );
void start();
void pause();
void resume();
......@@ -72,7 +75,7 @@ public:
private:
void updateStats();
virtual void done( std::shared_ptr<parser::Task> task,
parser::Status status ) override;
Status status ) override;
virtual void onIdleChanged( bool idle ) override;
private:
......@@ -90,3 +93,5 @@ private:
};
}
}
......@@ -98,7 +98,8 @@ void ParserWorker::parse( std::shared_ptr<parser::Task> t )
}
}
bool ParserWorker::initialize( MediaLibrary* ml, IParserCb* parserCb, std::unique_ptr<IParserService> service )
bool ParserWorker::initialize( MediaLibrary* ml, parser::IParserCb* parserCb,
std::unique_ptr<IParserService> service )
{
m_ml = ml;
m_service = std::move( service );
......
......@@ -36,7 +36,11 @@
namespace medialibrary
{
namespace parser
{
class IParserCb;
}
class ModificationNotifier;
class MediaLibrary;
......@@ -60,7 +64,7 @@ public:
///
void stop();
void parse( std::shared_ptr<parser::Task> t );
bool initialize( MediaLibrary* ml, IParserCb* parserCb, std::unique_ptr<IParserService> service );
bool initialize( MediaLibrary* ml, parser::IParserCb* parserCb, std::unique_ptr<IParserService> service );
bool isIdle() const;
///
/// \brief flush flush every currently scheduled tasks
......@@ -85,7 +89,7 @@ private:
private:
MediaLibrary* m_ml;
std::unique_ptr<IParserService> m_service;
IParserCb* m_parserCb;
parser::IParserCb* m_parserCb;
bool m_stopParser;
bool m_paused;
std::atomic_bool m_idle;
......
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