Jsonrpc.Server

g GObject.Object GObject.Object Jsonrpc.Server Jsonrpc.Server GObject.Object->Jsonrpc.Server

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

accept_io_stream (io_stream)

add_handler (method, handler, *handler_data)

foreach (foreach_func, *user_data)

remove_handler (handler_id)

Virtual Methods

Inherited:

GObject.Object (7)

do_client_accepted (client)

do_client_closed (client)

do_handle_call (client, method, id, params)

do_notification (client, method, params)

Properties

None

Signals

Inherited:

GObject.Object (1)

Name

Short Description

client-accepted

This signal is emitted when a new client has been accepted.

client-closed

This signal is emitted when a new client has been lost.

handle-call

This method is emitted when the client requests a method call.

notification

This signal is emitted when the client has sent a notification to us.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Jsonrpc.Server(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Jsonrpc.ServerClass

A server for JSON-RPC communication

The Jsonrpc.Server class can help you implement a JSON-RPC server. You can accept connections and then communicate with clients using the [class`Client`] API.

classmethod new()
Returns:

A newly created Jsonrpc.Server instance.

Return type:

Jsonrpc.Server

Creates a new Jsonrpc.Server.

New in version 3.26.

accept_io_stream(io_stream)
Parameters:

io_stream (Gio.IOStream) – A Gio.IOStream

This function accepts io_stream as a new client to the Jsonrpc.Server by wrapping it in a Jsonrpc.Client and starting the message accept loop.

New in version 3.26.

add_handler(method, handler, *handler_data)
Parameters:
  • method (str) – A method to handle

  • handler (Jsonrpc.ServerHandler) – A handler to execute when an incoming method matches methods

  • handler_data (object or None) – User data for handler

Returns:

A handler id that can be used to remove the handler with [method`Server`.remove_handler].

Return type:

int

Adds a new handler that will be dispatched when a matching method arrives.

New in version 3.26.

foreach(foreach_func, *user_data)
Parameters:
  • foreach_func (GLib.Func) – A callback for each client

  • user_data (object or None) – Closure data for foreach_func

Calls foreach_func for every client connected.

New in version 3.28.

remove_handler(handler_id)
Parameters:

handler_id (int) – A handler returned from [method`Server`.add_handler]

Removes a handler that was previously registered with [method`Server`.add_handler].

New in version 3.26.

do_client_accepted(client) virtual
Parameters:

client (Jsonrpc.Client) –

do_client_closed(client) virtual
Parameters:

client (Jsonrpc.Client) –

do_handle_call(client, method, id, params) virtual
Parameters:
Return type:

bool

do_notification(client, method, params) virtual
Parameters:

Signal Details

Jsonrpc.Server.signals.client_accepted(server, client)
Signal Name:

client-accepted

Flags:

RUN_LAST

Parameters:

This signal is emitted when a new client has been accepted.

New in version 3.28.

Jsonrpc.Server.signals.client_closed(server, client)
Signal Name:

client-closed

Flags:

RUN_LAST

Parameters:

This signal is emitted when a new client has been lost.

New in version 3.30.

Jsonrpc.Server.signals.handle_call(server, client, method, id, params)
Signal Name:

handle-call

Flags:

RUN_LAST

Parameters:
Returns:

True if the request was handled.

Return type:

bool

This method is emitted when the client requests a method call.

If you return True from this function, you should reply to it (even upon failure), using [method`Client`.reply] or [method`Client`.reply_async].

New in version 3.26.

Jsonrpc.Server.signals.notification(server, client, method, id)
Signal Name:

notification

Flags:

RUN_LAST

Parameters:

This signal is emitted when the client has sent a notification to us.

New in version 3.26.