QDBusPendingCallPrivate: save 8 bytes on 64-bit archs
[profile/ivi/qtbase.git] / src / dbus / qdbusutil_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 //
43 //  W A R N I N G
44 //  -------------
45 //
46 // This file is not part of the Qt API.  It exists for the convenience
47 // of the QLibrary class.  This header file may change from
48 // version to version without notice, or even be removed.
49 //
50 // We mean it.
51 //
52
53 #ifndef QDBUSUTIL_H
54 #define QDBUSUTIL_H
55
56 #include <QtCore/qstring.h>
57 #include <QtCore/qvariant.h>
58
59 #include <QtDBus/qdbusmacros.h>
60 #include <QtDBus/qdbuserror.h>
61
62 #ifndef QT_NO_DBUS
63
64 QT_BEGIN_HEADER
65
66 QT_BEGIN_NAMESPACE
67
68 namespace QDBusUtil
69 {
70     Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
71
72     Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QString &busName);
73
74     Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
75
76     Q_DBUS_EXPORT bool isValidMemberName(const QString &memberName);
77
78     Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
79
80     Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QString &path);
81
82     Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
83
84     Q_DBUS_EXPORT bool isValidFixedType(int c);
85
86     Q_DBUS_EXPORT bool isValidBasicType(int c);
87
88     Q_DBUS_EXPORT bool isValidSignature(const QString &signature);
89
90     Q_DBUS_EXPORT bool isValidSingleSignature(const QString &signature);
91
92     Q_DBUS_EXPORT QString argumentToString(const QVariant &variant);
93
94     enum AllowEmptyFlag {
95         EmptyAllowed,
96         EmptyNotAllowed
97     };
98
99     inline bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
100     {
101         if (name.isEmpty()) {
102             if (empty == EmptyAllowed) return true;
103             *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Interface name cannot be empty"));
104             return false;
105         }
106         if (isValidInterfaceName(name)) return true;
107         *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid interface class: %1").arg(name));
108         return false;
109     }
110
111     inline bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
112     {
113         if (name.isEmpty()) {
114             if (empty == EmptyAllowed) return true;
115             *error = QDBusError(QDBusError::InvalidService, QLatin1String("Service name cannot be empty"));
116             return false;
117         }
118         if (isValidBusName(name)) return true;
119         *error = QDBusError(QDBusError::InvalidService, QString::fromLatin1("Invalid service name: %1").arg(name));
120         return false;
121     }
122
123     inline bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
124     {
125         if (path.isEmpty()) {
126             if (empty == EmptyAllowed) return true;
127             *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Object path cannot be empty"));
128             return false;
129         }
130         if (isValidObjectPath(path)) return true;
131         *error = QDBusError(QDBusError::InvalidObjectPath, QString::fromLatin1("Invalid object path: %1").arg(path));
132         return false;
133     }
134
135     inline bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType = 0)
136     {
137         if (!nameType) nameType = "member";
138         if (name.isEmpty()) {
139             if (empty == EmptyAllowed) return true;
140             *error = QDBusError(QDBusError::InvalidMember, QLatin1String(nameType) + QLatin1String(" name cannot be empty"));
141             return false;
142         }
143         if (isValidMemberName(name)) return true;
144         *error = QDBusError(QDBusError::InvalidMember, QString::fromLatin1("Invalid %1 name: %2")
145                             .arg(QString::fromLatin1(nameType), name));
146         return false;
147     }
148
149     inline bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
150     {
151         if (name.isEmpty()) {
152             if (empty == EmptyAllowed) return true;
153             *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Error name cannot be empty"));
154             return false;
155         }
156         if (isValidErrorName(name)) return true;
157         *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid error name: %1").arg(name));
158         return false;
159     }
160 }
161
162 QT_END_NAMESPACE
163
164 QT_END_HEADER
165
166 #endif // QT_NO_DBUS
167 #endif