Loading...
Searching...
No Matches
IConnection.h File Reference
`#include <sdbus-c++/TypeTraits.h>`
`#include <chrono>`
`#include <cstdint>`
`#include <memory>`
`#include <optional>`
`#include <string>`

Go to the source code of this file.

## Classes

class | sdbus::IConnection
struct | sdbus::IConnection::PollData

## Typedefs

using | sdbus::ServiceName = BusName

## Functions

std::unique_ptr< IConnection > | sdbus::createBusConnection ()
| Creates/opens D-Bus session bus connection when in a user context, and a system bus connection, otherwise.
std::unique_ptr< IConnection > | sdbus::createBusConnection (const ServiceName &name)
| Creates/opens D-Bus session bus connection with a name when in a user context, and a system bus connection with a name, otherwise.
std::unique_ptr< IConnection > | sdbus::createSystemBusConnection ()
| Creates/opens D-Bus system bus connection.
std::unique_ptr< IConnection > | sdbus::createSystemBusConnection (const ServiceName &name)
| Creates/opens D-Bus system bus connection with a name.
std::unique_ptr< IConnection > | sdbus::createSessionBusConnection ()
| Creates/opens D-Bus session bus connection.
std::unique_ptr< IConnection > | sdbus::createSessionBusConnection (const ServiceName &name)
| Creates/opens D-Bus session bus connection with a name.
std::unique_ptr< IConnection > | sdbus::createSessionBusConnectionWithAddress (const std::string &address)
| Creates/opens D-Bus session bus connection at a custom address.
std::unique_ptr< IConnection > | sdbus::createRemoteSystemBusConnection (const std::string &host)
| Creates/opens D-Bus system connection on a remote host using ssh.
std::unique_ptr< IConnection > | sdbus::createDirectBusConnection (const std::string &address)
| Opens direct D-Bus connection at a custom address.
std::unique_ptr< IConnection > | sdbus::createDirectBusConnection (int fd)
| Opens direct D-Bus connection at the given file descriptor.
std::unique_ptr< IConnection > | sdbus::createServerBus (int fd)
| Opens direct D-Bus connection at fd as a server.
std::unique_ptr< IConnection > | sdbus::createBusConnection (sd_bus *bus)
| Creates sdbus-c++ bus connection representation out of underlying sd_bus instance.

## Detailed Description

