libQuotient
A Qt library for building matrix clients
Quotient::BaseJob Class Reference

#include <basejob.h>

Inherits QObject.

Inherited by Quotient::Add3PIDJob, Quotient::BanJob, Quotient::Bind3PIDJob, Quotient::ChangePasswordJob, Quotient::CheckUsernameAvailabilityJob, Quotient::ClaimKeysJob, Quotient::CreateContentJob, Quotient::CreateRoomJob, Quotient::DeactivateAccountJob, Quotient::DefineFilterJob, Quotient::Delete3pidFromAccountJob, Quotient::DeleteDeviceJob, Quotient::DeleteDevicesJob, Quotient::DeletePushRuleJob, Quotient::DeleteRoomAliasJob, Quotient::DeleteRoomKeyBySessionIdJob, Quotient::DeleteRoomKeysByRoomIdJob, Quotient::DeleteRoomKeysJob, Quotient::DeleteRoomKeysVersionJob, Quotient::DeleteRoomTagJob, Quotient::DownloadFileJob, Quotient::ForgetRoomJob, Quotient::GenerateLoginTokenJob, Quotient::GetAccount3PIDsJob, Quotient::GetAccountDataJob, Quotient::GetAccountDataPerRoomJob, Quotient::GetAvatarUrlJob, Quotient::GetCapabilitiesJob, Quotient::GetConfigAuthedJob, Quotient::GetConfigJob, Quotient::GetContentAuthedJob, Quotient::GetContentJob, Quotient::GetContentOverrideNameAuthedJob, Quotient::GetContentOverrideNameJob, Quotient::GetContentThumbnailAuthedJob, Quotient::GetContentThumbnailJob, Quotient::GetDeviceJob, Quotient::GetDevicesJob, Quotient::GetDisplayNameJob, Quotient::GetEventByTimestampJob, Quotient::GetEventContextJob, Quotient::GetFilterJob, Quotient::GetJoinedMembersByRoomJob, Quotient::GetJoinedRoomsJob, Quotient::GetKeysChangesJob, Quotient::GetLocalAliasesJob, Quotient::GetLoginFlowsJob, Quotient::GetMembersByRoomJob, Quotient::GetNotificationsJob, Quotient::GetOneRoomEventJob, Quotient::GetPresenceJob, Quotient::GetProtocolMetadataJob, Quotient::GetProtocolsJob, Quotient::GetPublicRoomsJob, Quotient::GetPushRuleActionsJob, Quotient::GetPushRuleJob, Quotient::GetPushRulesGlobalJob, Quotient::GetPushRulesJob, Quotient::GetPushersJob, Quotient::GetRelatingEventsJob, Quotient::GetRelatingEventsWithRelTypeAndEventTypeJob, Quotient::GetRelatingEventsWithRelTypeJob, Quotient::GetRoomEventsJob, Quotient::GetRoomIdByAliasJob, Quotient::GetRoomKeyBySessionIdJob, Quotient::GetRoomKeysByRoomIdJob, Quotient::GetRoomKeysJob, Quotient::GetRoomKeysVersionCurrentJob, Quotient::GetRoomKeysVersionJob, Quotient::GetRoomStateJob, Quotient::GetRoomStateWithKeyJob, Quotient::GetRoomTagsJob, Quotient::GetRoomVisibilityOnDirectoryJob, Quotient::GetSpaceHierarchyJob, Quotient::GetThreadRootsJob, Quotient::GetTokenOwnerJob, Quotient::GetTurnServerJob, Quotient::GetUrlPreviewAuthedJob, Quotient::GetUrlPreviewJob, Quotient::GetUserProfileJob, Quotient::GetVersionsJob, Quotient::GetWellknownJob, Quotient::GetWellknownSupportJob, Quotient::GetWhoIsJob, Quotient::InviteBy3PIDJob, Quotient::InviteUserJob, Quotient::IsPushRuleEnabledJob, Quotient::JoinRoomByIdJob, Quotient::JoinRoomJob, Quotient::KickJob, Quotient::KnockRoomJob, Quotient::LeaveRoomJob, Quotient::LoginJob, Quotient::LogoutAllJob, Quotient::LogoutJob, Quotient::MediaThumbnailJob, Quotient::PeekEventsJob, Quotient::Post3PIDsJob, Quotient::PostPusherJob, Quotient::PostReceiptJob, Quotient::PostRoomKeysVersionJob, Quotient::PutRoomKeyBySessionIdJob, Quotient::PutRoomKeysByRoomIdJob, Quotient::PutRoomKeysJob, Quotient::PutRoomKeysVersionJob, Quotient::QueryKeysJob, Quotient::QueryLocationByAliasJob, Quotient::QueryLocationByProtocolJob, Quotient::QueryPublicRoomsJob, Quotient::QueryUserByIDJob, Quotient::QueryUserByProtocolJob, Quotient::RedactEventJob, Quotient::RedirectToIdPJob, Quotient::RedirectToSSOJob, Quotient::RefreshJob, Quotient::RegisterJob, Quotient::RegistrationTokenValidityJob, Quotient::ReportContentJob, Quotient::RequestOpenIdTokenJob, Quotient::RequestTokenTo3PIDEmailJob, Quotient::RequestTokenTo3PIDMSISDNJob, Quotient::RequestTokenToRegisterEmailJob, Quotient::RequestTokenToRegisterMSISDNJob, Quotient::RequestTokenToResetPasswordEmailJob, Quotient::RequestTokenToResetPasswordMSISDNJob, Quotient::SearchJob, Quotient::SearchUserDirectoryJob, Quotient::SendMessageJob, Quotient::SendToDeviceJob, Quotient::SetAccountDataJob, Quotient::SetAccountDataPerRoomJob, Quotient::SetAvatarUrlJob, Quotient::SetDisplayNameJob, Quotient::SetPresenceJob, Quotient::SetPushRuleActionsJob, Quotient::SetPushRuleEnabledJob, Quotient::SetPushRuleJob, Quotient::SetReadMarkerJob, Quotient::SetRoomAliasJob, Quotient::SetRoomStateWithKeyJob, Quotient::SetRoomTagJob, Quotient::SetRoomVisibilityOnDirectoryJob, Quotient::SetTypingJob, Quotient::SyncJob, Quotient::UnbanJob, Quotient::Unbind3pidFromAccountJob, Quotient::UpdateAppserviceRoomDirectoryVisibilityJob, Quotient::UpdateDeviceJob, Quotient::UpgradeRoomJob, Quotient::UploadContentJob, Quotient::UploadContentToMXCJob, Quotient::UploadCrossSigningKeysJob, Quotient::UploadCrossSigningSignaturesJob, and Quotient::UploadKeysJob.

