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

Parser: cosmetics

parent 247865d9
......@@ -26,7 +26,7 @@
#include "IMedia.h"
Parser::Parser(DBConnection dbConnection , IMediaLibraryCb* cb)
Parser::Parser( DBConnection dbConnection, IMediaLibraryCb* cb )
: m_stopParser( false )
, m_dbConnection( dbConnection )
, m_callback( cb )
......@@ -56,7 +56,7 @@ Parser::~Parser()
}
}
void Parser::addService(std::unique_ptr<IMetadataService> service)
void Parser::addService( std::unique_ptr<IMetadataService> service )
{
m_services.emplace_back( std::move( service ) );
std::push_heap( m_services.begin(), m_services.end(), []( const ServicePtr& a, const ServicePtr& b )
......@@ -168,17 +168,15 @@ void Parser::updateStats()
}
}
Parser::Task::Task(std::shared_ptr<Media> file, Parser::ServiceList& serviceList, IMediaLibraryCb* metadataCb )
: file(file)
Parser::Task::Task( std::shared_ptr<Media> file, Parser::ServiceList& serviceList, IMediaLibraryCb* metadataCb )
: file( file )
, it( serviceList.begin() )
, end( serviceList.end() )
, cb( metadataCb )
{
}
void Parser::done(std::shared_ptr<Media> file, IMetadataService::Status status, void* data )
void Parser::done( std::shared_ptr<Media> file, IMetadataService::Status status, void* data )
{
++m_opDone;
updateStats();
......
......@@ -20,8 +20,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef PARSER_H
#define PARSER_H
#pragma once
#include <atomic>
#include <condition_variable>
......@@ -35,47 +34,45 @@
class Parser : public IMetadataServiceCb
{
public:
Parser( DBConnection dbConnection, IMediaLibraryCb* cb );
~Parser();
void addService(std::unique_ptr<IMetadataService> service );
void parse( std::shared_ptr<Media> file );
void start();
void pause();
void resume();
public:
Parser( DBConnection dbConnection, IMediaLibraryCb* cb );
~Parser();
void addService( std::unique_ptr<IMetadataService> service );
void parse( std::shared_ptr<Media> file );
void start();
void pause();
void resume();
private:
virtual void done( std::shared_ptr<Media> file, IMetadataService::Status status, void* data ) override;
void run();
// Queues all unparsed files for parsing.
void restore();
void updateStats();
private:
virtual void done( std::shared_ptr<Media> file, IMetadataService::Status status, void* data ) override;
void run();
// Queues all unparsed files for parsing.
void restore();
void updateStats();
private:
typedef std::unique_ptr<IMetadataService> ServicePtr;
typedef std::vector<ServicePtr> ServiceList;
struct Task
{
Task(std::shared_ptr<Media> file, ServiceList& serviceList , IMediaLibraryCb* metadataCb);
std::shared_ptr<Media> file;
ServiceList::iterator it;
ServiceList::iterator end;
IMediaLibraryCb* cb;
};
private:
typedef std::unique_ptr<IMetadataService> ServicePtr;
typedef std::vector<ServicePtr> ServiceList;
struct Task
{
Task( std::shared_ptr<Media> file, ServiceList& serviceList, IMediaLibraryCb* metadataCb );
std::shared_ptr<Media> file;
ServiceList::iterator it;
ServiceList::iterator end;
IMediaLibraryCb* cb;
};
private:
ServiceList m_services;
std::queue<Task*> m_tasks;
std::thread m_thread;
std::mutex m_lock;
std::condition_variable m_cond;
std::atomic_bool m_stopParser;
DBConnection m_dbConnection;
IMediaLibraryCb* m_callback;
std::atomic_uint m_opToDo;
std::atomic_uint m_opDone;
std::atomic_uint m_percent;
bool m_paused;
private:
ServiceList m_services;
std::queue<Task*> m_tasks;
std::thread m_thread;
std::mutex m_lock;
std::condition_variable m_cond;
std::atomic_bool m_stopParser;
DBConnection m_dbConnection;
IMediaLibraryCb* m_callback;
std::atomic_uint m_opToDo;
std::atomic_uint m_opDone;
std::atomic_uint m_percent;
bool m_paused;
};
#endif // PARSER_H
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