BluezQt

initmanagerjob.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 "initmanagerjob.h"
10#include "debug.h"
11#include "manager.h"
12#include "manager_p.h"
13
14namespace BluezQt
15{
16class InitManagerJobPrivate : public QObject
17{
18public:
19 explicit InitManagerJobPrivate(InitManagerJob *q, Manager *manager);
20
21 void doStart();
22 void initError(const QString &errorText);
23 void initFinished();
24
25 InitManagerJob *q;
26 Manager *m_manager;
27};
28
29InitManagerJobPrivate::InitManagerJobPrivate(InitManagerJob *q, Manager *manager)
30 : QObject(q)
31 , q(q)
32 , m_manager(manager)
33{
34}
35
36void InitManagerJobPrivate::doStart()
37{
38 if (m_manager->d->m_initialized) {
39 qCWarning(BLUEZQT) << "InitManagerJob: Manager already initialized!";
40 q->emitResult();
41 return;
42 }
43
44 m_manager->d->init();
45 connect(m_manager->d.get(), &ManagerPrivate::initError, this, &InitManagerJobPrivate::initError);
46 connect(m_manager->d.get(), &ManagerPrivate::initFinished, this, &InitManagerJobPrivate::initFinished);
47}
48
49void InitManagerJobPrivate::initError(const QString &errorText)
50{
51 qCWarning(BLUEZQT) << "GetManagerJob Error:" << errorText;
52
53 q->setError(InitManagerJob::UserDefinedError);
54 q->setErrorText(errorText);
55 q->emitResult();
56}
57
58void InitManagerJobPrivate::initFinished()
59{
60 q->emitResult();
61}
62
63InitManagerJob::InitManagerJob(Manager *manager)
64 : Job(manager)
65 , d(new InitManagerJobPrivate(this, manager))
66{
67}
68
69InitManagerJob::~InitManagerJob()
70{
71 if (isRunning()) {
72 qCWarning(BLUEZQT) << "InitManagerJob Error: Job was deleted before finished!";
73
74 setError(UserDefinedError);
75 setErrorText(QStringLiteral("Job was deleted before finished."));
76 emitResult();
77 }
78}
79
80Manager *InitManagerJob::manager() const
81{
82 return d->m_manager;
83}
84
85void InitManagerJob::doStart()
86{
87 d->doStart();
88}
89
90void InitManagerJob::doEmitResult()
91{
92 Q_EMIT result(this);
93}
94
95} // namespace BluezQt
96
97#include "moc_initmanagerjob.cpp"
Bluetooth manager.
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 Sat Dec 21 2024 16:59:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.