QtBase
v6.3.1
|
The QDBusServiceWatcher class allows the user to watch for a bus service change. More...
#include <qdbusservicewatcher.h>
Public Types | |
enum | WatchModeFlag { WatchForRegistration = 0x01 , WatchForUnregistration = 0x02 , WatchForOwnerChange = 0x03 } |
Signals | |
void | serviceRegistered (const QString &service) |
void | serviceUnregistered (const QString &service) |
void | serviceOwnerChanged (const QString &service, const QString &oldOwner, const QString &newOwner) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Properties | |
QStringList | watchedServices |
the list of services watched. More... | |
WatchMode | watchMode |
the current watch mode for this QDBusServiceWatcher object. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
The QDBusServiceWatcher class allows the user to watch for a bus service change.
A QDBusServiceWatcher object can be used to notify the application about an ownership change of a service name on the bus. It has three watch modes:
\list
Besides being created or deleted, services may change owners without a unregister/register operation happening. So the serviceRegistered() and serviceUnregistered() signals may not be emitted if that happens.
This class is more efficient than using the QDBusConnectionInterface::serviceOwnerChanged() signal because it allows one to receive only the signals for which the class is interested in.
Ending a service name with the character '*' will match all service names within the specified namespace.
For example "com.example.backend1*" will match \list
Definition at line 53 of file qdbusservicewatcher.h.
QDBusServiceWatcher supports three different watch modes, which are configured by this flag:
\value WatchForRegistration watch for service registration only, ignoring any signals related to other service ownership change.
\value WatchForUnregistration watch for service unregistration only, ignoring any signals related to other service ownership change.
\value WatchForOwnerChange watch for any kind of service ownership change.
Enumerator | |
---|---|
WatchForRegistration | |
WatchForUnregistration | |
WatchForOwnerChange |
Definition at line 60 of file qdbusservicewatcher.h.
Creates a QDBusServiceWatcher object. Note that until you set a connection with setConnection(), this object will not emit any signals.
The parent parameter is passed to QObject to set the parent of this object.
Definition at line 248 of file qdbusservicewatcher.cpp.
QDBusServiceWatcher::QDBusServiceWatcher | ( | const QString & | service, |
const QDBusConnection & | connection, | ||
WatchMode | watchMode = WatchForOwnerChange , |
||
QObject * | parent = nullptr |
||
) |
Creates a QDBusServiceWatcher object and attaches it to the connection connection. Also, this function immediately starts watching for watchMode changes to service service.
The parent parameter is passed to QObject to set the parent of this object.
Definition at line 261 of file qdbusservicewatcher.cpp.
QDBusServiceWatcher::~QDBusServiceWatcher | ( | ) |
Destroys the QDBusServiceWatcher object and releases any resources associated with it.
Definition at line 271 of file qdbusservicewatcher.cpp.
Adds newService to the list of services to be watched by this object. This function is more efficient than setWatchedServices() and should be used whenever possible to add services.
Removes any existing binding of watchedServices.
Definition at line 318 of file qdbusservicewatcher.cpp.
QBindable< QStringList > QDBusServiceWatcher::bindableWatchedServices | ( | ) |
Definition at line 305 of file qdbusservicewatcher.cpp.
QBindable< QDBusServiceWatcher::WatchMode > QDBusServiceWatcher::bindableWatchMode | ( | ) |
Definition at line 365 of file qdbusservicewatcher.cpp.
QDBusConnection QDBusServiceWatcher::connection | ( | ) | const |
Returns the QDBusConnection that this object is attached to.
Definition at line 385 of file qdbusservicewatcher.cpp.
Removes the service from the list of services being watched by this object. Note that D-Bus notifications are asynchronous, so there may still be signals pending delivery about service. Those signals will still be emitted whenever the D-Bus messages are processed.
Removes any existing binding of watchedServices.
This function returns true
if any services were removed.
Definition at line 343 of file qdbusservicewatcher.cpp.
|
signal |
This signal is emitted whenever this object detects that there was a service ownership change relating to the serviceName service. The oldOwner parameter contains the old owner name and newOwner is the new owner. Both oldOwner and newOwner are unique connection names.
Note that this signal is also emitted whenever the serviceName service was registered or unregistered. If it was registered, oldOwner will contain an empty string, whereas if it was unregistered, newOwner will contain an empty string.
If you need only to find out if the service is registered or unregistered only, without being notified that the ownership changed, consider using the specific modes for those operations. This class is more efficient if you use the more specific modes.
This signal is emitted whenever this object detects that the service serviceName became available on the bus.
This signal is emitted whenever this object detects that the service serviceName was unregistered from the bus and is no longer available.
void QDBusServiceWatcher::setConnection | ( | const QDBusConnection & | connection | ) |
Sets the D-Bus connection that this object is attached to be connection. All services watched will be transferred to this connection.
Note that QDBusConnection objects are reference counted: QDBusServiceWatcher will keep a reference for this connection while it exists. The connection is not closed until the reference count drops to zero, so this will ensure that any notifications are received while this QDBusServiceWatcher object exists.
Definition at line 402 of file qdbusservicewatcher.cpp.
void QDBusServiceWatcher::setWatchedServices | ( | const QStringList & | services | ) |
Sets the list of D-Bus services being watched to be services.
Note that setting the entire list means removing all previous rules for watching services and adding new ones. This is an expensive operation and should be avoided, if possible. Instead, use addWatchedService() and removeWatchedService() if you can to manipulate entries in the list.
Removes any existing binding of watchedServices.
Definition at line 295 of file qdbusservicewatcher.cpp.
void QDBusServiceWatcher::setWatchMode | ( | WatchMode | mode | ) |
Definition at line 370 of file qdbusservicewatcher.cpp.
QStringList QDBusServiceWatcher::watchedServices | ( | ) | const |
Returns the list of D-Bus services that are being watched.
Definition at line 280 of file qdbusservicewatcher.cpp.
QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode | ( | ) | const |
Definition at line 360 of file qdbusservicewatcher.cpp.
|
readwrite |
the list of services watched.
Definition at line 99 of file qdbusservicewatcher.h.
|
readwrite |
the current watch mode for this QDBusServiceWatcher object.
The default value for this property is QDBusServiceWatcher::WatchForOwnershipChange.
Definition at line 99 of file qdbusservicewatcher.h.