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 "Util.hxx"
|
||||
#include "Expat.hxx"
|
||||
#include "Log.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -99,16 +98,15 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
UPnPDevice::UPnPDevice(const std::string &url, const char *description)
|
||||
:ok(false)
|
||||
bool
|
||||
UPnPDevice::Parse(const std::string &url, const char *description,
|
||||
Error &error)
|
||||
{
|
||||
UPnPDeviceParser mparser(*this);
|
||||
Error error;
|
||||
if (!mparser.Parse(description, strlen(description), true,
|
||||
error)) {
|
||||
// TODO: pass Error to caller
|
||||
LogError(error);
|
||||
return;
|
||||
{
|
||||
UPnPDeviceParser mparser(*this);
|
||||
if (!mparser.Parse(description, strlen(description),
|
||||
true, error))
|
||||
return false;
|
||||
}
|
||||
|
||||
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 {
|
||||
public:
|
||||
bool ok;
|
||||
// e.g. urn:schemas-upnp-org:device:MediaServer:1
|
||||
std::string deviceType;
|
||||
// e.g. MediaTomb
|
||||
|
@ -78,17 +77,17 @@ public:
|
|||
// Services provided by this device.
|
||||
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
|
||||
* @param url where the description came from
|
||||
* @param description the xml device description
|
||||
*/
|
||||
UPnPDevice(const std::string &url, const char *description);
|
||||
|
||||
UPnPDevice() : ok(false) {}
|
||||
|
||||
UPnPDevice(const UPnPDevice &) = delete;
|
||||
UPnPDevice(UPnPDevice &&) = default;
|
||||
UPnPDevice &operator=(UPnPDevice &&) = default;
|
||||
bool Parse(const std::string &url, const char *description,
|
||||
Error &error);
|
||||
};
|
||||
|
||||
#endif /* _UPNPDEV_HXX_INCLUDED_ */
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "Domain.hxx"
|
||||
#include "ContentDirectoryService.hxx"
|
||||
#include "upnpplib.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <upnp/upnptools.h>
|
||||
|
||||
|
@ -73,12 +74,17 @@ UPnPDeviceDirectory::discoExplorer()
|
|||
}
|
||||
|
||||
// Update or insert the device
|
||||
ContentDirectoryDescriptor d(tsk->url, buf,
|
||||
time(0), tsk->expires);
|
||||
free(buf);
|
||||
if (!d.device.ok) {
|
||||
delete tsk;
|
||||
continue;
|
||||
ContentDirectoryDescriptor d(time(0), tsk->expires);
|
||||
|
||||
{
|
||||
Error error2;
|
||||
bool success = d.Parse(tsk->url, buf, error2);
|
||||
free(buf);
|
||||
if (!success) {
|
||||
delete tsk;
|
||||
LogError(error2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const ScopeLock protect(mutex);
|
||||
|
|
|
@ -65,15 +65,19 @@ class UPnPDeviceDirectory {
|
|||
*/
|
||||
class ContentDirectoryDescriptor {
|
||||
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;
|
||||
time_t last_seen;
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue