input/Tidal*Request: add Start() method

The caller should be able to safely store the instance pointer before
his callback is invoked.
This commit is contained in:
Max Kellermann 2018-01-19 11:09:18 +01:00
parent 1ecad094bd
commit 2fed3b5e5b
6 changed files with 14 additions and 4 deletions

View File

@ -91,6 +91,7 @@ TidalInputStream::OnTidalSession() noexcept
tidal_session->GetSession().c_str(),
track_id.c_str(),
handler);
track_request->Start();
} catch (...) {
Failed(std::current_exception());
}

View File

@ -59,8 +59,6 @@ TidalLoginRequest::TidalLoginRequest(CurlGlobal &curl,
request.SetOption(CURLOPT_COPYPOSTFIELDS,
EncodeForm(request.Get(),
{{"username", username}, {"password", password}}).c_str());
request.StartIndirect();
}
TidalLoginRequest::~TidalLoginRequest() noexcept

View File

@ -44,6 +44,8 @@ public:
/**
* An asynchronous Tidal "login/username" request.
*
* After construction, call Start() to initiate the request.
*/
class TidalLoginRequest final : CurlResponseHandler {
CurlSlist request_headers;
@ -71,6 +73,10 @@ public:
~TidalLoginRequest() noexcept;
void Start() {
request.StartIndirect();
}
private:
/* virtual methods from CurlResponseHandler */
void OnHeaders(unsigned status,

View File

@ -60,6 +60,7 @@ TidalSessionManager::AddLoginHandler(TidalSessionHandler &h) noexcept
token,
username, password,
handler);
login_request->Start();
} catch (...) {
error = std::current_exception();
ScheduleInvokeHandlers();

View File

@ -61,8 +61,6 @@ TidalTrackRequest::TidalTrackRequest(CurlGlobal &curl,
request_headers.Append((std::string("X-Tidal-SessionId:")
+ session).c_str());
request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get());
request.StartIndirect();
}
TidalTrackRequest::~TidalTrackRequest() noexcept

View File

@ -46,6 +46,8 @@ public:
/**
* An asynchronous request for the streaming URL of a Tidal track.
*
* After construction, call Start() to initiate the request.
*/
class TidalTrackRequest final : CurlResponseHandler {
CurlSlist request_headers;
@ -74,6 +76,10 @@ public:
~TidalTrackRequest() noexcept;
void Start() {
request.StartIndirect();
}
private:
/* virtual methods from CurlResponseHandler */
void OnHeaders(unsigned status,