lib/upnp/Discovery: forward-declare inner class Downloader

This commit is contained in:
Max Kellermann 2024-01-04 13:10:49 +01:00
parent ee4b49d12f
commit f40eb963fd
2 changed files with 45 additions and 45 deletions

View File

@ -6,7 +6,10 @@
#include "Log.hxx"
#include "Error.hxx"
#include "lib/curl/Global.hxx"
#include "lib/curl/Handler.hxx"
#include "lib/curl/Request.hxx"
#include "event/Call.hxx"
#include "event/InjectEvent.hxx"
#include "util/DeleteDisposer.hxx"
#include "util/ScopeExit.hxx"
#include "util/SpanCast.hxx"
@ -15,6 +18,47 @@
#include <stdlib.h>
class UPnPDeviceDirectory::Downloader final
: public IntrusiveListHook<>, CurlResponseHandler
{
InjectEvent defer_start_event;
UPnPDeviceDirectory &parent;
std::string id;
const std::string url;
const std::chrono::steady_clock::duration expires;
CurlRequest request;
std::string data;
public:
Downloader(UPnPDeviceDirectory &_parent,
const UpnpDiscovery &disco);
void Start() noexcept {
defer_start_event.Schedule();
}
void Destroy() noexcept;
private:
void OnDeferredStart() noexcept {
try {
request.Start();
} catch (...) {
OnError(std::current_exception());
}
}
/* virtual methods from CurlResponseHandler */
void OnHeaders(unsigned status, Curl::Headers &&headers) override;
void OnData(std::span<const std::byte> data) override;
void OnEnd() override;
void OnError(std::exception_ptr e) noexcept override;
};
UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
const UpnpDiscovery &disco)
:defer_start_event(_parent.GetEventLoop(),

View File

@ -4,14 +4,9 @@
#include "Callback.hxx"
#include "Device.hxx"
#include "lib/curl/Init.hxx"
#include "lib/curl/Handler.hxx"
#include "lib/curl/Request.hxx"
#include "thread/Mutex.hxx"
#include "event/InjectEvent.hxx"
#include "util/IntrusiveList.hxx"
#include <upnp.h>
#include <list>
#include <vector>
#include <string>
@ -60,46 +55,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
}
};
class Downloader final
: public IntrusiveListHook<>, CurlResponseHandler
{
InjectEvent defer_start_event;
UPnPDeviceDirectory &parent;
std::string id;
const std::string url;
const std::chrono::steady_clock::duration expires;
CurlRequest request;
std::string data;
public:
Downloader(UPnPDeviceDirectory &_parent,
const UpnpDiscovery &disco);
void Start() noexcept {
defer_start_event.Schedule();
}
void Destroy() noexcept;
private:
void OnDeferredStart() noexcept {
try {
request.Start();
} catch (...) {
OnError(std::current_exception());
}
}
/* virtual methods from CurlResponseHandler */
void OnHeaders(unsigned status, Curl::Headers &&headers) override;
void OnData(std::span<const std::byte> data) override;
void OnEnd() override;
void OnError(std::exception_ptr e) noexcept override;
};
class Downloader;
CurlInit curl;