Qt 4.8
|
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 } |
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 QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () 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 > | |
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 QMetaObject * | metaObject () 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 |
QObject * | parent () 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... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (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... | |
QObject * | sender () 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< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. 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:
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.
Definition at line 59 of file qdbusservicewatcher.h.
QDBusServiceWatcher supports three different watch modes, which are configured by this flag:
Enumerator | |
---|---|
WatchForRegistration | |
WatchForUnregistration | |
WatchForOwnerChange |
Definition at line 65 of file qdbusservicewatcher.h.
|
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.
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.
QDBusServiceWatcher::~QDBusServiceWatcher | ( | ) |
Destroys the QDBusServiceWatcher object and releases any resources associated with it.
Definition at line 296 of file qdbusservicewatcher.cpp.
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.
QDBusConnection QDBusServiceWatcher::connection | ( | ) | const |
Returns the QDBusConnection that this object is attached to.
Definition at line 373 of file qdbusservicewatcher.cpp.
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.
|
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.
|
signal |
This signal is emitted whenever this object detects that the service serviceName became available on the bus.
|
signal |
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 390 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.
Definition at line 318 of file qdbusservicewatcher.cpp.
void QDBusServiceWatcher::setWatchMode | ( | WatchMode | mode | ) |
Definition at line 360 of file qdbusservicewatcher.cpp.
QStringList QDBusServiceWatcher::watchedServices | ( | ) | const |
Referenced by ~QDBusServiceWatcher().
WatchMode QDBusServiceWatcher::watchMode | ( | ) | const |
Referenced by removeWatchedService().
|
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().
Definition at line 62 of file qdbusservicewatcher.h.
|
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.