summaryrefslogtreecommitdiff
path: root/src/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2011-02-16 15:04:57 +0100
committerThiago Macieira <thiago.macieira@nokia.com>2011-04-13 14:56:22 +0200
commit6d325d6f70c419d1fee49da1738633a3e03b46d4 (patch)
tree60924397e8048d9f38c077275b09282909f48c9f /src/dbus
parent8334e79a0340c9fcd5ccedeb867a84044d4d83dd (diff)
downloadqt4-tools-6d325d6f70c419d1fee49da1738633a3e03b46d4.tar.gz
Add support for Unix file-descriptor passing to QtDBus
Task-number: QTBUG-17477
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusargument.cpp28
-rw-r--r--src/dbus/qdbusargument.h4
-rw-r--r--src/dbus/qdbusargument_p.h8
-rw-r--r--src/dbus/qdbusdemarshaller.cpp17
-rw-r--r--src/dbus/qdbusmarshaller.cpp20
-rw-r--r--src/dbus/qdbusmetatype.cpp1
-rw-r--r--src/dbus/qdbusunixfiledescriptor.h1
7 files changed, 78 insertions, 1 deletions
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp
index 09f0e8238f..806b7fec16 100644
--- a/src/dbus/qdbusargument.cpp
+++ b/src/dbus/qdbusargument.cpp
@@ -487,6 +487,20 @@ QDBusArgument &QDBusArgument::operator<<(const QDBusSignature &arg)
/*!
\overload
+ \since 4.8
+ \internal
+ Appends the primitive value \a arg of type \c{UNIX_FILE_DESCRIPTOR} (Unix
+ File Descriptor) to the D-Bus stream.
+*/
+QDBusArgument &QDBusArgument::operator<<(const QDBusUnixFileDescriptor &arg)
+{
+ if (QDBusArgumentPrivate::checkWrite(d))
+ d->marshaller()->append(arg);
+ return *this;
+}
+
+/*!
+ \overload
Appends the primitive value \a arg of type \c{VARIANT} to the D-Bus stream.
A D-Bus variant type can contain any type, including other
@@ -729,6 +743,20 @@ const QDBusArgument &QDBusArgument::operator>>(QDBusSignature &arg) const
/*!
\overload
+ \since 4.8
+ \internal
+ Extracts one D-Bus primitive argument of type \c{UNIX_FILE_DESCRIPTOR}
+ (Unix file descriptor) from the D-Bus stream.
+*/
+const QDBusArgument &QDBusArgument::operator>>(QDBusUnixFileDescriptor &arg) const
+{
+ if (QDBusArgumentPrivate::checkReadAndDetach(d))
+ arg = d->demarshaller()->toUnixFileDescriptor();
+ return *this;
+}
+
+/*!
+ \overload
Extracts one D-Bus primitive argument of type \c{VARIANT} from the
D-Bus stream.
diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h
index e331d8ff4c..f80723e6b4 100644
--- a/src/dbus/qdbusargument.h
+++ b/src/dbus/qdbusargument.h
@@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE
QT_MODULE(DBus)
+class QDBusUnixFileDescriptor;
+
class QDBusArgumentPrivate;
class QDBusDemarshaller;
class QDBusMarshaller;
@@ -96,6 +98,7 @@ public:
QDBusArgument &operator<<(const QDBusVariant &arg);
QDBusArgument &operator<<(const QDBusObjectPath &arg);
QDBusArgument &operator<<(const QDBusSignature &arg);
+ QDBusArgument &operator<<(const QDBusUnixFileDescriptor &arg);
QDBusArgument &operator<<(const QStringList &arg);
QDBusArgument &operator<<(const QByteArray &arg);
@@ -127,6 +130,7 @@ public:
const QDBusArgument &operator>>(QDBusVariant &arg) const;
const QDBusArgument &operator>>(QDBusObjectPath &arg) const;
const QDBusArgument &operator>>(QDBusSignature &arg) const;
+ const QDBusArgument &operator>>(QDBusUnixFileDescriptor &arg) const;
const QDBusArgument &operator>>(QStringList &arg) const;
const QDBusArgument &operator>>(QByteArray &arg) const;
diff --git a/src/dbus/qdbusargument_p.h b/src/dbus/qdbusargument_p.h
index 89a383f1a1..1c713a3433 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -54,10 +54,16 @@
//
#include <qdbusargument.h>
+#include "qdbusunixfiledescriptor.h"
#include "qdbus_symbols_p.h"
#ifndef QT_NO_DBUS
+#ifndef DBUS_TYPE_UNIX_FD
+# define DBUS_TYPE_UNIX_FD int('h')
+# define DBUS_TYPE_UNIX_FD_AS_STRING "h"
+#endif
+
QT_BEGIN_NAMESPACE
class QDBusMarshaller;
@@ -117,6 +123,7 @@ public:
void append(const QString &arg);
void append(const QDBusObjectPath &arg);
void append(const QDBusSignature &arg);
+ void append(const QDBusUnixFileDescriptor &arg);
void append(const QStringList &arg);
void append(const QByteArray &arg);
bool append(const QDBusVariant &arg); // this one can fail
@@ -172,6 +179,7 @@ public:
QString toString();
QDBusObjectPath toObjectPath();
QDBusSignature toSignature();
+ QDBusUnixFileDescriptor toUnixFileDescriptor();
QDBusVariant toVariant();
QStringList toStringList();
QByteArray toByteArray();
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index 111122e84c..3910381284 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qdbusargument_p.h"
+#include "qdbusconnection.h"
#include <stdlib.h>
QT_BEGIN_NAMESPACE
@@ -126,6 +127,13 @@ inline QDBusSignature QDBusDemarshaller::toSignature()
return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator)));
}
+inline QDBusUnixFileDescriptor QDBusDemarshaller::toUnixFileDescriptor()
+{
+ QDBusUnixFileDescriptor fd;
+ fd.giveFileDescriptor(qIterGet<dbus_int32_t>(&iterator));
+ return fd;
+}
+
inline QDBusVariant QDBusDemarshaller::toVariant()
{
QDBusDemarshaller sub(capabilities);
@@ -173,6 +181,10 @@ QDBusArgument::ElementType QDBusDemarshaller::currentType()
case DBUS_TYPE_DICT_ENTRY:
return QDBusArgument::MapEntryType;
+ case DBUS_TYPE_UNIX_FD:
+ return capabilities & QDBusConnection::UnixFileDescriptorPassing ?
+ QDBusArgument::BasicType : QDBusArgument::UnknownType;
+
case DBUS_TYPE_INVALID:
return QDBusArgument::UnknownType;
@@ -231,6 +243,11 @@ QVariant QDBusDemarshaller::toVariantInternal()
case DBUS_TYPE_STRUCT:
return QVariant::fromValue(duplicate());
+ case DBUS_TYPE_UNIX_FD:
+ if (capabilities & QDBusConnection::UnixFileDescriptorPassing)
+ return qVariantFromValue(toUnixFileDescriptor());
+ // fall through
+
default:
// qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'",
// q_dbus_message_iter_get_arg_type(&iterator),
diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp
index 76d76cc310..edf743e0a0 100644
--- a/src/dbus/qdbusmarshaller.cpp
+++ b/src/dbus/qdbusmarshaller.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qdbusargument_p.h"
+#include "qdbusconnection.h"
#include "qdbusmetatype_p.h"
#include "qdbusutil_p.h"
@@ -138,6 +139,16 @@ inline void QDBusMarshaller::append(const QDBusSignature &arg)
qIterAppend(&iterator, ba, DBUS_TYPE_SIGNATURE, &cdata);
}
+inline void QDBusMarshaller::append(const QDBusUnixFileDescriptor &arg)
+{
+ int fd = arg.fileDescriptor();
+ if (!ba && fd == -1) {
+ error(QLatin1String("Invalid file descriptor passed in arguments"));
+ } else {
+ qIterAppend(&iterator, ba, DBUS_TYPE_UNIX_FD, &fd);
+ }
+}
+
inline void QDBusMarshaller::append(const QByteArray &arg)
{
if (ba) {
@@ -474,6 +485,13 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
qFatal("QDBusMarshaller::appendVariantInternal got a DICT_ENTRY!");
return false;
+ case DBUS_TYPE_UNIX_FD:
+ if (capabilities & QDBusConnection::UnixFileDescriptorPassing || ba) {
+ append(qvariant_cast<QDBusUnixFileDescriptor>(arg));
+ return true;
+ }
+ // fall through
+
default:
qWarning("QDBusMarshaller::appendVariantInternal: Found unknown D-BUS type '%s'",
signature);
@@ -507,7 +525,7 @@ bool QDBusMarshaller::appendCrossMarshalling(QDBusDemarshaller *demarshaller)
if (code == DBUS_TYPE_ARRAY) {
int element = q_dbus_message_iter_get_element_type(&demarshaller->iterator);
- if (q_dbus_type_is_fixed(element)) {
+ if (q_dbus_type_is_fixed(element) && element != DBUS_TYPE_UNIX_FD) {
// another optimization: fixed size arrays
// code is exactly like QDBusDemarshaller::toByteArray
DBusMessageIter sub;
diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp
index a361762d35..9d9112cde5 100644
--- a/src/dbus/qdbusmetatype.cpp
+++ b/src/dbus/qdbusmetatype.cpp
@@ -147,6 +147,7 @@ void QDBusMetaTypeId::init()
qDBusRegisterMetaType<QList<double> >();
qDBusRegisterMetaType<QList<QDBusObjectPath> >();
qDBusRegisterMetaType<QList<QDBusSignature> >();
+ qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >();
#endif
initialized = true;
diff --git a/src/dbus/qdbusunixfiledescriptor.h b/src/dbus/qdbusunixfiledescriptor.h
index 3ac3f9fcf5..92a770ccc7 100644
--- a/src/dbus/qdbusunixfiledescriptor.h
+++ b/src/dbus/qdbusunixfiledescriptor.h
@@ -96,6 +96,7 @@ protected:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QDBusUnixFileDescriptor)
+Q_DECLARE_METATYPE(QList<QDBusUnixFileDescriptor>)
QT_END_HEADER