Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: DBusServer

[28:7] extends: object

GDBusServer is a helper for listening to and accepting D-Bus connections. 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 [func@Gio.bus_own_name]. An example of peer-to-peer communication with GDBus can be found in gdbus-example-peer.c. Note that a minimal GDBusServer will accept connections from any peer. In many use-cases it will be necessary to add a [class@Gio.DBusAuthObserver] that only accepts connections that have successfully authenticated as the same user that is running the GDBusServer. Since GLib 2.68 this can be achieved more simply by passing the G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag to the server.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • DBusServer (address = null, flags = null, guid = null, observer = null, cancellable = null)

    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. To have control over the available authentication mechanisms and the users that are authorized to connect, it is strongly recommended to provide a non-%NULL #GDBusAuthObserver. Connect to the #GDBusServer::new-connection signal to handle incoming connections. The returned #GDBusServer isn't active - you have to start it with g_dbus_server_start(). #GDBusServer is used in this example. This is a synchronous failable constructor. There is currently no asynchronous version.

    • @p address is A D-Bus address..
    • @p flags is Flags from the #GDBusServerFlags enumeration..
    • @p guid is A D-Bus GUID..
    • @p observer is A #GDBusAuthObserver or %NULL..
    • @p cancellable is A #GCancellable or %NULL..
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asObject ()

    Wraps this handle as Object.

    • @r A Object object.
  • asInitable ()

    Wraps this handle as Initable.

    • @r A Initable object.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnNewconnection (callback Fn, UserData = null)

    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 #GDBusConnection::closed signal. If #GDBusServer:flags contains %G_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 (see [method@GLib.MainContext.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.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (DBusServer Self, DBusConnection Connection).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • get_client_address ()

    Gets a D-Bus address string that can be used by clients to connect to @server. This is valid and non-empty if initializing the #GDBusServer succeeded.

  • get_flags ()

    Gets the flags for @server.

  • get_guid ()

    Gets the GUID for @server, as provided to g_dbus_server_new_sync().

  • is_active ()

    Gets whether @server is active.

  • start ()

    Starts @server.

    • @r None.
  • stop ()

    Stops @server.

    • @r None.

class: DBusServerMeta

[341:14] static extends: object

Generated metadata helpers for DBusServer class surfaces.

Methods

  • properties ()

    Returns property metadata for DBusServer.

    • @r A list.
  • signals ()

    Returns signal metadata for DBusServer.

    • @r A list.

class: DBusServerNewconnectionCallback

[270:7] extends: object

Generated low-level callback wrapper for GIR callback new-connection.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • DBusServerNewconnectionCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, connection, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.