Skip to content

Commit

Permalink
sdbusplus: better mirror bus aquisition methods
Browse files Browse the repository at this point in the history
This adds new functions:
 * new_default_user() -> return default user bus connection
 * new_default_system() -> returns default system connection

And changes new_default() to return the default type of connection for
the user as per the man page:
https://www.freedesktop.org/software/systemd/man/sd_bus_default.html

Also, update the example and the README to use the default bus calls.

Change-Id: I13cd77dda847c4f6018da38e0019816da07710d1
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
  • Loading branch information
vmauery committed Dec 11, 2018
1 parent f042393 commit 8ca6025
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type-safety and memory leak protection afforded by modern C++ practices.

Consider the following code:
```
auto b = bus::new_system();
auto b = bus::new_default_system();
auto m = b.new_method_call("org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
Expand Down
2 changes: 1 addition & 1 deletion example/list-users.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main()
{
using namespace sdbusplus;

auto b = bus::new_system();
auto b = bus::new_default_system();
auto m =
b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1",
"org.freedesktop.login1.Manager", "ListUsers");
Expand Down
20 changes: 19 additions & 1 deletion sdbusplus/bus.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,31 @@ inline bus::bus(busp_t b, std::false_type) : _intf(&sdbus_impl), _bus(b)
#endif
}

/* Create a new default connection: system bus if root, session bus if user */
inline bus new_default()
{
sd_bus* b = nullptr;
sd_bus_open(&b);
sd_bus_default(&b);
return bus(b, std::false_type());
}

/* Create a new default connection to the session bus */
inline bus new_default_user()
{
sd_bus* b = nullptr;
sd_bus_default_user(&b);
return bus(b, std::false_type());
}

/* Create a new default connection to the system bus */
inline bus new_default_system()
{
sd_bus* b = nullptr;
sd_bus_default_system(&b);
return bus(b, std::false_type());
}

/* WARNING: THESE ARE NOT THE FUNCTIONS YOU ARE LOOKING FOR! */
inline bus new_user()
{
sd_bus* b = nullptr;
Expand Down

0 comments on commit 8ca6025

Please sign in to comment.