Collaboration diagram for Quotient::BaseJob:

Classes

struct  Status
 The status of a job. More...
 

Public Types

enum  StatusCode {
  Success = 0 , NoError = Success , Pending = 1 , WarningLevel = 20 ,
  UnexpectedResponseType = 21 , UnexpectedResponseTypeWarning = UnexpectedResponseType , Unprepared = 25 , Abandoned = 50 ,
  ErrorLevel = 100 , NetworkError = 101 , Timeout , Unauthorised ,
  ContentAccessError , NotFound , IncorrectRequest , IncorrectResponse ,
  TooManyRequests , RateLimited = TooManyRequests , RequestNotImplemented , UnsupportedRoomVersion ,
  NetworkAuthRequired , UserConsentRequired , CannotLeaveRoom , UserDeactivated ,
  FileError , AccountLocked , UserDefinedError = 256
}
 Job status codes. More...
 
using duration_ms_t = std::chrono::milliseconds::rep
 

Public Slots

void initiate (Quotient::ConnectionData *connData, bool inBackground)
 
void abandon ()
 Abandon the result of this job, arrived or unarrived. More...
 

Signals

void aboutToSendRequest (QNetworkRequest *req)
 The job is about to send a network request. More...
 
void sentRequest ()
 The job has sent a network request. More...
 
void statusChanged (Quotient::BaseJob::Status newStatus)
 The job has changed its status. More...
 
void retryScheduled (int nextAttempt, Quotient::BaseJob::duration_ms_t inMilliseconds)
 A retry of the network request is scheduled after the previous request failed. More...
 
void rateLimited ()
 The job has been rate-limited. More...
 
void finished (Quotient::BaseJob *job)
 The job has finished - either with a result, or abandoned. More...
 
void result (Quotient::BaseJob *job)
 The job has finished with a result, successful or unsuccessful. More...
 
