qdbusmisc.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtDBus module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <string.h> -
43 -
44#ifndef QT_BOOTSTRAPPED -
45#include <QtCore/qcoreapplication.h> -
46#include <QtCore/qvariant.h> -
47#include <QtCore/qmetaobject.h> -
48 -
49#include "qdbusutil_p.h" -
50#include "qdbusconnection_p.h" -
51#include "qdbusabstractadaptor_p.h" // for QCLASSINFO_DBUS_* -
52#endif -
53#include <QtCore/qvector.h> -
54#include "qdbusmetatype_p.h" -
55 -
56#ifndef QT_NO_DBUS -
57 -
58QT_BEGIN_NAMESPACE -
59 -
60bool qDBusCheckAsyncTag(const char *tag) -
61{ -
62 static const char noReplyTag[] = "Q_NOREPLY"; -
63 if (!tag || !*tag)
partially evaluated: !tag
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1018
partially evaluated: !*tag
TRUEFALSE
yes
Evaluation Count:1018
no
Evaluation Count:0
0-1018
64 return false;
executed: return false;
Execution Count:1018
1018
65 -
66 const char *p = strstr(tag, noReplyTag);
never executed (the execution status of this line is deduced): const char *p = strstr(tag, noReplyTag);
-
67 if (p != NULL &&
never evaluated: p != __null
0
68 (p == tag || *(p-1) == ' ') &&
never evaluated: p == tag
never evaluated: *(p-1) == ' '
0
69 (p[sizeof noReplyTag - 1] == '\0' || p[sizeof noReplyTag - 1] == ' '))
never evaluated: p[sizeof noReplyTag - 1] == '\0'
never evaluated: p[sizeof noReplyTag - 1] == ' '
0
70 return true;
never executed: return true;
0
71 -
72 return false;
never executed: return false;
0
73} -
74 -
75#ifndef QT_BOOTSTRAPPED -
76 -
77QString qDBusInterfaceFromMetaObject(const QMetaObject *mo) -
78{ -
79 QString interface;
executed (the execution status of this line is deduced): QString interface;
-
80 -
81 int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
executed (the execution status of this line is deduced): int idx = mo->indexOfClassInfo("D-Bus Interface");
-
82 if (idx >= mo->classInfoOffset()) {
evaluated: idx >= mo->classInfoOffset()
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:2
2-144
83 interface = QLatin1String(mo->classInfo(idx).value());
executed (the execution status of this line is deduced): interface = QLatin1String(mo->classInfo(idx).value());
-
84 } else {
executed: }
Execution Count:144
144
85 interface = QLatin1String(mo->className());
executed (the execution status of this line is deduced): interface = QLatin1String(mo->className());
-
86 interface.replace(QLatin1String("::"), QLatin1String("."));
executed (the execution status of this line is deduced): interface.replace(QLatin1String("::"), QLatin1String("."));
-
87 -
88 if (interface.startsWith(QLatin1String("QDBus"))) {
partially evaluated: interface.startsWith(QLatin1String("QDBus"))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
89 interface.prepend(QLatin1String("org.qtproject.QtDBus."));
never executed (the execution status of this line is deduced): interface.prepend(QLatin1String("org.qtproject.QtDBus."));
-
90 } else if (interface.startsWith(QLatin1Char('Q')) &&
never executed: }
partially evaluated: interface.startsWith(QLatin1Char('Q'))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
91 interface.length() >= 2 && interface.at(1).isUpper()) {
never evaluated: interface.length() >= 2
never evaluated: interface.at(1).isUpper()
0
92 // assume it's Qt -
93 interface.prepend(QLatin1String("org.qtproject.Qt."));
never executed (the execution status of this line is deduced): interface.prepend(QLatin1String("org.qtproject.Qt."));
-
94 } else if (!QCoreApplication::instance()||
never executed: }
partially evaluated: !QCoreApplication::instance()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
95 QCoreApplication::instance()->applicationName().isEmpty()) {
partially evaluated: QCoreApplication::instance()->applicationName().isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
96 interface.prepend(QLatin1String("local."));
never executed (the execution status of this line is deduced): interface.prepend(QLatin1String("local."));
-
97 } else {
never executed: }
0
98 interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
executed (the execution status of this line is deduced): interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
-
99 QStringList domainName =
executed (the execution status of this line is deduced): QStringList domainName =
-
100 QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
executed (the execution status of this line is deduced): QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
-
101 QString::SkipEmptyParts);
executed (the execution status of this line is deduced): QString::SkipEmptyParts);
-
102 if (domainName.isEmpty())
partially evaluated: domainName.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
103 interface.prepend(QLatin1String("local."));
executed: interface.prepend(QLatin1String("local."));
Execution Count:2
2
104 else -
105 for (int i = 0; i < domainName.count(); ++i)
never evaluated: i < domainName.count()
0
106 interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
never executed: interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
0
107 } -
108 } -
109 -
110 return interface;
executed: return interface;
Execution Count:146
146
111} -
112 -
113bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name) -
114{ -
115 const QMetaObject *mo = obj->metaObject();
executed (the execution status of this line is deduced): const QMetaObject *mo = obj->metaObject();
-
116 for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
partially evaluated: mo != &QObject::staticMetaObject
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-45
117 if (interface_name == qDBusInterfaceFromMetaObject(mo))
evaluated: interface_name == qDBusInterfaceFromMetaObject(mo)
TRUEFALSE
yes
Evaluation Count:44
yes
Evaluation Count:1
1-44
118 return true;
executed: return true;
Execution Count:44
44
119 return false;
never executed: return false;
0
120} -
121 -
122// calculates the metatypes for the method -
123// the slot must have the parameters in the following form: -
124// - zero or more value or const-ref parameters of any kind -
125// - zero or one const ref of QDBusMessage -
126// - zero or more non-const ref parameters -
127// No parameter may be a template. -
128// this function returns -1 if the parameters don't match the above form -
129// this function returns the number of *input* parameters, including the QDBusMessage one if any -
130// this function does not check the return type, so metaTypes[0] is always 0 and always present -
131// metaTypes.count() >= retval + 1 in all cases -
132// -
133// sig must be the normalised signature for the method -
134int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes) -
135{ -
136 return qDBusParametersForMethod(mm.parameterTypes(), metaTypes);
executed: return qDBusParametersForMethod(mm.parameterTypes(), metaTypes);
Execution Count:1414
1414
137} -
138 -
139#endif // QT_BOOTSTRAPPED -
140 -
141int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QVector<int>& metaTypes) -
142{ -
143 QDBusMetaTypeId::init();
executed (the execution status of this line is deduced): QDBusMetaTypeId::init();
-
144 metaTypes.clear();
executed (the execution status of this line is deduced): metaTypes.clear();
-
145 -
146 metaTypes.append(0); // return type
executed (the execution status of this line is deduced): metaTypes.append(0);
-
147 int inputCount = 0;
executed (the execution status of this line is deduced): int inputCount = 0;
-
148 bool seenMessage = false;
executed (the execution status of this line is deduced): bool seenMessage = false;
-
149 QList<QByteArray>::ConstIterator it = parameterTypes.constBegin();
executed (the execution status of this line is deduced): QList<QByteArray>::ConstIterator it = parameterTypes.constBegin();
-
150 QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
executed (the execution status of this line is deduced): QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
-
151 for ( ; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:904
yes
Evaluation Count:1409
904-1409
152 const QByteArray &type = *it;
executed (the execution status of this line is deduced): const QByteArray &type = *it;
-
153 if (type.endsWith('*')) {
partially evaluated: type.endsWith('*')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:904
0-904
154 //qWarning("Could not parse the method '%s'", mm.methodSignature().constData()); -
155 // pointer? -
156 return -1;
never executed: return -1;
0
157 } -
158 -
159 if (type.endsWith('&')) {
evaluated: type.endsWith('&')
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:892
12-892
160 QByteArray basictype = type;
executed (the execution status of this line is deduced): QByteArray basictype = type;
-
161 basictype.truncate(type.length() - 1);
executed (the execution status of this line is deduced): basictype.truncate(type.length() - 1);
-
162 -
163 int id = QMetaType::type(basictype);
executed (the execution status of this line is deduced): int id = QMetaType::type(basictype);
-
164 if (id == 0) {
partially evaluated: id == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
165 //qWarning("Could not parse the method '%s'", mm.methodSignature().constData()); -
166 // invalid type in method parameter list -
167 return -1;
never executed: return -1;
0
168 } else if (QDBusMetaType::typeToSignature(id) == 0)
partially evaluated: QDBusMetaType::typeToSignature(id) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
169 return -1;
never executed: return -1;
0
170 -
171 metaTypes.append( id );
executed (the execution status of this line is deduced): metaTypes.append( id );
-
172 seenMessage = true; // it cannot appear anymore anyways
executed (the execution status of this line is deduced): seenMessage = true;
-
173 continue;
executed: continue;
Execution Count:12
12
174 } -
175 -
176 if (seenMessage) { // && !type.endsWith('&')
partially evaluated: seenMessage
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:892
0-892
177 //qWarning("Could not parse the method '%s'", mm.methodSignature().constData()); -
178 // non-output parameters after message or after output params -
179 return -1; // not allowed
never executed: return -1;
0
180 } -
181 -
182 int id = QMetaType::type(type);
executed (the execution status of this line is deduced): int id = QMetaType::type(type);
-
183 if (id == QMetaType::UnknownType) {
evaluated: id == QMetaType::UnknownType
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:887
5-887
184 //qWarning("Could not parse the method '%s'", mm.methodSignature().constData()); -
185 // invalid type in method parameter list -
186 return -1;
executed: return -1;
Execution Count:5
5
187 } -
188 -
189 if (id == QDBusMetaTypeId::message())
evaluated: id == QDBusMetaTypeId::message()
TRUEFALSE
yes
Evaluation Count:204
yes
Evaluation Count:683
204-683
190 seenMessage = true;
executed: seenMessage = true;
Execution Count:204
204
191 else if (QDBusMetaType::typeToSignature(id) == 0)
partially evaluated: QDBusMetaType::typeToSignature(id) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:683
0-683
192 return -1;
never executed: return -1;
0
193 -
194 metaTypes.append(id);
executed (the execution status of this line is deduced): metaTypes.append(id);
-
195 ++inputCount;
executed (the execution status of this line is deduced): ++inputCount;
-
196 }
executed: }
Execution Count:887
887
197 -
198 return inputCount;
executed: return inputCount;
Execution Count:1409
1409
199} -
200 -
201QT_END_NAMESPACE -
202 -
203#endif // QT_NO_DBUS -
204 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial