Qt 4.8
Public Types | Signals | Public 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:
QObject

Public Types

enum  WatchModeFlag { WatchForRegistration = 0x01, WatchForUnregistration = 0x02, WatchForOwnerChange = 0x03 }
 QDBusServiceWatcher supports three different watch modes, which are configured by this flag: More...
 

Signals

void serviceOwnerChanged (const QString &service, const QString &oldOwner, const QString &newOwner)
 This signal is emitted whenever this object detects that there was a service ownership change relating to the serviceName service. More...
 
void serviceRegistered (const QString &service)
 This signal is emitted whenever this object detects that the service serviceName became available on the bus. More...
 
void serviceUnregistered (const QString &service)
 This signal is emitted whenever this object detects that the service serviceName was unregistered from the bus and is no longer available. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void addWatchedService (const QString &newService)
 Adds newService to the list of services to be watched by this object. More...
 
QDBusConnection connection () const
 Returns the QDBusConnection that this object is attached to. More...
 
 QDBusServiceWatcher (QObject *parent=0)
 Creates a QDBusServiceWatcher object. More...
 
 QDBusServiceWatcher (const QString &service, const QDBusConnection &connection, WatchMode watchMode=WatchForOwnerChange, QObject *parent=0)
 Creates a QDBusServiceWatcher object and attaches it to the connection connection. More...
 
bool removeWatchedService (const QString &service)
 Removes the service from the list of services being watched by this object. More...
 
void setConnection (const QDBusConnection &connection)
 Sets the D-Bus connection that this object is attached to be connection. More...
 
void setWatchedServices (const QStringList &services)
 Sets the list of D-Bus services being watched to be services. More...
 
void setWatchMode (WatchMode mode)
 
QStringList watchedServices () const
 
WatchMode watchMode () const
 
 ~QDBusServiceWatcher ()
 Destroys the QDBusServiceWatcher object and releases any resources associated with it. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Properties

QStringList watchedServices
 The servicesWatched property holds the list of services watched. More...
 
WatchMode watchMode
 The watchMode property holds the current watch mode for this QDBusServiceWatcher object. More...
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

Since
4.6
Attention
Module: 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:

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.

See also
QDBusConnection

Definition at line 59 of file qdbusservicewatcher.h.

Enumerations

◆ WatchModeFlag

QDBusServiceWatcher supports three different watch modes, which are configured by this flag:

  • WatchForRegistration watch for service registration only, ignoring any signals related to other service ownership change.
  • WatchForUnregistration watch for service unregistration only, ignoring any signals related to other service ownership change.
  • WatchForOwnerChange watch for any kind of service ownership change.
Enumerator
WatchForRegistration 
WatchForUnregistration 
WatchForOwnerChange 

Definition at line 65 of file qdbusservicewatcher.h.

Constructors and Destructors

◆ QDBusServiceWatcher() [1/2]

QDBusServiceWatcher::QDBusServiceWatcher ( QObject parent = 0)
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 273 of file qdbusservicewatcher.cpp.

274  : QObject(*new QDBusServiceWatcherPrivate(QDBusConnection(QString()), WatchForOwnerChange), parent)
275 {
276 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QDBusConnection class represents a connection to the D-Bus bus daemon.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QDBusServiceWatcher() [2/2]

QDBusServiceWatcher::QDBusServiceWatcher ( const QString service,
const QDBusConnection connection,
WatchMode  watchMode = WatchForOwnerChange,
QObject parent = 0 
)

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 286 of file qdbusservicewatcher.cpp.

287  : QObject(*new QDBusServiceWatcherPrivate(connection, watchMode), parent)
288 {
289  d_func()->setConnection(QStringList() << service, connection, watchMode);
290 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
WatchMode watchMode() const
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QDBusServiceWatcher()

QDBusServiceWatcher::~QDBusServiceWatcher ( )

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

Definition at line 296 of file qdbusservicewatcher.cpp.

297 {
298 }

Functions

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

Definition at line 331 of file qdbusservicewatcher.cpp.

332 {
334  if (d->servicesWatched.contains(newService))
335  return;
336  d->addService(newService);
337  d->servicesWatched << newService;
338 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDBusServiceWatcher class allows the user to watch for a bus service change.

◆ connection()

QDBusConnection QDBusServiceWatcher::connection ( ) const

Returns the QDBusConnection that this object is attached to.

See also
setConnection()

Definition at line 373 of file qdbusservicewatcher.cpp.

374 {
375  return d_func()->connection;
376 }

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

This function returns true if any services were removed.

Definition at line 348 of file qdbusservicewatcher.cpp.

349 {
351  d->removeService(service);
352  return d->servicesWatched.removeOne(service);
353 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDBusServiceWatcher class allows the user to watch for a bus service change.

◆ 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()

◆ 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 390 of file qdbusservicewatcher.cpp.

391 {
393  if (connection.name() == d->connection.name())
394  return;
395  d->setConnection(d->servicesWatched, connection, d->watchMode);
396 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString name() const
Returns the connection name for this connection, as given as the name parameter to connectToBus()...
The QDBusServiceWatcher class allows the user to watch for a bus service change.

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

Definition at line 318 of file qdbusservicewatcher.cpp.

319 {
321  if (services == d->servicesWatched)
322  return;
323  d->setConnection(services, d->connection, d->watchMode);
324 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDBusServiceWatcher class allows the user to watch for a bus service change.

◆ setWatchMode()

void QDBusServiceWatcher::setWatchMode ( WatchMode  mode)

Definition at line 360 of file qdbusservicewatcher.cpp.

361 {
363  if (mode == d->watchMode)
364  return;
365  d->setConnection(d->servicesWatched, d->connection, mode);
366 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDBusServiceWatcher class allows the user to watch for a bus service change.

◆ watchedServices()

QStringList QDBusServiceWatcher::watchedServices ( ) const

Referenced by ~QDBusServiceWatcher().

◆ watchMode()

WatchMode QDBusServiceWatcher::watchMode ( ) const

Referenced by removeWatchedService().

Properties

◆ watchedServices

QStringList QDBusServiceWatcher::watchedServices
private

The servicesWatched property holds the list of services watched.

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

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

See also
setWatchedServices()

Definition at line 62 of file qdbusservicewatcher.h.

◆ watchMode

QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode
private

The watchMode property holds the current watch mode for this QDBusServiceWatcher object.

The default value for this property is QDBusServiceWatcher::WatchForOwnershipChange.

Definition at line 63 of file qdbusservicewatcher.h.


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