AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection Class Reference

#include <LibcurlHTTP2Connection.h>

Inheritance diagram for alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection:
Collaboration graph
[legend]

Public Member Functions

 ~LibcurlHTTP2Connection ()
 
HTTP2ConnectionInterface methods.
std::shared_ptr< avsCommon::utils::http2::HTTP2RequestInterfacecreateAndSendRequest (const http2::HTTP2RequestConfig &config) override
 
void disconnect () override
 
void addObserver (std::shared_ptr< avsCommon::utils::http2::HTTP2ConnectionObserverInterface > observer) override
 
void removeObserver (std::shared_ptr< avsCommon::utils::http2::HTTP2ConnectionObserverInterface > observer) override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::http2::HTTP2ConnectionInterface
virtual ~HTTP2ConnectionInterface ()=default
 
virtual void addObserver (std::shared_ptr< HTTP2ConnectionObserverInterface > observer)=0
 
virtual void removeObserver (std::shared_ptr< HTTP2ConnectionObserverInterface > observer)=0
 

Static Public Member Functions

static std::shared_ptr< LibcurlHTTP2Connectioncreate (const std::shared_ptr< LibcurlSetCurlOptionsCallbackInterface > &setCurlOptionsCallback=nullptr)
 

Protected Types

using ActiveStreamMap = std::map< CURL *, std::shared_ptr< LibcurlHTTP2Request > >
 

Protected Member Functions

 LibcurlHTTP2Connection (const std::shared_ptr< LibcurlSetCurlOptionsCallbackInterface > &setCurlOptionsCallback=nullptr)
 
bool addStream (std::shared_ptr< LibcurlHTTP2Request > stream)
 
bool createMultiHandle ()
 
bool releaseStream (ActiveStreamMap::iterator &iterator)
 
void networkLoop ()
 
bool isStopping ()
 
void setIsStopping ()
 
void cleanupFinishedStreams ()
 
void cleanupCancelledAndStalledStreams ()
 
bool areStreamsPaused ()
 
void unPauseActiveStreams ()
 
bool cancelActiveStream (ActiveStreamMap::iterator &iterator)
 
void cancelActiveStreams ()
 
void cancelPendingStreams ()
 
void cancelAllStreams ()
 
std::shared_ptr< LibcurlHTTP2RequestdequeueRequest ()
 
void processNextRequest ()
 
void notifyObserversOfGoawayReceived ()
 

Protected Attributes

std::thread m_networkThread
 Main thread for this class. More...
 
std::shared_ptr< avsCommon::utils::libcurlUtils::CurlMultiHandleWrapperm_multi
 Represents a CURL multi handle. Intended to only be accessed by the network loop thread and in addStream. More...
 
std::mutex m_mutex
 Serializes concurrent access to the m_requestQueue and m_isStopping members. More...
 
std::condition_variable m_cv
 
ActiveStreamMap m_activeStreams
 
std::deque< std::shared_ptr< LibcurlHTTP2Request > > m_requestQueue
 Queue of requests send. Serialized by m_mutex. More...
 
std::mutex m_observersMutex
 Mutex for observers. More...
 
std::unordered_set< std::shared_ptr< avsCommon::utils::http2::HTTP2ConnectionObserverInterface > > m_observers
 Observers. More...
 
bool m_isStopping
 Set to true when we want to exit the network loop. More...
 
std::shared_ptr< LibcurlSetCurlOptionsCallbackInterfacem_setCurlOptionsCallback
 The LibcurlSetCurlOptionsCallbackInterface used for this connection. More...
 

Member Typedef Documentation

◆ ActiveStreamMap

Alias for c++ ordered map where key is curl handle and value is pointer to LibcurlHTTP2Request.

Constructor & Destructor Documentation

◆ ~LibcurlHTTP2Connection()

alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::~LibcurlHTTP2Connection ( )

Destructor.

◆ LibcurlHTTP2Connection()

alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::LibcurlHTTP2Connection ( const std::shared_ptr< LibcurlSetCurlOptionsCallbackInterface > &  setCurlOptionsCallback = nullptr)
protected

Constructor.

Parameters
setCurlOptionsCallbackThe optional LibcurlSetCurlOptionsCallbackInterface to set curl options when a new http2 connection is being created.

Member Function Documentation

◆ addObserver()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::addObserver ( std::shared_ptr< avsCommon::utils::http2::HTTP2ConnectionObserverInterface observer)
override

◆ addStream()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::addStream ( std::shared_ptr< LibcurlHTTP2Request stream)
protected

Adds a configured stream into this connection.

Parameters
streamRequest object with a configured curl handle.
Returns
libcurl code indicating the result of this operation.

◆ areStreamsPaused()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::areStreamsPaused ( )
protected

Determine whether all non-intermittent streams are paused. An intermittent stream would be a persistent downchannel stream, for instace.

Returns
True if all non-intermittent streams are paused, false otherwise.

◆ cancelActiveStream()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cancelActiveStream ( ActiveStreamMap::iterator &  iterator)
protected

Cancel an active stream and report CANCELLED completion status.

Parameters
[in,out]iteratorThe iterator to ActiveStreamMap to erase.
Returns
Whether the operation was successful.

◆ cancelActiveStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cancelActiveStreams ( )
protected

