mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
chore: cleanup jsonrpc library
This commit is contained in:
14
include/jsonrpc.h
Normal file
14
include/jsonrpc.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef JSONRPC_H
|
||||
#define JSONRPC_H
|
||||
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jsonrpc/method_invoke_fn.h>
|
||||
#include <jsonrpc/proxy.h>
|
||||
#include <jsonrpc/proxy_finished_fn.h>
|
||||
#include <jsonrpc/request.h>
|
||||
#include <jsonrpc/response.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/server.h>
|
||||
#include <jsonrpc/status.h>
|
||||
|
||||
#endif
|
||||
8
include/jsonrpc/api.h
Normal file
8
include/jsonrpc/api.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef JSONRPC_API_H
|
||||
#define JSONRPC_API_H
|
||||
|
||||
#ifndef JSONRPC_API
|
||||
#define JSONRPC_API
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef JSONRPC_METHOD_H
|
||||
#define JSONRPC_METHOD_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
typedef void jsonrpc_method_invoke_fn(
|
||||
struct jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data);
|
||||
|
||||
struct jsonrpc_method
|
||||
{
|
||||
struct jsonrpc_method * next;
|
||||
char * name;
|
||||
jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct jsonrpc_method * jsonrpc_method_create(
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_method_dispose(
|
||||
struct jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
26
include/jsonrpc/method_invoke_fn.h
Normal file
26
include/jsonrpc/method_invoke_fn.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef JSONRPC_METHOD_INVOKE_FN_H
|
||||
#define JSONRPC_METHOD_INVOKE_FN_H
|
||||
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
typedef void jsonrpc_method_invoke_fn(
|
||||
struct jsonrpc_request * request,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
void * user_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,10 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/proxy_finished_fn.h>
|
||||
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
|
||||
@@ -20,40 +23,20 @@ using std::size_t;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
struct jsonrpc_proxy;
|
||||
|
||||
|
||||
struct jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
jsonrpc_proxy_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_impl_timer timer;
|
||||
};
|
||||
|
||||
struct jsonrpc_proxy
|
||||
{
|
||||
struct jsonrpc_request request;
|
||||
int timeout;
|
||||
jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void jsonrpc_proxy_init(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
extern JSONRPC_API struct jsonrpc_proxy *
|
||||
jsonrpc_proxy_create(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
int timeout,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_proxy_cleanup(
|
||||
extern JSONRPC_API void jsonrpc_proxy_dispose(
|
||||
struct jsonrpc_proxy * proxy);
|
||||
|
||||
extern void jsonrpc_proxy_invoke(
|
||||
|
||||
extern JSONRPC_API void jsonrpc_proxy_invoke(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
jsonrpc_proxy_finished_fn * finished,
|
||||
void * user_data,
|
||||
@@ -62,14 +45,14 @@ extern void jsonrpc_proxy_invoke(
|
||||
...
|
||||
);
|
||||
|
||||
extern void jsonrpc_proxy_notify(
|
||||
extern JSONRPC_API void jsonrpc_proxy_notify(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void jsonrpc_proxy_onresult(
|
||||
extern JSONRPC_API void jsonrpc_proxy_onresult(
|
||||
struct jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
|
||||
|
||||
20
include/jsonrpc/proxy_finished_fn.h
Normal file
20
include/jsonrpc/proxy_finished_fn.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef JSONRPC_PROXY_FINISHED_FN_H
|
||||
#define JSONRPC_PROXY_FINISHED_FN_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,7 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
#include <jsonrpc/api.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -22,27 +22,28 @@ extern "C"
|
||||
|
||||
struct jsonrpc_request;
|
||||
|
||||
extern bool jsonrpc_is_request(
|
||||
extern JSONRPC_API bool jsonrpc_is_request(
|
||||
json_t * message);
|
||||
|
||||
extern struct jsonrpc_request * jsonrpc_request_create(
|
||||
extern JSONRPC_API struct jsonrpc_request * jsonrpc_request_create(
|
||||
int id,
|
||||
jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_request_dispose(
|
||||
extern JSONRPC_API void jsonrpc_request_dispose(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void * jsonrpc_request_get_userdata(
|
||||
extern JSONRPC_API void * jsonrpc_request_get_userdata(
|
||||
struct jsonrpc_request * request);
|
||||
|
||||
extern void jsonrpc_respond(
|
||||
extern JSONRPC_API void jsonrpc_respond(
|
||||
struct jsonrpc_request * request,
|
||||
json_t * result);
|
||||
|
||||
extern void jsonrpc_respond_error(
|
||||
extern JSONRPC_API void jsonrpc_respond_error(
|
||||
struct jsonrpc_request * request,
|
||||
wf_status status);
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,40 +1,23 @@
|
||||
#ifndef WF_JSONRPC_RESPONSE_H
|
||||
#define WF_JSONRPC_RESPONSE_H
|
||||
#ifndef JSONRPC_RESPONSE_H
|
||||
#define JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <jsonrpc/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_response
|
||||
{
|
||||
json_t * result;
|
||||
json_t * error;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern bool jsonrpc_is_response(
|
||||
extern JSONRPC_API bool jsonrpc_is_response(
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_response_init(
|
||||
struct jsonrpc_response * response,
|
||||
json_t * message);
|
||||
|
||||
extern void jsonrpc_response_cleanup(
|
||||
struct jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include <jsonrpc/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
||||
@@ -9,32 +9,31 @@
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "jsonrpc/send_fn.h"
|
||||
#include "jsonrpc/method.h"
|
||||
#include <jsonrpc/api.h>
|
||||
#include <jsonrpc/send_fn.h>
|
||||
#include <jsonrpc/method_invoke_fn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct jsonrpc_server
|
||||
{
|
||||
struct jsonrpc_method * methods;
|
||||
};
|
||||
struct jsonrpc_server;
|
||||
|
||||
extern void jsonrpc_server_init(
|
||||
extern JSONRPC_API struct jsonrpc_server *
|
||||
jsonrpc_server_create(void);
|
||||
|
||||
extern JSONRPC_API void
|
||||
jsonrpc_server_dispose(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern void jsonrpc_server_cleanup(
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern void jsonrpc_server_add(
|
||||
extern JSONRPC_API void jsonrpc_server_add(
|
||||
struct jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void jsonrpc_server_process(
|
||||
extern JSONRPC_API void jsonrpc_server_process(
|
||||
struct jsonrpc_server * server,
|
||||
json_t * request,
|
||||
jsonrpc_send_fn * send,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#define JSONRPC_GOOD 0
|
||||
#define JSONRPC_BAD -1
|
||||
#define JSONRPC_BAD_NOTIMPLEMENTED -2
|
||||
#define JSONRPC_BAD_TIMEOUT -3
|
||||
#define JSONRPC_BAD_BUSY -4
|
||||
#define JSONRPC_BAD_FORMAT -5
|
||||
|
||||
Reference in New Issue
Block a user