From 92614294a89c1f450b82c2b6e35614cf124dc344 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 20 Aug 2019 18:10:46 +0900 Subject: Connection::run() Finally, clients can pre-create job objects and then separately submit them for execution on a given connection - previously such separation was a privilege of Connection (others had to use Connection::callApi<>, which invoked jobs right away). --- lib/connection.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/connection.h') diff --git a/lib/connection.h b/lib/connection.h index c807b827..7e32e5c9 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -37,6 +37,8 @@ class Account; } namespace Quotient { +Q_NAMESPACE + class Room; class User; class ConnectionData; @@ -89,10 +91,12 @@ static inline user_factory_t defaultUserFactory() /** Enumeration with flags defining the network job running policy * So far only background/foreground flags are available. * - * \sa Connection::callApi + * \sa Connection::callApi, Connection::run */ enum RunningPolicy { ForegroundRequest = 0x0, BackgroundRequest = 0x1 }; +Q_ENUM_NS(RunningPolicy) + class Connection : public QObject { Q_OBJECT @@ -352,9 +356,12 @@ public: bool lazyLoading() const; void setLazyLoading(bool newValue); - /** Start a job of a specified type with specified arguments and policy + /*! Start a pre-created job object on this connection */ + void run(BaseJob* job, RunningPolicy runningPolicy = ForegroundRequest) const; + + /*! Start a job of a specified type with specified arguments and policy * - * This is a universal method to start a job of a type passed + * This is a universal method to create and start a job of a type passed * as a template parameter. The policy allows to fine-tune the way * the job is executed - as of this writing it means a choice * between "foreground" and "background". @@ -368,14 +375,13 @@ public: JobT* callApi(RunningPolicy runningPolicy, JobArgTs&&... jobArgs) const { auto job = new JobT(std::forward(jobArgs)...); - connect(job, &BaseJob::failure, this, &Connection::requestFailed); - job->start(connectionData(), runningPolicy & BackgroundRequest); + run(job, runningPolicy); return job; } - /** Start a job of a specified type with specified arguments + /*! Start a job of a specified type with specified arguments * - * This is an overload that calls the job with "foreground" policy. + * This is an overload that runs the job with "foreground" policy. */ template JobT* callApi(JobArgTs&&... jobArgs) const -- cgit v1.2.3