GCC Code Coverage Report


Directory: ./
File: lib/getconfigoperation.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 18 46 39.1%
Branches: 2 16 12.5%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2014 Daniel Vratil <dvratil@redhat.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19 #include "getconfigoperation.h"
20 #include "backendinterface.h"
21 #include "backendmanager_p.h"
22 #include "config.h"
23 #include "configoperation_p.h"
24 #include "configserializer_p.h"
25 #include "log.h"
26 #include "output.h"
27
28 using namespace Disman;
29
30 namespace Disman
31 {
32
33 class GetConfigOperationPrivate : public ConfigOperationPrivate
34 {
35 Q_OBJECT
36
37 public:
38 GetConfigOperationPrivate(GetConfigOperation* qq);
39
40 void backend_ready(org::kwinft::disman::backend* backend) override;
41 void onConfigReceived(QDBusPendingCallWatcher* watcher);
42
43 public:
44 ConfigPtr config;
45
46 // For out-of-process
47 QPointer<org::kwinft::disman::backend> mBackend;
48
49 private:
50 Q_DECLARE_PUBLIC(GetConfigOperation)
51 };
52
53 }
54
55 61 GetConfigOperationPrivate::GetConfigOperationPrivate(GetConfigOperation* qq)
56 61 : ConfigOperationPrivate(qq)
57 {
58 61 }
59
60 void GetConfigOperationPrivate::backend_ready(org::kwinft::disman::backend* backend)
61 {
62 Q_ASSERT(BackendManager::instance()->method() == BackendManager::OutOfProcess);
63 ConfigOperationPrivate::backend_ready(backend);
64
65 Q_Q(GetConfigOperation);
66
67 if (!backend) {
68 q->set_error(tr("Failed to prepare backend"));
69 q->emit_result();
70 return;
71 }
72
73 mBackend = backend;
74 QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(mBackend->getConfig(), this);
75 connect(watcher,
76 &QDBusPendingCallWatcher::finished,
77 this,
78 &GetConfigOperationPrivate::onConfigReceived);
79 }
80
81 void GetConfigOperationPrivate::onConfigReceived(QDBusPendingCallWatcher* watcher)
82 {
83 Q_ASSERT(BackendManager::instance()->method() == BackendManager::OutOfProcess);
84 Q_Q(GetConfigOperation);
85
86 QDBusPendingReply<QVariantMap> reply = *watcher;
87 watcher->deleteLater();
88 if (reply.isError()) {
89 q->set_error(reply.error().message());
90 q->emit_result();
91 return;
92 }
93
94 config = ConfigSerializer::deserialize_config(reply.value());
95 if (!config) {
96 q->set_error(tr("Failed to deserialize backend response"));
97 }
98
99 q->emit_result();
100 }
101
102 61 GetConfigOperation::GetConfigOperation(QObject* parent)
103 61 : ConfigOperation(new GetConfigOperationPrivate(this), parent)
104 {
105 61 }
106
107 244 GetConfigOperation::~GetConfigOperation()
108 {
109 244 }
110
111 61 Disman::ConfigPtr GetConfigOperation::config() const
112 {
113 61 Q_D(const GetConfigOperation);
114 61 return d->config;
115 }
116
117 61 void GetConfigOperation::start()
118 {
119 61 Q_D(GetConfigOperation);
120
1/2
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
61 if (BackendManager::instance()->method() == BackendManager::InProcess) {
121 61 auto backend = d->loadBackend();
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
61 if (!backend) {
123 return; // loadBackend() already set error and called emit_result() for us
124 }
125 61 d->config = backend->config()->clone();
126 61 emit_result();
127 } else {
128 d->request_backend();
129 }
130 }
131
132 #include "getconfigoperation.moc"
133