lib/upnp/Discovery: apply naming convention

This commit is contained in:
Max Kellermann 2015-02-02 21:12:19 +00:00
parent e660229c40
commit 3d446d3266
5 changed files with 42 additions and 42 deletions

View File

@ -222,7 +222,7 @@ UpnpDatabase::GetSong(const char *uri, Error &error) const
} }
ContentDirectoryService server; ContentDirectoryService server;
if (!discovery->getServer(vpath.front().c_str(), server, error)) if (!discovery->GetServer(vpath.front().c_str(), server, error))
return nullptr; return nullptr;
vpath.pop_front(); vpath.pop_front();
@ -689,7 +689,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
auto vpath = stringToTokens(selection.uri, "/", true); auto vpath = stringToTokens(selection.uri, "/", true);
if (vpath.empty()) { if (vpath.empty()) {
std::vector<ContentDirectoryService> servers; std::vector<ContentDirectoryService> servers;
if (!discovery->getDirServices(servers, error)) if (!discovery->GetDirectories(servers, error))
return false; return false;
for (const auto &server : servers) { for (const auto &server : servers) {
@ -714,7 +714,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
vpath.pop_front(); vpath.pop_front();
ContentDirectoryService server; ContentDirectoryService server;
if (!discovery->getServer(servername.c_str(), server, error)) if (!discovery->GetServer(servername.c_str(), server, error))
return false; return false;
return VisitServer(server, vpath, selection, return VisitServer(server, vpath, selection,
@ -733,7 +733,7 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
return true; return true;
std::vector<ContentDirectoryService> servers; std::vector<ContentDirectoryService> servers;
if (!discovery->getDirServices(servers, error)) if (!discovery->GetDirectories(servers, error))
return false; return false;
std::set<std::string> values; std::set<std::string> values;

View File

@ -62,7 +62,8 @@ public:
/** /**
* Construct by copying data from device and service objects. * Construct by copying data from device and service objects.
* *
* The discovery service does this: use getDirServices() * The discovery service does this: use
* UPnPDeviceDirectory::GetDirectories()
*/ */
ContentDirectoryService(const UPnPDevice &device, ContentDirectoryService(const UPnPDevice &device,
const UPnPService &service); const UPnPService &service);

View File

@ -107,12 +107,12 @@ UPnPDeviceDirectory::LockRemove(const std::string &id)
} }
inline void inline void
UPnPDeviceDirectory::discoExplorer() UPnPDeviceDirectory::Explore()
{ {
for (;;) { for (;;) {
DiscoveredTask *tsk = 0; DiscoveredTask *tsk = 0;
if (!discoveredQueue.take(tsk)) { if (!queue.take(tsk)) {
discoveredQueue.workerExit(); queue.workerExit();
return; return;
} }
@ -128,7 +128,7 @@ UPnPDeviceDirectory::discoExplorer()
} }
// Update or insert the device // Update or insert the device
ContentDirectoryDescriptor d(std::move(tsk->deviceId), ContentDirectoryDescriptor d(std::move(tsk->device_id),
MonotonicClockS(), tsk->expires); MonotonicClockS(), tsk->expires);
{ {
@ -148,10 +148,10 @@ UPnPDeviceDirectory::discoExplorer()
} }
void * void *
UPnPDeviceDirectory::discoExplorer(void *ctx) UPnPDeviceDirectory::Explore(void *ctx)
{ {
UPnPDeviceDirectory &directory = *(UPnPDeviceDirectory *)ctx; UPnPDeviceDirectory &directory = *(UPnPDeviceDirectory *)ctx;
directory.discoExplorer(); directory.Explore();
return (void*)1; return (void*)1;
} }
@ -161,7 +161,7 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco)
if (isMSDevice(disco->DeviceType) || if (isMSDevice(disco->DeviceType) ||
isCDService(disco->ServiceType)) { isCDService(disco->ServiceType)) {
DiscoveredTask *tp = new DiscoveredTask(disco); DiscoveredTask *tp = new DiscoveredTask(disco);
if (discoveredQueue.put(tp)) if (queue.put(tp))
return UPNP_E_FINISH; return UPNP_E_FINISH;
} }
@ -210,7 +210,7 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp)
} }
bool bool
UPnPDeviceDirectory::expireDevices(Error &error) UPnPDeviceDirectory::ExpireDevices(Error &error)
{ {
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
const unsigned now = MonotonicClockS(); const unsigned now = MonotonicClockS();
@ -227,7 +227,7 @@ UPnPDeviceDirectory::expireDevices(Error &error)
} }
if (didsomething) if (didsomething)
return search(error); return Search(error);
return true; return true;
} }
@ -236,8 +236,8 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(UpnpClient_Handle _handle,
UPnPDiscoveryListener *_listener) UPnPDiscoveryListener *_listener)
:handle(_handle), :handle(_handle),
listener(_listener), listener(_listener),
discoveredQueue("DiscoveredQueue"), queue("DiscoveredQueue"),
m_searchTimeout(2), m_lastSearch(0) search_timeout(2), last_search(0)
{ {
} }
@ -249,24 +249,24 @@ UPnPDeviceDirectory::~UPnPDeviceDirectory()
bool bool
UPnPDeviceDirectory::Start(Error &error) UPnPDeviceDirectory::Start(Error &error)
{ {
if (!discoveredQueue.start(1, discoExplorer, this)) { if (!queue.start(1, Explore, this)) {
error.Set(upnp_domain, "Discover work queue start failed"); error.Set(upnp_domain, "Discover work queue start failed");
return false; return false;
} }
return search(error); return Search(error);
} }
bool bool
UPnPDeviceDirectory::search(Error &error) UPnPDeviceDirectory::Search(Error &error)
{ {
const unsigned now = MonotonicClockS(); const unsigned now = MonotonicClockS();
if (now - m_lastSearch < 10) if (now - last_search < 10)
return true; return true;
m_lastSearch = now; last_search = now;
// We search both for device and service just in case. // We search both for device and service just in case.
int code = UpnpSearchAsync(handle, m_searchTimeout, int code = UpnpSearchAsync(handle, search_timeout,
ContentDirectorySType, GetUpnpCookie()); ContentDirectorySType, GetUpnpCookie());
if (code != UPNP_E_SUCCESS) { if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code, error.Format(upnp_domain, code,
@ -275,7 +275,7 @@ UPnPDeviceDirectory::search(Error &error)
return false; return false;
} }
code = UpnpSearchAsync(handle, m_searchTimeout, code = UpnpSearchAsync(handle, search_timeout,
MediaServerDType, GetUpnpCookie()); MediaServerDType, GetUpnpCookie());
if (code != UPNP_E_SUCCESS) { if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code, error.Format(upnp_domain, code,
@ -288,11 +288,11 @@ UPnPDeviceDirectory::search(Error &error)
} }
bool bool
UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out, UPnPDeviceDirectory::GetDirectories(std::vector<ContentDirectoryService> &out,
Error &error) Error &error)
{ {
// Has locking, do it before our own lock // Has locking, do it before our own lock
if (!expireDevices(error)) if (!ExpireDevices(error))
return false; return false;
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
@ -310,12 +310,12 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out,
} }
bool bool
UPnPDeviceDirectory::getServer(const char *friendlyName, UPnPDeviceDirectory::GetServer(const char *friendly_name,
ContentDirectoryService &server, ContentDirectoryService &server,
Error &error) Error &error)
{ {
// Has locking, do it before our own lock // Has locking, do it before our own lock
if (!expireDevices(error)) if (!ExpireDevices(error))
return false; return false;
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
@ -323,7 +323,7 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
for (const auto &i : directories) { for (const auto &i : directories) {
const auto &device = i.device; const auto &device = i.device;
if (device.friendlyName != friendlyName) if (device.friendlyName != friendly_name)
continue; continue;
for (const auto &service : device.services) { for (const auto &service : device.services) {

View File

@ -55,13 +55,13 @@ class UPnPDeviceDirectory final : UpnpCallback {
*/ */
struct DiscoveredTask { struct DiscoveredTask {
std::string url; std::string url;
std::string deviceId; std::string device_id;
unsigned expires; // Seconds valid unsigned expires; // Seconds valid
DiscoveredTask(const Upnp_Discovery *disco) DiscoveredTask(const Upnp_Discovery *disco)
:url(disco->Location), :url(disco->Location),
deviceId(disco->DeviceId), device_id(disco->DeviceId),
expires(disco->Expires) {} expires(disco->Expires) {}
}; };
/** /**
@ -97,19 +97,19 @@ class UPnPDeviceDirectory final : UpnpCallback {
Mutex mutex; Mutex mutex;
std::list<ContentDirectoryDescriptor> directories; std::list<ContentDirectoryDescriptor> directories;
WorkQueue<DiscoveredTask *> discoveredQueue; WorkQueue<DiscoveredTask *> queue;
/** /**
* The UPnP device search timeout, which should actually be * The UPnP device search timeout, which should actually be
* called delay because it's the base of a random delay that * called delay because it's the base of a random delay that
* the devices apply to avoid responding all at the same time. * the devices apply to avoid responding all at the same time.
*/ */
int m_searchTimeout; int search_timeout;
/** /**
* The MonotonicClockS() time stamp of the last search. * The MonotonicClockS() time stamp of the last search.
*/ */
unsigned m_lastSearch; unsigned last_search;
public: public:
UPnPDeviceDirectory(UpnpClient_Handle _handle, UPnPDeviceDirectory(UpnpClient_Handle _handle,
@ -122,24 +122,24 @@ public:
bool Start(Error &error); bool Start(Error &error);
/** Retrieve the directory services currently seen on the network */ /** Retrieve the directory services currently seen on the network */
bool getDirServices(std::vector<ContentDirectoryService> &, Error &); bool GetDirectories(std::vector<ContentDirectoryService> &, Error &);
/** /**
* Get server by friendly name. * Get server by friendly name.
*/ */
bool getServer(const char *friendlyName, bool GetServer(const char *friendly_name,
ContentDirectoryService &server, ContentDirectoryService &server,
Error &error); Error &error);
private: private:
bool search(Error &error); bool Search(Error &error);
/** /**
* Look at the devices and get rid of those which have not * Look at the devices and get rid of those which have not
* been seen for too long. We do this when listing the top * been seen for too long. We do this when listing the top
* directory. * directory.
*/ */
bool expireDevices(Error &error); bool ExpireDevices(Error &error);
void LockAdd(ContentDirectoryDescriptor &&d); void LockAdd(ContentDirectoryDescriptor &&d);
void LockRemove(const std::string &id); void LockRemove(const std::string &id);
@ -149,12 +149,11 @@ private:
* devices appearing and disappearing, and update the * devices appearing and disappearing, and update the
* directory pool accordingly. * directory pool accordingly.
*/ */
static void *discoExplorer(void *); static void *Explore(void *);
void discoExplorer(); void Explore();
int OnAlive(Upnp_Discovery *disco); int OnAlive(Upnp_Discovery *disco);
int OnByeBye(Upnp_Discovery *disco); int OnByeBye(Upnp_Discovery *disco);
int cluCallBack(Upnp_EventType et, void *evp);
/* virtual methods from class UpnpCallback */ /* virtual methods from class UpnpCallback */
virtual int Invoke(Upnp_EventType et, void *evp) override; virtual int Invoke(Upnp_EventType et, void *evp) override;

View File

@ -100,7 +100,7 @@ UpnpNeighborExplorer::GetList() const
{ {
Error error; Error error;
if (!discovery->getDirServices(tmp, error)) if (!discovery->GetDirectories(tmp, error))
LogError(error); LogError(error);
} }