diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-20 18:10:46 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-20 18:10:46 +0900 |
commit | 92614294a89c1f450b82c2b6e35614cf124dc344 (patch) | |
tree | e7dc69dc683e6139d7a15fa383d1948ff2332c85 /lib | |
parent | 8629748c5c609882486d25d989becfe0ae2352ed (diff) | |
download | libquotient-92614294a89c1f450b82c2b6e35614cf124dc344.tar.gz libquotient-92614294a89c1f450b82c2b6e35614cf124dc344.zip |
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).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 11 | ||||
-rw-r--r-- | lib/connection.h | 20 |
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index c9623729..5f90ed55 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -780,7 +780,7 @@ ForgetRoomJob* Connection::forgetRoom(const QString& id) [this, leaveJob, forgetJob, room] { if (leaveJob->error() == BaseJob::Success || leaveJob->error() == BaseJob::NotFoundError) { - forgetJob->start(connectionData()); + run(forgetJob); // If the matching /sync response hasn't arrived yet, // mark the room for explicit deletion if (room->joinState() != JoinState::Leave) @@ -794,7 +794,7 @@ ForgetRoomJob* Connection::forgetRoom(const QString& id) }); connect(leaveJob, &BaseJob::failure, forgetJob, &BaseJob::abandon); } else - forgetJob->start(connectionData()); + run(forgetJob); connect(forgetJob, &BaseJob::result, this, [this, id, forgetJob] { // Leave room in case of success, or room not known by server if (forgetJob->error() == BaseJob::Success @@ -1355,6 +1355,13 @@ void Connection::setLazyLoading(bool newValue) } } +void Connection::run(BaseJob* job, RunningPolicy runningPolicy) const +{ + connect(job, &BaseJob::failure, this, &Connection::requestFailed); + job->start(d->data.get(), runningPolicy & BackgroundRequest); + d->data->submit(job); +} + void Connection::getTurnServers() { auto job = callApi<GetTurnServerJob>(); 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<JobArgTs>(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 <typename JobT, typename... JobArgTs> JobT* callApi(JobArgTs&&... jobArgs) const |