void success (Quotient::BaseJob *)
 The job has finished with a successful result. More...
 
void failure (Quotient::BaseJob *)
 The job has finished with a failure result Emitted together with result() when the job resulted in an error. Mutually exclusive with success(): after result() is emitted, exactly one of success() and failure() will be emitted next. Will not be emitted in case of abandon()ing. More...
 
void downloadProgress (qint64 bytesReceived, qint64 bytesTotal)
 
void uploadProgress (qint64 bytesSent, qint64 bytesTotal)
 

Public Member Functions

 BaseJob (HttpVerb verb, const QString &name, QByteArray endpoint, bool needsToken=true)
 
 BaseJob (HttpVerb verb, const QString &name, QByteArray endpoint, const QUrlQuery &query, RequestData &&data={}, bool needsToken=true)
 
QUrl requestUrl () const
 
bool isBackground () const
 
Status status () const
 Current status of the job. More...
 
QString statusCaption () const
 Short human-friendly message on the job status. More...
 
QByteArray rawData (int bytesAtMost) const
 Get first bytes of the raw response body as received from the server. More...
 
const QByteArray & rawData () const
 Access the whole response body as received from the server. More...
 
QString rawDataSample (int bytesAtMost=65535) const
 Get UI-friendly sample of raw data. More...
 
QJsonObject jsonData () const
 Get the response body as a JSON object. More...
 
QJsonArray jsonItems () const
 Get the response body as a JSON array. More...
 
template<typename T >
loadFromJson (auto keyName, T &&defaultValue={}) const
 Load the property from the JSON response assuming a given C++ type. More...
 
template<typename T >
takeFromJson (auto key, T &&defaultValue={})
 Load the property from the JSON response and delete it from JSON. More...
 
int error () const
 Error (more generally, status) code. More...
 
virtual QString errorString () const
 Error-specific message, as returned by the server. More...
 
QUrl errorUrl () const
 A URL to help/clarify the error, if provided by the server. More...
 
int maxRetries () const
 
void setMaxRetries (int newMaxRetries)
 
std::chrono::seconds getCurrentTimeout () const
 
Q_INVOKABLE Quotient::BaseJob::duration_ms_t getCurrentTimeoutMs () const
 
std::chrono::seconds getNextRetryInterval () const
 
Q_INVOKABLE Quotient::BaseJob::duration_ms_t getNextRetryMs () const
 
std::chrono::milliseconds timeToRetry () const
 
Q_INVOKABLE Quotient::BaseJob::duration_ms_t millisToRetry () const
 

Static Public Member Functions

template<typename... StrTs>
static QByteArray makePath (QByteArrayView base, StrTs &&... parts)
 

Protected Types

using headers_t = QHash< QByteArray, QByteArray >
 

Protected Slots

void timeout ()
 

Protected Member Functions

QByteArray apiEndpoint () const
 
void setApiEndpoint (QByteArray apiEndpoint)
 
const headers_trequestHeaders () const
 
void setRequestHeader (const headers_t::key_type &headerName, const headers_t::mapped_type &headerValue)
 
void setRequestHeaders (const headers_t &headers)
 
QUrlQuery query () const
 
void setRequestQuery (const QUrlQuery &query)
 
const RequestDatarequestData () const
 
void setRequestData (RequestData &&data)
 
const QByteArrayList & expectedContentTypes () const
 
void addExpectedContentType (const QByteArray &contentType)
 
void setExpectedContentTypes (const QByteArrayList &contentTypes)
 
QStringList expectedKeys () const
 
void addExpectedKey (QString key)
 
void setExpectedKeys (const QStringList &keys)
 
const QNetworkReply * reply () const
 
QNetworkReply * reply ()
 
virtual void doPrepare (const ConnectionData *)
 Prepare the job for execution. More...
 
virtual void onSentRequest (QNetworkReply *)
 Postprocessing after the network request has been sent. More...
 
virtual void beforeAbandon ()
 
virtual Status checkReply (const QNetworkReply *reply) const
 Check the pending or received reply for upfront issues. More...
 
virtual Status prepareResult ()
 An extension point for additional reply processing. More...
 
virtual Status prepareError (Status currentStatus)
 Process details of the error. More...
 
QJsonValue takeValueFromJson (QAnyStringView key)
 Retrieve a value for one specific key and delete it from the JSON response object. More...
 
