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

MediaLibrary: Handle multiple calls to initialize gracefully()

parent 6e149fac
......@@ -155,6 +155,9 @@ class IMediaLibrary
///
/// \param dbPath Path to the database
/// \return true in case of success, false otherwise
/// If initialize returns false, this medialibrary must not be used anymore, and should be
/// disposed off.
/// If it returns true the first time, calling this method again is a no-op
///
virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* metadataCb ) = 0;
virtual void setVerbosity( LogLevel v ) = 0;
......
......@@ -93,6 +93,7 @@ const uint32_t MediaLibrary::DbModelVersion = 2;
MediaLibrary::MediaLibrary()
: m_callback( nullptr )
, m_verbosity( LogLevel::Error )
, m_initialized( false )
{
Log::setLogLevel( m_verbosity );
}
......@@ -208,6 +209,8 @@ bool MediaLibrary::validateSearchPattern( const std::string& pattern )
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback )
{
if ( m_initialized == true )
return true;
if ( m_deviceLister == nullptr )
{
m_deviceLister = factory::createDeviceLister();
......@@ -251,6 +254,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
}
startDiscoverer();
startParser();
m_initialized = true;
return true;
}
......
......@@ -179,6 +179,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
std::shared_ptr<ModificationNotifier> m_modificationNotifier;
LogLevel m_verbosity;
Settings m_settings;
bool m_initialized;
};
}
......
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