1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "initobexmanagerjob.h"
10#include "debug.h"
11#include "obexmanager.h"
12#include "obexmanager_p.h"
13
14namespace BluezQt
15{
16class InitObexManagerJobPrivate : public QObject
17{
18public:
19 explicit InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager);
20
21 void doStart();
22 void initError(const QString &errorText);
23 void initFinished();
24
25 InitObexManagerJob *q;
26 ObexManager *m_manager;
27};
28
29InitObexManagerJobPrivate::InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager)
30 : QObject(q)
31 , q(q)
32 , m_manager(manager)
33{
34}
35
36void InitObexManagerJobPrivate::doStart()
37{
38 if (m_manager->d->m_initialized) {
39 qCWarning(BLUEZQT) << "InitObexManagerJob: ObexManager already initialized!";
40 q->emitResult();
41 return;
42 }
43
44 connect(sender: m_manager->d.get(), signal: &ObexManagerPrivate::initError, context: this, slot: &InitObexManagerJobPrivate::initError);
45 connect(sender: m_manager->d.get(), signal: &ObexManagerPrivate::initFinished, context: this, slot: &InitObexManagerJobPrivate::initFinished);
46
47 m_manager->d->init();
48}
49
50void InitObexManagerJobPrivate::initError(const QString &errorText)
51{
52 qCWarning(BLUEZQT) << "InitObexManagerJob Error:" << errorText;
53
54 q->setError(InitObexManagerJob::UserDefinedError);
55 q->setErrorText(errorText);
56 q->emitResult();
57}
58
59void InitObexManagerJobPrivate::initFinished()
60{
61 q->emitResult();
62}
63
64InitObexManagerJob::InitObexManagerJob(ObexManager *manager)
65 : Job(manager)
66 , d(new InitObexManagerJobPrivate(this, manager))
67{
68}
69
70InitObexManagerJob::~InitObexManagerJob()
71{
72 if (isRunning()) {
73 qCWarning(BLUEZQT) << "InitObexManagerJob Error: Job was deleted before finished!";
74
75 setError(UserDefinedError);
76 setErrorText(QStringLiteral("Job was deleted before finished."));
77 emitResult();
78 }
79}
80
81ObexManager *InitObexManagerJob::manager() const
82{
83 return d->m_manager;
84}
85
86void InitObexManagerJob::doStart()
87{
88 d->doStart();
89}
90
91void InitObexManagerJob::doEmitResult()
92{
93 Q_EMIT result(job: this);
94}
95
96} // namespace BluezQt
97
98#include "moc_initobexmanagerjob.cpp"
99

source code of bluez-qt/src/initobexmanagerjob.cpp