[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtDBus module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include <string.h>
|
---|
| 43 |
|
---|
[561] | 44 | #include <QtCore/qcoreapplication.h>
|
---|
[2] | 45 | #include <QtCore/qvariant.h>
|
---|
| 46 | #include <QtCore/qmetaobject.h>
|
---|
| 47 |
|
---|
| 48 | #include "qdbusutil_p.h"
|
---|
| 49 | #include "qdbusconnection_p.h"
|
---|
| 50 | #include "qdbusmetatype_p.h"
|
---|
[561] | 51 | #include "qdbusabstractadaptor_p.h" // for QCLASSINFO_DBUS_*
|
---|
[2] | 52 |
|
---|
[846] | 53 | #ifndef QT_NO_DBUS
|
---|
| 54 |
|
---|
[2] | 55 | QT_BEGIN_NAMESPACE
|
---|
| 56 |
|
---|
| 57 | bool qDBusCheckAsyncTag(const char *tag)
|
---|
| 58 | {
|
---|
| 59 | static const char noReplyTag[] = "Q_NOREPLY";
|
---|
| 60 | if (!tag || !*tag)
|
---|
| 61 | return false;
|
---|
| 62 |
|
---|
| 63 | const char *p = strstr(tag, noReplyTag);
|
---|
| 64 | if (p != NULL &&
|
---|
| 65 | (p == tag || *(p-1) == ' ') &&
|
---|
| 66 | (p[sizeof noReplyTag - 1] == '\0' || p[sizeof noReplyTag - 1] == ' '))
|
---|
| 67 | return true;
|
---|
| 68 |
|
---|
| 69 | return false;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | int qDBusNameToTypeId(const char *name)
|
---|
| 73 | {
|
---|
| 74 | int id = static_cast<int>( QVariant::nameToType(name) );
|
---|
| 75 | if (id == QVariant::UserType)
|
---|
| 76 | id = QMetaType::type(name);
|
---|
| 77 | return id;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[561] | 80 | QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
|
---|
| 81 | {
|
---|
| 82 | QString interface;
|
---|
| 83 |
|
---|
| 84 | int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
|
---|
| 85 | if (idx >= mo->classInfoOffset()) {
|
---|
| 86 | interface = QLatin1String(mo->classInfo(idx).value());
|
---|
| 87 | } else {
|
---|
| 88 | interface = QLatin1String(mo->className());
|
---|
| 89 | interface.replace(QLatin1String("::"), QLatin1String("."));
|
---|
| 90 |
|
---|
| 91 | if (interface.startsWith(QLatin1String("QDBus"))) {
|
---|
| 92 | interface.prepend(QLatin1String("com.trolltech.QtDBus."));
|
---|
| 93 | } else if (interface.startsWith(QLatin1Char('Q')) &&
|
---|
| 94 | interface.length() >= 2 && interface.at(1).isUpper()) {
|
---|
| 95 | // assume it's Qt
|
---|
| 96 | interface.prepend(QLatin1String("com.trolltech.Qt."));
|
---|
| 97 | } else if (!QCoreApplication::instance()||
|
---|
| 98 | QCoreApplication::instance()->applicationName().isEmpty()) {
|
---|
| 99 | interface.prepend(QLatin1String("local."));
|
---|
| 100 | } else {
|
---|
| 101 | interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
|
---|
| 102 | QStringList domainName =
|
---|
| 103 | QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
|
---|
| 104 | QString::SkipEmptyParts);
|
---|
| 105 | if (domainName.isEmpty())
|
---|
| 106 | interface.prepend(QLatin1String("local."));
|
---|
| 107 | else
|
---|
| 108 | for (int i = 0; i < domainName.count(); ++i)
|
---|
| 109 | interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | return interface;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
|
---|
| 117 | {
|
---|
| 118 | const QMetaObject *mo = obj->metaObject();
|
---|
| 119 | for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
|
---|
| |
---|