db/upnp: move the UPnPDeviceDirectory instance to class UpnpDatabase

Delete the object when closing the database.
This commit is contained in:
Max Kellermann 2014-01-16 09:03:41 +01:00
parent a827714823
commit 1a09003a6e
3 changed files with 8 additions and 19 deletions

View File

@ -163,9 +163,10 @@ UpnpDatabase::Open(Error &error)
if (!m_lib)
return false;
m_superdir = UPnPDeviceDirectory::getTheDir();
if (!m_superdir || !m_superdir->ok()) {
error.Set(upnp_domain, "Discovery services startup failed");
m_superdir = new UPnPDeviceDirectory();
if (!m_superdir->ok()) {
error.Set(m_superdir->GetError());
delete m_superdir;
return false;
}
@ -180,7 +181,8 @@ void
UpnpDatabase::Close()
{
delete m_root;
// TBD decide what we do with the lib and superdir objects
delete m_superdir;
// TBD decide what we do with the lib object
}
void

View File

@ -275,17 +275,6 @@ UPnPDeviceDirectory::search()
return true;
}
UPnPDeviceDirectory *UPnPDeviceDirectory::getTheDir()
{
// TODO: elimate static variable
static UPnPDeviceDirectory *theDevDir;
if (theDevDir == nullptr)
theDevDir = new UPnPDeviceDirectory();
if (theDevDir && !theDevDir->ok())
return 0;
return theDevDir;
}
bool
UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out)
{

View File

@ -46,14 +46,12 @@ class UPnPDeviceDirectory {
time_t m_lastSearch;
UPnPDeviceDirectory();
public:
UPnPDeviceDirectory();
UPnPDeviceDirectory(const UPnPDeviceDirectory &) = delete;
UPnPDeviceDirectory& operator=(const UPnPDeviceDirectory &) = delete;
/** This class is a singleton. Get the instance here */
static UPnPDeviceDirectory *getTheDir();
/** Retrieve the directory services currently seen on the network */
bool getDirServices(std::vector<ContentDirectoryService> &);