1 /* qdbusmisc.cpp Miscellaneous routines that didn't fit anywhere else
3 * Copyright (C) 2006 Trolltech AS. All rights reserved.
4 * Author: Thiago Macieira <thiago.macieira@trolltech.com>
6 * Licensed under the Academic Free License version 2.1
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.
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.
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 Foundation
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <QtCore/qvariant.h>
27 #include <QtCore/qmetaobject.h>
29 #include "qdbusconnection_p.h"
30 #include "qdbustypehelper_p.h"
32 bool qDBusCheckAsyncTag(const char *tag)
37 const char *p = strstr(tag, "async");
39 (p == tag || *(p-1) == ' ') &&
40 (p[5] == '\0' || p[5] == ' '))
43 p = strstr(tag, "Q_ASYNC");
45 (p == tag || *(p-1) == ' ') &&
46 (p[7] == '\0' || p[7] == ' '))
52 int qDBusNameToTypeId(const char *name)
54 int id = static_cast<int>( QVariant::nameToType(name) );
55 if (id == QVariant::UserType)
56 id = QMetaType::type(name);
63 case QMetaType::Short:
64 case QMetaType::UShort:
65 case QMetaType::UChar:
66 case QVariant::LongLong:
67 case QVariant::ULongLong:
68 case QVariant::Double:
69 case QVariant::String:
72 case QVariant::DateTime:
74 case QVariant::StringList:
75 case QVariant::ByteArray:
80 if (id == QDBusConnectionPrivate::registerMessageMetaType() ||
81 id == QDBusTypeHelper<QVariant>::id() ||
82 id == QDBusTypeHelper<bool>::listId() ||
83 id == QDBusTypeHelper<short>::listId() ||
84 id == QDBusTypeHelper<ushort>::listId() ||
85 id == QDBusTypeHelper<int>::listId() ||
86 id == QDBusTypeHelper<qlonglong>::listId() ||
87 id == QDBusTypeHelper<qulonglong>::listId() ||
88 id == QDBusTypeHelper<double>::listId())
95 // calculates the metatypes for the method
96 // the slot must have the parameters in the following form:
97 // - zero or more value or const-ref parameters of any kind
98 // - zero or one const ref of QDBusMessage
99 // - zero or more non-const ref parameters
100 // No parameter may be a template.
101 // this function returns -1 if the parameters don't match the above form
102 // this function returns the number of *input* parameters, including the QDBusMessage one if any
103 // this function does not check the return type, so metaTypes[0] is always 0 and always present
104 // metaTypes.count() >= retval + 1 in all cases
106 // sig must be the normalised signature for the method
107 int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes)
109 QList<QByteArray> parameterTypes = mm.parameterTypes();
112 metaTypes.append(0); // return type
114 bool seenMessage = false;
115 foreach (QByteArray type, parameterTypes) {
116 if (type.endsWith('*')) {
117 //qWarning("Could not parse the method '%s'", mm.signature());
122 if (type.endsWith('&')) {
123 type.truncate(type.length() - 1);
124 int id = qDBusNameToTypeId(type);
126 //qWarning("Could not parse the method '%s'", mm.signature());
127 // invalid type in method parameter list
131 metaTypes.append( id );
132 seenMessage = true; // it cannot appear anymore anyways
136 if (seenMessage) { // && !type.endsWith('&')
137 //qWarning("Could not parse the method '%s'", mm.signature());
138 // non-output parameters after message or after output params
139 return -1; // not allowed
142 int id = qDBusNameToTypeId(type);
144 //qWarning("Could not parse the method '%s'", mm.signature());
145 // invalid type in method parameter list
148 metaTypes.append(id);
151 if (id == QDBusConnectionPrivate::registerMessageMetaType())