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

Parser: Require the ML callback to be passed during initialization

parent 08eea9cc
......@@ -114,7 +114,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
m_snapshotPath = snapshotPath;
m_callback = mlCallback;
m_dbConnection.reset( new SqliteConnection( dbPath ) );
m_parser.reset( new Parser( m_dbConnection.get() ) );
m_parser.reset( new Parser( m_dbConnection.get(), m_callback ) );
if ( mlCallback != nullptr )
......@@ -217,7 +217,7 @@ std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, FolderPtr
}
if ( m_callback != nullptr )
m_callback->onFileAdded( fptr );
m_parser->parse( fptr, m_callback );
m_parser->parse( fptr );
return fptr;
}
......
......@@ -26,10 +26,11 @@
#include "IMedia.h"
Parser::Parser( DBConnection dbConnection )
Parser::Parser(DBConnection dbConnection , IMediaLibraryCb* cb)
: m_thread( &Parser::run, this )
, m_stopParser( false )
, m_dbConnection( dbConnection )
, m_callback( cb )
{
}
......@@ -105,8 +106,7 @@ void Parser::restore()
for ( auto& it : media )
{
auto m = std::static_pointer_cast<Media>( it );
//FIXME: No callback here
m_tasks.push( new Task( m, m_services, nullptr ) );
m_tasks.push( new Task( m, m_services, m_callback ) );
}
}
......
......@@ -36,10 +36,10 @@
class Parser : public IMetadataServiceCb
{
public:
Parser(DBConnection dbConnection);
Parser( DBConnection dbConnection, IMediaLibraryCb* cb );
~Parser();
void addService(std::unique_ptr<IMetadataService> service );
void parse( std::shared_ptr<Media> file, IMediaLibraryCb* cb );
void parse( std::shared_ptr<Media> file );
private:
virtual void done( std::shared_ptr<Media> file, IMetadataService::Status status, void* data ) override;
......@@ -67,6 +67,7 @@ class Parser : public IMetadataServiceCb
std::condition_variable m_cond;
std::atomic_bool m_stopParser;
DBConnection m_dbConnection;
IMediaLibraryCb* m_callback;
};
#endif // PARSER_H
Supports Markdown
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