qdbuserror.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtDBus module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qdbuserror.h" -
43 -
44#include <qdebug.h> -
45#include <qvarlengtharray.h> -
46 -
47#ifndef QT_BOOTSTRAPPED -
48#include "qdbus_symbols_p.h" -
49#include "qdbusmessage.h" -
50#include "qdbusmessage_p.h" -
51#endif -
52 -
53#ifndef QT_NO_DBUS -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57/* -
58 * Use the following Perl script to generate the error string index list: -
59===== PERL SCRIPT ==== -
60print "static const char errorMessages_string[] =\n"; -
61$counter = 0; -
62$i = 0; -
63while (<STDIN>) { -
64 chomp; -
65 print " \"$_\\0\"\n"; -
66 $sizes[$i++] = $counter; -
67 $counter += 1 + length $_; -
68} -
69print " \"\\0\";\n\nstatic const int errorMessages_indices[] = {\n "; -
70for ($j = 0; $j < $i; ++$j) { -
71 printf "$sizes[$j], "; -
72} -
73print "0\n};\n"; -
74===== PERL SCRIPT ==== -
75 -
76 * The input data is as follows: -
77other -
78org.freedesktop.DBus.Error.Failed -
79org.freedesktop.DBus.Error.NoMemory -
80org.freedesktop.DBus.Error.ServiceUnknown -
81org.freedesktop.DBus.Error.NoReply -
82org.freedesktop.DBus.Error.BadAddress -
83org.freedesktop.DBus.Error.NotSupported -
84org.freedesktop.DBus.Error.LimitsExceeded -
85org.freedesktop.DBus.Error.AccessDenied -
86org.freedesktop.DBus.Error.NoServer -
87org.freedesktop.DBus.Error.Timeout -
88org.freedesktop.DBus.Error.NoNetwork -
89org.freedesktop.DBus.Error.AddressInUse -
90org.freedesktop.DBus.Error.Disconnected -
91org.freedesktop.DBus.Error.InvalidArgs -
92org.freedesktop.DBus.Error.UnknownMethod -
93org.freedesktop.DBus.Error.TimedOut -
94org.freedesktop.DBus.Error.InvalidSignature -
95org.freedesktop.DBus.Error.UnknownInterface -
96org.freedesktop.DBus.Error.UnknownObject -
97org.freedesktop.DBus.Error.UnknownProperty -
98org.freedesktop.DBus.Error.PropertyReadOnly -
99org.qtproject.QtDBus.Error.InternalError -
100org.qtproject.QtDBus.Error.InvalidService -
101org.qtproject.QtDBus.Error.InvalidObjectPath -
102org.qtproject.QtDBus.Error.InvalidInterface -
103org.qtproject.QtDBus.Error.InvalidMember -
104*/ -
105 -
106// in the same order as KnownErrors! -
107static const char errorMessages_string[] = -
108 "other\0" -
109 "org.freedesktop.DBus.Error.Failed\0" -
110 "org.freedesktop.DBus.Error.NoMemory\0" -
111 "org.freedesktop.DBus.Error.ServiceUnknown\0" -
112 "org.freedesktop.DBus.Error.NoReply\0" -
113 "org.freedesktop.DBus.Error.BadAddress\0" -
114 "org.freedesktop.DBus.Error.NotSupported\0" -
115 "org.freedesktop.DBus.Error.LimitsExceeded\0" -
116 "org.freedesktop.DBus.Error.AccessDenied\0" -
117 "org.freedesktop.DBus.Error.NoServer\0" -
118 "org.freedesktop.DBus.Error.Timeout\0" -
119 "org.freedesktop.DBus.Error.NoNetwork\0" -
120 "org.freedesktop.DBus.Error.AddressInUse\0" -
121 "org.freedesktop.DBus.Error.Disconnected\0" -
122 "org.freedesktop.DBus.Error.InvalidArgs\0" -
123 "org.freedesktop.DBus.Error.UnknownMethod\0" -
124 "org.freedesktop.DBus.Error.TimedOut\0" -
125 "org.freedesktop.DBus.Error.InvalidSignature\0" -
126 "org.freedesktop.DBus.Error.UnknownInterface\0" -
127 "org.freedesktop.DBus.Error.UnknownObject\0" -
128 "org.freedesktop.DBus.Error.UnknownProperty\0" -
129 "org.freedesktop.DBus.Error.PropertyReadOnly\0" -
130 "org.qtproject.QtDBus.Error.InternalError\0" -
131 "org.qtproject.QtDBus.Error.InvalidService\0" -
132 "org.qtproject.QtDBus.Error.InvalidObjectPath\0" -
133 "org.qtproject.QtDBus.Error.InvalidInterface\0" -
134 "org.qtproject.QtDBus.Error.InvalidMember\0" -
135 "\0"; -
136 -
137static const int errorMessages_indices[] = { -
138 0, 6, 40, 76, 118, 153, 191, 231, -
139 273, 313, 349, 384, 421, 461, 501, 540, -
140 581, 617, 661, 705, 746, 789, 833, 874, -
141 916, 961, 1005, -1 -
142}; -
143 -
144static const int errorMessages_count = sizeof errorMessages_indices / -
145 sizeof errorMessages_indices[0] - 1; -
146 -
147static inline const char *get(QDBusError::ErrorType code) -
148{ -
149 int intcode = qBound(0, int(code) - int(QDBusError::Other), errorMessages_count);
executed (the execution status of this line is deduced): int intcode = qBound(0, int(code) - int(QDBusError::Other), errorMessages_count);
-
150 return errorMessages_string + errorMessages_indices[intcode];
executed: return errorMessages_string + errorMessages_indices[intcode];
Execution Count:219
219
151} -
152 -
153static inline QDBusError::ErrorType get(const char *name) -
154{ -
155 if (!name || !*name)
partially evaluated: !name
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:339
partially evaluated: !*name
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:339
0-339
156 return QDBusError::NoError;
never executed: return QDBusError::NoError;
0
157 for (int i = 0; i < errorMessages_count; ++i)
evaluated: i < errorMessages_count
TRUEFALSE
yes
Evaluation Count:6265
yes
Evaluation Count:15
15-6265
158 if (strcmp(name, errorMessages_string + errorMessages_indices[i]) == 0)
evaluated: strcmp(name, errorMessages_string + errorMessages_indices[i]) == 0
TRUEFALSE
yes
Evaluation Count:324
yes
Evaluation Count:5941
324-5941
159 return QDBusError::ErrorType(i + int(QDBusError::Other));
executed: return QDBusError::ErrorType(i + int(QDBusError::Other));
Execution Count:324
324
160 return QDBusError::Other;
executed: return QDBusError::Other;
Execution Count:15
15
161} -
162 -
163/*! -
164 \class QDBusError -
165 \inmodule QtDBus -
166 \since 4.2 -
167 -
168 \brief The QDBusError class represents an error received from the -
169 D-Bus bus or from remote applications found in the bus. -
170 -
171 When dealing with the D-Bus bus service or with remote -
172 applications over D-Bus, a number of error conditions can -
173 happen. This error conditions are sometimes signalled by a -
174 returned error value or by a QDBusError. -
175 -
176 C++ and Java exceptions are a valid analogy for D-Bus errors: -
177 instead of returning normally with a return value, remote -
178 applications and the bus may decide to throw an error -
179 condition. However, the Qt D-Bus implementation does not use the C++ -
180 exception-throwing mechanism, so you will receive QDBusErrors in -
181 the return reply (see QDBusReply::error()). -
182 -
183 QDBusError objects are used to inspect the error name and message -
184 as received from the bus and remote applications. You should not -
185 create such objects yourself to signal error conditions when -
186 called from D-Bus: instead, use QDBusMessage::createError() and -
187 QDBusConnection::send(). -
188 -
189 \sa QDBusConnection::send(), QDBusMessage, QDBusReply -
190*/ -
191 -
192/*! -
193 \enum QDBusError::ErrorType -
194 -
195 In order to facilitate verification of the most common D-Bus errors generated by the D-Bus -
196 implementation and by the bus daemon itself, QDBusError can be compared to a set of pre-defined -
197 values: -
198 -
199 \value NoError QDBusError is invalid (i.e., the call succeeded) -
200 \value Other QDBusError contains an error that is one of the well-known ones -
201 \value Failed The call failed (\c org.freedesktop.DBus.Error.Failed) -
202 \value NoMemory Out of memory (\c org.freedesktop.DBus.Error.NoMemory) -
203 \value ServiceUnknown The called service is not known -
204 (\c org.freedesktop.DBus.Error.ServiceUnknown) -
205 \value NoReply The called method did not reply within the specified timeout -
206 (\c org.freedesktop.DBus.Error.NoReply) -
207 \value BadAddress The address given is not valid -
208 (\c org.freedesktop.DBus.Error.BadAddress) -
209 \value NotSupported The call/operation is not supported -
210 (\c org.freedesktop.DBus.Error.NotSupported) -
211 \value LimitsExceeded The limits allocated to this process/call/connection exceeded the -
212 pre-defined values (\c org.freedesktop.DBus.Error.LimitsExceeded) -
213 \value AccessDenied The call/operation tried to access a resource it isn't allowed to -
214 (\c org.freedesktop.DBus.Error.AccessDenied) -
215 \value NoServer \e {Documentation doesn't say what this is for} -
216 (\c org.freedesktop.DBus.Error.NoServer) -
217 \value Timeout \e {Documentation doesn't say what this is for or how it's used} -
218 (\c org.freedesktop.DBus.Error.Timeout) -
219 \value NoNetwork \e {Documentation doesn't say what this is for} -
220 (\c org.freedesktop.DBus.Error.NoNetwork) -
221 \value AddressInUse QDBusServer tried to bind to an address that is already in use -
222 (\c org.freedesktop.DBus.Error.AddressInUse) -
223 \value Disconnected The call/process/message was sent after QDBusConnection disconnected -
224 (\c org.freedesktop.DBus.Error.Disconnected) -
225 \value InvalidArgs The arguments passed to this call/operation are not valid -
226 (\c org.freedesktop.DBus.Error.InvalidArgs) -
227 \value UnknownMethod The method called was not found in this object/interface with the -
228 given parameters (\c org.freedesktop.DBus.Error.UnknownMethod) -
229 \value TimedOut \e {Documentation doesn't say...} -
230 (\c org.freedesktop.DBus.Error.TimedOut) -
231 \value InvalidSignature The type signature is not valid or compatible -
232 (\c org.freedesktop.DBus.Error.InvalidSignature) -
233 \value UnknownInterface The interface is not known in this object -
234 (\c org.freedesktop.DBus.Error.UnknownInterface) -
235 \value UnknownObject The object path points to an object that does not exist -
236 (\c org.freedesktop.DBus.Error.UnknownObject) -
237 \value UnknownProperty The property does not exist in this interface -
238 (\c org.freedesktop.DBus.Error.UnknownProperty) -
239 \value PropertyReadOnly The property set failed because the property is read-only -
240 (\c org.freedesktop.DBus.Error.PropertyReadOnly) -
241 -
242 \value InternalError An internal error occurred -
243 -
244 \value InvalidObjectPath The object path provided is invalid. -
245 -
246 \value InvalidService The service requested is invalid. -
247 -
248 \value InvalidMember The member is invalid. -
249 -
250 \value InvalidInterface The interface is invalid. -
251*/ -
252 -
253/*! -
254 \internal -
255 Constructs a QDBusError that represents no error. -
256*/ -
257QDBusError::QDBusError() -
258 : code(NoError) -
259{ -
260 -
261}
executed: }
Execution Count:3472
3472
262 -
263#ifndef QT_BOOTSTRAPPED -
264/*! -
265 \internal -
266 Constructs a QDBusError from a DBusError structure. -
267*/ -
268QDBusError::QDBusError(const DBusError *error) -
269 : code(NoError) -
270{ -
271 if (!error || !q_dbus_error_is_set(error))
partially evaluated: !error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
partially evaluated: !q_dbus_error_is_set(error)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
272 return;
never executed: return;
0
273 -
274 code = ::get(error->name);
executed (the execution status of this line is deduced): code = ::get(error->name);
-
275 msg = QString::fromUtf8(error->message);
executed (the execution status of this line is deduced): msg = QString::fromUtf8(error->message);
-
276 nm = QString::fromUtf8(error->name);
executed (the execution status of this line is deduced): nm = QString::fromUtf8(error->name);
-
277}
executed: }
Execution Count:17
17
278 -
279/*! -
280 \internal -
281 Constructs a QDBusError from a QDBusMessage. -
282*/ -
283QDBusError::QDBusError(const QDBusMessage &qdmsg) -
284 : code(NoError) -
285{ -
286 if (qdmsg.type() != QDBusMessage::ErrorMessage)
evaluated: qdmsg.type() != QDBusMessage::ErrorMessage
TRUEFALSE
yes
Evaluation Count:1882
yes
Evaluation Count:322
322-1882
287 return;
executed: return;
Execution Count:1882
1882
288 -
289 code = ::get(qdmsg.errorName().toUtf8().constData());
executed (the execution status of this line is deduced): code = ::get(qdmsg.errorName().toUtf8().constData());
-
290 nm = qdmsg.errorName();
executed (the execution status of this line is deduced): nm = qdmsg.errorName();
-
291 msg = qdmsg.errorMessage();
executed (the execution status of this line is deduced): msg = qdmsg.errorMessage();
-
292}
executed: }
Execution Count:322
322
293#endif -
294 -
295/*! -
296 \internal -
297 Constructs a QDBusError from a well-known error code -
298*/ -
299QDBusError::QDBusError(ErrorType error, const QString &mess) -
300 : code(error) -
301{ -
302 nm = QLatin1String(::get(error));
executed (the execution status of this line is deduced): nm = QLatin1String(::get(error));
-
303 msg = mess;
executed (the execution status of this line is deduced): msg = mess;
-
304}
executed: }
Execution Count:104
104
305 -
306/*! -
307 \internal -
308 Constructs a QDBusError from another QDBusError object -
309*/ -
310QDBusError::QDBusError(const QDBusError &other) -
311 : code(other.code), msg(other.msg), nm(other.nm) -
312{ -
313}
executed: }
Execution Count:92
92
314 -
315/*! -
316 \internal -
317 Assignment operator -
318*/ -
319 -
320QDBusError &QDBusError::operator=(const QDBusError &other) -
321{ -
322 code = other.code;
executed (the execution status of this line is deduced): code = other.code;
-
323 msg = other.msg;
executed (the execution status of this line is deduced): msg = other.msg;
-
324 nm = other.nm;
executed (the execution status of this line is deduced): nm = other.nm;
-
325 return *this;
executed: return *this;
Execution Count:2406
2406
326} -
327 -
328#ifndef QT_BOOTSTRAPPED -
329/*! -
330 \internal -
331 Assignment operator from a QDBusMessage -
332*/ -
333QDBusError &QDBusError::operator=(const QDBusMessage &qdmsg) -
334{ -
335 if (qdmsg.type() == QDBusMessage::ErrorMessage) {
never evaluated: qdmsg.type() == QDBusMessage::ErrorMessage
0
336 code = ::get(qdmsg.errorName().toUtf8().constData());
never executed (the execution status of this line is deduced): code = ::get(qdmsg.errorName().toUtf8().constData());
-
337 nm = qdmsg.errorName();
never executed (the execution status of this line is deduced): nm = qdmsg.errorName();
-
338 msg = qdmsg.errorMessage();
never executed (the execution status of this line is deduced): msg = qdmsg.errorMessage();
-
339 } else {
never executed: }
0
340 code =NoError;
never executed (the execution status of this line is deduced): code =NoError;
-
341 nm.clear();
never executed (the execution status of this line is deduced): nm.clear();
-
342 msg.clear();
never executed (the execution status of this line is deduced): msg.clear();
-
343 }
never executed: }
0
344 return *this;
never executed: return *this;
0
345} -
346#endif -
347 -
348/*! -
349 Returns this error's ErrorType. -
350 -
351 \sa ErrorType -
352*/ -
353 -
354QDBusError::ErrorType QDBusError::type() const -
355{ -
356 return code;
executed: return code;
Execution Count:30
30
357} -
358 -
359/*! -
360 Returns this error's name. Error names are similar to D-Bus Interface names, like -
361 \c org.freedesktop.DBus.InvalidArgs. -
362 -
363 \sa type() -
364*/ -
365 -
366QString QDBusError::name() const -
367{ -
368 return nm;
executed: return nm;
Execution Count:117
117
369} -
370 -
371/*! -
372 Returns the message that the callee associated with this error. Error messages are -
373 implementation defined and usually contain a human-readable error code, though this does not -
374 mean it is suitable for your end-users. -
375*/ -
376 -
377QString QDBusError::message() const -
378{ -
379 return msg;
executed: return msg;
Execution Count:94
94
380} -
381 -
382/*! -
383 Returns true if this is a valid error condition (i.e., if there was an error), -
384 otherwise false. -
385*/ -
386 -
387bool QDBusError::isValid() const -
388{ -
389 return (code != NoError);
executed: return (code != NoError);
Execution Count:1281
1281
390} -
391 -
392/*! -
393 \since 4.3 -
394 Returns the error name associated with error condition \a error. -
395*/ -
396QString QDBusError::errorString(ErrorType error) -
397{ -
398 return QLatin1String(::get(error));
executed: return QLatin1String(::get(error));
Execution Count:115
115
399} -
400 -
401#ifndef QT_NO_DEBUG_STREAM -
402QDebug operator<<(QDebug dbg, const QDBusError &msg) -
403{ -
404 dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ')';
never executed (the execution status of this line is deduced): dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ')';
-
405 return dbg.space();
never executed: return dbg.space();
0
406} -
407#endif -
408 -
409QT_END_NAMESPACE -
410 -
411#endif // QT_NO_DBUS -
412 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial