glibmm 2.56.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
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]

## Public Member Functions
| Server (Server&& src) noexcept
Server& | operator= (Server&& src) noexcept
| ~Server () noexcept override
GDBusServer* | gobj ()
| Provides access to the underlying C GObject. More...
const GDBusServer* | gobj () const
| Provides access to the underlying C GObject. More...
GDBusServer* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
void | start ()
| Starts server. More...
void | stop ()
| Stops server. More...
bool | is_active () const
| Gets whether server is active. More...
std::string | get_guid () const
| Gets the GUID for server. More...
ServerFlags | get_flags () const
| Gets the flags for server. More...
std::string | get_client_address () const
| Gets a D-Bus address string that can be used by clients to connect to server. More...
Glib::PropertyProxy_ReadOnly< bool > | property_active () const
| Whether the server is currently active. More...
Glib::PropertyProxy_ReadOnly< std::string > | property_address () const
| The D-Bus address to listen on. More...
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< AuthObserver > > | property_authentication_observer () const
| A DBusAuthObserver object to assist in the authentication process or `nullptr`. More...
Glib::PropertyProxy_ReadOnly< std::string > | property_client_address () const
| The D-Bus address that clients can use. More...
Glib::PropertyProxy_ReadOnly< ServerFlags > | property_flags () const
| Flags from the DBusServerFlags enumeration. More...
Glib::PropertyProxy_ReadOnly< std::string > | property_guid () const
| The guid of the server. More...
Glib::SignalProxy< bool, const Glib::RefPtr< Connection >&> | signal_new_connection ()
Public Member Functions inherited from Glib::Object
| Object (const Object&)=delete
Object& | operator= (const Object&)=delete
| Object (Object&& src) noexcept
Object& | operator= (Object&& src) noexcept
void* | get_data (const QueryQuark& key)
void | set_data (const Quark& key, void* data)
void | set_data (const Quark& key, void* data, DestroyNotify notify)
void | remove_data (const QueryQuark& quark)
void* | steal_data (const QueryQuark& quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase&)=delete
ObjectBase& | operator= (const ObjectBase&)=delete
void | set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring& property_name, const PropertyType& value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring& property_name, PropertyType& value) const
| You probably want to use a specific property_*() accessor method instead. More...
void | connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | connect_property_changed (const Glib::ustring& property_name, sigc::slot< void >&& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, sigc::slot< void >&& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const
Public Member Functions inherited from Gio::Initable
| Initable (Initable&& src) noexcept
Initable& | operator= (Initable&& src) noexcept
| ~Initable () noexcept override
GInitable* | gobj ()
| Provides access to the underlying C GObject. More...
const GInitable* | gobj () const
| Provides access to the underlying C GObject. More...
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor. More...
| Interface (Interface&& src) noexcept
Interface& | operator= (Interface&& src) noexcept
| Interface (const Glib::Interface_Class& interface_class)
| Called by constructors of derived classes. More...
| Interface (GObject* castitem)
| Called by constructors of derived classes. More...
| ~Interface () noexcept override
| Interface (const Interface&)=delete
Interface& | operator= (const Interface&)=delete
GObject* | gobj ()
const GObject* | gobj () const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
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. More...
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. More...
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(). More...
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(). More...
Static Public Member Functions inherited from Gio::Initable
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| Server (const std::string& address, const std::string& guid, const Glib::RefPtr< AuthObserver >& observer, const Glib::RefPtr< Cancellable >& cancellable, ServerFlags flags)
| Server (const std::string& address, const std::string& guid, const Glib::RefPtr< Cancellable >& cancellable, ServerFlags flags)
| Server (const std::string& address, const std::string& guid, const Glib::RefPtr< AuthObserver >& observer, ServerFlags flags)
| Server (const std::string& address, const std::string& guid, ServerFlags flags)
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams& construct_params)
| Object (GObject* castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info& custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase&& src) noexcept
ObjectBase& | operator= (ObjectBase&& src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject* castitem)
void | initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)
Protected Member Functions inherited from Gio::Initable
| Initable ()
| You should derive from this class to use it. More...
void | init (const Glib::RefPtr< Cancellable >& cancellable)
| Initializes the object implementing the interface. More...
void | init ()
| A init() convenience overload. More...
virtual bool | init_vfunc (const Glib::RefPtr< Cancellable >& cancellable, GError** error)

