Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QValueSpaceObject Class Reference
[QtBaseModule]

The QValueSpaceObject class allows applications to add entries to the Value Space. More...

    #include <QValueSpaceObject>

Inherits QObject.

Public Functions

Public Slots

Signals

Static Public Members

Additional Inherited Members


Detailed Description

The QValueSpaceObject class allows applications to add entries to the Value Space.

For an overview of the Qt Extended Value Space, please see the QValueSpaceItem documentation.

The QValueSpaceObject class allows applications to write entries into the Value Space that are automatically removed when the QValueSpaceObject is destroyed, or the application exits either cleanly or abnormally. All applications in the system will have access to the data set through QValueSpaceObject and, if desired, can be notified when the data changes.

Although, logically, the Value Space is a simple collection of hierarchical paths, these paths can conceptually be visualized as a set of objects with attributes. For example, rather than viewing the following list as 12 distinct Value Space paths:

    /Device/Network/Interfaces/eth0/Name
    /Device/Network/Interfaces/eth0/Type
    /Device/Network/Interfaces/eth0/Status
    /Device/Network/Interfaces/eth0/BytesSent
    /Device/Network/Interfaces/eth0/BytesReceived
    /Device/Network/Interfaces/eth0/Time
    /Device/Network/Interfaces/ppp0/Name
    /Device/Network/Interfaces/ppp0/Type
    /Device/Network/Interfaces/ppp0/Status
    /Device/Network/Interfaces/ppp0/BytesSent
    /Device/Network/Interfaces/ppp0/BytesReceived
    /Device/Network/Interfaces/ppp0/Time

it can be thought of as describing two Value Space objects, { /Device/Network/Interfaces/eth0, /Device/Network/Interfaces/ppp0 }, each with the six attributes {Name, Type, Status, BytesSent, BytesReceived, Time}. The QValueSpaceObject class encapsulates this abstraction.

In the case of two or more applications creating an application object with overlapping attributes, only the first is visible to observers in the system. The other attributes are not discarded, but are buffered until the first releases its hold on the attribute, either by manually removing it, destroying the QValueSpaceObject or by terminating. For example:

    QValueSpaceObject * object1 = new QValueSpaceObject("/Device");
    object1->setAttribute("Buttons", 2);

    // QValueSpaceItem("/Device/Buttons") == QVariant(2)

    QValueSpaceObject * object2 = new QValueSpaceObject("/Device");
    object2->setAttribute("Buttons", 3);

    // QValueSpaceItem("/Device/Buttons") == QVariant(2)

    object2->removeAttribute("Buttons");
    // QValueSpaceItem("/Device/Buttons") == QVariant(3)

For performance reasons the setting of and removing of attributes is buffered internally by the QValueSpaceObject and applied as a batch sometime later. Normally this occurs the next time the application enters the Qt event loop, but this behaviour should not be relied apon. If an application must synchronize application objects with others, the QValueSpaceObject::sync() method can be used to force the application of changes. This call is generally unnecessary, and should be used sparingly to prevent unnecessary load on the system.

Note: The QValueSpaceObject class is not thread safe and may only be used from an application's main thread.

See also QValueSpaceItem.


Member Function Documentation

QValueSpaceObject::QValueSpaceObject ( const QByteArray & objectPath, QObject * parent = 0 )

Construct a Value Space object rooted at objectPath with the specified parent.

QValueSpaceObject::QValueSpaceObject ( const char * objectPath, QObject * parent = 0 )

Construct a Value Space object rooted at objectPath with the specified parent. This constructor is equivalent to QValueSpaceObject(QByteArray(objectPath), parent).

QValueSpaceObject::QValueSpaceObject ( const QString & objectPath, QObject * parent = 0 )

Construct a Value Space object rooted at objectPath with the specified parent. This constructor is equivalent to QValueSpaceObject(objectPath.toUtf8(), parent).

QValueSpaceObject::~QValueSpaceObject ()

Destroys the Value Space object. This will remove the object and all its attributes from the Value Space.

void QValueSpaceObject::itemRemove ( const QByteArray & attribute )   [signal]

Emitted whenever a client requests that the attribute be removed through a call to QValueSpaceItem::remove(). The provider of this object may choose to honor, ignore or transform the remove request.

void QValueSpaceObject::itemSetValue ( const QByteArray & attribute, const QVariant & value )   [signal]

Emitted whenever a client requests that the attribute value be changed to value through a call to QValueSpaceItem::setValue(). The provider of this object may chose to honor, ignore or transform the set value request.

QString QValueSpaceObject::objectPath () const

Returns the full path to this object as passed to the QValueSpaceObject constructor.

void QValueSpaceObject::removeAttribute ( const QByteArray & attribute )   [slot]

Removes the object attribute and all sub-attributes from the system.

For example:

    QValueSpaceObject object("/Device");
    object.setAttribute("State", "Starting");
    object.setAttribute("State/Memory", "1000");
    object.sync();
    // QValueSpaceItem("/Device/State").value() == QVariant("Starting")
    // QValueSpaceItem("/Device/State/Memory").value() == QVariant("1000")

    object.removeAttribute("State");
    object.sync();
    // QValueSpaceItem("/Device/State").value() == QVariant();
    // QValueSpaceItem("/Device/State/Memory").value() == QVariant();

void QValueSpaceObject::removeAttribute ( const QString & attribute )   [slot]

This is an overloaded member function, provided for convenience.

This is a convenience overload and is equivalent to removeAttribute(attribute.toUtf8()).

void QValueSpaceObject::removeAttribute ( const char * attribute )   [slot]

This is an overloaded member function, provided for convenience.

This is a convenience overload and is equivalent to removeAttribute(QByteArray(attribute)).

void QValueSpaceObject::setAttribute ( const QByteArray & attribute, const QVariant & data )   [slot]

Set an attribute on the object to data. If attribute is empty, this call will set the object's value.

For example:

    QValueSpaceObject object("/Device");
    object.setAttribute("State", "Starting");
    object.sync();

    // QValueSpaceItem("/Device/State").value() == QVariant("Starting")

void QValueSpaceObject::setAttribute ( const char * attribute, const QVariant & data )   [slot]

This is an overloaded member function, provided for convenience.

This is a convenience overload and is equivalent to setAttribute(QByteArray(attribute), data).

void QValueSpaceObject::setAttribute ( const QString & attribute, const QVariant & data )   [slot]

This is an overloaded member function, provided for convenience.

This is a convenience overload and is equivalent to setAttribute(attribute.toUtf8(), data).

void QValueSpaceObject::sync ()   [static]

Forcibly sync all Value Space objects.

For performance reasons attribute changes are batched internally by QValueSpaceObject instances. In cases where the visibility of changes must be synchronized with other processes, calling QValueSpaceObject::sync() will flush these batches. By the time sync() returns, all other processes in the system will be able to see the attribute changes.

In the common asynchronous case, calling sync() is unnecessary.


Copyright © 2009 Nokia Trademarks
Qt Extended 4.4.3