BluezQt

initmanagerjob.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2014 David Rosca <[email protected]>
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_p.h"
12 
13 namespace BluezQt
14 {
15 class InitManagerJobPrivate : public QObject
16 {
17 public:
18  explicit InitManagerJobPrivate(InitManagerJob *q, Manager *manager);
19 
20  void doStart();
21  void initError(const QString &errorText);
22  void initFinished();
23 
24  InitManagerJob *q;
25  Manager *m_manager;
26 };
27 
28 InitManagerJobPrivate::InitManagerJobPrivate(InitManagerJob *q, Manager *manager)
29  : QObject(q)
30  , q(q)
31  , m_manager(manager)
32 {
33 }
34 
35 void InitManagerJobPrivate::doStart()
36 {
37  if (m_manager->d->m_initialized) {
38  qCWarning(BLUEZQT) << "InitManagerJob: Manager already initialized!";
39  q->emitResult();
40  return;
41  }
42 
43  m_manager->d->init();
44  connect(m_manager->d, &ManagerPrivate::initError, this, &InitManagerJobPrivate::initError);
45  connect(m_manager->d, &ManagerPrivate::initFinished, this, &InitManagerJobPrivate::initFinished);
46 }
47 
48 void InitManagerJobPrivate::initError(const QString &errorText)
49 {
50  qCWarning(BLUEZQT) << "GetManagerJob Error:" << errorText;
51 
53  q->setErrorText(errorText);
54  q->emitResult();
55 }
56 
57 void InitManagerJobPrivate::initFinished()
58 {
59  q->emitResult();
60 }
61 
62 InitManagerJob::InitManagerJob(Manager *manager)
63  : Job(manager)
64  , d(new InitManagerJobPrivate(this, manager))
65 {
66 }
67 
69 {
70  if (isRunning()) {
71  qCWarning(BLUEZQT) << "InitManagerJob Error: Job was deleted before finished!";
72 
74  setErrorText(QStringLiteral("Job was deleted before finished."));
75  emitResult();
76  }
77  delete d;
78 }
79 
80 Manager *InitManagerJob::manager() const
81 {
82  return d->m_manager;
83 }
84 
85 void InitManagerJob::doStart()
86 {
87  d->doStart();
88 }
89 
90 void InitManagerJob::doEmitResult()
91 {
92  Q_EMIT result(this);
93 }
94 
95 } // namespace BluezQt
bool isRunning() const
Returns whether the job is currently running.
Definition: job.cpp:83
void result(InitManagerJob *job)
Indicates that the job have finished.
void setErrorText(const QString &errorText)
Sets the error text.
Definition: job.cpp:98
Q_EMITQ_EMIT
~InitManagerJob() override
Destroys an InitManagerJob object.
@ UserDefinedError
Subclasses should define error codes starting at this value.
Definition: job.h:74
void setError(int errorCode)
Sets the error code.
Definition: job.cpp:93
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: job.cpp:55
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:19:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.