Skip to content

Commit

Permalink
automate async method/slot calls based on return type
Browse files Browse the repository at this point in the history
this is continuation of my Q_NOREPLY tag removal effort in other commit

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
  • Loading branch information
Ivailo Monev committed Oct 22, 2016
1 parent f04a591 commit badb333
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 43 deletions.
12 changes: 8 additions & 4 deletions src/dbus/qdbusabstractinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,15 @@ QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode,
// 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;
// check type:
if (mm.methodType() != QMetaMethod::Slot && mm.methodType() != QMetaMethod::Method)
continue;

break;
const int returnType = qDBusNameToTypeId(mm.typeName());
if (returnType == QMetaType::Void) {
mode = QDBus::NoBlock;
break;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/dbus/qdbusconnection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ private slots:
// in qdbusmisc.cpp
extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes);
extern int qDBusNameToTypeId(const char *name);
extern bool qDBusCheckAsyncTag(const char *tag);
extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
extern QString qDBusInterfaceFromMetaObject(const QMetaObject *mo);

Expand Down
11 changes: 3 additions & 8 deletions src/dbus/qdbusintegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,8 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
if (paren != name.length() || !slotname.startsWith(name))
continue;

int returnType = qDBusNameToTypeId(mm.typeName());
bool isAsync = qDBusCheckAsyncTag(mm.tag());
bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;

// consistency check:
if (isAsync && returnType != QMetaType::Void)
continue;
const int returnType = qDBusNameToTypeId(mm.typeName());
const bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;

int inputCount = qDBusParametersForMethod(mm, metaTypes);
if (inputCount == -1)
Expand Down Expand Up @@ -703,7 +698,7 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
continue;

// consistency check:
if (isAsync && metaTypes.count() > i + 1)
if (returnType == QMetaType::Void && metaTypes.count() > i + 1)
continue;

if (mm.methodType() == QMetaMethod::Slot) {
Expand Down
7 changes: 0 additions & 7 deletions src/dbus/qdbusmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class QDBusMetaObjectGenerator
struct Method {
QByteArray parameters;
QByteArray typeName;
QByteArray tag;
QByteArray name;
QByteArray inputSignature;
QByteArray outputSignature;
Expand Down Expand Up @@ -276,10 +275,6 @@ void QDBusMetaObjectGenerator::parseMethods()
prototype.append(')');
}

// check the async tag
if (m.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"))
mm.tag = "Q_NOREPLY";

// meta method flags
mm.flags = AccessPublic | MethodSlot | MethodScriptable;

Expand Down Expand Up @@ -443,8 +438,6 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
stringdata += mm.typeName;
stringdata += null;
idata[offset++] = stringdata.length();
stringdata += mm.tag;
stringdata += null;
idata[offset++] = mm.flags;

idata[signatureOffset++] = stringdata.length();
Expand Down
15 changes: 0 additions & 15 deletions src/dbus/qdbusmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@

QT_BEGIN_NAMESPACE

bool qDBusCheckAsyncTag(const char *tag)
{
static const char noReplyTag[] = "Q_NOREPLY";
if (!tag || !*tag)
return false;

const char *p = strstr(tag, noReplyTag);
if (p != NULL &&
(p == tag || *(p-1) == ' ') &&
(p[sizeof noReplyTag - 1] == '\0' || p[sizeof noReplyTag - 1] == ' '))
return true;

return false;
}

int qDBusNameToTypeId(const char *name)
{
int id = static_cast<int>( QVariant::nameToType(name) );
Expand Down
10 changes: 2 additions & 8 deletions src/dbus/qdbusxmlgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,8 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
if ((flags & wantedMask) != wantedMask)
continue;

if (qDBusCheckAsyncTag(mm.tag()))
// add the no-reply annotation
xml += QLatin1String(" <annotation name=\"" ANNOTATION_NO_WAIT "\""
" value=\"true\"/>\n");

retval += xml;
retval += QString::fromLatin1(" </%1>\n")
.arg(isSignal ? QLatin1String("signal") : QLatin1String("method"));
retval += xml + QString::fromLatin1(" </%1>\n")
.arg(isSignal ? QLatin1String("signal") : QLatin1String("method"));
}

return retval;
Expand Down

0 comments on commit badb333

Please sign in to comment.