mjsonrpc 1.0
A lightweight JSON-RPC 2.0 message parser and generator based on cJSON
Loading...
Searching...
No Matches
Functions
Method Management Functions

Functions for registering and unregistering RPC methods. More...

Functions

int mjrpc_add_method (mjrpc_handle_t *handle, mjrpc_func function_pointer, const char *method_name, void *arg2func)
 Register a new RPC method.
 
int mjrpc_del_method (mjrpc_handle_t *handle, const char *method_name)
 Unregister an RPC method.
 

Detailed Description

Functions for registering and unregistering RPC methods.

Function Documentation

◆ mjrpc_add_method()

int mjrpc_add_method ( mjrpc_handle_t handle,
mjrpc_func  function_pointer,
const char *  method_name,
void *  arg2func 
)

Register a new RPC method.

Adds a new method to the JSON-RPC handle with the specified callback function, method name, and optional user argument.

Parameters
handleJSON-RPC handle (must not be NULL)
function_pointerCallback function for the method (must not be NULL)
method_nameName of the method (must not be NULL)
arg2funcUser argument passed to the callback function (can be NULL)
Returns
Error code from enum mjrpc_error_return
Return values
MJRPC_RET_OKIf successful
MJRPC_RET_ERROR_HANDLE_NOT_INITIALIZEDIf handle is NULL
MJRPC_RET_ERROR_INVALID_PARAMIf function_pointer or method_name is NULL
MJRPC_RET_ERROR_MEM_ALLOC_FAILEDIf memory allocation failed
Note
If a method with the same name already exists, it will be replaced
The method_name will be copied internally
Example:
cJSON *hello_method(mjrpc_func_ctx_t *ctx, cJSON *params, cJSON *id) {
return cJSON_CreateString("Hello, World!");
}
int ret = mjrpc_add_method(handle, hello_method, "hello", NULL);
if (ret != MJRPC_RET_OK) {
// Handle error...
}
mjrpc_handle_t * mjrpc_create_handle(size_t initial_capacity)
Create a new JSON-RPC handle.
int mjrpc_add_method(mjrpc_handle_t *handle, mjrpc_func function_pointer, const char *method_name, void *arg2func)
Register a new RPC method.
@ MJRPC_RET_OK
Operation completed successfully.
Definition mjsonrpc.h:87
Context structure passed to RPC method callback functions.
Definition mjsonrpc.h:122
Main handle structure for managing RPC methods.
Definition mjsonrpc.h:175

◆ mjrpc_del_method()

int mjrpc_del_method ( mjrpc_handle_t handle,
const char *  method_name 
)

Unregister an RPC method.

Removes the specified method from the JSON-RPC handle and frees associated memory.

Parameters
handleJSON-RPC handle (must not be NULL)
method_nameName of the method to remove (must not be NULL)
Returns
Error code from enum mjrpc_error_return
Return values
MJRPC_RET_OKIf successful
MJRPC_RET_ERROR_INVALID_PARAMIf method_name is NULL
MJRPC_RET_ERROR_NOT_FOUNDIf method was not found
Example:
int ret = mjrpc_del_method(handle, "hello");
printf("Method 'hello' not found\n");
}
int mjrpc_del_method(mjrpc_handle_t *handle, const char *method_name)
Unregister an RPC method.
@ MJRPC_RET_ERROR_NOT_FOUND
Requested method not found.
Definition mjsonrpc.h:96