c++ - Difference in two versions of QDBusPendingReply::argumentAt -
i use following helper functions call d-bus methods in implementations of d-bus interfaces.
template< typename ...out > bool iserror(const qdbuspendingreply< out... > & reply) { q_assert(reply.isfinished()); if (!reply.iserror()) { return false; } const auto error = reply.error(); qcritical().noquote() << qdbusinterface::tr("asynchronous call finished error: %1 (%2)") .arg(error.name(), error.message()); return true; } template< typename ...out, typename r, int ...indices > void unpackreply(const r & reply, std::integer_sequence< int, indices... >, out &... results) { ((results = reply.template argumentat< indices >()), ...); } template< typename ...out > bool extractresults(qdbusmessage message, out &... results) { qdbuspendingreply< out... > reply = message; if (!reply.isfinished()) { reply.waitforfinished(); } if (iserror(reply)) { return false; } q_assert(reply.isvalid()); #if 1 // 1 (reply.argumentat(0).template value< qdbusargument >() >> ... >> results); #elif 0 // 2 int = 0; ((reply.argumentat(i++).template value< qdbusargument >() >> results), ...); #else // 3 unpackreply< out... >(reply, std::make_integer_sequence< int, sizeof...(out) >{}, results...); #endif return true; }
in subclass of qdbusabstractinterface
use helper dbuscall
:
template< typename ...out > bool dbuscall(qstring method, qvariantlist arguments, out &... results) { return extractresults(callwithargumentlist(qdbus::blockwithgui, method, qmove(arguments)), results...); }
call of method looks following:
qdbusobjectpath networkmanagerinterface::addandactivateconnection(nmvariantmapmap connection, qdbusobjectpath device, qdbusobjectpath specificobject, qdbusobjectpath & activeconnection) { qdbusobjectpath path; dbuscall("addandactivateconnection", makevariantlist{connection, device, specificobject}, path, activeconnection); return path; }
why 3 variants, marked // 1
, // 2
, // 3
, behaves equivalently?
// 3
works fine - expected, how // 1
can correct? it's equivalency // 2
means, qdbusargument
returned argumentat
ascending indices descending parts of argumentat(0)
.
why qdbuspendingreply::argumentat(int)
return qvariant
containing qdbusargument
. 3 variants executed when user types registered qdbusregistermetatype
.
seems, qdbuspendingreply::argumentat(int)
return not de-marshalled qdbusargument
(underlying corresponding call), implicitly-shared , modified successive applying of operator >>
.
qtdbus
looks outdated , abandoned part of qt. say, there no support new syntax in signal/slot connections d-bus signals. arity of qdbuspendingreply
can not limited 8, variadic (not useful, generic). maybe there place clarification , refactoring of library structure.
additional:
the correct way use qdbus_cast
unary (there two) overloading qvariant
(it not documented, present sources):
template< typename ...out > bool extractresults(qdbusmessage message, out &... results) { qdbuspendingreply< out... > reply = message; if (!reply.isfinished()) { reply.waitforfinished(); } if (iserror(reply)) { return false; } q_assert(reply.isvalid()); int = 0; ((results = qdbus_cast< out >(reply.argumentat(i++))), ...); return true; }
Comments
Post a Comment