source: trunk/src/dbus/qdbuserror.cpp@ 628

Last change on this file since 628 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 12.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtDBus module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qdbuserror.h"
43
44#include <qdebug.h>
45#include <qvarlengtharray.h>
46
47#include "qdbus_symbols_p.h"
48#include "qdbusmessage.h"
49#include "qdbusmessage_p.h"
50
51QT_BEGIN_NAMESPACE
52
53/*
54 * Use the following Perl script to generate the error string index list:
55===== PERL SCRIPT ====
56print "static const char errorMessages_string[] =\n";
57$counter = 0;
58$i = 0;
59while (<STDIN>) {
60 chomp;
61 print " \"$_\\0\"\n";
62 $sizes[$i++] = $counter;
63 $counter += 1 + length $_;
64}
65print " \"\\0\";\n\nstatic const int errorMessages_indices[] = {\n ";
66for ($j = 0; $j < $i; ++$j) {
67 printf "$sizes[$j], ";
68}
69print "0\n};\n";
70===== PERL SCRIPT ====
71
72 * The input data is as follows:
73other
74org.freedesktop.DBus.Error.Failed
75org.freedesktop.DBus.Error.NoMemory
76org.freedesktop.DBus.Error.ServiceUnknown
77org.freedesktop.DBus.Error.NoReply
78org.freedesktop.DBus.Error.BadAddress
79org.freedesktop.DBus.Error.NotSupported
80org.freedesktop.DBus.Error.LimitsExceeded
81org.freedesktop.DBus.Error.AccessDenied
82org.freedesktop.DBus.Error.NoServer
83org.freedesktop.DBus.Error.Timeout
84org.freedesktop.DBus.Error.NoNetwork
85org.freedesktop.DBus.Error.AddressInUse
86org.freedesktop.DBus.Error.Disconnected
87org.freedesktop.DBus.Error.InvalidArgs
88org.freedesktop.DBus.Error.UnknownMethod
89org.freedesktop.DBus.Error.TimedOut
90org.freedesktop.DBus.Error.InvalidSignature
91org.freedesktop.DBus.Error.UnknownInterface
92com.trolltech.QtDBus.Error.InternalError
93org.freedesktop.DBus.Error.UnknownObject
94com.trolltech.QtDBus.Error.InvalidService
95com.trolltech.QtDBus.Error.InvalidObjectPath
96com.trolltech.QtDBus.Error.InvalidInterface
97com.trolltech.QtDBus.Error.InvalidMember
98*/
99
100// in the same order as KnownErrors!
101static const char errorMessages_string[] =
102 "other\0"
103 "org.freedesktop.DBus.Error.Failed\0"
104 "org.freedesktop.DBus.Error.NoMemory\0"
105 "org.freedesktop.DBus.Error.ServiceUnknown\0"
106 "org.freedesktop.DBus.Error.NoReply\0"
107 "org.freedesktop.DBus.Error.BadAddress\0"
108 "org.freedesktop.DBus.Error.NotSupported\0"
109 "org.freedesktop.DBus.Error.LimitsExceeded\0"
110 "org.freedesktop.DBus.Error.AccessDenied\0"
111 "org.freedesktop.DBus.Error.NoServer\0"
112 "org.freedesktop.DBus.Error.Timeout\0"
113 "org.freedesktop.DBus.Error.NoNetwork\0"
114 "org.freedesktop.DBus.Error.AddressInUse\0"
115 "org.freedesktop.DBus.Error.Disconnected\0"
116 "org.freedesktop.DBus.Error.InvalidArgs\0"
117 "org.freedesktop.DBus.Error.UnknownMethod\0"
118 "org.freedesktop.DBus.Error.TimedOut\0"
119 "org.freedesktop.DBus.Error.InvalidSignature\0"
120 "org.freedesktop.DBus.Error.UnknownInterface\0"
121 "com.trolltech.QtDBus.Error.InternalError\0"
122 "org.freedesktop.DBus.Error.UnknownObject\0"
123 "com.trolltech.QtDBus.Error.InvalidService\0"
124 "com.trolltech.QtDBus.Error.InvalidObjectPath\0"
125 "com.trolltech.QtDBus.Error.InvalidInterface\0"
126 "com.trolltech.QtDBus.Error.InvalidMember\0"
127 "\0";
128
129static const int errorMessages_indices[] = {
130 0, 6, 40, 76, 118, 153, 191, 231,
131 273, 313, 349, 384, 421, 461, 501, 540,
132 581, 617, 661, 705, 746, 787, 829, 874,
133 918, 0
134};
135
136static const int errorMessages_count = sizeof errorMessages_indices /
137 sizeof errorMessages_indices[0];
138
139static inline const char *get(QDBusError::ErrorType code)
140{
141 int intcode = qBound(0, int(code) - int(QDBusError::Other), errorMessages_count);
142 return errorMessages_string + errorMessages_indices[intcode];
143}
144
145static inline QDBusError::ErrorType get(const char *name)
146{
147 if (!name || !*name)
148 return QDBusError::NoError;
149 for (int i = 0; i < errorMessages_count; ++i)
150 if (strcmp(name, errorMessages_string + errorMessages_indices[i]) == 0)
151 return QDBusError::ErrorType(i + int(QDBusError::Other));
152 return QDBusError::Other;
153}
154
155/*!
156 \class QDBusError
157 \inmodule QtDBus
158 \since 4.2
159
160 \brief The QDBusError class represents an error received from the
161 D-Bus bus or from remote applications found in the bus.
162
163 When dealing with the D-Bus bus service or with remote
164 applications over D-Bus, a number of error conditions can
165 happen. This error conditions are sometimes signalled by a
166 returned error value or by a QDBusError.
167
168 C++ and Java exceptions are a valid analogy for D-Bus errors:
169 instead of returning normally with a return value, remote
170 applications and the bus may decide to throw an error
171 condition. However, the QtDBus implementation does not use the C++
172 exception-throwing mechanism, so you will receive QDBusErrors in
173 the return reply (see QDBusReply::error()).
174
175 QDBusError objects are used to inspect the error name and message
176 as received from the bus and remote applications. You should not
177 create such objects yourself to signal error conditions when
178 called from D-Bus: instead, use QDBusMessage::createError() and
179 QDBusConnection::send().
180
181 \sa QDBusConnection::send(), QDBusMessage, QDBusReply
182*/
183
184/*!
185 \enum QDBusError::ErrorType
186
187 In order to facilitate verification of the most common D-Bus errors generated by the D-Bus
188 implementation and by the bus daemon itself, QDBusError can be compared to a set of pre-defined
189 values:
190
191 \value NoError QDBusError is invalid (i.e., the call succeeded)
192 \value Other QDBusError contains an error that is one of the well-known ones
193 \value Failed The call failed (\c org.freedesktop.DBus.Error.Failed)
194 \value NoMemory Out of memory (\c org.freedesktop.DBus.Error.NoMemory)
195 \value ServiceUnknown The called service is not known
196 (\c org.freedesktop.DBus.Error.ServiceUnknown)
197 \value NoReply The called method did not reply within the specified timeout
198 (\c org.freedesktop.DBus.Error.NoReply)
199 \value BadAddress The address given is not valid
200 (\c org.freedesktop.DBus.Error.BadAddress)
201 \value NotSupported The call/operation is not supported
202 (\c org.freedesktop.DBus.Error.NotSupported)
203 \value LimitsExceeded The limits allocated to this process/call/connection exceeded the
204 pre-defined values (\c org.freedesktop.DBus.Error.LimitsExceeded)
205 \value AccessDenied The call/operation tried to access a resource it isn't allowed to
206 (\c org.freedesktop.DBus.Error.AccessDenied)
207 \value NoServer \e {Documentation doesn't say what this is for}
208 (\c org.freedesktop.DBus.Error.NoServer)
209 \value Timeout \e {Documentation doesn't say what this is for or how it's used}
210 (\c org.freedesktop.DBus.Error.Timeout)
211 \value NoNetwork \e {Documentation doesn't say what this is for}
212 (\c org.freedesktop.DBus.Error.NoNetwork)
213 \value AddressInUse QDBusServer tried to bind to an address that is already in use
214 (\c org.freedesktop.DBus.Error.AddressInUse)
215 \value Disconnected The call/process/message was sent after QDBusConnection disconnected
216 (\c org.freedesktop.DBus.Error.Disconnected)
217 \value InvalidArgs The arguments passed to this call/operation are not valid