void setStatus (Status s)
 
void setStatus (int code, QString message)
 
void forceResult (QJsonDocument resultDoc, Status s={ Success })
 Force completion of the job for sake of testing. More...
 
void setLoggingCategory (QMessageLogger::CategoryFunction lcf)
 Set the logging category for the given job instance. More...
 
 ~BaseJob () override
 

Static Protected Member Functions

static QUrl makeRequestUrl (const HomeserverData &hsData, const QByteArray &encodedPath, const QUrlQuery &query={})
 Construct a URL out of baseUrl, path and query. More...
 

Properties

QUrl requestUrl
 
int maxRetries
 
int statusCode
 

Friends

class ConnectionData
 
template<class JobT >
class JobHandle
 
QDebug operator<< (QDebug dbg, const BaseJob *j)
 

Detailed Description

Definition at line 26 of file basejob.h.

Member Typedef Documentation

◆ duration_ms_t

using Quotient::BaseJob::duration_ms_t = std::chrono::milliseconds::rep

Definition at line 212 of file basejob.h.

◆ headers_t

using Quotient::BaseJob::headers_t = QHash<QByteArray, QByteArray>
protected

Definition at line 311 of file basejob.h.

Member Enumeration Documentation

◆ StatusCode

Job status codes.

Every job is created in Unprepared status; upon calling Connection::prepare(), if things are fine, it becomes Pending and remains so until the reply arrives; then the status code is set according to the job result. At any point in time the job can be abandon()ed, causing it to become Abandoned for a brief period before deletion.

Enumerator
Success 
NoError 
Pending 
WarningLevel 

Warnings have codes starting from this.

UnexpectedResponseType 
UnexpectedResponseTypeWarning 
Unprepared 

Initial job state is incomplete, hence warning level.

Abandoned 

A tiny period between abandoning and object deletion.

ErrorLevel 

Errors have codes starting from this.

NetworkError 
Timeout 
Unauthorised 
ContentAccessError 
NotFound 
IncorrectRequest 
IncorrectResponse 
TooManyRequests 
RateLimited 
RequestNotImplemented 
UnsupportedRoomVersion 
NetworkAuthRequired 
UserConsentRequired 
CannotLeaveRoom 
UserDeactivated 
FileError 
AccountLocked 
UserDefinedError 

Definition at line 46 of file basejob.h.

Constructor & Destructor Documentation

◆ BaseJob() [1/2]

Quotient::BaseJob::BaseJob ( HttpVerb  verb,
const QString &  name,
QByteArray  endpoint,
bool  needsToken = true 
)

◆ BaseJob() [2/2]

Quotient::BaseJob::BaseJob ( HttpVerb  verb,
const QString &  name,
QByteArray  endpoint,
const QUrlQuery &  query,
RequestData &&  data = {},
bool  needsToken = true 
)

◆ ~BaseJob()

Quotient::BaseJob::~BaseJob ( )
overrideprotected

Member Function Documentation

◆ abandon

void Quotient::BaseJob::abandon ( )
slot

Abandon the result of this job, arrived or unarrived.

This aborts waiting for a reply from the server (if there was any pending) and deletes the job object. No result signals (result, success, failure) are emitted, only finished() is.

◆ aboutToSendRequest

void Quotient::BaseJob::aboutToSendRequest ( QNetworkRequest *  req)
signal

The job is about to send a network request.

This signal is emitted every time a network request is made (which can occur several times due to job retries). You can use it to change the request parameters (such as redirect policy) if necessary. If you need to set additional request headers or query items, do that using setRequestHeaders() and setRequestQuery() instead.

Note
req is not guaranteed to exist (i.e. it may point to garbage) unless this signal is handled via a DirectConnection (or BlockingQueuedConnection if in another thread), i.e., synchronously.
See also
setRequestHeaders, setRequestQuery

◆ addExpectedContentType()

void Quotient::BaseJob::addExpectedContentType ( const QByteArray &  contentType)
protected

◆ addExpectedKey()

void Quotient::BaseJob::addExpectedKey ( QString  key)
protected

◆ apiEndpoint()

QByteArray Quotient::BaseJob::apiEndpoint ( ) const
protected

◆ beforeAbandon()

virtual void Quotient::BaseJob::beforeAbandon ( )
protectedvirtual

◆ checkReply()

virtual Status Quotient::BaseJob::checkReply ( const QNetworkReply *  reply) const
protectedvirtual

Check the pending or received reply for upfront issues.

This is invoked when headers are first received and also once the complete reply is obtained; the base implementation checks the HTTP headers to detect general issues such as network errors or access denial and it's strongly recommended to call it from overrides, as early as possible.

This slot is const and cannot read the response body from the reply. If you need to read the body on the fly, override onSentRequest() and connect in it to reply->readyRead(); and if you only need to validate the body after it fully arrived, use prepareResult() for that. Returning anything except NoError/Success switches further processing from prepareResult() to prepareError().

Returns
the result of checking the reply
See also
gotReply

◆ doPrepare()

virtual void Quotient::BaseJob::doPrepare ( const ConnectionData )
protectedvirtual

Prepare the job for execution.

This method is called no more than once per job lifecycle, when it's first scheduled for execution; in particular, it is not called on retries.

◆ downloadProgress

void Quotient::BaseJob::downloadProgress ( qint64  bytesReceived,
qint64  bytesTotal 
)
signal

◆ error()

int Quotient::BaseJob::error ( ) const

Error (more generally, status) code.

Equivalent to status().code

See also
status, StatusCode

◆ errorString()

virtual QString Quotient::BaseJob::errorString ( ) const
virtual

Error-specific message, as returned by the server.

◆ errorUrl()

QUrl Quotient::BaseJob::errorUrl ( ) const

A URL to help/clarify the error, if provided by the server.

◆ expectedContentTypes()

const QByteArrayList& Quotient::BaseJob::expectedContentTypes ( ) const
protected

◆ expectedKeys()

QStringList Quotient::BaseJob::expectedKeys ( ) const
protected

◆ failure

void Quotient::BaseJob::failure ( Quotient::BaseJob )
signal

The job has finished with a failure result Emitted together with result() when the job resulted in an error. Mutually exclusive with success(): after result() is emitted, exactly one of success() and failure() will be emitted next. Will not be emitted in case of abandon()ing.

See also
result, success

◆ finished

void Quotient::BaseJob::finished ( Quotient::BaseJob job)
signal

The job has finished - either with a result, or abandoned.

Emitted when the job is finished, in any case. It is used to notify observers that the job is terminated and that progress can be hidden.

This should not be emitted directly by subclasses; use finishJob() instead.

In general, to be notified of a job's completion, client code should connect to result(), success(), or failure() rather than finished(). However if you need to track the job's lifecycle you should connect to this instead of result(); in particular, only this signal will be emitted on abandoning, the others won't.

Parameters
jobthe job that emitted this signal
See also
result, success, failure

◆ forceResult()

void Quotient::BaseJob::forceResult ( QJsonDocument  resultDoc,
Status  s = Success } 
)
protected

Force completion of the job for sake of testing.

Normal jobs should never use; this is only meant to be used in test mocks.

See also
Mocked

◆ getCurrentTimeout()

std::chrono::seconds Quotient::BaseJob::getCurrentTimeout ( ) const

◆ getCurrentTimeoutMs()

Q_INVOKABLE Quotient::BaseJob::duration_ms_t Quotient::BaseJob::getCurrentTimeoutMs ( ) const

◆ getNextRetryInterval()

std::chrono::seconds Quotient::BaseJob::getNextRetryInterval ( ) const

◆ getNextRetryMs()

Q_INVOKABLE Quotient::BaseJob::duration_ms_t Quotient::BaseJob::getNextRetryMs ( ) const

◆ initiate

void Quotient::BaseJob::initiate ( Quotient::ConnectionData connData,
bool  inBackground 
)
slot

◆ isBackground()

bool Quotient::BaseJob::isBackground ( ) const

◆ jsonData()

QJsonObject Quotient::BaseJob::jsonData ( ) const

Get the response body as a JSON object.

If the job's returned content type is not application/json or if the top-level JSON entity is not an object, an empty object is returned.

◆ jsonItems()

QJsonArray Quotient::BaseJob::jsonItems ( ) const

Get the response body as a JSON array.

If the job's returned content type is not application/json or if the top-level JSON entity is not an array, an empty array is returned.

◆ loadFromJson()

template<typename T >
T Quotient::BaseJob::loadFromJson ( auto  keyName,
T &&  defaultValue = {} 
) const
inline

