glibmm: Gio::DBus::Server Class Reference

glibmm 2.28.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Related Functions
Gio::DBus::Server Class Reference
D-Bus API

This is a helper for listening to and accepting D-Bus connections. More...

`#include <giomm/dbusserver.h>`

Inheritance diagram for Gio::DBus::Server:
[legend]

List of all members.

## Public Member Functions
virtual | ~Server ()
GDBusServer* | gobj ()
| Provides access to the underlying C GObject.
const GDBusServer* | gobj () const
| Provides access to the underlying C GObject.
GDBusServer* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
void | start ()
| Starts server.
void | stop ()
| Stops server.
bool | is_active () const
| Gets whether server is active.
std::string | get_guid () const
| Gets the GUID for server.
ServerFlags | get_flags () const
| Gets the flags for server.
std::string | get_client_address () const
| Gets a D-Bus address string that can be used by clients to connect to server.
Glib::PropertyProxy_ReadOnly < bool > | property_active () const
| Whether the server is currently active.
Glib::PropertyProxy_ReadOnly < std::string > | property_address () const
| The address to listen on.
Glib::PropertyProxy_ReadOnly < Glib::RefPtr< AuthObserver > > | property_authentication_observer () const
| Object used to assist in the authentication process.
Glib::PropertyProxy_ReadOnly < std::string > | property_client_address () const
| The address clients can use.
Glib::PropertyProxy_ReadOnly < ServerFlags > | property_flags () const
| Flags for the server.
Glib::PropertyProxy_ReadOnly < std::string > | property_guid () const
| The guid of the server.
Glib::SignalProxy1< bool, const Glib::RefPtr< Connection >& > | signal_new_connection ()
| Emitted when a new authenticated connection has been made.
## Static Public Member Functions
static Glib::RefPtr< Server > | create_sync (const std::string& address, const std::string& guid, const Glib::RefPtr< AuthObserver >& observer, const Glib::RefPtr< Cancellable >& cancellable, ServerFlags flags=Gio::DBus::SERVER_FLAGS_NONE)
| Creates a new D-Bus server that listens on the first address in address that works.
static Glib::RefPtr< Server > | create_sync (const std::string& address, const std::string& guid, const Glib::RefPtr< Cancellable >& cancellable, ServerFlags flags=Gio::DBus::SERVER_FLAGS_NONE)
| Creates a new D-Bus server that listens on the first address in address that works.
static Glib::RefPtr< Server > | create_sync (const std::string& address, const std::string& guid, const Glib::RefPtr< AuthObserver >& observer, ServerFlags flags=Gio::DBus::SERVER_FLAGS_NONE)
| Non-cancellable version of create_sync().
static Glib::RefPtr< Server > | create_sync (const std::string& address, const std::string& guid, ServerFlags flags=Gio::DBus::SERVER_FLAGS_NONE)
| Non-cancellable version of create_sync().
## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::DBus::Server > | wrap (GDBusServer* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

This is a helper for listening to and accepting D-Bus connections.

Since Server derives from Initiable, its constructors can throw an exception if construction fails.

This can be used to create a new D-Bus server, allowing two peers to use the D-Bus protocol for their own specialized communication. A server instance provided in this way will not perform message routing or implement the org.freedesktop.DBus interface.

To just export an object on a well-known name on a message bus, such as the session or system bus, you should instead use Gio::DBus::own_name().

Since glibmm 2.28:

## Constructor & Destructor Documentation

virtual Gio::DBus::Server::~Server | ( |  | ) | `[virtual]`

## Member Function Documentation

static Glib::RefPtr<Server> Gio::DBus::Server::create_sync | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< AuthObserver >& | observer,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | ServerFlags | flags = `Gio::DBus::SERVER_FLAGS_NONE`
| ) |  | `[static]`

Creates a new D-Bus server that listens on the first address in address that works.

Once constructed, you can use g_dbus_server_get_client_address() to get a D-Bus address string that clients can use to connect.

Connect to the DBusServer::new-connection signal to handle incoming connections.

The returned DBusServer isn't active - you have to start it with g_dbus_server_start().

See <xref linkend="gdbus-peer-to-peer"> for how DBusServer can be used.

This is a synchronous failable constructor. See Glib::dbus_server_new() for the asynchronous version.

Since glibmm 2.26:

Parameters:

  address | A D-Bus address.
  flags | Flags from the DBusServerFlags enumeration.
  guid | A D-Bus GUID.
  observer | A DBusAuthObserver or `0`.
  cancellable | A Cancellable or `0`.

Returns:
  A DBusServer or `0` if error is set. Free with Glib::object_unref().

Exceptions:

  Glib::Error. |

static Glib::RefPtr<Server> Gio::DBus::Server::create_sync | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | ServerFlags | flags = `Gio::DBus::SERVER_FLAGS_NONE`
| ) |  | `[static]`

