File indexing completed on 2024-12-08 12:15:34

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "initobexmanagerjob.h"
0010 #include "debug.h"
0011 #include "obexmanager.h"
0012 #include "obexmanager_p.h"
0013 
0014 namespace BluezQt
0015 {
0016 class InitObexManagerJobPrivate : public QObject
0017 {
0018 public:
0019     explicit InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager);
0020 
0021     void doStart();
0022     void initError(const QString &errorText);
0023     void initFinished();
0024 
0025     InitObexManagerJob *q;
0026     ObexManager *m_manager;
0027 };
0028 
0029 InitObexManagerJobPrivate::InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager)
0030     : QObject(q)
0031     , q(q)
0032     , m_manager(manager)
0033 {
0034 }
0035 
0036 void InitObexManagerJobPrivate::doStart()
0037 {
0038     if (m_manager->d->m_initialized) {
0039         qCWarning(BLUEZQT) << "InitObexManagerJob: ObexManager already initialized!";
0040         q->emitResult();
0041         return;
0042     }
0043 
0044     connect(m_manager->d, &ObexManagerPrivate::initError, this, &InitObexManagerJobPrivate::initError);
0045     connect(m_manager->d, &ObexManagerPrivate::initFinished, this, &InitObexManagerJobPrivate::initFinished);
0046 
0047     m_manager->d->init();
0048 }
0049 
0050 void InitObexManagerJobPrivate::initError(const QString &errorText)
0051 {
0052     qCWarning(BLUEZQT) << "InitObexManagerJob Error:" << errorText;
0053 
0054     q->setError(InitObexManagerJob::UserDefinedError);
0055     q->setErrorText(errorText);
0056     q->emitResult();
0057 }
0058 
0059 void InitObexManagerJobPrivate::initFinished()
0060 {
0061     q->emitResult();
0062 }
0063 
0064 InitObexManagerJob::InitObexManagerJob(ObexManager *manager)
0065     : Job(manager)
0066     , d(new InitObexManagerJobPrivate(this, manager))
0067 {
0068 }
0069 
0070 InitObexManagerJob::~InitObexManagerJob()
0071 {
0072     if (isRunning()) {
0073         qCWarning(BLUEZQT) << "InitObexManagerJob Error: Job was deleted before finished!";
0074 
0075         setError(UserDefinedError);
0076         setErrorText(QStringLiteral("Job was deleted before finished."));
0077         emitResult();
0078     }
0079     delete d;
0080 }
0081 
0082 ObexManager *InitObexManagerJob::manager() const
0083 {
0084     return d->m_manager;
0085 }
0086 
0087 void InitObexManagerJob::doStart()
0088 {
0089     d->doStart();
0090 }
0091 
0092 void InitObexManagerJob::doEmitResult()
0093 {
0094     Q_EMIT result(this);
0095 }
0096 
0097 } // namespace BluezQt
0098 
0099 #include "moc_initobexmanagerjob.cpp"