Load the property from the JSON response assuming a given C++ type.

If there's no top-level JSON object in the response or if there's no node with the key keyName, defaultValue is returned.

Definition at line 178 of file basejob.h.

◆ makePath()

template<typename... StrTs>
static QByteArray Quotient::BaseJob::makePath ( QByteArrayView  base,
StrTs &&...  parts 
)
inlinestatic

Definition at line 78 of file basejob.h.

◆ makeRequestUrl()

static QUrl Quotient::BaseJob::makeRequestUrl ( const HomeserverData hsData,
const QByteArray &  encodedPath,
const QUrlQuery &  query = {} 
)
staticprotected

Construct a URL out of baseUrl, path and query.

The function ensures exactly one '/' between the path component of baseUrl and path. The query component of baseUrl is ignored.

Note
Unlike most of BaseJob, this function is thread-safe

◆ maxRetries()

int Quotient::BaseJob::maxRetries ( ) const

◆ millisToRetry()

Q_INVOKABLE Quotient::BaseJob::duration_ms_t Quotient::BaseJob::millisToRetry ( ) const

◆ onSentRequest()

virtual void Quotient::BaseJob::onSentRequest ( QNetworkReply *  )
protectedvirtual

Postprocessing after the network request has been sent.

This method is called every time the job receives a running QNetworkReply object from NetworkAccessManager - basically, after successfully sending a network request (including retries).

◆ prepareError()

virtual Status Quotient::BaseJob::prepareError ( Status  currentStatus)
protectedvirtual

Process details of the error.

The function processes the reply in case when status from checkReply() was not good (usually because of an unsuccessful HTTP code). The base implementation assumes Matrix JSON error object in the body; overrides are strongly recommended to call it for all stock Matrix responses as early as possible and only then process custom errors, with JSON or non-JSON payload.

Returns
updated (if necessary) job status

◆ prepareResult()

virtual Status Quotient::BaseJob::prepareResult ( )
protectedvirtual

An extension point for additional reply processing.

The base implementation simply returns Success without doing anything else.

See also
gotReply

Reimplemented in Quotient::SyncJob.

◆ query()

QUrlQuery Quotient::BaseJob::query ( ) const
protected

◆ rateLimited

void Quotient::BaseJob::rateLimited ( )
signal

The job has been rate-limited.

The previous network request has been rate-limited; the next attempt will be queued and run sometime later. Since other jobs may already wait in the queue, it's not possible to predict the wait time.

◆ rawData() [1/2]

const QByteArray& Quotient::BaseJob::rawData ( ) const

Access the whole response body as received from the server.

◆ rawData() [2/2]

QByteArray Quotient::BaseJob::rawData ( int  bytesAtMost) const

Get first bytes of the raw response body as received from the server.

Parameters
bytesAtMostthe number of leftmost bytes to return
See also
rawDataSample

◆ rawDataSample()

QString Quotient::BaseJob::rawDataSample ( int  bytesAtMost = 65535) const

Get UI-friendly sample of raw data.

This is almost the same as rawData but appends the "truncated" suffix if not all data fit in bytesAtMost. This call is recommended to present a sample of raw data as "details" next to error messages. Note that the default bytesAtMost value is also tailored to UI cases.

See also
//! rawData

◆ reply() [1/2]

QNetworkReply* Quotient::BaseJob::reply ( )
protected

◆ reply() [2/2]

const QNetworkReply* Quotient::BaseJob::reply ( ) const
protected

◆ requestData()

const RequestData& Quotient::BaseJob::requestData ( ) const
protected

◆ requestHeaders()

const headers_t& Quotient::BaseJob::requestHeaders ( ) const
protected

◆ requestUrl()

QUrl Quotient::BaseJob::requestUrl ( ) const

◆ result

void Quotient::BaseJob::result ( Quotient::BaseJob job)
signal

The job has finished with a result, successful or unsuccessful.

Use error() or status().good() to know if the job has finished successfully.

Parameters
jobthe job that emitted this signal
See also
success, failure

◆ retryScheduled

void Quotient::BaseJob::retryScheduled ( int  nextAttempt,
Quotient::BaseJob::duration_ms_t  inMilliseconds 
)
signal

A retry of the network request is scheduled after the previous request failed.

