Call Qt DBus Monitor Method

I would like to know if there is an easy way through QtDbus to “track” method calls to a specific service. For example, I would like when there is a call to the Notify method for org.freedesktop.Notifications to be able to "catch" it and read its arguments.

Note *

I might have found a solution that uses the dbus-monitor application, but I would like to know if there is a better way through the Qt Dbus library.

+4
source share
1 answer

, ( ) 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 Specification , matchString.

, , QDBus QDBUS_DEBUG=1, dbus.

+6

Source: https://habr.com/ru/post/1533060/


All Articles