Creates a new D-Bus server that listens on the first address in address that works.

Once constructed, you can use g_dbus_server_get_client_address() to get a D-Bus address string that clients can use to connect.

Connect to the DBusServer::new-connection signal to handle incoming connections.

The returned DBusServer isn't active - you have to start it with g_dbus_server_start().

See <xref linkend="gdbus-peer-to-peer"> for how DBusServer can be used.

This is a synchronous failable constructor. See Glib::dbus_server_new() for the asynchronous version.

Since glibmm 2.26:

Parameters:

  address | A D-Bus address.
  flags | Flags from the DBusServerFlags enumeration.
  guid | A D-Bus GUID.
  observer | A DBusAuthObserver or `0`.
  cancellable | A Cancellable or `0`.

Returns:
  A DBusServer or `0` if error is set. Free with Glib::object_unref().

Exceptions:

  Glib::Error. |

static Glib::RefPtr<Server> Gio::DBus::Server::create_sync | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< AuthObserver >& | observer,
|  | ServerFlags | flags = `Gio::DBus::SERVER_FLAGS_NONE`
| ) |  | `[static]`

Non-cancellable version of create_sync().

static Glib::RefPtr<Server> Gio::DBus::Server::create_sync | ( | const std::string & | address,
|  | const std::string & | guid,
|  | ServerFlags | flags = `Gio::DBus::SERVER_FLAGS_NONE`
| ) |  | `[static]`

Non-cancellable version of create_sync().

std::string Gio::DBus::Server::get_client_address | ( |  | ) | const

Gets a D-Bus address string that can be used by clients to connect to server.

Since glibmm 2.26:

Returns:
  A D-Bus address string. Do not free, the string is owned by server.

ServerFlags Gio::DBus::Server::get_flags | ( |  | ) | const

Gets the flags for server.

Since glibmm 2.26:

Returns:
  A set of flags from the DBusServerFlags enumeration.

std::string Gio::DBus::Server::get_guid | ( |  | ) | const

Gets the GUID for server.

Since glibmm 2.26:

Returns:
  A D-Bus GUID. Do not free this string, it is owned by server.

const GDBusServer* Gio::DBus::Server::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gio::Initable.

GDBusServer* Gio::DBus::Server::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gio::Initable.

GDBusServer* Gio::DBus::Server::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

bool Gio::DBus::Server::is_active | ( |  | ) | const

Gets whether server is active.

Since glibmm 2.26:

Returns:
  `true` if server is active, `false` otherwise.

Glib::PropertyProxy_ReadOnly<bool> Gio::DBus::Server::property_active | ( |  | ) | const

Whether the server is currently active.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<std::string> Gio::DBus::Server::property_address | ( |  | ) | const

The address to listen on.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<AuthObserver> > Gio::DBus::Server::property_authentication_observer | ( |  | ) | const

Object used to assist in the authentication process.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<std::string> Gio::DBus::Server::property_client_address | ( |  | ) | const

The address clients can use.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<ServerFlags> Gio::DBus::Server::property_flags | ( |  | ) | const

Flags for the server.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<std::string> Gio::DBus::Server::property_guid | ( |  | ) | const

The guid of the server.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::SignalProxy1< bool,const Glib::RefPtr<Connection>& > Gio::DBus::Server::signal_new_connection | ( |  | ) |

Emitted when a new authenticated connection has been made.

Use Gio::DBus::Connection::get_peer_credentials() to figure out what identity (if any), was authenticated.

If you want to accept the connection, keep a global reference to the connection (by keeping it in a global RefPtr<>) and return `true`. When you are done with the connection call Gio::DBus::Connection::close(). Note that the other peer may disconnect at any time - a typical thing to do when accepting a connection is to listen to the Gio::DBus::Connection::signal_closed() signal.

If property_flags() contains Gio::DBus::SERVER_FLAGS_RUN_IN_THREAD then the signal is emitted in a new thread dedicated to the connection. Otherwise the signal is emitted in the thread-default main loop of the thread that server was constructed in.

You are guaranteed that signal handlers for this signal runs before incoming messages on the connection are processed. This means that it's suitable to call Gio::DBus::Connection::register_object() or similar from the signal handler.

Prototype:
  `bool on_my_new_connection(const Glib::RefPtr<Connection>& connection)`

void Gio::DBus::Server::start | ( |  | ) |

Starts server.

Since glibmm 2.26:

void Gio::DBus::Server::stop | ( |  | ) |

Stops server.

Since glibmm 2.26:

## Friends And Related Function Documentation

Glib::RefPtr< Gio::DBus::Server > wrap | ( | GDBusServer * | object,
|  | bool | take_copy = `false`
| ) |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.