Qt DBus监视器方法调用
Qt DBus Monitor Method Calls
我想知道是否有一种简单的方法通过QtDbus来"监视"某个服务的方法调用。例如,我希望当有一个Notify方法调用org.freedesktop.Notifications能够"捕获"它并读取它的参数。
注意*
我可能已经找到了一个解决方案,这是使用Dbus -monitor应用程序,但我想知道是否有更好的方法通过Qt Dbus库。
是的,您应该能够通过QtDBus(做一点工作)做到这一点。基本上,消息总线上的任何客户端都可以订阅任何消息——仅受总线安全策略的限制。(因此,没有办法监视显式不合作的应用程序,除非您对它或消息总线具有调试访问权限。)关键是您将希望在总线本身上使用org.freedesktop.DBus.AddMatch
方法:
// first connect our handler object to the QDBusConnection so that it knows what
// to do with the incoming Notify calls
// slotNotifyObserved() must have a compatible signature to the DBus call
QDBusConnection::sessionBus().connect("", // any service name
"", // any object path
"org.freedesktop.Notifications",
"Notify",
myImplementingQObject,
SLOT(slotNotifyObserved(...)));
// then ask the bus to send us a copy of each Notify call message
QString matchString = "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'";
QDBusInterface busInterface("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus");
busInterface.call("AddMatch", matchString);
// once we get back to the event loop our object should be called as other programs
// make Notify() calls
DBus规范给出了matchString
中可能出现的各种匹配字段的列表。
为了更好地了解发生了什么,QDBus文档建议设置环境变量QDBUS_DEBUG=1
,以使应用程序记录有关其dbus消息传递的信息。
相关文章:
- 在c++中多次调用方法
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 接收字符串并使用它来调用方法C++
- 使用 gmock c++ 在真实对象上调用方法
- 不带预处理器的调用方法/文件的文件名/行号
- JNI从Android调用C++方法
- 在 C++ 的 Switch Case 中创建对象后对对象调用方法
- 如何使用接口指针调用方法,该指针是其具体类的一部分,而不是接口的一部分
- 从内部类中的方法从包含类调用方法
- 在销毁期间从另一个线程调用对象上调用方法是否未定义行为?
- 为什么派生类的实例从基类调用方法?
- 实例化对象并调用方法,使用单行语法在 C# 或 C++ 中返回值?
- C++当您取消引用指向类对象的指针,然后将其作为引用返回时,是否可以对此引用调用方法
- 通过模板函数对未知类型调用方法
- 从基于迭代器的for循环转换后,如何在map::find()中调用方法
- 创建一个C++DLL以从C#DLL调用方法
- 如何从qt中的类中调用方法
- 如何在不迭代的情况下对数组中的每个元素调用方法
- C++11 - 获取编译时的所有类变量,并在没有 Boost 的情况下为它们调用方法
- C ++:如何在不创建对象的情况下在主函数中调用方法