g_dbus_connection_register_object

发布时间 2023-04-16 18:16:28作者: lydstory

/**
* g_dbus_connection_register_object:
* @connection: A #GDBusConnection.
* @object_path: The object path to register at.
* @interface_info: Introspection data for the interface.
* @vtable: A #GDBusInterfaceVTable to call into or %NULL.
* @user_data: Data to pass to functions in @vtable.
* @user_data_free_func: Function to call when the object path is unregistered.
* @error: Return location for error or %NULL.
*
* Registers callbacks for exported objects at @object_path with the
* D-Bus interface that is described in @interface_info.
*
* Calls to functions in @vtable (and @user_data_free_func) will
* happen in the <link linkend="g-main-context-push-thread-default">thread-default main
* loop</link> of the thread you are calling this method from.
*
* Note that all #GVariant values passed to functions in @vtable will match
* the signature given in @interface_info - if a remote caller passes
* incorrect values, the <literal>org.freedesktop.DBus.Error.InvalidArgs</literal>
* is returned to the remote caller.
*
* Additionally, if the remote caller attempts to invoke methods or
* access properties not mentioned in @interface_info the
* <literal>org.freedesktop.DBus.Error.UnknownMethod</literal> resp.
* <literal>org.freedesktop.DBus.Error.InvalidArgs</literal> errors
* are returned to the caller.
*
* It is considered a programming error if the
* #GDBusInterfaceGetPropertyFunc function in @vtable returns a
* #GVariant of incorrect type.
*
* If an existing callback is already registered at @object_path and
* @interface_name, then @error is set to #G_IO_ERROR_EXISTS.
*
* GDBus automatically implements the standard D-Bus interfaces
* org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable
* and org.freedesktop.Peer, so you don't have to implement those for
* the objects you export. You <emphasis>can</emphasis> implement
* org.freedesktop.DBus.Properties yourself, e.g. to handle getting
* and setting of properties asynchronously.
*
* Note that the reference count on @interface_info will be
* incremented by 1 (unless allocated statically, e.g. if the
* reference count is -1, see g_dbus_interface_info_ref()) for as long
* as the object is exported. Also note that @vtable will be copied.
*
* See <xref linkend="gdbus-server"/> for an example of how to use this method.
*
* Returns: 0 if @error is set, otherwise a registration id (never 0)
* that can be used with g_dbus_connection_unregister_object() .
*
* Since: 2.26