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 }
TQT_DBusError::stdIOError
static TQT_DBusError stdIOError(const TQString &message)
Creates a D-Bus standard error for generic IO errors.
Definition: tqdbuserror.cpp:163
TQT_DBusError::UnknownMethod
@ UnknownMethod
A method call addresses and unknown method.
Definition: tqdbuserror.h:218
TQT_DBusError
Class for transporting D-Bus errors.
Definition: tqdbuserror.h:40
TQT_DBusError::AuthFailed
@ AuthFailed
An authentification mechanism failed.
Definition: tqdbuserror.h:159
TQT_DBusError::message
TQString message() const
Returns a string describing the error.
Definition: tqdbuserror.h:295
TQT_DBusError::stdLimitsExceeded
static TQT_DBusError stdLimitsExceeded(const TQString &message)
Creates a D-Bus standard error for exceeding a limited resource.
Definition: tqdbuserror.cpp:173
TQT_DBusError::stdAccessDenied
static TQT_DBusError stdAccessDenied(const TQString &message)
Creates a D-Bus standard error for access to a resource being denied.
Definition: tqdbuserror.cpp:178
TQT_DBusError::stdFailed
static TQT_DBusError stdFailed(const TQString &message)
Creates a D-Bus standard error for generic failure.
Definition: tqdbuserror.cpp:148
qDBusErrorTypeForName
static TQT_DBusError::ErrorType qDBusErrorTypeForName(const TQString &name)
Definition: tqdbuserror.cpp:103
TQT_DBusError::FileExists
@ FileExists
Target file exists but operation does not allow overwriting.
Definition: tqdbuserror.h:211
TQT_DBusError::ErrorType
ErrorType
Enum of standard D-Bus error types.
Definition: tqdbuserror.h:59
TQT_DBusError::stdUnknownMethod
static TQT_DBusError stdUnknownMethod(const TQString &message)
Creates a D-Bus standard error for an unknown methods being called.
Definition: tqdbuserror.cpp:208
TQT_DBusError::LimitsExceeded
@ LimitsExceeded
Use of a limited resource reached its limit.
Definition: tqdbuserror.h:141
TQT_DBusError::stdAuthFailed
static TQT_DBusError stdAuthFailed(const TQString &message)
Creates a D-Bus standard error for failed authentification.
Definition: tqdbuserror.cpp:183
TQT_DBusError::TQT_DBusError
TQT_DBusError()
Creates an empty and invalid error object.
Definition: tqdbuserror.cpp:116
TQT_DBusError::stdNoMemory
static TQT_DBusError stdNoMemory(const TQString &message)
Creates a D-Bus standard error for out of memory situations.
Definition: tqdbuserror.cpp:153
TQT_DBusError::stdInvalidArgs
static TQT_DBusError stdInvalidArgs(const TQString &message)
Creates a D-Bus standard error for call arguments being invalid.
Definition: tqdbuserror.cpp:193
qDBusErrorSetupNameMapping
static void qDBusErrorSetupNameMapping()
Definition: tqdbuserror.cpp:94
TQT_DBusError::InvalidSignature
@ InvalidSignature
An type signature is not valid.
Definition: tqdbuserror.h:241
TQT_DBusError::stdNotSupported
static TQT_DBusError stdNotSupported(const TQString &message)
Creates a D-Bus standard error for unsupported operations.
Definition: tqdbuserror.cpp:168
TQT_DBusError::NoNetwork
@ NoNetwork
The network intended as a transport channel is not available.
Definition: tqdbuserror.h:179
TQT_DBusError::msg
TQString msg
Definition: tqdbuserror.h:463
TQT_DBusError::nm
TQString nm
Definition: tqdbuserror.h:463
TQT_DBusError::ServiceUnknown
@ ServiceUnknown
An addressed service is neither connected nor can it be activated.
Definition: tqdbuserror.h:88
TQT_DBusError::NameHasNoOwner
@ NameHasNoOwner
A non-unique name used in a message is not known.
Definition: tqdbuserror.h:97
TQT_DBusError::NotSupported
@ NotSupported
An otherwise valid operation request could not be handled.
Definition: tqdbuserror.h:134
errorTypesByName
static ErrorNameMap errorTypesByName
Definition: tqdbuserror.cpp:32
TQT_DBusError::Timeout
@ Timeout
An timeout occured during an operation.
Definition: tqdbuserror.h:174
ErrorNameMap
TQMap< TQString, TQT_DBusError::ErrorType > ErrorNameMap
Definition: tqdbuserror.cpp:31
tqdbuserror.h
TQT_DBusError::NoReply
@ NoReply
An call failed to send a reply but one was expected.
Definition: tqdbuserror.h:104
TQT_DBusError::isValid
bool isValid() const
Returns whether the error object is valid.
Definition: tqdbuserror.cpp:137
TQT_DBusError::BadAddress
@ BadAddress
Caused by trying to connect to a malformed address.
Definition: tqdbuserror.h:124
TQT_DBusError::stdInvalidSignature
static TQT_DBusError stdInvalidSignature(const TQString &message)
Creates a D-Bus standard error for D-Bus type signature not valid.
Definition: tqdbuserror.cpp:213
TQT_DBusError::stdFileNotFound
static TQT_DBusError stdFileNotFound(const TQString &message)
Creates a D-Bus standard error for a file not being available.
Definition: tqdbuserror.cpp:198
TQT_DBusData::type
Type type() const
Returns the Type of the data object.
Definition: tqdbusdata.cpp:317
TQT_DBusError::AccessDenied
@ AccessDenied
Caused by security restrictions denying an operation.
Definition: tqdbuserror.h:152
TQT_DBusError::UserDefined
@ UserDefined
Generic type for all errors not matching on of the other predefined.
Definition: tqdbuserror.h:248
TQT_DBusError::IOError
@ IOError
An IO error occured during an operation.
Definition: tqdbuserror.h:114
TQT_DBusError::FileNotFound
@ FileNotFound
A file necessary for an operation is not avaiable.
Definition: tqdbuserror.h:204
TQT_DBusError::stdFileExists
static TQT_DBusError stdFileExists(const TQString &message)
Creates a D-Bus standard error for a file being in the way.
Definition: tqdbuserror.cpp:203
TQT_DBusError::stdTimeout
static TQT_DBusError stdTimeout(const TQString &message)
Creates a D-Bus standard error for timeouts during operations.
Definition: tqdbuserror.cpp:188
qDBusErrorNameForType
static TQString qDBusErrorNameForType(TQT_DBusError::ErrorType type)
Definition: tqdbuserror.cpp:34
TQT_DBusError::NoMemory
@ NoMemory
An operation could not allocate enough memory.
Definition: tqdbuserror.h:83
TQT_DBusError::Disconnected
@ Disconnected
Caused by trying to use an unconnected D-Bus connection.
Definition: tqdbuserror.h:186
TQT_DBusError::errorType
ErrorType errorType
Definition: tqdbuserror.h:460
TQT_DBusError::Failed
@ Failed
Generic failure cause.
Definition: tqdbuserror.h:76
TQT_DBusError::InvalidError
@ InvalidError
TQT_DBusError specific value, to represent invalid error objects.
Definition: tqdbuserror.h:66
TQT_DBusError::stdNoReply
static TQT_DBusError stdNoReply(const TQString &message)
Creates a D-Bus standard error for expected reply missing.
Definition: tqdbuserror.cpp:158
TQT_DBusError::NoServer
@ NoServer
Connection to a D-Bus server failed.
Definition: tqdbuserror.h:164
TQT_DBusError::type
ErrorType type() const
Returns a type for checking of standard errors.
Definition: tqdbuserror.h:307
TQT_DBusError::TimedOut
@ TimedOut
An operation timed out.
Definition: tqdbuserror.h:226
TQT_DBusError::InvalidArgs
@ InvalidArgs
Caused by invalid arguments passed to a method call.
Definition: tqdbuserror.h:197