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