本文整理汇总了C++中QDBusMessage::createReply方法的典型用法代码示例。如果您正苦于以下问题:C++ QDBusMessage::createReply方法的具体用法?C++ QDBusMessage::createReply怎么用?C++ QDBusMessage::createReply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDBusMessage
的用法示例。
在下文中一共展示了QDBusMessage::createReply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrentUrl
void MumbleDBus::getCurrentUrl(const QDBusMessage &msg) {
if (!g.sh || !g.sh->isRunning() || ! g.uiSession) {
QDBusConnection::sessionBus().send(msg.createErrorReply(QLatin1String("net.sourceforge.mumble.Error.connection"), QLatin1String("Not connected")));
return;
}
QString host, user, pw;
unsigned short port;
QUrl u;
g.sh->getConnectionInfo(host, port, user, pw);
u.setScheme(QLatin1String("mumble"));
u.setHost(host);
u.setPort(port);
u.setUserName(user);
#if QT_VERSION >= 0x050000
QUrlQuery query;
query.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
u.setQuery(query);
#else
u.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
#endif
QStringList path;
Channel *c = ClientUser::get(g.uiSession)->cChannel;
while (c->cParent) {
path.prepend(c->qsName);
c = c->cParent;
}
u.setPath(path.join(QLatin1String("/")));
QDBusConnection::sessionBus().send(msg.createReply(QString::fromLatin1(u.toEncoded())));
}
示例2: propertyWriteReply
static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &interface_name,
const QByteArray &property_name, int status)
{
switch (status) {
case PropertyNotFound:
return propertyNotFoundError(msg, interface_name, property_name);
case PropertyTypeMismatch:
return msg.createErrorReply(QDBusError::InvalidArgs,
QString::fromLatin1("Invalid arguments for writing to property %1%2%3")
.arg(interface_name,
QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
QString::fromLatin1(property_name)));
case PropertyReadOnly:
return msg.createErrorReply(QDBusError::PropertyReadOnly,
QString::fromLatin1("Property %1%2%3 is read-only")
.arg(interface_name,
QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
QString::fromLatin1(property_name)));
case PropertyWriteFailed:
return msg.createErrorReply(QDBusError::InternalError,
QString::fromLatin1("Internal error"));
case PropertyWriteSuccess:
return msg.createReply();
}
Q_ASSERT_X(false, "", "Should not be reached");
return QDBusMessage();
}
示例3: GetSignalEmissions
void DBusObject::GetSignalEmissions(int object_id, QString signal_name, const QDBusMessage &message)
{
QDBusMessage reply = message.createReply();
SignalId signal(object_id, signal_name);
if (signal_watchers_.contains(signal))
{
SignalSpyPtr signal_spy = signal_watchers_[signal];
QList<QVariant> signal_emit_list;
qDebug() << "Signal emissions" << signal_spy.data()->length() << signal_spy.data();
for (int i = 0; i < signal_spy->length(); ++i)
{
QList<QVariant> signal_emission;
foreach(const QVariant &arg, signal_spy->at(i)) {
// We cannot marshall QObject* or QObject:
// Marshalling a pointer through DBus makes no sense as its just an address to protected memory
// Marshalling a QObject (without pointer) is not possible because of QObjects no-copy-nature
if((int)arg.type() != (int)QMetaType::QObjectStar) {
signal_emission.append(arg);
}
}
signal_emit_list.append(QVariant(signal_emission));
}
reply << QVariant(signal_emit_list);
}
示例4: GetVariable
Values AsebaNetworkInterface::GetVariable(const QString& node, const QString& variable, const QDBusMessage &message)
{
// make sure the node exists
NodesNamesMap::const_iterator nodeIt(nodesNames.find(node));
if (nodeIt == nodesNames.end())
{
DBusConnectionBus().send(message.createErrorReply(QDBusError::InvalidArgs, QString("node %0 does not exists").arg(node)));
return Values();
}
const unsigned nodeId(nodeIt.value());
unsigned pos(unsigned(-1));
unsigned length(unsigned(-1));
// check whether variable is user-defined
const UserDefinedVariablesMap::const_iterator userVarMapIt(userDefinedVariablesMap.find(node));
if (userVarMapIt != userDefinedVariablesMap.end())
{
const VariablesMap& userVarMap(userVarMapIt.value());
const VariablesMap::const_iterator userVarIt(userVarMap.find(variable.toStdWString()));
if (userVarIt != userVarMap.end())
{
pos = userVarIt->second.first;
length = userVarIt->second.second;
}
}
// if variable is not user-defined, check whether it is provided by this node
if (pos == unsigned(-1))
{
bool ok1, ok2;
pos = getVariablePos(nodeId, variable.toStdWString(), &ok1);
length = getVariableSize(nodeId, variable.toStdWString(), &ok2);
if (!(ok1 && ok2))
{
DBusConnectionBus().send(message.createErrorReply(QDBusError::InvalidArgs, QString("variable %0 does not exists in node %1").arg(variable).arg(node)));
return Values();
}
}
// send request to aseba network
{
GetVariables msg(nodeId, pos, length);
hub->sendMessage(msg);
}
// build bookkeeping for async reply
RequestData *request = new RequestData;
request->nodeId = nodeId;
request->pos = pos;
message.setDelayedReply(true);
request->reply = message.createReply();
pendingReads.push_back(request);
return Values();
}
示例5: handleMessage
bool DeclarativeDBusAdaptor::handleMessage(const QDBusMessage &message, const QDBusConnection &connection)
{
QVariant variants[10];
QGenericArgument arguments[10];
const QMetaObject * const meta = metaObject();
const QVariantList dbusArguments = message.arguments();
QString member = message.member();
QString interface = message.interface();
// Don't try to handle introspect call. It will be handled
// internally for QDBusVirtualObject derived classes.
if (interface == QLatin1String("org.freedesktop.DBus.Introspectable")) {
return false;
} else if (interface == QLatin1String("org.freedesktop.DBus.Properties")) {
if (member == QLatin1String("Get")) {
interface = dbusArguments.value(0).toString();
member = dbusArguments.value(1).toString();
const QMetaObject * const meta = metaObject();
if (!member.isEmpty() && member.at(0).isUpper())
member = "rc" + member;
for (int propertyIndex = meta->propertyOffset();
propertyIndex < meta->propertyCount();
++propertyIndex) {
QMetaProperty property = meta->property(propertyIndex);
if (QLatin1String(property.name()) != member)
continue;
QVariant value = property.read(this);
if (value.userType() == qMetaTypeId<QJSValue>())
value = value.value<QJSValue>().toVariant();
if (value.userType() == QVariant::List) {
QVariantList variantList = value.toList();
if (variantList.count() > 0) {
QDBusArgument list;
list.beginArray(variantList.first().userType());
foreach (const QVariant &listValue, variantList) {
list << listValue;
}
list.endArray();
value = QVariant::fromValue(list);
}
}
QDBusMessage reply = message.createReply(QVariantList() << value);
connection.call(reply, QDBus::NoBlock);
return true;
}
示例6: createReply
QScriptValue QScriptDBusMessageConstructor::createReply(QScriptContext *context, QScriptEngine *engine)
{
QDBusMessage msg;
scriptValueToMessage(context->thisObject(), msg);
QList<QVariant> args;
for (int i = 0; i < context->argumentCount(); ++i) {
QScriptValue value = context->argument(i);
args.append(value.toVariant());
}
return messageToScriptValue(engine, msg.createReply(args));
}
示例7: sendDelayReply
uchar SyncBackup::sendDelayReply (const QDBusMessage &message)
{
FUNCTION_CALL_TRACE;
#ifdef UNIT_TEST
return 0;
#endif
// coverity[unreachable] //Suppressing false positives with code annotations
message.setDelayedReply(true);
if (!iReply)
iReply = new QDBusMessage;
*iReply = message.createReply();
return 0;
}
示例8: requestConnect
void UserAgent::requestConnect(const QDBusMessage &msg)
{
QList<QVariant> arguments2;
arguments2 << QVariant("Clear");
requestMessage = msg.createReply(arguments2);
QList<QVariant> arguments;
arguments << QVariant(connectionRequestType());
QDBusMessage error = msg.createReply(arguments);
if (!QDBusConnection::systemBus().send(error)) {
qWarning() << "Could not queue message";
}
if (connectionRequestType() == "Suppress") {
return;
}
Q_EMIT connectionRequest();
Q_EMIT userConnectRequested(msg);
setConnectionRequestType("Suppress");
}
示例9: qDBusPropertyGetAll
QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg)
{
Q_ASSERT(msg.arguments().count() == 1);
Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
"QDBusConnection: internal threading error",
"function called for an object that is in another thread!!");
QString interface_name = msg.arguments().at(0).toString();
bool interfaceFound = false;
QVariantMap result;
QDBusAdaptorConnector *connector;
if (node.flags & QDBusConnection::ExportAdaptors &&
(connector = qDBusFindAdaptorConnector(node.obj))) {
if (interface_name.isEmpty()) {
// iterate over all interfaces
for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(),
end = connector->adaptors.constEnd(); it != end; ++it) {
result += readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties);
}
} else {
// find the class that implements interface_name
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
interface_name);
if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
interfaceFound = true;
result = readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties);
}
}
}
if (node.flags & QDBusConnection::ExportAllProperties &&
(!interfaceFound || interface_name.isEmpty())) {
// try the object itself
result += readAllProperties(node.obj, node.flags);
interfaceFound = true;
}
if (!interfaceFound && !interface_name.isEmpty()) {
// the interface was not found
return interfaceNotFoundError(msg, interface_name);
}
return msg.createReply(QVariant::fromValue(result));
}
示例10: Confirm
void QBluetoothPasskeyAgent_Private::Confirm(const QString &path,
const QString &address,
const QString &value,
const QDBusMessage &msg)
{
QString devname = path.mid(11);
QBluetoothAddress addr(address);
msg.setDelayedReply(true);
QDBusMessage reply;
if (m_parent->confirmPasskey(devname, addr, value)) {
reply = msg.createReply();
}
else {
reply = msg.createErrorReply("org.bluez.Error.Rejected", "Rejected");
}
QDBusConnection::systemBus().send(reply);
}
示例11: RequestInput
void AgentAdaptor::RequestInput(const QDBusObjectPath &service_path,
const QVariantMap &fields,
const QDBusMessage &message)
{
QVariantMap json;
Q_FOREACH (const QString &key, fields.keys()){
QVariantMap payload = qdbus_cast<QVariantMap>(fields[key]);
json.insert(key, payload);
}
message.setDelayedReply(true);
ServiceRequestData *reqdata = new ServiceRequestData;
reqdata->objectPath = service_path.path();
reqdata->fields = json;
reqdata->reply = message.createReply();
reqdata->msg = message;
m_userAgent->requestUserInput(reqdata);
}
示例12: propertyWriteReply
static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &interface_name,
const QByteArray &property_name, int status)
{
switch (status) {
case PropertyNotFound:
return propertyNotFoundError(msg, interface_name, property_name);
case PropertyTypeMismatch:
return msg.createErrorReply(QDBusError::InvalidArgs,
QString::fromLatin1("Invalid arguments for writing to property %1%2%3")
.arg(interface_name,
QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
QString::fromLatin1(property_name)));
case PropertyWriteFailed:
return msg.createErrorReply(QDBusError::InternalError,
QString::fromLatin1("Internal error"));
case PropertyWriteSuccess:
return msg.createReply();
}
Q_UNREACHABLE();
}
示例13: Request
void QBluetoothPasskeyAgent_Private::Request(const QString &path,
const QString &address,
const QDBusMessage &msg)
{
QString devname = path.mid(11);
QBluetoothAddress addr(address);
QBluetoothPasskeyRequest req(devname, addr);
m_parent->requestPasskey(req);
msg.setDelayedReply(true);
QDBusMessage reply;
if (req.isRejected()) {
reply = msg.createErrorReply("org.bluez.Error.Rejected", "Rejected");
}
else {
reply = msg.createReply(req.passkey());
}
QDBusConnection::systemBus().send(reply);
}
示例14: qDBusPropertyGet
QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg)
{
Q_ASSERT(msg.arguments().count() == 2);
Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
"QDBusConnection: internal threading error",
"function called for an object that is in another thread!!");
QString interface_name = msg.arguments().at(0).toString();
QByteArray property_name = msg.arguments().at(1).toString().toUtf8();
QDBusAdaptorConnector *connector;
QVariant value;
bool interfaceFound = false;
if (node.flags & QDBusConnection::ExportAdaptors &&
(connector = qDBusFindAdaptorConnector(node.obj))) {
// find the class that implements interface_name or try until we've found the property
// in case of an empty interface
if (interface_name.isEmpty()) {
for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(),
end = connector->adaptors.constEnd(); it != end; ++it) {
const QMetaObject *mo = it->adaptor->metaObject();
int pidx = mo->indexOfProperty(property_name);
if (pidx != -1) {
value = mo->property(pidx).read(it->adaptor);
break;
}
}
} else {
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
interface_name);
if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
interfaceFound = true;
value = it->adaptor->property(property_name);
}
}
}
if (!interfaceFound && !value.isValid()
&& node.flags & (QDBusConnection::ExportAllProperties |
QDBusConnection::ExportNonScriptableProperties)) {
// try the object itself
if (!interface_name.isEmpty())
interfaceFound = qDBusInterfaceInObject(node.obj, interface_name);
if (interfaceFound) {
int pidx = node.obj->metaObject()->indexOfProperty(property_name);
if (pidx != -1) {
QMetaProperty mp = node.obj->metaObject()->property(pidx);
if ((mp.isScriptable() && (node.flags & QDBusConnection::ExportScriptableProperties)) ||
(!mp.isScriptable() && (node.flags & QDBusConnection::ExportNonScriptableProperties)))
value = mp.read(node.obj);
}
}
}
if (!value.isValid()) {
// the property was not found
if (!interfaceFound)
return interfaceNotFoundError(msg, interface_name);
return propertyNotFoundError(msg, interface_name, property_name);
}
return msg.createReply(QVariant::fromValue(QDBusVariant(value)));
}
示例15: handleMessage
bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnection& connection)
{
/* Check to make sure we're getting properties on our interface */
if (message.type() != QDBusMessage::MessageType::MethodCallMessage) {
return false;
}
/* Break down the path to just the app id */
bool validpath = true;
QString pathtemp = message.path();
if (!pathtemp.startsWith(QLatin1String("/com/canonical/Unity/Launcher/"))) {
validpath = false;
}
pathtemp.remove(QStringLiteral("/com/canonical/Unity/Launcher/"));
if (pathtemp.indexOf('/') >= 0) {
validpath = false;
}
/* Find ourselves an appid */
QString appid = decodeAppId(pathtemp);
// First handle methods of the Launcher interface
if (message.interface() == QLatin1String("com.canonical.Unity.Launcher")) {
if (message.member() == QLatin1String("Refresh")) {
QDBusMessage reply = message.createReply();
Q_EMIT refreshCalled();
return connection.send(reply);
}
} else if (message.interface() == QLatin1String("com.canonical.Unity.Launcher.Item")) {
// Handle methods of the Launcher-Item interface
if (message.member() == QLatin1String("Alert") && validpath) {
QDBusMessage reply = message.createReply();
Q_EMIT alertCalled(appid);
return connection.send(reply);
}
}
// Now handle dynamic properties (for launcher emblems)
if (message.interface() != QLatin1String("org.freedesktop.DBus.Properties")) {
return false;
}
if (message.member() == QLatin1String("Get") && (message.arguments().count() != 2 || message.arguments()[0].toString() != QLatin1String("com.canonical.Unity.Launcher.Item"))) {
return false;
}
if (message.member() == QLatin1String("Set") && (message.arguments().count() != 3 || message.arguments()[0].toString() != QLatin1String("com.canonical.Unity.Launcher.Item"))) {
return false;
}
if (!validpath) {
return false;
}
int index = m_launcherModel->findApplication(appid);
LauncherItem *item = static_cast<LauncherItem*>(m_launcherModel->get(index));
QVariantList retval;
if (message.member() == QLatin1String("Get")) {
QString cachedString = message.arguments()[1].toString();
if (!item) {
return false;
}
if (cachedString == QLatin1String("count")) {
retval.append(QVariant::fromValue(QDBusVariant(item->count())));
} else if (cachedString == QLatin1String("countVisible")) {
retval.append(QVariant::fromValue(QDBusVariant(item->countVisible())));
} else if (cachedString == QLatin1String("progress")) {
retval.append(QVariant::fromValue(QDBusVariant(item->progress())));
}
} else if (message.member() == QLatin1String("Set")) {
QString cachedString = message.arguments()[1].toString();
if (cachedString == QLatin1String("count")) {
int newCount = message.arguments()[2].value<QDBusVariant>().variant().toInt();
if (!item || newCount != item->count()) {
Q_EMIT countChanged(appid, newCount);
notifyPropertyChanged(QStringLiteral("com.canonical.Unity.Launcher.Item"), encodeAppId(appid), QStringLiteral("count"), QVariant(newCount));
}
} else if (cachedString == QLatin1String("countVisible")) {
bool newVisible = message.arguments()[2].value<QDBusVariant>().variant().toBool();
if (!item || newVisible != item->countVisible()) {
Q_EMIT countVisibleChanged(appid, newVisible);
notifyPropertyChanged(QStringLiteral("com.canonical.Unity.Launcher.Item"), encodeAppId(appid), QStringLiteral("countVisible"), newVisible);
}
} else if (cachedString == QLatin1String("progress")) {
int newProgress = message.arguments()[2].value<QDBusVariant>().variant().toInt();
if (!item || newProgress != item->progress()) {
Q_EMIT progressChanged(appid, newProgress);
notifyPropertyChanged(QStringLiteral("com.canonical.Unity.Launcher.Item"), encodeAppId(appid), QStringLiteral("progress"), QVariant(newProgress));
}
}
} else if (message.member() == QLatin1String("GetAll")) {
if (item) {
QVariantMap all;
all.insert(QStringLiteral("count"), item->count());
all.insert(QStringLiteral("countVisible"), item->countVisible());
all.insert(QStringLiteral("progress"), item->progress());
retval.append(all);
}
} else {
//.........这里部分代码省略.........