sdbus-c++ 2.4.0
High-level C++ D-Bus library based on systemd D-Bus implementation
Loading...
Searching...
No Matches
sdbus::Track Class Reference

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

Detailed Description

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.

Member Function Documentation

◆ addName()

void sdbus::Track::addName ( const BusName & name)

Adds a bus name to the track.

Parameters
[in]nameUnique 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.

Exceptions
sdbus::Errorin case of failure

◆ addSender()

void sdbus::Track::addSender ( const Message & message)

Adds the sender of a D-Bus message to the track.

Parameters
[in]messageD-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.

Exceptions
sdbus::Errorin case of failure

◆ contains()

bool sdbus::Track::contains ( const BusName & name) const
nodiscard

Checks whether a bus name is tracked.

Parameters
[in]nameBus name to look up
Returns
True if the name is tracked, false otherwise

For more information, consult man sd_bus_track_contains.

◆ count()

std::size_t sdbus::Track::count ( ) const
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.

◆ getNames()

std::vector< BusName > sdbus::Track::getNames ( ) const
nodiscard

Returns all tracked bus names.

For more information, consult man sd_bus_track_first.

Exceptions
sdbus::Errorin case of failure

◆ isRecursive()

bool sdbus::Track::isRecursive ( ) const
nodiscard

Checks whether the track is in recursive mode.

For more information, consult man sd_bus_track_get_recursive.

Exceptions
sdbus::Errorin case of failure

◆ removeName()

void sdbus::Track::removeName ( const BusName & name)

Removes a bus name from the track.

Parameters
[in]nameBus 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.

Exceptions
sdbus::Errorin case of failure

◆ removeSender()

void sdbus::Track::removeSender ( const Message & message)

Removes the sender of a D-Bus message from the track.

Parameters
[in]messageD-Bus message whose sender shall be removed

For more information, consult man sd_bus_track_remove_sender.

Exceptions
sdbus::Errorin case of failure

◆ setRecursive()

void sdbus::Track::setRecursive ( bool recursive)

Enables or disables recursive mode of the track.

Parameters
[in]recursiveTrue 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.

Exceptions
sdbus::Errorin case of failure

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