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

Various C++ fixes

parent 4d4b192b
......@@ -10,7 +10,7 @@
class IParserCb
{
public:
virtual ~IParserCb() {}
virtual ~IParserCb() = default;
/**
* @brief onServiceDone will be called after each MetadataService completes
......@@ -71,7 +71,7 @@ class IMediaLibrary
* This method will call service->initialize(), therefor the passed ServiceStatus
* is expected to be uninitialized.
*/
virtual void addMetadataService( IMetadataService* service ) = 0;
virtual void addMetadataService( std::unique_ptr<IMetadataService> service ) = 0;
virtual void parse( FilePtr file, IParserCb* cb ) = 0;
};
......
......@@ -227,10 +227,10 @@ MoviePtr MediaLibrary::createMovie( const std::string& title )
return Movie::create( m_dbConnection, title );
}
void MediaLibrary::addMetadataService(IMetadataService* service)
void MediaLibrary::addMetadataService(std::unique_ptr<IMetadataService> service)
{
service->initialize( m_parser.get(), this );
m_parser->addService( service );
m_parser->addService( std::move( service ) );
}
void MediaLibrary::parse(FilePtr file , IParserCb* cb)
......
......@@ -37,7 +37,7 @@ class MediaLibrary : public IMediaLibrary
virtual MoviePtr movie( const std::string& title );
virtual MoviePtr createMovie( const std::string& title );
virtual void addMetadataService( IMetadataService* service );
virtual void addMetadataService( std::unique_ptr<IMetadataService> service );
virtual void parse( FilePtr file, IParserCb* cb );
private:
......
......@@ -21,15 +21,14 @@ Parser::~Parser()
m_thread->join();
}
void Parser::addService(IMetadataService* service)
void Parser::addService(std::unique_ptr<IMetadataService> service)
{
std::function<bool(const ServicePtr&, const ServicePtr&)> comp = []( const ServicePtr& a, const ServicePtr& b )
m_services.push_back( std::move( service ) );
std::push_heap( m_services.begin(), m_services.end(), []( const ServicePtr& a, const ServicePtr& b )
{
// We want higher priority first
return a->priority() > b->priority();
};
m_services.push_back( ServicePtr( service ) );
std::push_heap( m_services.begin(), m_services.end(), comp );
});
}
void Parser::parse(FilePtr file, IParserCb* cb)
......
......@@ -18,7 +18,7 @@ class Parser : public IMetadataServiceCb
public:
Parser();
~Parser();
void addService( IMetadataService* service );
void addService(std::unique_ptr<IMetadataService> service );
void parse( FilePtr file, IParserCb* cb );
......
......@@ -59,11 +59,10 @@ class VLCMetadataServices : public Tests
"-vv"
};
VLC::Instance vlcInstance( sizeof(args) / sizeof(args[0]), args );
auto vlcService = new VLCMetadataService( vlcInstance );
auto vlcService = std::unique_ptr<VLCMetadataService>( new VLCMetadataService( vlcInstance ) );
// This takes ownership of vlcService
//FIXME: This sucks because ownership isn't expressed properly...
ml->addMetadataService( vlcService );
ml->addMetadataService( std::move( vlcService ) );
}
};
......
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