|
sdbus-c++ 2.4.0
High-level C++ D-Bus library based on systemd D-Bus implementation
|
#include <Track.h>
Public Member Functions | |
| Track (const Track &) noexcept | |
| Track & | operator= (const Track &) noexcept |
| Track (Track &&other) noexcept | |
| Track & | operator= (Track &&other) noexcept |
| void | addName (const BusName &name) |
| Adds a bus name to the track. | |
| void | addSender (const Message &message) |
| Adds the sender of a D-Bus message to the track. | |
| void | removeName (const BusName &name) |
| Removes a bus name from the track. | |
| void | removeSender (const Message &message) |
| Removes the sender of a D-Bus message from the track. | |
| bool | contains (const BusName &name) const |
| Checks whether a bus name is tracked. | |
| std::size_t | count () const |
| Returns the number of tracked bus names. | |
| std::vector< BusName > | getNames () const |
| Returns all tracked bus names. | |
| void | setRecursive (bool recursive) |
| Enables or disables recursive mode of the track. | |
| bool | isRecursive () const |
| Checks whether the track is in recursive mode. | |
Track represents a set of D-Bus peers (identified by their bus names) that are tracked on a bus connection. Once all tracked peers disappear from the bus, the handler provided upon track creation is invoked. A typical use case is releasing resources held on behalf of a client (e.g. a lock) when the client disconnects from the bus.
The handler is invoked when the whole track becomes empty, not for each individual name. To be notified of each peer separately, create a separate track for each peer.
Track objects are created via IConnection::createTrack(). Copies of a track object refer to the same underlying sd-bus track. A track object must not outlive the connection it was created on.
For more information, consult man sd_bus_track_new and man sd_bus_track_add_name.
| void sdbus::Track::addName | ( | const BusName & | name | ) |
Adds a bus name to the track.
| [in] | name | Unique or well-known bus name to track |
If the track is recursive, adding an already tracked name increases its reference counter. Otherwise, adding an already tracked name has no effect.
For more information, consult man sd_bus_track_add_name.
| sdbus::Error | in case of failure |
| void sdbus::Track::addSender | ( | const Message & | message | ) |
Adds the sender of a D-Bus message to the track.
| [in] | message | D-Bus message whose sender shall be tracked |
A typical use is tracking the caller of a D-Bus method, within a method callback handler. The message must have been received on the same bus connection the track was created on.
For more information, consult man sd_bus_track_add_sender.
| sdbus::Error | in case of failure |
|
nodiscard |
Checks whether a bus name is tracked.
| [in] | name | Bus name to look up |
For more information, consult man sd_bus_track_contains.
|
nodiscard |
Returns the number of tracked bus names.
Each name is counted once, regardless of its reference counter in a recursive track.
For more information, consult man sd_bus_track_count.
|
nodiscard |
Returns all tracked bus names.
For more information, consult man sd_bus_track_first.
| sdbus::Error | in case of failure |
|
nodiscard |
Checks whether the track is in recursive mode.
For more information, consult man sd_bus_track_get_recursive.
| sdbus::Error | in case of failure |
| void sdbus::Track::removeName | ( | const BusName & | name | ) |
Removes a bus name from the track.
| [in] | name | Bus name to remove |
If the track is recursive, the reference counter of the name is decreased, and the name is removed once the counter drops to zero. Otherwise, the name is removed regardless of how many times it was added.
For more information, consult man sd_bus_track_remove_name.
| sdbus::Error | in case of failure |
| void sdbus::Track::removeSender | ( | const Message & | message | ) |
Removes the sender of a D-Bus message from the track.
| [in] | message | D-Bus message whose sender shall be removed |
For more information, consult man sd_bus_track_remove_sender.
| sdbus::Error | in case of failure |
| void sdbus::Track::setRecursive | ( | bool | recursive | ) |
Enables or disables recursive mode of the track.
| [in] | recursive | True to enable recursive mode |
In recursive mode, each name has a reference counter, and it is only removed from the track once removed as many times as it was added. The mode can only be changed while the track is empty. Recursive mode works correctly with libsystemd v251 or newer only, older versions do not count repeated names.
For more information, consult man sd_bus_track_set_recursive.
| sdbus::Error | in case of failure |