### Class

# Jsonrpc Client

since: 3.26

#### Description [src]

    class Jsonrpc.Client : GObject.Object {
      parent_instance: GObject
    }

A client for JSON-RPC communication

The `JsonrpcClient` class provides a convenient API to coordinate with a JSON-RPC server. You can provide the underlying `GIOStream` to communicate with allowing you to control the negotiation of how you setup your communications channel. One such method might be to use a `GSubprocess` 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 `jsonrpc_client_close()` or `jsonrpc_client_close_async()` when they no longer need the client. This is because `JsonrpcClient` contains an asynchronous read-loop to process incoming messages. Until `jsonrpc_client_close()` or `jsonrpc_client_close_async()` have been called, this read loop will prevent the object from finalizing (being freed).

To make an RPC call, use `jsonrpc_client_call()` or `jsonrpc_client_call_async()` and provide the method name and the parameters as a `GVariant` for call.

It is a programming error to mix synchronous and asynchronous API calls of the `JsonrpcClient` class.

For synchronous calls, `JsonrpcClient` will use the thread-default `GMainContext`. If you have special needs here ensure you’ve set the context before calling into any `JsonrpcClient` API.

Available since: 3.26

#### Hierarchy

#### Ancestors

- GObject

#### Constructors

###### jsonrpc_client_new

Creates a new `JsonrpcClient` instance.

since: 3.26

#### Functions

###### jsonrpc_client_error_quark

No description available.

#### Instance methods

###### jsonrpc_client_call

Synchronously calls `method` with `params` on the remote peer.

since: 3.26

###### jsonrpc_client_call_async

Asynchronously calls `method` with `params` on the remote peer.

since: 3.26

###### jsonrpc_client_call_finish

Completes an asynchronous call to `jsonrpc_client_call_async()`.

since: 3.26

###### jsonrpc_client_call_with_id_async

Asynchronously calls `method` with `params` on the remote peer.

since: 3.30

###### jsonrpc_client_close

Closes the underlying streams and cancels any inflight operations of the `JsonrpcClient`.

since: 3.26

###### jsonrpc_client_close_async

Asynchronous version of `jsonrpc_client_close()`.

since: 3.26

###### jsonrpc_client_close_finish

Completes an asynchronous request of `jsonrpc_client_close_async()`.

since: 3.26

###### jsonrpc_client_get_use_gvariant

Gets the `JsonrpcClient:use-gvariant` property.

since: 3.26

###### jsonrpc_client_reply

Synchronous variant of `jsonrpc_client_reply_async()`.

since: 3.26

###### jsonrpc_client_reply_async

No description available.

###### jsonrpc_client_reply_error_async

Asynchronously replies to the peer, sending a JSON-RPC error message.

since: 3.28

###### jsonrpc_client_reply_error_finish

No description available.

###### jsonrpc_client_reply_finish

Completes an asynchronous request to `jsonrpc_client_reply_async()`.

since: 3.26

###### jsonrpc_client_send_notification

Synchronously calls `method` with `params` on the remote peer.

since: 3.26

###### jsonrpc_client_send_notification_async

Asynchronously calls `method` with `params` on the remote peer.

since: 3.26

###### jsonrpc_client_send_notification_finish

Completes an asynchronous call to `jsonrpc_client_send_notification_async()`.

since: 3.26

###### jsonrpc_client_set_use_gvariant

Sets the `JsonrpcClient:use-gvariant` property.

since: 3.26

###### jsonrpc_client_start_listening

This function requests that client start processing incoming messages from the peer.

since: 3.26

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Jsonrpc.Client:io-stream

The “io-stream” property is the `GIOStream` to use for communicating with a JSON-RPC peer.

since: 3.26

###### Jsonrpc.Client:use-gvariant

The “use-gvariant” property denotes if `GVariant` should be used to communicate with the peer instead of JSON. You should only set this if you know the peer is also a Jsonrpc-GLib based client.

since: 3.26

#### Signals

###### Jsonrpc.Client::failed

The “failed” signal is called when the client has failed communication or the connection has been knowingly closed.

since: 3.28

###### Jsonrpc.Client::handle-call

This signal is emitted when an RPC has been received from the peer we are connected to. Return `TRUE` if you have handled this message, even asynchronously. If no handler has returned `TRUE` an error will be synthesized.

since: 3.26

###### Jsonrpc.Client::notification

This signal is emitted when a notification has been received from a peer. Unlike `JsonrpcClient::handle-call`, this does not have an “id” parameter because notifications do not have ids. They do not round trip.

since: 3.26

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct JsonrpcClientClass {
      GObjectClass parent_class;
      void (* notification) (
        JsonrpcClient* self,
        const gchar* method_name,
        GVariant* params
      );
      gboolean (* handle_call) (
        JsonrpcClient* self,
        const gchar* method,
        GVariant* id,
        GVariant* params
      );
      void (* failed) (
        JsonrpcClient* self
      );
      gpointer _reserved2;
      gpointer _reserved3;
      gpointer _reserved4;
      gpointer _reserved5;
      gpointer _reserved6;
      gpointer _reserved7;
      gpointer _reserved8;

    }

No description available.

###### Class members

`parent_class: GObjectClass`
  No description available.
`notification: void (* notification) ( JsonrpcClient* self, const gchar* method_name, GVariant* params )`
  No description available.
`handle_call: gboolean (* handle_call) ( JsonrpcClient* self, const gchar* method, GVariant* id, GVariant* params )`
  No description available.
`failed: void (* failed) ( JsonrpcClient* self )`
  No description available.
`_reserved2: gpointer`
  No description available.
`_reserved3: gpointer`
  No description available.
`_reserved4: gpointer`
  No description available.
`_reserved5: gpointer`
  No description available.
`_reserved6: gpointer`
  No description available.
`_reserved7: gpointer`
  No description available.
`_reserved8: gpointer`
  No description available.

#### Virtual methods

###### Jsonrpc.ClientClass.failed

No description available.

###### Jsonrpc.ClientClass.handle_call

No description available.

###### Jsonrpc.ClientClass.notification

No description available.