9#include "pendingcall.h"
10#include "bluezqt_dbustypes.h"
12#include "obexfiletransferentry.h"
13#include "obextransfer.h"
14#include "obextransfer_p.h"
16#include <QDBusPendingCallWatcher>
22 if (
name.
startsWith(QLatin1String(
"org.freedesktop.DBus.Error"))) {
30#define FROM_BLUEZ_ERROR(string, value) \
31 if (errorName == QLatin1String(string)) { \
35 const QString &errorName =
name.
mid(16);
55#undef FROM_BLUEZ_ERROR
60class PendingCallPrivate
63 explicit PendingCallPrivate(PendingCall *parent);
65 void processReply(QDBusPendingCallWatcher *call);
66 void processVoidReply(
const QDBusPendingReply<> &reply);
67 void processUint32Reply(
const QDBusPendingReply<quint32> &reply);
68 void processStringReply(
const QDBusPendingReply<QString> &reply);
69 void processStringListReply(
const QDBusPendingReply<QStringList> &reply);
70 void processObjectPathReply(
const QDBusPendingReply<QDBusObjectPath> &reply);
71 void processFileTransferListReply(
const QDBusPendingReply<QVariantMapList> &reply);
72 void processTransferWithPropertiesReply(
const QDBusPendingReply<QDBusObjectPath, QVariantMap> &reply);
73 void processByteArrayReply(
const QDBusPendingReply<QByteArray> &reply);
74 void processError(
const QDBusError &m_error);
77 void emitInternalError(
const QString &errorText);
78 void pendingCallFinished(QDBusPendingCallWatcher *m_watcher);
85 PendingCall::ReturnType m_type;
86 QDBusPendingCallWatcher *m_watcher;
89PendingCallPrivate::PendingCallPrivate(
PendingCall *parent)
100 case PendingCall::ReturnVoid:
101 processVoidReply(*call);
104 case PendingCall::ReturnUint32:
105 processUint32Reply(*call);
108 case PendingCall::ReturnString:
109 processStringReply(*call);
112 case PendingCall::ReturnStringList:
113 processStringListReply(*call);
116 case PendingCall::ReturnObjectPath:
117 processObjectPathReply(*call);
120 case PendingCall::ReturnFileTransferList:
121 processFileTransferListReply(*call);
124 case PendingCall::ReturnTransferWithProperties:
125 processTransferWithPropertiesReply(*call);
128 case PendingCall::ReturnByteArray:
129 processByteArrayReply(*call);
139 processError(reply.
error());
144 processError(reply.
error());
146 m_value.append(reply.
value());
152 processError(reply.
error());
154 m_value.append(reply.
value());
160 processError(reply.
error());
162 m_value.append(reply.
value());
168 processError(reply.
error());
176 processError(reply.
error());
180 const auto maps = reply.
value();
181 for (
const QVariantMap &map : maps) {
182 items.
append(ObexFileTransferEntry(map));
190 processError(reply.
error());
195 ObexTransferPtr transfer = ObexTransferPtr(
new ObexTransfer(reply.
argumentAt<0>().path(), reply.
argumentAt<1>()));
196 transfer->d->q = transfer.toWeakRef();
197 transfer->d->m_suspendable =
true;
203 processError(reply.
error());
209void PendingCallPrivate::processError(
const QDBusError &error)
211 if (
error.isValid()) {
212 qCWarning(BLUEZQT) <<
"PendingCall Error:" <<
error.message();
213 m_error = nameToError(
error.name());
214 m_errorText =
error.message();
218void PendingCallPrivate::emitFinished()
220 m_watcher->deleteLater();
222 Q_EMIT q->finished(q);
226void PendingCallPrivate::emitInternalError(
const QString &errorText)
228 qCWarning(BLUEZQT) <<
"PendingCall Internal error:" << errorText;
229 m_error = PendingCall::InternalError;
230 m_errorText = errorText;
236 processReply(watcher);
242 , d(new PendingCallPrivate(this))
244 qDBusRegisterMetaType<QVariantMapList>();
250 d->pendingCallFinished(watcher);
254PendingCall::PendingCall(PendingCall::Error error,
const QString &errorText,
QObject *parent)
256 , d(new PendingCallPrivate(this))
259 d->m_errorText = errorText;
264 Q_EMIT finished(
this);
271 , d(new PendingCallPrivate(this))
273 qDBusRegisterMetaType<QVariantMapList>();
277 externalProcessor(watcher, std::bind(&PendingCallPrivate::processError, d.get(), std::placeholders::_1), &d->m_value);
282PendingCall::~PendingCall() =
default;
286 if (d->m_value.isEmpty()) {
289 return d->m_value.first();
292QVariantList PendingCall::values()
const
297int PendingCall::error()
const
304 return d->m_errorText;
307bool PendingCall::isFinished()
const
310 return d->m_watcher->isFinished();
318 d->m_watcher->waitForFinished();
324 return d->m_userData;
329 d->m_userData = userData;
334#include "moc_pendingcall.cpp"
@ DoesNotExist
Indicates that an agent, service or pairing operation does not exists.
@ AlreadyExists
Indicates that an agent or pairing record already exists.
@ NotSupported
Indicates that the action is not supported.
@ ConnectionAttemptFailed
Indicates that the connection attempt have failed.
@ NotPermitted
Indicates that the action is not permitted (e.g.
@ ConnectFailed
Indicates that the connection to the device have failed.
@ NotReady
Indicates that the device is not ready.
@ AuthenticationCanceled
Indicates that the authentication was canceled.
@ AuthenticationTimeout
Indicates that the authentication timed out.
@ InvalidLength
Indicates that the data provided generates a data packet which is too long.
@ AuthenticationRejected
Indicates that the authentication was rejected.
@ Failed
Indicates that the action have failed.
@ InvalidArguments
Indicates that invalid arguments were passed.
@ AlreadyConnected
Indicates that the device is already connected.
@ UnknownError
Indicates an unknown error.
@ DBusError
Indicates an error with D-Bus.
@ NotAuthorized
Indicates that the caller is not authorized to do the action.
@ Rejected
Indicates that the action was rejected.
@ Canceled
Indicates that the action was canceled.
@ NotConnected
Indicates that the device is not connected.
@ AuthenticationFailed
Indicates that the authentication have failed.
void setUserData(const QVariant &userData)
Sets the user data of the call.
void waitForFinished()
Waits for the call to finish.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString name(StandardAction id)
void finished(QDBusPendingCallWatcher *self)
QVariant argumentAt(int index) const const
QDBusError error() const const
bool isError() const const
typename Select< 0 >::Type value() const const
void append(QList< T > &&value)
void reserve(qsizetype size)
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)