(C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland (C) 2016 - 2026 Stanislav Angelovic stani.nosp@m.slav.nosp@m..ange.nosp@m.lovi.nosp@m.c@pro.nosp@m.tonm.nosp@m.ail.c.nosp@m.om

Created on: Nov 8, 2016 Project: sdbus-c++ Description: High-level D-Bus IPC C++ library based on sd-bus

This file is part of sdbus-c++.

sdbus-c++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version.

sdbus-c++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with sdbus-c++. If not, see http://www.gnu.org/licenses/.

## Function Documentation

## createBusConnection() [1/3]

std::unique_ptr< IConnection > sdbus::createBusConnection | ( |  | ) |

nodiscard

Creates/opens D-Bus session bus connection when in a user context, and a system bus connection, otherwise.

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createBusConnection() [2/3]

std::unique_ptr< IConnection > sdbus::createBusConnection | ( | const ServiceName & | name | ) |

nodiscard

Creates/opens D-Bus session bus connection with a name when in a user context, and a system bus connection with a name, otherwise.

Parameters

  [in] | name | Name to request on the connection after its opening

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createBusConnection() [3/3]

std::unique_ptr< IConnection > sdbus::createBusConnection | ( | sd_bus * | bus | ) |

nodiscard

Creates sdbus-c++ bus connection representation out of underlying sd_bus instance.

Parameters

  [in] | bus | File descriptor to use for server DBus connection

Returns
  Connection instance

This functions is helpful in cases where clients need a custom, tweaked configuration of their bus object. Since sdbus-c++ does not provide C++ API for all bus connection configuration functions of the underlying sd-bus library, clients can use these sd-bus functions themselves to create and configure their sd_bus object, and create sdbus-c++ IConnection on top of it.

The IConnection instance assumes unique ownership of the provided bus object. The bus object must have been started by the client before this call. The bus object will get flushed, closed, and unreffed when the IConnection instance is destroyed.

Exceptions

  sdbus::Error | in case of failure

Code example:

sd_bus* bus{};
::sd_bus_new(&bus);
::sd_bus_set_address(bus, address);
::sd_bus_set_anonymous(bus, true);
::sd_bus_start(bus);
auto con = sdbus::createBusConnection(bus); // IConnection consumes sd_bus object
sdbus::createBusConnection
std::unique_ptr< IConnection > createBusConnection()
Creates/opens D-Bus session bus connection when in a user context, and a system bus connection,...

## createDirectBusConnection() [1/2]

std::unique_ptr< IConnection > sdbus::createDirectBusConnection | ( | const std::string & | address | ) |

nodiscard

Opens direct D-Bus connection at a custom address.

Parameters

  [in] | address | ";"-separated list of addresses of bus brokers to try to connect to

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createDirectBusConnection() [2/2]

std::unique_ptr< IConnection > sdbus::createDirectBusConnection | ( | int | fd | ) |

nodiscard

Opens direct D-Bus connection at the given file descriptor.

Parameters

  [in] | fd | File descriptor used to communicate directly from/to a D-Bus server

Returns
  Connection instance

The underlying sdbus-c++ connection instance takes over ownership of fd, so the caller can let it go. If, however, the call throws an exception, the ownership of fd remains with the caller.

Exceptions

  sdbus::Error | in case of failure

## createRemoteSystemBusConnection()

std::unique_ptr< IConnection > sdbus::createRemoteSystemBusConnection | ( | const std::string & | host | ) |

nodiscard

Creates/opens D-Bus system connection on a remote host using ssh.

Parameters

  [in] | host | Name of the host to connect

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createServerBus()

std::unique_ptr< IConnection > sdbus::createServerBus | ( | int | fd | ) |

nodiscard

Opens direct D-Bus connection at fd as a server.

Parameters

  [in] | fd | File descriptor to use for server DBus connection

Returns
  Server connection instance

This creates a new, custom bus object in server mode. One can then call createDirectBusConnection() on client side to connect to this bus.

The underlying sdbus-c++ connection instance takes over ownership of fd, so the caller can let it go. If, however, the call throws an exception, the ownership of fd remains with the caller.

Exceptions

  sdbus::Error | in case of failure

## createSessionBusConnection() [1/2]

std::unique_ptr< IConnection > sdbus::createSessionBusConnection | ( |  | ) |

nodiscard

Creates/opens D-Bus session bus connection.

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createSessionBusConnection() [2/2]

std::unique_ptr< IConnection > sdbus::createSessionBusConnection | ( | const ServiceName & | name | ) |

nodiscard

Creates/opens D-Bus session bus connection with a name.

Parameters

  [in] | name | Name to request on the connection after its opening

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createSessionBusConnectionWithAddress()

std::unique_ptr< IConnection > sdbus::createSessionBusConnectionWithAddress | ( | const std::string & | address | ) |

nodiscard

Creates/opens D-Bus session bus connection at a custom address.

Parameters

  [in] | address | ";"-separated list of addresses of bus brokers to try to connect

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

Consult manual pages for sd_bus_set_address of the underlying sd-bus library for more information.

## createSystemBusConnection() [1/2]

std::unique_ptr< IConnection > sdbus::createSystemBusConnection | ( |  | ) |

nodiscard

Creates/opens D-Bus system bus connection.

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure

## createSystemBusConnection() [2/2]

std::unique_ptr< IConnection > sdbus::createSystemBusConnection | ( | const ServiceName & | name | ) |

nodiscard

Creates/opens D-Bus system bus connection with a name.

Parameters

  [in] | name | Name to request on the connection after its opening

Returns
  Connection instance

Exceptions

  sdbus::Error | in case of failure