db/upnp/Device: move code to method Parse()
Forward the Error to the caller.
This commit is contained in:
parent
04b7648e00
commit
22dd3c8048
|
@ -21,7 +21,6 @@
|
||||||
#include "Device.hxx"
|
#include "Device.hxx"
|
||||||
#include "Util.hxx"
|
#include "Util.hxx"
|
||||||
#include "Expat.hxx"
|
#include "Expat.hxx"
|
||||||
#include "Log.hxx"
|
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -99,16 +98,15 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
UPnPDevice::UPnPDevice(const std::string &url, const char *description)
|
bool
|
||||||
:ok(false)
|
UPnPDevice::Parse(const std::string &url, const char *description,
|
||||||
|
Error &error)
|
||||||
{
|
{
|
||||||
UPnPDeviceParser mparser(*this);
|
{
|
||||||
Error error;
|
UPnPDeviceParser mparser(*this);
|
||||||
if (!mparser.Parse(description, strlen(description), true,
|
if (!mparser.Parse(description, strlen(description),
|
||||||
error)) {
|
true, error))
|
||||||
// TODO: pass Error to caller
|
return false;
|
||||||
LogError(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (URLBase.empty()) {
|
if (URLBase.empty()) {
|
||||||
|
@ -129,5 +127,6 @@ UPnPDevice::UPnPDevice(const std::string &url, const char *description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ok = true;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ struct UPnPService {
|
||||||
*/
|
*/
|
||||||
class UPnPDevice {
|
class UPnPDevice {
|
||||||
public:
|
public:
|
||||||
bool ok;
|
|
||||||
// e.g. urn:schemas-upnp-org:device:MediaServer:1
|
// e.g. urn:schemas-upnp-org:device:MediaServer:1
|
||||||
std::string deviceType;
|
std::string deviceType;
|
||||||
// e.g. MediaTomb
|
// e.g. MediaTomb
|
||||||
|
@ -78,17 +77,17 @@ public:
|
||||||
// Services provided by this device.
|
// Services provided by this device.
|
||||||
std::vector<UPnPService> services;
|
std::vector<UPnPService> services;
|
||||||
|
|
||||||
|
UPnPDevice() = default;
|
||||||
|
UPnPDevice(const UPnPDevice &) = delete;
|
||||||
|
UPnPDevice(UPnPDevice &&) = default;
|
||||||
|
UPnPDevice &operator=(UPnPDevice &&) = default;
|
||||||
|
|
||||||
/** Build device from xml description downloaded from discovery
|
/** Build device from xml description downloaded from discovery
|
||||||
* @param url where the description came from
|
* @param url where the description came from
|
||||||
* @param description the xml device description
|
* @param description the xml device description
|
||||||
*/
|
*/
|
||||||
UPnPDevice(const std::string &url, const char *description);
|
bool Parse(const std::string &url, const char *description,
|
||||||
|
Error &error);
|
||||||
UPnPDevice() : ok(false) {}
|
|
||||||
|
|
||||||
UPnPDevice(const UPnPDevice &) = delete;
|
|
||||||
UPnPDevice(UPnPDevice &&) = default;
|
|
||||||
UPnPDevice &operator=(UPnPDevice &&) = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UPNPDEV_HXX_INCLUDED_ */
|
#endif /* _UPNPDEV_HXX_INCLUDED_ */
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "ContentDirectoryService.hxx"
|
#include "ContentDirectoryService.hxx"
|
||||||
#include "upnpplib.hxx"
|
#include "upnpplib.hxx"
|
||||||
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <upnp/upnptools.h>
|
#include <upnp/upnptools.h>
|
||||||
|
|
||||||
|
@ -73,12 +74,17 @@ UPnPDeviceDirectory::discoExplorer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update or insert the device
|
// Update or insert the device
|
||||||
ContentDirectoryDescriptor d(tsk->url, buf,
|
ContentDirectoryDescriptor d(time(0), tsk->expires);
|
||||||
time(0), tsk->expires);
|
|
||||||
free(buf);
|
{
|
||||||
if (!d.device.ok) {
|
Error error2;
|
||||||
delete tsk;
|
bool success = d.Parse(tsk->url, buf, error2);
|
||||||
continue;
|
free(buf);
|
||||||
|
if (!success) {
|
||||||
|
delete tsk;
|
||||||
|
LogError(error2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ScopeLock protect(mutex);
|
const ScopeLock protect(mutex);
|
||||||
|
|
|
@ -65,15 +65,19 @@ class UPnPDeviceDirectory {
|
||||||
*/
|
*/
|
||||||
class ContentDirectoryDescriptor {
|
class ContentDirectoryDescriptor {
|
||||||
public:
|
public:
|
||||||
ContentDirectoryDescriptor() = default;
|
|
||||||
|
|
||||||
ContentDirectoryDescriptor(const std::string &url,
|
|
||||||
const char *description,
|
|
||||||
time_t last, int exp)
|
|
||||||
:device(url, description), last_seen(last), expires(exp+20) {}
|
|
||||||
UPnPDevice device;
|
UPnPDevice device;
|
||||||
time_t last_seen;
|
time_t last_seen;
|
||||||
int expires; // seconds valid
|
int expires; // seconds valid
|
||||||
|
|
||||||
|
ContentDirectoryDescriptor() = default;
|
||||||
|
|
||||||
|
ContentDirectoryDescriptor(time_t last, int exp)
|
||||||
|
:last_seen(last), expires(exp+20) {}
|
||||||
|
|
||||||
|
bool Parse(const std::string &url, const char *description,
|
||||||
|
Error &_error) {
|
||||||
|
return device.Parse(url, description, _error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LibUPnP *const lib;
|
LibUPnP *const lib;
|
||||||
|
|
Loading…
Reference in New Issue