mongoose/src/rpc.h

26 lines
1.0 KiB
C
Raw Normal View History

2022-07-27 00:46:05 +01:00
#pragma once
2022-07-28 10:18:17 +01:00
#include "fmt.h"
2022-07-27 00:46:05 +01:00
#include "json.h"
// JSON-RPC request descriptor
struct mg_rpc_req {
2022-07-30 07:55:26 +01:00
void **head; // List of all RPC handlers
2022-07-27 00:46:05 +01:00
mg_pfn_t pfn; // Response printing function
void *pfn_data; // Response printing function data
2022-07-30 07:55:26 +01:00
void *handler_data; // Endpoint handler data
void *process_data; // Arbitrary user data
struct mg_str frame; // Request, e.g. {"id":1,"method":"add","params":[1,2]}
2022-07-27 00:46:05 +01:00
};
void mg_rpc_add(void **head, struct mg_str method_pattern,
void (*handler)(struct mg_rpc_req *), void *handler_data);
2022-07-30 21:13:30 +01:00
void mg_rpc_del(void **head, void (*handler)(struct mg_rpc_req *));
2022-07-30 07:55:26 +01:00
void mg_rpc_process(struct mg_rpc_req *);
2022-07-27 00:46:05 +01:00
// Helper functions to print result or error frame
void mg_rpc_ok(struct mg_rpc_req *, const char *fmt, ...);
void mg_rpc_vok(struct mg_rpc_req *, const char *fmt, va_list *ap);
void mg_rpc_err(struct mg_rpc_req *, int code, const char *fmt, ...);
void mg_rpc_verr(struct mg_rpc_req *, int code, const char *fmt, va_list *);
void mg_rpc_list(struct mg_rpc_req *r);