mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 13:58:58 -04:00
move some structure definitions from evrpc.h to evrpc-internal.h
svn:r817
This commit is contained in:
parent
1bce6f7434
commit
aa4b92574b
@ -30,6 +30,7 @@
|
||||
#include "http-internal.h"
|
||||
|
||||
struct evrpc;
|
||||
struct evrpc_request_wrapper;
|
||||
|
||||
#define EVRPC_URI_PREFIX "/.rpc."
|
||||
|
||||
@ -125,4 +126,79 @@ static struct evrpc_hook_meta *evrpc_hook_meta_new(void);
|
||||
/* frees the meta data associated with a request */
|
||||
static void evrpc_hook_context_free(struct evrpc_hook_meta *ctx);
|
||||
|
||||
/* the server side of an rpc */
|
||||
|
||||
/* We alias the RPC specific structs to this voided one */
|
||||
struct evrpc_req_generic {
|
||||
/*
|
||||
* allows association of meta data via hooks - needs to be
|
||||
* synchronized with evrpc_request_wrapper
|
||||
*/
|
||||
struct evrpc_hook_meta *hook_meta;
|
||||
|
||||
/* the unmarshaled request object */
|
||||
void *request;
|
||||
|
||||
/* the empty reply object that needs to be filled in */
|
||||
void *reply;
|
||||
|
||||
/*
|
||||
* the static structure for this rpc; that can be used to
|
||||
* automatically unmarshal and marshal the http buffers.
|
||||
*/
|
||||
struct evrpc *rpc;
|
||||
|
||||
/*
|
||||
* the http request structure on which we need to answer.
|
||||
*/
|
||||
struct evhttp_request* http_req;
|
||||
|
||||
/*
|
||||
* Temporary data store for marshaled data
|
||||
*/
|
||||
struct evbuffer* rpc_data;
|
||||
};
|
||||
|
||||
/* the client side of an rpc request */
|
||||
struct evrpc_request_wrapper {
|
||||
/*
|
||||
* allows association of meta data via hooks - needs to be
|
||||
* synchronized with evrpc_req_generic.
|
||||
*/
|
||||
struct evrpc_hook_meta *hook_meta;
|
||||
|
||||
TAILQ_ENTRY(evrpc_request_wrapper) next;
|
||||
|
||||
/* pool on which this rpc request is being made */
|
||||
struct evrpc_pool *pool;
|
||||
|
||||
/* connection on which the request is being sent */
|
||||
struct evhttp_connection *evcon;
|
||||
|
||||
/* the actual request */
|
||||
struct evhttp_request *req;
|
||||
|
||||
/* event for implementing request timeouts */
|
||||
struct event ev_timeout;
|
||||
|
||||
/* the name of the rpc */
|
||||
char *name;
|
||||
|
||||
/* callback */
|
||||
void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg);
|
||||
void *cb_arg;
|
||||
|
||||
void *request;
|
||||
void *reply;
|
||||
|
||||
/* unmarshals the buffer into the proper request structure */
|
||||
void (*request_marshal)(struct evbuffer *, void *);
|
||||
|
||||
/* removes all stored state in the reply */
|
||||
void (*reply_clear)(void *);
|
||||
|
||||
/* marshals the reply into a buffer */
|
||||
int (*reply_unmarshal)(void *, struct evbuffer*);
|
||||
};
|
||||
|
||||
#endif /* _EVRPC_INTERNAL_H_ */
|
||||
|
25
evrpc.c
25
evrpc.c
@ -189,7 +189,6 @@ evrpc_process_hooks(struct evrpc_hook_list *head, void *ctx,
|
||||
|
||||
static void evrpc_pool_schedule(struct evrpc_pool *pool);
|
||||
static void evrpc_request_cb(struct evhttp_request *, void *);
|
||||
void evrpc_request_done(struct evrpc_req_generic*);
|
||||
|
||||
/*
|
||||
* Registers a new RPC with the HTTP server. The evrpc object is expected
|
||||
@ -286,7 +285,6 @@ evrpc_request_cb(struct evhttp_request *req, void *arg)
|
||||
rpc_state->rpc = rpc;
|
||||
rpc_state->http_req = req;
|
||||
rpc_state->rpc_data = NULL;
|
||||
rpc_state->done = evrpc_request_done;
|
||||
|
||||
if (TAILQ_FIRST(&rpc->base->input_hooks) != NULL) {
|
||||
int hook_res;
|
||||
@ -1037,3 +1035,26 @@ evrpc_hook_get_connection(void *ctx)
|
||||
struct evrpc_request_wrapper *req = ctx;
|
||||
return (req->hook_meta != NULL ? req->hook_meta->evcon : NULL);
|
||||
}
|
||||
|
||||
/** accessors for obscure and undocumented functionality */
|
||||
struct evrpc_pool *
|
||||
evrpc_request_get_pool(struct evrpc_request_wrapper *ctx)
|
||||
{
|
||||
return (ctx->pool);
|
||||
}
|
||||
|
||||
void
|
||||
evrpc_request_set_pool(struct evrpc_request_wrapper *ctx,
|
||||
struct evrpc_pool *pool)
|
||||
{
|
||||
ctx->pool = pool;
|
||||
}
|
||||
|
||||
void
|
||||
evrpc_request_set_cb(struct evrpc_request_wrapper *ctx,
|
||||
void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg),
|
||||
void *cb_arg)
|
||||
{
|
||||
ctx->cb = cb;
|
||||
ctx->cb_arg = cb_arg;
|
||||
}
|
||||
|
94
evrpc.h
94
evrpc.h
@ -71,6 +71,7 @@ extern "C" {
|
||||
struct evbuffer;
|
||||
struct event_base;
|
||||
struct evrpc_req_generic;
|
||||
struct evrpc_request_wrapper;
|
||||
|
||||
/* Encapsulates a request */
|
||||
struct evrpc {
|
||||
@ -118,41 +119,7 @@ struct evhttp_request;
|
||||
struct evrpc_status;
|
||||
struct evrpc_hook_meta;
|
||||
|
||||
/* We alias the RPC specific structs to this voided one */
|
||||
struct evrpc_req_generic {
|
||||
/*
|
||||
* allows association of meta data via hooks - needs to be
|
||||
* synchronized with evrpc_request_wrapper
|
||||
*/
|
||||
struct evrpc_hook_meta *hook_meta;
|
||||
|
||||
/* the unmarshaled request object */
|
||||
void *request;
|
||||
|
||||
/* the empty reply object that needs to be filled in */
|
||||
void *reply;
|
||||
|
||||
/*
|
||||
* the static structure for this rpc; that can be used to
|
||||
* automatically unmarshal and marshal the http buffers.
|
||||
*/
|
||||
struct evrpc *rpc;
|
||||
|
||||
/*
|
||||
* the http request structure on which we need to answer.
|
||||
*/
|
||||
struct evhttp_request* http_req;
|
||||
|
||||
/*
|
||||
* Temporary data store for marshaled data
|
||||
*/
|
||||
struct evbuffer* rpc_data;
|
||||
|
||||
/*
|
||||
* callback to reply and finish answering this rpc
|
||||
*/
|
||||
void (*done)(struct evrpc_req_generic* rpc);
|
||||
};
|
||||
/* the structure below needs to be synchornized with evrpc_req_generic */
|
||||
|
||||
/** Creates the definitions and prototypes for an RPC
|
||||
*
|
||||
@ -173,8 +140,6 @@ EVRPC_STRUCT(rpcname) { \
|
||||
struct evrpc* rpc; \
|
||||
struct evhttp_request* http_req; \
|
||||
struct evbuffer* rpc_data; \
|
||||
void (*done)(struct evrpc_status *, \
|
||||
struct evrpc* rpc, void *request, void *reply); \
|
||||
}; \
|
||||
int evrpc_send_request_##rpcname(struct evrpc_pool *, \
|
||||
struct reqstruct *, struct rplystruct *, \
|
||||
@ -264,6 +229,9 @@ error: \
|
||||
*/
|
||||
#define EVRPC_REQUEST_HTTP(rpc_req) (rpc_req)->http_req
|
||||
|
||||
/** completes the server response to an rpc request */
|
||||
void evrpc_request_done(struct evrpc_req_generic *req);
|
||||
|
||||
/** Creates the reply to an RPC request
|
||||
*
|
||||
* EVRPC_REQUEST_DONE is used to answer a request; the reply is expected
|
||||
@ -274,7 +242,7 @@ error: \
|
||||
*/
|
||||
#define EVRPC_REQUEST_DONE(rpc_req) do { \
|
||||
struct evrpc_req_generic *_req = (struct evrpc_req_generic *)(rpc_req); \
|
||||
_req->done(_req); \
|
||||
evrpc_request_done(_req); \
|
||||
} while (0)
|
||||
|
||||
|
||||
@ -378,47 +346,6 @@ struct evrpc_status {
|
||||
struct evhttp_request *http_req;
|
||||
};
|
||||
|
||||
struct evrpc_request_wrapper {
|
||||
/*
|
||||
* allows association of meta data via hooks - needs to be
|
||||
* synchronized with evrpc_req_generic.
|
||||
*/
|
||||
struct evrpc_hook_meta *hook_meta;
|
||||
|
||||
TAILQ_ENTRY(evrpc_request_wrapper) next;
|
||||
|
||||
/* pool on which this rpc request is being made */
|
||||
struct evrpc_pool *pool;
|
||||
|
||||
/* connection on which the request is being sent */
|
||||
struct evhttp_connection *evcon;
|
||||
|
||||
/* the actual request */
|
||||
struct evhttp_request *req;
|
||||
|
||||
/* event for implementing request timeouts */
|
||||
struct event ev_timeout;
|
||||
|
||||
/* the name of the rpc */
|
||||
char *name;
|
||||
|
||||
/* callback */
|
||||
void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg);
|
||||
void *cb_arg;
|
||||
|
||||
void *request;
|
||||
void *reply;
|
||||
|
||||
/* unmarshals the buffer into the proper request structure */
|
||||
void (*request_marshal)(struct evbuffer *, void *);
|
||||
|
||||
/* removes all stored state in the reply */
|
||||
void (*reply_clear)(void *);
|
||||
|
||||
/* marshals the reply into a buffer */
|
||||
int (*reply_unmarshal)(void *, struct evbuffer*);
|
||||
};
|
||||
|
||||
/** launches an RPC and sends it to the server
|
||||
*
|
||||
* EVRPC_MAKE_REQUEST() is used by the client to send an RPC to the server.
|
||||
@ -590,6 +517,15 @@ int evrpc_hook_find_meta(void *ctx, const char *key,
|
||||
* @return a pointer to the evhttp_connection object
|
||||
*/
|
||||
struct evhttp_connection *evrpc_hook_get_connection(void *ctx);
|
||||
|
||||
/** accessors for obscure and undocumented functionality */
|
||||
struct evrpc_pool* evrpc_request_get_pool(struct evrpc_request_wrapper *ctx);
|
||||
void evrpc_request_set_pool(struct evrpc_request_wrapper *ctx,
|
||||
struct evrpc_pool *pool);
|
||||
void evrpc_request_set_cb(struct evrpc_request_wrapper *ctx,
|
||||
void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg),
|
||||
void *cb_arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user