Top |
GDBusServer * | g_dbus_server_new_sync () |
void | g_dbus_server_start () |
void | g_dbus_server_stop () |
gboolean | g_dbus_server_is_active () |
const gchar * | g_dbus_server_get_guid () |
GDBusServerFlags | g_dbus_server_get_flags () |
const gchar * | g_dbus_server_get_client_address () |
gboolean | active | Read |
gchar * | address | Read / Write / Construct Only |
GDBusAuthObserver * | authentication-observer | Read / Write / Construct Only |
gchar * | client-address | Read |
GDBusServerFlags | flags | Read / Write / Construct Only |
gchar * | guid | Read / Write / Construct Only |
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 g_bus_own_name()
.
An example of peer-to-peer communication with G-DBus can be found in gdbus-example-peer.c.
GDBusServer * g_dbus_server_new_sync (const gchar *address
,GDBusServerFlags flags
,const gchar *guid
,GDBusAuthObserver *observer
,GCancellable *cancellable
,GError **error
);
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 “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. See
g_dbus_server_new()
for the asynchronous version.
address |
A D-Bus address. |
|
flags |
Flags from the GDBusServerFlags enumeration. |
|
guid |
A D-Bus GUID. |
|
observer |
A GDBusAuthObserver or |
[allow-none] |
cancellable |
A GCancellable or |
[allow-none] |
error |
Return location for server or |
Since: 2.26
gboolean
g_dbus_server_is_active (GDBusServer *server
);
Gets whether server
is active.
Since: 2.26
const gchar *
g_dbus_server_get_guid (GDBusServer *server
);
Gets the GUID for server
.
Since: 2.26
GDBusServerFlags
g_dbus_server_get_flags (GDBusServer *server
);
Gets the flags for server
.
Since: 2.26
const gchar *
g_dbus_server_get_client_address (GDBusServer *server
);
Gets a D-Bus address string that can be used by clients to connect
to server
.
Since: 2.26
typedef struct _GDBusServer GDBusServer;
The GDBusServer structure contains only private data and should only be accessed using the provided API.
Since: 2.26
Flags used when creating a GDBusServer.
No flags set. |
||
All “new-connection” signals will run in separated dedicated threads (see signal for details). |
||
Allow the anonymous authentication method. |
Since: 2.26
“active”
property“active” gboolean
Whether the server is currently active.
Flags: Read
Default value: FALSE
Since: 2.26
“address”
property“address” gchar *
The D-Bus address to listen on.
Flags: Read / Write / Construct Only
Default value: NULL
Since: 2.26
“authentication-observer”
property“authentication-observer” GDBusAuthObserver *
A GDBusAuthObserver object to assist in the authentication process or NULL
.
Flags: Read / Write / Construct Only
Since: 2.26
“client-address”
property“client-address” gchar *
The D-Bus address that clients can use.
Flags: Read
Default value: NULL
Since: 2.26
“flags”
property“flags” GDBusServerFlags
Flags from the GDBusServerFlags enumeration.
Flags: Read / Write / Construct Only
Since: 2.26
“new-connection”
signalgboolean user_function (GDBusServer *server, GDBusConnection *connection, gpointer user_data)
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 “closed” signal.
If “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
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.
server |
The GDBusServer emitting the signal. |
|
connection |
A GDBusConnection for the new connection. |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
Since: 2.26