📄 qdbusabstractinterface.cpp
字号:
\warning If you use \c UseEventLoop, your code must be prepared to deal with any reentrancy: other method calls and signals may be delivered before this function returns, as well as other Qt queued signals and events. \threadsafe*/QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode, const QString& method, const QList<QVariant>& args){ Q_D(QDBusAbstractInterface); QString m = method; // split out the signature from the method int pos = method.indexOf(QLatin1Char('.')); if (pos != -1) m.truncate(pos); if (mode == QDBus::AutoDetect) { // determine if this a sync or async call mode = QDBus::Block; const QMetaObject *mo = metaObject(); QByteArray match = m.toLatin1() + '('; for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) { QMetaMethod mm = mo->method(i); if (QByteArray(mm.signature()).startsWith(match)) { // found a method with the same name as what we're looking for // hopefully, nobody is overloading asynchronous and synchronous methods with // the same name QList<QByteArray> tags = QByteArray(mm.tag()).split(' '); if (tags.contains("Q_NOREPLY")) mode = QDBus::NoBlock; break; } } } QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), m); msg.setArguments(args); QDBusMessage reply = d->connection.call(msg, mode); d->lastError = reply; // will clear if reply isn't an error // ensure that there is at least one element if (reply.arguments().isEmpty()) reply << QVariant(); return reply;}/*! \overload Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function will return immediately after queueing the call. The reply from the remote function or any errors emitted by it will be delivered to the \a slot slot on object \a receiver. This function returns true if the queueing succeeded: it does not indicate that the call succeeded. If it failed, the slot will be called with an error message. lastError() will not be set under those circumstances. \sa QDBusError, QDBusMessage*/bool QDBusAbstractInterface::callWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *slot){ Q_D(QDBusAbstractInterface); QString m = method; // split out the signature from the method int pos = method.indexOf(QLatin1Char('.')); if (pos != -1) m.truncate(pos); QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), m); msg.setArguments(args); d->lastError = 0; // clear return d->connection.callWithCallback(msg, receiver, slot);}/*! \internal Catch signal connections.*/void QDBusAbstractInterface::connectNotify(const char *signal){ // someone connecting to one of our signals Q_D(QDBusAbstractInterface); d->connectionPrivate()->connectRelay(d->service, d->path, d->interface, this, signal);}/*! \internal Catch signal disconnections.*/void QDBusAbstractInterface::disconnectNotify(const char *signal){ // someone disconnecting from one of our signals Q_D(QDBusAbstractInterface); d->connectionPrivate()->disconnectRelay(d->service, d->path, d->interface, this, signal);}/*! \internal Get the value of the property \a propname.*/QVariant QDBusAbstractInterface::internalPropGet(const char *propname) const{ // assume this property exists and is readable // we're only called from generated code anyways int idx = metaObject()->indexOfProperty(propname); if (idx != -1) return d_func()->property(metaObject()->property(idx)); qWarning("QDBusAbstractInterface::internalPropGet called with unknown property '%s'", propname); return QVariant(); // error}/*! \internal Set the value of the property \a propname to \a value.*/void QDBusAbstractInterface::internalPropSet(const char *propname, const QVariant &value){ Q_D(QDBusAbstractInterface); // assume this property exists and is writeable // we're only called from generated code anyways int idx = metaObject()->indexOfProperty(propname); if (idx != -1) d->setProperty(metaObject()->property(idx), value); else qWarning("QDBusAbstractInterface::internalPropGet called with unknown property '%s'", propname);}/*! Calls the method \a method on this interface and passes the parameters to this function to the method. The parameters to \c call are passed on to the remote function via D-Bus as input arguments. Output arguments are returned in the QDBusMessage reply. If the reply is an error reply, lastError() will also be set to the contents of the error message. This function can be used with up to 8 parameters, passed in arguments \a arg1, \a arg2, \a arg3, \a arg4, \a arg5, \a arg6, \a arg7 and \a arg8. If you need more than 8 parameters or if you have a variable number of parameters to be passed, use callWithArgumentList(). It can be used the following way: \code QString value = retrieveValue(); QDBusMessage reply; QDBusReply<int> api = interface->call(QLatin1String("GetAPIVersion")); if (api >= 14) reply = interface->call(QLatin1String("ProcessWorkUnicode"), value); else reply = interface->call(QLatin1String("ProcessWork"), QLatin1String("UTF-8"), value.toUtf8()); \endcode This example illustrates function calling with 0, 1 and 2 parameters and illustrates different parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one Unicode string, the second call to \c "ProcessWork" will contain one string and one byte array).*/QDBusMessage QDBusAbstractInterface::call(const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8){ return call(QDBus::AutoDetect, method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);}/*! \overload Calls the method \a method on this interface and passes the parameters to this function to the method. If \a mode is \c NoWaitForReply, then this function will return immediately after placing the call, without waiting for a reply from the remote method. Otherwise, \a mode indicates whether this function should activate the Qt Event Loop while waiting for the reply to arrive. This function can be used with up to 8 parameters, passed in arguments \a arg1, \a arg2, \a arg3, \a arg4, \a arg5, \a arg6, \a arg7 and \a arg8. If you need more than 8 parameters or if you have a variable number of parameters to be passed, use callWithArgumentList(). If this function reenters the Qt event loop in order to wait for the reply, it will exclude user input. During the wait, it may deliver signals and other method calls to your application. Therefore, it must be prepared to handle a reentrancy whenever a call is placed with call().*/QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8){ QList<QVariant> argList; int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() + arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid(); switch (count) { case 8: argList.prepend(arg8); case 7: argList.prepend(arg7); case 6: argList.prepend(arg6); case 5: argList.prepend(arg5); case 4: argList.prepend(arg4); case 3: argList.prepend(arg3); case 2: argList.prepend(arg2); case 1: argList.prepend(arg1); } return callWithArgumentList(mode, method, argList);}/*! \internal*/QDBusMessage QDBusAbstractInterface::internalConstCall(QDBus::CallMode mode, const QString &method, const QList<QVariant> &args) const{ // ### move the code here, and make the other functions call this return const_cast<QDBusAbstractInterface*>(this)->callWithArgumentList(mode, method, args);}#include "moc_qdbusabstractinterface.cpp"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -