Qt 4.8
Functions
qdbusmisc.cpp File Reference
#include <string.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qvariant.h>
#include <QtCore/qmetaobject.h>
#include "qdbusutil_p.h"
#include "qdbusconnection_p.h"
#include "qdbusmetatype_p.h"
#include "qdbusabstractadaptor_p.h"

Go to the source code of this file.

Functions

bool qDBusCheckAsyncTag (const char *tag)
 
QString qDBusInterfaceFromMetaObject (const QMetaObject *mo)
 
bool qDBusInterfaceInObject (QObject *obj, const QString &interface_name)
 
int qDBusNameToTypeId (const char *name)
 
int qDBusParametersForMethod (const QMetaMethod &mm, QList< int > &metaTypes)
 

Function Documentation

◆ qDBusCheckAsyncTag()

bool qDBusCheckAsyncTag ( const char *  tag)

Definition at line 57 of file qdbusmisc.cpp.

Referenced by findSlot(), and generateInterfaceXml().

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 }

◆ qDBusInterfaceFromMetaObject()

QString qDBusInterfaceFromMetaObject ( const QMetaObject mo)

Definition at line 80 of file qdbusmisc.cpp.

Referenced by qDBusGenerateMetaObjectXml(), and qDBusInterfaceInObject().

81 {
82  QString interface;
83 
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("org.qtproject.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("org.qtproject.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 =
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 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString organizationDomain
the Internet domain of the organization that wrote this application
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * className
Definition: qwizard.cpp:137
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static bool isEmpty(const char *str)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define QCLASSINFO_DBUS_INTERFACE
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool isUpper() const
Returns true if the character is an uppercase letter, i.
Definition: qchar.h:273
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
int classInfoOffset() const
Returns the class information offset for this class; i.e.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qDBusInterfaceInObject()

bool qDBusInterfaceInObject ( QObject obj,
const QString interface_name 
)

Definition at line 116 of file qdbusmisc.cpp.

Referenced by QDBusConnectionPrivate::activateObject(), qDBusPropertyGet(), and qDBusPropertySet().

117 {
118  const QMetaObject *mo = obj->metaObject();
119  for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
120  if (interface_name == qDBusInterfaceFromMetaObject(mo))
121  return true;
122  return false;
123 }
QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
Definition: qdbusmisc.cpp:80
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qDBusNameToTypeId()

int qDBusNameToTypeId ( const char *  name)

Definition at line 72 of file qdbusmisc.cpp.

Referenced by findSlot(), generateInterfaceXml(), qDBusParametersForMethod(), readAllProperties(), and writeProperty().

73 {
74  int id = static_cast<int>( QVariant::nameToType(name) );
75  if (id == QVariant::UserType)
76  id = QMetaType::type(name);
77  return id;
78 }
const char * name
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
static Type nameToType(const char *name)
Converts the string representation of the storage type given in name, to its enum representation...
Definition: qvariant.cpp:2026

◆ qDBusParametersForMethod()

int qDBusParametersForMethod ( const QMetaMethod mm,
QList< int > &  metaTypes 
)

Definition at line 137 of file qdbusmisc.cpp.

Referenced by QDBusConnectionPrivate::findSlot(), findSlot(), generateInterfaceXml(), and QDBusAdaptorConnector::relay().

138 {
140 
141  QList<QByteArray> parameterTypes = mm.parameterTypes();
142  metaTypes.clear();
143 
144  metaTypes.append(0); // return type
145  int inputCount = 0;
146  bool seenMessage = false;
148  QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
149  for ( ; it != end; ++it) {
150  const QByteArray &type = *it;
151  if (type.endsWith('*')) {
152  //qWarning("Could not parse the method '%s'", mm.signature());
153  // pointer?
154  return -1;
155  }
156 
157  if (type.endsWith('&')) {
158  QByteArray basictype = type;
159  basictype.truncate(type.length() - 1);
160 
161  int id = qDBusNameToTypeId(basictype);
162  if (id == 0) {
163  //qWarning("Could not parse the method '%s'", mm.signature());
164  // invalid type in method parameter list
165  return -1;
166  } else if (QDBusMetaType::typeToSignature(id) == 0)
167  return -1;
168 
169  metaTypes.append( id );
170  seenMessage = true; // it cannot appear anymore anyways
171  continue;
172  }
173 
174  if (seenMessage) { // && !type.endsWith('&')
175  //qWarning("Could not parse the method '%s'", mm.signature());
176  // non-output parameters after message or after output params
177  return -1; // not allowed
178  }
179 
180  int id = qDBusNameToTypeId(type);
181  if (id == 0) {
182  //qWarning("Could not parse the method '%s'", mm.signature());
183  // invalid type in method parameter list
184  return -1;
185  }
186 
187  if (id == QDBusMetaTypeId::message)
188  seenMessage = true;
189  else if (QDBusMetaType::typeToSignature(id) == 0)
190  return -1;
191 
192  metaTypes.append(id);
193  ++inputCount;
194  }
195 
196  return inputCount;
197 }
int type
Definition: qmetatype.cpp:239
void truncate(int pos)
Truncates the byte array at index position pos.
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static int message
static void init()
void clear()
Removes all items from the list.
Definition: qlist.h:764
int length() const
Same as size().
Definition: qbytearray.h:356
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
static const KeyPair *const end
int qDBusNameToTypeId(const char *name)
Definition: qdbusmisc.cpp:72
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272