75 TAILQ_ENTRY(
evrpc) next;
81 void *(*request_new)(void);
84 void (*request_free)(
void *);
87 int (*request_unmarshal)(
void *,
struct evbuffer *);
90 void *(*reply_new)(void);
93 void (*reply_free)(
void *);
96 int (*reply_complete)(
void *);
99 void (*reply_marshal)(
struct evbuffer*,
void *);
113 #define EVRPC_STRUCT(rpcname) struct evrpc_req__##rpcname
154 #define EVRPC_HEADER(rpcname, reqstruct, rplystruct) \
155 EVRPC_STRUCT(rpcname) { \
156 struct reqstruct* request; \
157 struct rplystruct* reply; \
159 struct evhttp_request* http_req; \
160 void (*done)(struct evrpc_status *, \
161 struct evrpc* rpc, void *request, void *reply); \
163 int evrpc_send_request_##rpcname(struct evrpc_pool *, \
164 struct reqstruct *, struct rplystruct *, \
165 void (*)(struct evrpc_status *, \
166 struct reqstruct *, struct rplystruct *, void *cbarg), \
179 #define EVRPC_GENERATE(rpcname, reqstruct, rplystruct) \
180 int evrpc_send_request_##rpcname(struct evrpc_pool *pool, \
181 struct reqstruct *request, struct rplystruct *reply, \
182 void (*cb)(struct evrpc_status *, \
183 struct reqstruct *, struct rplystruct *, void *cbarg), \
185 struct evrpc_status status; \
186 struct evrpc_request_wrapper *ctx; \
187 ctx = (struct evrpc_request_wrapper *) \
188 malloc(sizeof(struct evrpc_request_wrapper)); \
193 ctx->name = strdup(#rpcname); \
194 if (ctx->name == NULL) { \
198 ctx->cb = (void (*)(struct evrpc_status *, \
199 void *, void *, void *))cb; \
200 ctx->cb_arg = cbarg; \
201 ctx->request = (void *)request; \
202 ctx->reply = (void *)reply; \
203 ctx->request_marshal = (void (*)(struct evbuffer *, void *))reqstruct##_marshal; \
204 ctx->reply_clear = (void (*)(void *))rplystruct##_clear; \
205 ctx->reply_unmarshal = (int (*)(void *, struct evbuffer *))rplystruct##_unmarshal; \
206 return (evrpc_make_request(ctx)); \
208 memset(&status, 0, sizeof(status)); \
209 status.error = EVRPC_STATUS_ERR_UNSTARTED; \
210 (*(cb))(&status, request, reply, cbarg); \
223 #define EVRPC_REQUEST_HTTP(rpc_req) (rpc_req)->http_req
233 #define EVRPC_REQUEST_DONE(rpc_req) do { \
234 struct evrpc_req_generic *_req = (struct evrpc_req_generic *)(rpc_req); \
240 #define EVRPC_REGISTER_OBJECT(rpc, name, request, reply) \
242 (rpc)->uri = strdup(#name); \
243 if ((rpc)->uri == NULL) { \
244 fprintf(stderr, "failed to register object\n"); \
247 (rpc)->request_new = (void *(*)(void))request##_new; \
248 (rpc)->request_free = (void (*)(void *))request##_free; \
249 (rpc)->request_unmarshal = (int (*)(void *, struct evbuffer *))request##_unmarshal; \
250 (rpc)->reply_new = (void *(*)(void))reply##_new; \
251 (rpc)->reply_free = (void (*)(void *))reply##_free; \
252 (rpc)->reply_complete = (int (*)(void *))reply##_complete; \
253 (rpc)->reply_marshal = (void (*)(struct evbuffer*, void *))reply##_marshal; \
295 #define EVRPC_REGISTER(base, name, request, reply, callback, cbarg) \
297 struct evrpc* rpc = (struct evrpc *)calloc(1, sizeof(struct evrpc)); \
298 EVRPC_REGISTER_OBJECT(rpc, name, request, reply); \
299 evrpc_register_rpc(base, rpc, \
300 (void (*)(struct evrpc_req_generic*, void *))callback, cbarg); \
314 #define EVRPC_UNREGISTER(base, name) evrpc_unregister_rpc(base, #name)
316 int evrpc_unregister_rpc(
struct evrpc_base *base,
const char *
name);
329 #define EVRPC_STATUS_ERR_NONE 0
330 #define EVRPC_STATUS_ERR_TIMEOUT 1
331 #define EVRPC_STATUS_ERR_BADPAYLOAD 2
332 #define EVRPC_STATUS_ERR_UNSTARTED 3
333 #define EVRPC_STATUS_ERR_HOOKABORTED 4
350 struct event ev_timeout;
363 void (*request_marshal)(
struct evbuffer *,
void *);
366 void (*reply_clear)(
void *);
369 int (*reply_unmarshal)(
void *,
struct evbuffer*);
387 #define EVRPC_MAKE_REQUEST(name, pool, request, reply, cb, cbarg) \
388 evrpc_send_request_##name(pool, request, reply, cb, cbarg)
408 void evrpc_pool_free(
struct evrpc_pool *pool);
413 void evrpc_pool_add_connection(
struct evrpc_pool *,
431 void evrpc_pool_set_timeout(
struct evrpc_pool *pool,
int timeout_in_secs);
446 #define INPUT EVRPC_INPUT
449 #define OUTPUT EVRPC_OUTPUT
465 void *evrpc_add_hook(
void *vbase,
478 int evrpc_remove_hook(
void *vbase,