aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp11
-rw-r--r--lib/connection.h20
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