QtBase  v6.3.1
Public Types | Signals | Public Member Functions | Properties | List of all members
QDBusServiceWatcher Class Reference

The QDBusServiceWatcher class allows the user to watch for a bus service change. More...

#include <qdbusservicewatcher.h>

Inheritance diagram for QDBusServiceWatcher:
Inheritance graph
[legend]
Collaboration diagram for QDBusServiceWatcher:
Collaboration graph
[legend]

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)
 

Public Member Functions

 QDBusServiceWatcher (QObject *parent=nullptr)
 
 QDBusServiceWatcher (const QString &service, const QDBusConnection &connection, WatchMode watchMode=WatchForOwnerChange, QObject *parent=nullptr)
 
 ~QDBusServiceWatcher ()
 
QStringList watchedServices () const
 
void setWatchedServices (const QStringList &services)
 
void addWatchedService (const QString &newService)
 
bool removeWatchedService (const QString &service)
 
QBindable< QStringListbindableWatchedServices ()
 
WatchMode watchMode () const
 
void setWatchMode (WatchMode mode)
 
QBindable< WatchMode > bindableWatchMode ()
 
QDBusConnection connection () const
 
void setConnection (const QDBusConnection &connection)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

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...
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

The QDBusServiceWatcher class allows the user to watch for a bus service change.

Since
4.6 \inmodule QtDBus

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

See also
QDBusConnection

Definition at line 53 of file qdbusservicewatcher.h.

Member Enumeration Documentation

◆ WatchModeFlag

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.

Constructor & Destructor Documentation

◆ QDBusServiceWatcher() [1/2]

QDBusServiceWatcher::QDBusServiceWatcher ( QObject parent = nullptr)
explicit

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() [2/2]

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.

Here is the call graph for this function:

◆ ~QDBusServiceWatcher()

QDBusServiceWatcher::~QDBusServiceWatcher ( )

Destroys the QDBusServiceWatcher object and releases any resources associated with it.

Definition at line 271 of file qdbusservicewatcher.cpp.

Member Function Documentation

◆ addWatchedService()

void QDBusServiceWatcher::addWatchedService ( const QString newService)

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.

Here is the caller graph for this function:

◆ bindableWatchedServices()

QBindable< QStringList > QDBusServiceWatcher::bindableWatchedServices ( )

Definition at line 305 of file qdbusservicewatcher.cpp.

◆ bindableWatchMode()

QBindable< QDBusServiceWatcher::WatchMode > QDBusServiceWatcher::bindableWatchMode ( )

Definition at line 365 of file qdbusservicewatcher.cpp.

◆ connection()

QDBusConnection QDBusServiceWatcher::connection ( ) const

Returns the QDBusConnection that this object is attached to.

See also
setConnection()

Definition at line 385 of file qdbusservicewatcher.cpp.

Here is the caller graph for this function:

◆ removeWatchedService()

bool QDBusServiceWatcher::removeWatchedService ( const QString service)

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ serviceOwnerChanged

void QDBusServiceWatcher::serviceOwnerChanged ( const QString serviceName,
const QString oldOwner,
const QString newOwner 
)
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.

See also
serviceRegistered(), serviceUnregistered()

◆ serviceRegistered

void QDBusServiceWatcher::serviceRegistered ( const QString serviceName)
signal

This signal is emitted whenever this object detects that the service serviceName became available on the bus.

See also
serviceUnregistered(), serviceOwnerChanged()
Here is the caller graph for this function:

◆ serviceUnregistered

void QDBusServiceWatcher::serviceUnregistered ( const QString serviceName)
signal

This signal is emitted whenever this object detects that the service serviceName was unregistered from the bus and is no longer available.

See also
serviceRegistered(), serviceOwnerChanged()

◆ setConnection()

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.

See also
connection()

Definition at line 402 of file qdbusservicewatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWatchedServices()

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.

◆ setWatchMode()

void QDBusServiceWatcher::setWatchMode ( WatchMode  mode)

Definition at line 370 of file qdbusservicewatcher.cpp.

◆ watchedServices()

QStringList QDBusServiceWatcher::watchedServices ( ) const

Returns the list of D-Bus services that are being watched.

See also
setWatchedServices()

Definition at line 280 of file qdbusservicewatcher.cpp.

◆ watchMode()

QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode ( ) const

Definition at line 360 of file qdbusservicewatcher.cpp.

Property Documentation

◆ watchedServices

QDBusServiceWatcher::watchedServices
readwrite

the list of services watched.

Note
Modifying this list with setServicesWatched() is an expensive operation. If you can, prefer to change it by way of addWatchedService() and removeWatchedService().

Definition at line 99 of file qdbusservicewatcher.h.

◆ watchMode

QDBusServiceWatcher::watchMode
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.


The documentation for this class was generated from the following files: