DBus-1-TQt  1.0
tqdbuserror.cpp
Go to the documentation of this file.
1 /* qdbuserror.cpp TQT_DBusError object
2  *
3  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
4  * Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  *
23  */
24 
25 #include "tqdbuserror.h"
26 
27 #include <dbus/dbus.h>
28 
29 #include <tqmap.h>
30 
31 typedef TQMap<TQString, TQT_DBusError::ErrorType> ErrorNameMap;
33 
35 {
36  switch (type)
37  {
39  Q_ASSERT(false);
40  return TQString();
41 
43  return TQString::fromUtf8(DBUS_ERROR_FAILED);
45  return TQString::fromUtf8(DBUS_ERROR_NO_MEMORY);
47  return TQString::fromUtf8(DBUS_ERROR_SERVICE_UNKNOWN);
49  return TQString::fromUtf8(DBUS_ERROR_NAME_HAS_NO_OWNER);
51  return TQString::fromUtf8(DBUS_ERROR_NO_REPLY);
53  return TQString::fromUtf8(DBUS_ERROR_IO_ERROR);
55  return TQString::fromUtf8(DBUS_ERROR_BAD_ADDRESS);
57  return TQString::fromUtf8(DBUS_ERROR_NOT_SUPPORTED);
59  return TQString::fromUtf8(DBUS_ERROR_LIMITS_EXCEEDED);
61  return TQString::fromUtf8(DBUS_ERROR_ACCESS_DENIED);
63  return TQString::fromUtf8(DBUS_ERROR_AUTH_FAILED);
65  return TQString::fromUtf8(DBUS_ERROR_NO_SERVER);
67  return TQString::fromUtf8(DBUS_ERROR_TIMEOUT);
69  return TQString::fromUtf8(DBUS_ERROR_NO_NETWORK);
71  return TQString::fromUtf8(DBUS_ERROR_DISCONNECTED);
73  return TQString::fromUtf8(DBUS_ERROR_INVALID_ARGS);
75  return TQString::fromUtf8(DBUS_ERROR_FILE_NOT_FOUND);
77  return TQString::fromUtf8(DBUS_ERROR_FILE_EXISTS);
79  return TQString::fromUtf8(DBUS_ERROR_UNKNOWN_METHOD);
81  return TQString::fromUtf8(DBUS_ERROR_TIMED_OUT);
83  return TQString::fromUtf8(DBUS_ERROR_INVALID_SIGNATURE);
84 
86  Q_ASSERT(false);
87  return TQString();
88  }
89 
90  Q_ASSERT(false);
91  return TQString();
92 }
93 
95 {
97  {
100  }
101 }
102 
104 {
105  if (name.isEmpty()) return TQT_DBusError::InvalidError;
106 
107  if (errorTypesByName.isEmpty())
109 
110  ErrorNameMap::const_iterator it = errorTypesByName.find(name);
111  if (it != errorTypesByName.end()) return it.data();
112 
114 }
115 
116 TQT_DBusError::TQT_DBusError() : errorType(InvalidError), m_dbusErrorSet(false)
117 {
118 }
119 
120 TQT_DBusError::TQT_DBusError(const DBusError *error) : errorType(InvalidError), m_dbusErrorSet(false)
121 {
122  if (!error || !dbus_error_is_set(error))
123  return;
124 
125  nm = TQString::fromUtf8(error->name);
126  msg = TQString::fromUtf8(error->message);
127 
129 }
130 
131 TQT_DBusError::TQT_DBusError(const TQString& error, const TQString& message)
132  : errorType(UserDefined), m_dbusErrorSet(false), nm(error), msg(message)
133 {
135 }
136 
138 {
139  return errorType != InvalidError && !nm.isEmpty() && !msg.isEmpty();
140 }
141 
142 TQT_DBusError::TQT_DBusError(ErrorType type, const TQString& message)
143  : errorType(type), m_dbusErrorSet(false), msg(message)
144 {
146 }
147 
148 TQT_DBusError TQT_DBusError::stdFailed(const TQString& message)
149 {
151 }
152 
154 {
156 }
157 
158 TQT_DBusError TQT_DBusError::stdNoReply(const TQString& message)
159 {
161 }
162 
163 TQT_DBusError TQT_DBusError::stdIOError(const TQString& message)
164 {
166 }
167 
169 {
171 }
172 
174 {
176 }
177 
179 {
181 }
182 
184 {
186 }
187 
188 TQT_DBusError TQT_DBusError::stdTimeout(const TQString& message)
189 {
191 }
192 
194 {
196 }
197 
199 {
201 }
202 
204 {
206 }
207 
209 {
211 }
212 
214 {
216 }
Class for transporting D-Bus errors.
Definition: tqdbuserror.h:41
static TQT_DBusError stdNotSupported(const TQString &message)
Creates a D-Bus standard error for unsupported operations.
static TQT_DBusError stdInvalidArgs(const TQString &message)
Creates a D-Bus standard error for call arguments being invalid.
static TQT_DBusError stdFileNotFound(const TQString &message)
Creates a D-Bus standard error for a file not being available.
static TQT_DBusError stdUnknownMethod(const TQString &message)
Creates a D-Bus standard error for an unknown methods being called.
static TQT_DBusError stdTimeout(const TQString &message)
Creates a D-Bus standard error for timeouts during operations.
ErrorType errorType
Definition: tqdbuserror.h:460
static TQT_DBusError stdAccessDenied(const TQString &message)
Creates a D-Bus standard error for access to a resource being denied.
TQString nm
Definition: tqdbuserror.h:463
static TQT_DBusError stdFailed(const TQString &message)
Creates a D-Bus standard error for generic failure.
TQT_DBusError()
Creates an empty and invalid error object.
static TQT_DBusError stdIOError(const TQString &message)
Creates a D-Bus standard error for generic IO errors.
ErrorType type() const
Returns a type for checking of standard errors.
Definition: tqdbuserror.h:307
TQString message() const
Returns a string describing the error.
Definition: tqdbuserror.h:295
static TQT_DBusError stdNoReply(const TQString &message)
Creates a D-Bus standard error for expected reply missing.
ErrorType
Enum of standard D-Bus error types.
Definition: tqdbuserror.h:60
@ TimedOut
An operation timed out.
Definition: tqdbuserror.h:226
@ NotSupported
An otherwise valid operation request could not be handled.
Definition: tqdbuserror.h:134
@ ServiceUnknown
An addressed service is neither connected nor can it be activated.
Definition: tqdbuserror.h:88
@ Failed
Generic failure cause.
Definition: tqdbuserror.h:76
@ AccessDenied
Caused by security restrictions denying an operation.
Definition: tqdbuserror.h:152
@ UnknownMethod
A method call addresses and unknown method.
Definition: tqdbuserror.h:218
@ LimitsExceeded
Use of a limited resource reached its limit.
Definition: tqdbuserror.h:141
@ FileNotFound
A file necessary for an operation is not avaiable.
Definition: tqdbuserror.h:204
@ NoNetwork
The network intended as a transport channel is not available.
Definition: tqdbuserror.h:179
@ NoMemory
An operation could not allocate enough memory.
Definition: tqdbuserror.h:83
@ AuthFailed
An authentification mechanism failed.
Definition: tqdbuserror.h:159
@ InvalidError
TQT_DBusError specific value, to represent invalid error objects.
Definition: tqdbuserror.h:66
@ UserDefined
Generic type for all errors not matching on of the other predefined.
Definition: tqdbuserror.h:248
@ BadAddress
Caused by trying to connect to a malformed address.
Definition: tqdbuserror.h:124
@ NameHasNoOwner
A non-unique name used in a message is not known.
Definition: tqdbuserror.h:97
@ InvalidArgs
Caused by invalid arguments passed to a method call.
Definition: tqdbuserror.h:197
@ FileExists
Target file exists but operation does not allow overwriting.
Definition: tqdbuserror.h:211
@ NoReply
An call failed to send a reply but one was expected.
Definition: tqdbuserror.h:104
@ NoServer
Connection to a D-Bus server failed.
Definition: tqdbuserror.h:164
@ Disconnected
Caused by trying to use an unconnected D-Bus connection.
Definition: tqdbuserror.h:186
@ IOError
An IO error occured during an operation.
Definition: tqdbuserror.h:114
@ InvalidSignature
An type signature is not valid.
Definition: tqdbuserror.h:241
@ Timeout
An timeout occured during an operation.
Definition: tqdbuserror.h:174
TQString msg
Definition: tqdbuserror.h:463
static TQT_DBusError stdNoMemory(const TQString &message)
Creates a D-Bus standard error for out of memory situations.
static TQT_DBusError stdLimitsExceeded(const TQString &message)
Creates a D-Bus standard error for exceeding a limited resource.
static TQT_DBusError stdInvalidSignature(const TQString &message)
Creates a D-Bus standard error for D-Bus type signature not valid.
bool isValid() const
Returns whether the error object is valid.
static TQT_DBusError stdFileExists(const TQString &message)
Creates a D-Bus standard error for a file being in the way.
static TQT_DBusError stdAuthFailed(const TQString &message)
Creates a D-Bus standard error for failed authentification.
static void qDBusErrorSetupNameMapping()
Definition: tqdbuserror.cpp:94
static TQString qDBusErrorNameForType(TQT_DBusError::ErrorType type)
Definition: tqdbuserror.cpp:34
static TQT_DBusError::ErrorType qDBusErrorTypeForName(const TQString &name)
TQMap< TQString, TQT_DBusError::ErrorType > ErrorNameMap
Definition: tqdbuserror.cpp:31
static ErrorNameMap errorTypesByName
Definition: tqdbuserror.cpp:32