HydroCoupleOgc  0.1.0
OGC web service clients (WMS, WMTS, WCS, WFS) over Qt Network (0.1.0)
Loading...
Searching...
No Matches
HydroCouple::Ogc::HttpClient Class Reference

One network access manager, shared, with the bookkeeping around it that a tiled map needs. More...

#include <httpclient.h>

Inheritance diagram for HydroCouple::Ogc::HttpClient:
Collaboration diagram for HydroCouple::Ogc::HttpClient:

Public Types

using Callback = std::function<void(const HttpResponse &)>
 Called on the thread the client lives on, once, per get().
 
using RequestId = quint64
 What get() returns, and cancel() takes. Never 0 for a live ask.
 

Public Member Functions

 HttpClient (QObject *parent=nullptr)
 Constructs a client with nothing outstanding.
 
void setCacheDirectory (const QString &path, qint64 maximumBytes=0)
 Where responses are cached between sessions.
 
void setUserAgent (const QString &userAgent)
 Sent on every request; identifies the client to a server's logs.
 
void setTransferTimeout (int milliseconds)
 How long a request may stall before it is given up on.
 
RequestId get (const QUrl &url, const ServiceCredentials &credentials, Callback callback)
 Asks for url, calling callback when it is known.
 
RequestId get (const QUrl &url, Callback callback)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void cancel (RequestId id)
 Gives up on id.
 
void cancelAll ()
 Gives up on everything outstanding.
 
int pendingCount () const
 How many callers are waiting.
 
int inFlightCount () const
 How many requests are actually on the wire.
 

Detailed Description

One network access manager, shared, with the bookkeeping around it that a tiled map needs.

Panning a map asks for the same tile from several places at once and then abandons most of what it asked for. Two things follow, and both live here rather than in each layer that would otherwise repeat them: a second ask for something already in flight waits on the first request rather than making another, and a caller that gives up releases its claim without disturbing the callers that did not.

Member Typedef Documentation

◆ Callback

using HydroCouple::Ogc::HttpClient::Callback = std::function<void(const HttpResponse &)>

Called on the thread the client lives on, once, per get().

◆ RequestId

What get() returns, and cancel() takes. Never 0 for a live ask.

Constructor & Destructor Documentation

◆ HttpClient()

HydroCouple::Ogc::HttpClient::HttpClient ( QObject * parent = nullptr)
explicit

Constructs a client with nothing outstanding.

Destroying one abandons whatever it was fetching and calls none of the callbacks, which is what a layer being closed mid-pan needs — and follows from the manager being a child of the client and the callbacks being bound to it, so it needs no destructor of its own.

Member Function Documentation

◆ cancel()

void HydroCouple::Ogc::HttpClient::cancel ( RequestId id)

Gives up on id.

The callback will not be called. The request itself is abandoned only when no other caller is still waiting on it.

Here is the caller graph for this function:

◆ cancelAll()

void HydroCouple::Ogc::HttpClient::cancelAll ( )

Gives up on everything outstanding.

Here is the call graph for this function:

◆ get() [1/2]

HttpClient::RequestId HydroCouple::Ogc::HttpClient::get ( const QUrl & url,
Callback callback )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Here is the call graph for this function:

◆ get() [2/2]

HttpClient::RequestId HydroCouple::Ogc::HttpClient::get ( const QUrl & url,
const ServiceCredentials & credentials,
Callback callback )

Asks for url, calling callback when it is known.

When an identical ask is already in flight — the same URL under the same credentials — no second request is made and both callers are answered from the one response.

Returns
An id to cancel by, or 0 when url cannot be fetched.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inFlightCount()

int HydroCouple::Ogc::HttpClient::inFlightCount ( ) const
nodiscard

How many requests are actually on the wire.

Less than pendingCount() exactly when asks have been shared, which is the whole point of sharing them.

◆ pendingCount()

int HydroCouple::Ogc::HttpClient::pendingCount ( ) const
nodiscard

How many callers are waiting.

◆ setCacheDirectory()

void HydroCouple::Ogc::HttpClient::setCacheDirectory ( const QString & path,
qint64 maximumBytes = 0 )

Where responses are cached between sessions.

Off until set: a library that starts writing to a user's disk because it was linked has overstepped. Capabilities documents and tiles both carry cache headers worth honouring, and honouring them is what keeps a re-opened project from re-fetching a basemap.

◆ setTransferTimeout()

void HydroCouple::Ogc::HttpClient::setTransferTimeout ( int milliseconds)

How long a request may stall before it is given up on.

◆ setUserAgent()

void HydroCouple::Ogc::HttpClient::setUserAgent ( const QString & userAgent)

Sent on every request; identifies the client to a server's logs.


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