Client
Object Hierarchy:
Description:
[
CCode ( type_id =
"jsonrpc_client_get_type ()" ) ]
[
Version ( since =
"3.26" ) ]
public class Client :
Object
A client for JSON-RPC communication
The Client class provides a convenient API to coordinate with a JSON-RPC server. You can provide the
underlying [class@Gio.IOStream] to communicate with allowing you to control the negotiation of how you setup your communications channel.
One such method might be to use a [class@Gio.Subprocess] and communicate over stdin and stdout.
Because JSON-RPC allows for out-of-band notifications from the server to the client, it is important that the consumer of this API calls
[method@Client.close] or [method@Client.close_async] when they no longer need the client. This is because Client
contains an asynchronous read-loop to process incoming messages. Until [method@Client.close] or [method@Client.close_async] have
been called, this read loop will prevent the object from finalizing (being freed).
To make an RPC call, use [method@Client.call] or [method@Client.call_async] and provide the method name and the parameters as a [
struct@GLib.Variant] for call.
It is a programming error to mix synchronous and asynchronous API calls of the Client class.
For synchronous calls, Client will use the thread-default [struct@GLib.MainContext]. If you have special needs
here ensure you've set the context before calling into any Client API.
Content:
Properties:
Static methods:
Creation methods:
Methods:
- public bool call (string method, Variant? @params, Cancellable? cancellable, out Variant? return_value) throws Error
Synchronously calls method with params on
the remote peer.
- public async bool call_async (string method, Variant? @params, Cancellable? cancellable, out Variant? return_value) throws Error
Asynchronously calls method with params on
the remote peer.
- public async bool call_with_id_async (string method, Variant? @params, unowned Variant* id, Cancellable? cancellable, out Variant? return_value) throws Error
Asynchronously calls method with params on
the remote peer.
- public bool close (Cancellable? cancellable = null) throws Error
Closes the underlying streams and cancels any inflight operations of
the Client.
- public async bool close_async (Cancellable? cancellable) throws Error
Asynchronous version of [method@Client.
- public bool get_use_gvariant ()
Gets the [property@Client:use-gvariant] property.
- public bool reply (Variant id, Variant? result, Cancellable? cancellable = null) throws Error
Synchronous variant of [method@Client.
- public async bool reply_async (Variant id, Variant result, Cancellable? cancellable) throws Error
- public async bool reply_error_async (Variant id, int code, string? message, Cancellable? cancellable) throws Error
Asynchronously replies to the peer, sending a JSON-RPC error message.
- public bool send_notification (string method, Variant? @params, Cancellable? cancellable = null) throws Error
Synchronously calls method with params on
the remote peer.
- public async bool send_notification_async (string method, Variant? @params, Cancellable? cancellable) throws Error
Asynchronously calls method with params on
the remote peer.
- public void set_use_gvariant (bool use_gvariant)
Sets the [property@Client:use-gvariant] property.
- public void start_listening ()
This function requests that client start processing incoming messages
from the peer.
Signals:
- public virtual signal void failed ()
The "failed" signal is called when the client has failed communication
or the connection has been knowingly closed.
- public virtual signal bool handle_call (string method, Variant id, Variant? @params)
This signal is emitted when an RPC has been received from the peer we
are connected to.
- public virtual signal void notification (string method_name, Variant? @params)
This signal is emitted when a notification has been received from a
peer.
Inherited Members:
All known members inherited from class GLib.Object