Parameters
nextAttemptthe 1-based number of attempt (will always be more than 1)
inMillisecondsthe interval after which the next attempt will be taken

◆ sentRequest

void Quotient::BaseJob::sentRequest ( )
signal

The job has sent a network request.

◆ setApiEndpoint()

void Quotient::BaseJob::setApiEndpoint ( QByteArray  apiEndpoint)
protected

◆ setExpectedContentTypes()

void Quotient::BaseJob::setExpectedContentTypes ( const QByteArrayList &  contentTypes)
protected

◆ setExpectedKeys()

void Quotient::BaseJob::setExpectedKeys ( const QStringList keys)
protected

◆ setLoggingCategory()

void Quotient::BaseJob::setLoggingCategory ( QMessageLogger::CategoryFunction  lcf)
protected

Set the logging category for the given job instance.

Parameters
lcfThe logging category function to provide the category - the one you define with Q_LOGGING_CATEGORY (without parentheses, BaseJob will call it for you)

◆ setMaxRetries()

void Quotient::BaseJob::setMaxRetries ( int  newMaxRetries)

◆ setRequestData()

void Quotient::BaseJob::setRequestData ( RequestData &&  data)
protected

◆ setRequestHeader()

void Quotient::BaseJob::setRequestHeader ( const headers_t::key_type &  headerName,
const headers_t::mapped_type &  headerValue 
)
protected

◆ setRequestHeaders()

void Quotient::BaseJob::setRequestHeaders ( const headers_t headers)
protected

◆ setRequestQuery()

void Quotient::BaseJob::setRequestQuery ( const QUrlQuery &  query)
protected

◆ setStatus() [1/2]

void Quotient::BaseJob::setStatus ( int  code,
QString  message 
)
protected

◆ setStatus() [2/2]

void Quotient::BaseJob::setStatus ( Status  s)
protected

◆ status()

Status Quotient::BaseJob::status ( ) const

Current status of the job.

◆ statusCaption()

QString Quotient::BaseJob::statusCaption ( ) const

Short human-friendly message on the job status.

◆ statusChanged

void Quotient::BaseJob::statusChanged ( Quotient::BaseJob::Status  newStatus)
signal

The job has changed its status.

◆ success

void Quotient::BaseJob::success ( Quotient::BaseJob )
signal

The job has finished with a successful result.

See also
result, failure

◆ takeFromJson()

template<typename T >
T Quotient::BaseJob::takeFromJson ( auto  key,
T &&  defaultValue = {} 
)
inline

Load the property from the JSON response and delete it from JSON.

If there's no top-level JSON object in the response or if there's no node with the key keyName, defaultValue is returned.

Definition at line 189 of file basejob.h.

◆ takeValueFromJson()

QJsonValue Quotient::BaseJob::takeValueFromJson ( QAnyStringView  key)
protected

Retrieve a value for one specific key and delete it from the JSON response object.

This allows to implement deserialisation with "move" semantics for parts of the response. Assuming that the response body is a valid JSON object, the function calls QJsonObject::take(key) on it and returns the result.

Returns
QJsonValue::Undefined if the response content is not a JSON object or it doesn't have key; the value for key otherwise.
See also
takeFromJson

◆ timeout

void Quotient::BaseJob::timeout ( )
protectedslot

◆ timeToRetry()

std::chrono::milliseconds Quotient::BaseJob::timeToRetry ( ) const

◆ uploadProgress

void Quotient::BaseJob::uploadProgress ( qint64  bytesSent,
qint64  bytesTotal 
)
signal

Friends And Related Function Documentation

◆ ConnectionData

friend class ConnectionData
friend

Definition at line 431 of file basejob.h.

◆ JobHandle

template<class JobT >
friend class JobHandle
friend

Definition at line 433 of file basejob.h.

◆ operator<<

QDebug operator<< ( QDebug  dbg,
const BaseJob j 
)
friend

Definition at line 221 of file basejob.h.

Property Documentation

◆ maxRetries

int Quotient::BaseJob::maxRetries
readwrite

Definition at line 460 of file basejob.h.

◆ requestUrl

QUrl Quotient::BaseJob::requestUrl
read

Definition at line 460 of file basejob.h.

◆ statusCode

int Quotient::BaseJob::statusCode
read

Definition at line 460 of file basejob.h.


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