JsonrpcServer: Jsonrpc-GLib Reference Manual

## JsonrpcServer JsonrpcServer — A server for JSON-RPC communication |

## Functions

void | (*JsonrpcServerHandler) ()
JsonrpcServer * | jsonrpc_server_new ()
void | jsonrpc_server_accept_io_stream ()
guint | jsonrpc_server_add_handler ()
void | jsonrpc_server_remove_handler ()
void | jsonrpc_server_foreach ()

## Signals

void | client-accepted | Run Last
void | client-closed | Run Last
gboolean | handle-call | Run Last
void | notification | Run Last

## Types and Values

#define | JSONRPC_TYPE_SERVER
struct | JsonrpcServerClass
| JsonrpcServer

## Object Hierarchy

        GObject
        ╰── JsonrpcServer

## Description

The JsonrpcServer class can help you implement a JSON-RPC server. You can accept connections and then communicate with clients using the JsonrpcClient API.

## Functions

### JsonrpcServerHandler ()

    void
    (*JsonrpcServerHandler) (JsonrpcServer *self,
                             JsonrpcClient *client,
                             const gchar *method,
                             GVariant *id,
                             GVariant *params,
                             gpointer user_data);

### jsonrpc_server_new ()

    JsonrpcServer *
    jsonrpc_server_new (void);

Creates a new JsonrpcServer.

#### Returns

A newly created JsonrpcServer instance.

[transfer full]

Since: 3.26

### jsonrpc_server_accept_io_stream ()

    void
    jsonrpc_server_accept_io_stream (JsonrpcServer *self,
                                     GIOStream *io_stream);

This function accepts `io_stream` as a new client to the JsonrpcServer by wrapping it in a JsonrpcClient and starting the message accept loop.

#### Parameters

self | a JsonrpcServer |
io_stream | A GIOStream |

Since: 3.26

### jsonrpc_server_add_handler ()

    guint
    jsonrpc_server_add_handler (JsonrpcServer *self,
                                const gchar *method,
                                JsonrpcServerHandler handler,
                                gpointer handler_data,
                                GDestroyNotify handler_data_destroy);

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

#### Parameters

self | A JsonrpcServer |
method | A method to handle |
handler | A handler to execute when an incoming method matches `methods` . | [closure handler_data][destroy handler_data_destroy]
handler_data | user data for `handler` |
handler_data_destroy | a destroy callback for `handler_data` |

#### Returns

A handler id that can be used to remove the handler with `jsonrpc_server_remove_handler()`.

Since: 3.26

### jsonrpc_server_remove_handler ()

    void
    jsonrpc_server_remove_handler (JsonrpcServer *self,
                                   guint handler_id);

Removes a handler that was previously registered with `jsonrpc_server_add_handler()`.

#### Parameters

self | a JsonrpcServer |
handler_id | a handler returned from `jsonrpc_server_add_handler()` |

Since: 3.26

### jsonrpc_server_foreach ()

    void
    jsonrpc_server_foreach (JsonrpcServer *self,
                            GFunc foreach_func,
                            gpointer user_data);

Calls `foreach_func` for every client connected.

#### Parameters

self | a JsonrpcServer |
foreach_func | a callback for each client. | [scope call]
user_data | closure data for `foreach_func` |

Since: 3.28

## Types and Values

### JSONRPC_TYPE_SERVER

    #define JSONRPC_TYPE_SERVER (jsonrpc_server_get_type())

### struct JsonrpcServerClass

    struct JsonrpcServerClass {
      GObjectClass parent_class;

      gboolean (*handle_call)     (JsonrpcServer *self,
                                   JsonrpcClient *client,
                                   const gchar   *method,
                                   GVariant      *id,
                                   GVariant      *params);
      void     (*notification)    (JsonrpcServer *self,
                                   JsonrpcClient *client,
                                   const gchar   *method,
                                   GVariant      *params);
      void     (*client_accepted) (JsonrpcServer *self,
                                   JsonrpcClient *client);
      void     (*client_closed)   (JsonrpcServer *self,
                                   JsonrpcClient *client);
    };

### JsonrpcServer

    typedef struct _JsonrpcServer JsonrpcServer;

## Signal Details

### The `“client-accepted”` signal

    void
    user_function (JsonrpcServer *self,
                   JsonrpcClient *client,
                   gpointer       user_data)

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

#### Parameters

self | A JsonrpcServer |
client | A JsonrpcClient |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 3.28

### The `“client-closed”` signal

    void
    user_function (JsonrpcServer *self,
                   JsonrpcClient *client,
                   gpointer       user_data)

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

#### Parameters

self | A JsonrpcServer |
client | A JsonrpcClient |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 3.30

### The `“handle-call”` signal

    gboolean
    user_function (JsonrpcServer *self,
                   JsonrpcClient *client,
                   gchar         *method,
                   GVariant      *id,
                   GVariant      *params,
                   gpointer       user_data)

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 `jsonrpc_client_reply()` or `jsonrpc_client_reply_async()`.

#### Parameters

self | a JsonrpcServer |
client | a JsonrpcClient |
method | the method that was called |
id | the identifier of the method call |
params | the parameters of the method call |
user_data | user data set when the signal handler was connected. |

#### Returns

`TRUE` if the request was handled.

Flags: Run Last

Since: 3.26

### The `“notification”` signal

    void
    user_function (JsonrpcServer *self,
                   JsonrpcClient *client,
                   gchar         *method,
                   GVariant      *id,
                   gpointer       user_data)

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

#### Parameters

self | A JsonrpcServer |
client | A JsonrpcClient |
method | the notification name |
id | the params for the notification |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 3.26