![]() |
![]() |
![]() |
GIO Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Signals |
#include <gio/gio.h> GDBusServer; enum GDBusServerFlags; GDBusServer * g_dbus_server_new_sync (const gchar *address
,GDBusServerFlags flags
,const gchar *guid
,GDBusAuthObserver *observer
,GCancellable *cancellable
,GError **error
); void g_dbus_server_start (GDBusServer *server
); void g_dbus_server_stop (GDBusServer *server
); gboolean g_dbus_server_is_active (GDBusServer *server
); const gchar * g_dbus_server_get_guid (GDBusServer *server
); GDBusServerFlags g_dbus_server_get_flags (GDBusServer *server
); const gchar * g_dbus_server_get_client_address (GDBusServer *server
);
"active" gboolean : Read "address" gchar* : Read / Write / Construct Only "authentication-observer" GDBusAuthObserver* : Read / Write / Construct Only "client-address" gchar* : Read "flags" GDBusServerFlags : Read / Write / Construct Only "guid" gchar* : 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()
.
typedef struct _GDBusServer GDBusServer;
The GDBusServer structure contains only private data and should only be accessed using the provided API.
Since 2.26
typedef enum { G_DBUS_SERVER_FLAGS_NONE = 0, G_DBUS_SERVER_FLAGS_RUN_IN_THREAD = (1<<0), G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS = (1<<1) } GDBusServerFlags;
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
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()
.
See Example 6, “D-Bus peer-to-peer example” for how GDBusServer can be used.
This is a synchronous failable constructor. See
g_dbus_server_new()
for the asynchronous version.
|
A D-Bus address. |
|
Flags from the GDBusServerFlags enumeration. |
|
A D-Bus GUID. |
|
A GDBusAuthObserver or NULL . [allow-none]
|
|
A GCancellable or NULL . [allow-none]
|
|
Return location for server or NULL . |
Returns : |
A GDBusServer or NULL if error is set. Free with
g_object_unref() . |
Since 2.26
void g_dbus_server_start (GDBusServer *server
);
Starts server
.
|
A GDBusServer. |
Since 2.26
void g_dbus_server_stop (GDBusServer *server
);
Stops server
.
|
A GDBusServer. |
Since 2.26
gboolean g_dbus_server_is_active (GDBusServer *server
);
Gets whether server
is active.
|
A GDBusServer. |
Returns : |
TRUE if server is active, FALSE otherwise. |
Since 2.26
const gchar * g_dbus_server_get_guid (GDBusServer *server
);
Gets the GUID for server
.
|
A GDBusServer. |
Returns : |
A D-Bus GUID. Do not free this string, it is owned by server . |
Since 2.26
GDBusServerFlags g_dbus_server_get_flags (GDBusServer *server
);
Gets the flags for server
.
|
A GDBusServer. |
Returns : |
A set of flags from the GDBusServerFlags enumeration. |
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
.
|
A GDBusServer. |
Returns : |
A D-Bus address string. Do not free, the string is owned
by server . |
Since 2.26
"active"
property"active" gboolean : Read
Whether the server is currently active.
Default value: FALSE
Since 2.26
"address"
property"address" gchar* : Read / Write / Construct Only
The D-Bus address to listen on.
Default value: NULL
Since 2.26
"authentication-observer"
property"authentication-observer" GDBusAuthObserver* : Read / Write / Construct Only
A GDBusAuthObserver object to assist in the authentication process or NULL
.
Since 2.26
"client-address"
property"client-address" gchar* : Read
The D-Bus address that clients can use.
Default value: NULL
Since 2.26
"flags"
property"flags" GDBusServerFlags : Read / Write / Construct Only
Flags from the GDBusServerFlags enumeration.
Since 2.26
"guid"
property"guid" gchar* : Read / Write / Construct Only
The guid of the server.
Default value: NULL
Since 2.26
"new-connection"
signalgboolean user_function (GDBusServer *server,
GDBusConnection *connection,
gpointer user_data) : 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 "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 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.
|
The GDBusServer emitting the signal. |
|
A GDBusConnection for the new connection. |
|
user data set when the signal handler was connected. |
Returns : |
TRUE to claim connection , FALSE to let other handlers
run. |
Since 2.26