db/upnp/Discovery: move code to LockAdd(), LockRemove()
This commit is contained in:
parent
3afcfe3330
commit
c9af358e4b
@ -53,6 +53,22 @@ isMSDevice(const char *st)
|
|||||||
return memcmp(MediaServerDType, st, sz) == 0;
|
return memcmp(MediaServerDType, st, sz) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d)
|
||||||
|
{
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
directories[std::move(id)] = std::move(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
UPnPDeviceDirectory::LockRemove(const std::string &id)
|
||||||
|
{
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
auto i = directories.find(id);
|
||||||
|
if (i != directories.end())
|
||||||
|
directories.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
UPnPDeviceDirectory::discoExplorer()
|
UPnPDeviceDirectory::discoExplorer()
|
||||||
{
|
{
|
||||||
@ -88,10 +104,7 @@ UPnPDeviceDirectory::discoExplorer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.lock();
|
LockAdd(std::move(tsk->deviceId), std::move(d));
|
||||||
directories[std::move(tsk->deviceId)] = std::move(d);
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
delete tsk;
|
delete tsk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,14 +133,10 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco)
|
|||||||
inline int
|
inline int
|
||||||
UPnPDeviceDirectory::OnByeBye(Upnp_Discovery *disco)
|
UPnPDeviceDirectory::OnByeBye(Upnp_Discovery *disco)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isMSDevice(disco->DeviceType) ||
|
if (isMSDevice(disco->DeviceType) ||
|
||||||
isCDService(disco->ServiceType)) {
|
isCDService(disco->ServiceType)) {
|
||||||
// Device signals it is going off.
|
// Device signals it is going off.
|
||||||
const ScopeLock protect(mutex);
|
LockRemove(disco->DeviceId);
|
||||||
auto it = directories.find(disco->DeviceId);
|
|
||||||
if (it != directories.end())
|
|
||||||
directories.erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
|
@ -129,6 +129,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool expireDevices(Error &error);
|
bool expireDevices(Error &error);
|
||||||
|
|
||||||
|
void LockAdd(std::string &&id, ContentDirectoryDescriptor &&d);
|
||||||
|
void LockRemove(const std::string &id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Worker routine for the discovery queue. Get messages about
|
* Worker routine for the discovery queue. Get messages about
|
||||||
* devices appearing and disappearing, and update the
|
* devices appearing and disappearing, and update the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user