| 1 | /* |
| 2 | * This file is part of OnlineAccountsDaemon |
| 3 | * |
| 4 | * Copyright (C) 2015 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "async_operation.h" |
| 22 | |
| 23 | #include <QDebug> |
| 24 | #include "manager_adaptor.h" |
| 25 | |
| 26 | using namespace OnlineAccountsDaemon; |
| 27 | |
| 28 | namespace OnlineAccountsDaemon { |
| 29 | |
| 30 | class AsyncOperationPrivate |
| 31 | { |
| 32 | Q_DECLARE_PUBLIC(AsyncOperation) |
| 33 | |
| 34 | public: |
| 35 | AsyncOperationPrivate(AsyncOperation *q, const CallContext &context); |
| 36 | |
| 37 | private: |
| 38 | CallContext m_context; |
| 39 | AsyncOperation *q_ptr; |
| 40 | }; |
| 41 | |
| 42 | } // namespace |
| 43 | |
| 44 | AsyncOperationPrivate::AsyncOperationPrivate(AsyncOperation *q, |
| 45 | const CallContext &context): |
| 46 | m_context(context), |
| 47 | q_ptr(q) |
| 48 | { |
| 49 | m_context.setDelayedReply(true); |
| 50 | } |
| 51 | |
| 52 | AsyncOperation::AsyncOperation(const CallContext &context, QObject *parent): |
| 53 | QObject(parent), |
| 54 | d_ptr(new AsyncOperationPrivate(this, context)) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | AsyncOperation::~AsyncOperation() |
| 59 | { |
| 60 | delete d_ptr; |
| 61 | } |
| 62 | |
| 63 | const CallContext &AsyncOperation::context() const |
| 64 | { |
| 65 | Q_D(const AsyncOperation); |
| 66 | return d->m_context; |
| 67 | } |
| 68 | |
| 69 | void AsyncOperation::setReply(const QList<QVariant> &reply) |
| 70 | { |
| 71 | Q_D(AsyncOperation); |
| 72 | d->m_context.sendReply(reply); |
| 73 | this->deleteLater(); |
| 74 | } |
| 75 | |
| 76 | void AsyncOperation::setError(const QString &name, const QString &message) |
| 77 | { |
| 78 | Q_D(AsyncOperation); |
| 79 | d->m_context.sendError(name, message); |
| 80 | this->deleteLater(); |
| 81 | } |