## 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. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject* object, bool take_copy=false)
Related Functions inherited from Gio::Initable
Glib::RefPtr< Gio::Initable > | wrap (GInitable* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
Public Types inherited from Glib::Object
using | DestroyNotify = void(*)(gpointer data)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

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

## ◆ Server() [1/5]

Gio::DBus::Server::Server | ( | Server&& | src | ) |
| noexcept

## ◆ ~Server()

Gio::DBus::Server::~Server | ( |  | ) |
| override noexcept

## ◆ Server() [2/5]

Gio::DBus::Server::Server | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< AuthObserver >& | observer,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | ServerFlags | flags
| ) |  |
| protected

## ◆ Server() [3/5]

Gio::DBus::Server::Server | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | ServerFlags | flags
| ) |  |
| protected

## ◆ Server() [4/5]

Gio::DBus::Server::Server | ( | const std::string & | address,
|  | const std::string & | guid,
|  | const Glib::RefPtr< AuthObserver >& | observer,
|  | ServerFlags | flags
| ) |  |
| protected

## ◆ Server() [5/5]

Gio::DBus::Server::Server | ( | const std::string & | address,
|  | const std::string & | guid,
|  | ServerFlags | flags
| ) |  |
| protected

## Member Function Documentation

## ◆ create_sync() [1/4]

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::signal_new_connection() signal to handle incoming connections.

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

DBusServer is used in this [example][gdbus-peer-to-peer].

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 `nullptr`.
  cancellable | A Cancellable or `nullptr`.

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

Exceptions

  Glib::Error. |

## ◆ create_sync() [2/4]

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::signal_new_connection() signal to handle incoming connections.

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

DBusServer is used in this [example][gdbus-peer-to-peer].

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 `nullptr`.
  cancellable | A Cancellable or `nullptr`.

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

Exceptions

  Glib::Error. |

## ◆ create_sync() [3/4]

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().

## ◆ create_sync() [4/4]

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().

## ◆ get_client_address()

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.

## ◆ get_flags()

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.

## ◆ get_guid()

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.

## ◆ get_type()

static GType Gio::DBus::Server::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GDBusServer* Gio::DBus::Server::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

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

Provides access to the underlying C GObject.

## ◆ gobj_copy()

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.

## ◆ is_active()

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

Gets whether server is active.

Since glibmm 2.26:

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

## ◆ operator=()

Server& Gio::DBus::Server::operator= | ( | Server&& | src | ) |
| noexcept

## ◆ property_active()

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

Whether the server is currently active.

Since glibmm 2.26:

Default value: `false`

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

## ◆ property_address()

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

The D-Bus address to listen on.

Since glibmm 2.26:

Default value: ""

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

## ◆ property_authentication_observer()

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

A DBusAuthObserver object to assist in the authentication process or `nullptr`.

Since glibmm 2.26:

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

## ◆ property_client_address()

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

The D-Bus address that clients can use.

Since glibmm 2.26:

Default value: ""

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

## ◆ property_flags()

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

Flags from the DBusServerFlags enumeration.

Since glibmm 2.26:

Default value: DBUS_SERVER_FLAGS_NONE

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

## ◆ property_guid()

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

The guid of the server.

Since glibmm 2.26:

Default value: ""

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

## ◆ signal_new_connection()

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

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

Flags: Run Last

Emitted when a new authenticated connection has been made. Use g_dbus_connection_get_peer_credentials() to figure out what identity (if any), was authenticated.

If you want to accept the connection, take a reference to the connection object and return `true`. When you are done with the connection call g_dbus_connection_close() and give up your reference. Note that the other peer may disconnect at any time - a typical thing to do when accepting a connection is to listen to the DBusConnection::signal_closed() signal.

If DBusServer::property_flags() contains 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 context][g-main-context-push-thread-default] of the thread that server was constructed in.

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

Since glibmm 2.26:

Parameters

  connection | A DBusConnection for the new connection.

Returns
  `true` to claim connection, `false` to let other handlers run.

## ◆ start()

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

Starts server.

Since glibmm 2.26:

## ◆ stop()

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

Stops server.

Since glibmm 2.26:

## Friends And Related Function Documentation

## ◆ wrap()

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.