Release any active streams and report CANCELLED completion status.

◆ cancelAllStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cancelAllStreams ( )
protected

Cancels all streams on cleanup.

◆ cancelPendingStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cancelPendingStreams ( )
protected

Report CANCELLED completion status on any pending streams in the queue.

◆ cleanupCancelledAndStalledStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cleanupCancelledAndStalledStreams ( )
protected

Checks for streams that have been cancelled, removes them, and reports CANCELLED completion status. Checks for streams that have not progressed within their timeout, removes them, and reports the response code (if any) and completion status (TIMEOUT).

◆ cleanupFinishedStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::cleanupFinishedStreams ( )
protected

Checks if any active streams have finished and reports the response code and completion status for them.

◆ create()

static std::shared_ptr<LibcurlHTTP2Connection> alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::create ( const std::shared_ptr< LibcurlSetCurlOptionsCallbackInterface > &  setCurlOptionsCallback = nullptr)
static

Create an LibcurlHTTP2Connection.

Parameters
setCurlOptionsCallbackThe optional LibcurlSetCurlOptionsCallbackInterface to set curl options when a new http2 connection is being created.
Returns
The new LibcurlHTTP2Connection or nullptr if the operation fails.

◆ createAndSendRequest()

std::shared_ptr<avsCommon::utils::http2::HTTP2RequestInterface> alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::createAndSendRequest ( const http2::HTTP2RequestConfig config)
overridevirtual

Create an HTTP2 request. Send it immediately.

Parameters
configThe configuration object which defines the request.
Returns
A new HTTP2GetRequest instance.

Implements alexaClientSDK::avsCommon::utils::http2::HTTP2ConnectionInterface.

◆ createMultiHandle()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::createMultiHandle ( )
protected

Set up the multi-handle. Re-assign a new multi-handle, if m_multi is already non-null.

Returns
true if successful, false if a failure was encountered

◆ dequeueRequest()

std::shared_ptr<LibcurlHTTP2Request> alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::dequeueRequest ( )
protected

Take the next request from the queue;

Returns
next request, or nullPtr if queue is empty or the network loop is stopping.

◆ disconnect()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::disconnect ( )
overridevirtual

Terminate the HTTP2 connection, forcing immediate termination of any active requests.

Implements alexaClientSDK::avsCommon::utils::http2::HTTP2ConnectionInterface.

◆ isStopping()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::isStopping ( )
protected

Find out whether or not the network loop is stopping.

Returns
Whether or not the network loop is stopping.

◆ networkLoop()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::networkLoop ( )
protected

Main network loop. Repeatedly call curl_multi_perform in order to transfer data on the incorporated streams.

◆ notifyObserversOfGoawayReceived()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::notifyObserversOfGoawayReceived ( )
protected

Notify observers that a GOAWAY frame has been received.

◆ processNextRequest()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::processNextRequest ( )
protected

Dequeue next request and add it to the multi-handle

◆ releaseStream()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::releaseStream ( ActiveStreamMap::iterator &  iterator)
protected

Release a stream.

Parameters
[in,out]iteratorThe iterator to ActiveStreamMap to erase.
Returns
Whether the operation was successful.

◆ removeObserver()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::removeObserver ( std::shared_ptr< avsCommon::utils::http2::HTTP2ConnectionObserverInterface observer)
override

◆ setIsStopping()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::setIsStopping ( )
protected

Safely set m_isStopping to break out of the network loop.

◆ unPauseActiveStreams()

void alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::unPauseActiveStreams ( )
protected

UnPause all the active streams.

Member Data Documentation

◆ m_activeStreams

ActiveStreamMap alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_activeStreams
protected

The list of streams that either do not have HTTP response headers, or have outstanding response data. Only accessed from the network loop thread.

◆ m_cv

std::condition_variable alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_cv
protected

Used to notify the network loop thread that there is at least one request queued or that the loop has been instructed to stop.

◆ m_isStopping

bool alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_isStopping
protected

Set to true when we want to exit the network loop.

◆ m_multi

std::shared_ptr<avsCommon::utils::libcurlUtils::CurlMultiHandleWrapper> alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_multi
protected

Represents a CURL multi handle. Intended to only be accessed by the network loop thread and in addStream.

◆ m_mutex

std::mutex alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_mutex
protected

Serializes concurrent access to the m_requestQueue and m_isStopping members.

◆ m_networkThread

std::thread alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_networkThread
protected

Main thread for this class.

◆ m_observers

std::unordered_set<std::shared_ptr<avsCommon::utils::http2::HTTP2ConnectionObserverInterface> > alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_observers
protected

Observers.

◆ m_observersMutex

std::mutex alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_observersMutex
protected

Mutex for observers.

◆ m_requestQueue

std::deque<std::shared_ptr<LibcurlHTTP2Request> > alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_requestQueue
protected

Queue of requests send. Serialized by m_mutex.

◆ m_setCurlOptionsCallback

std::shared_ptr<LibcurlSetCurlOptionsCallbackInterface> alexaClientSDK::avsCommon::utils::libcurlUtils::LibcurlHTTP2Connection::m_setCurlOptionsCallback
protected

The LibcurlSetCurlOptionsCallbackInterface used for this connection.


The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0