BluezQt

initobexmanagerjob.cpp
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(m_manager->d.get(), &ObexManagerPrivate::initError, this, &InitObexManagerJobPrivate::initError);
45 connect(m_manager->d.get(), &ObexManagerPrivate::initFinished, this, &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(this);
94}
95
96} // namespace BluezQt
97
98#include "moc_initobexmanagerjob.cpp"
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.