rpc.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _EVENT2_RPC_H_
  28. #define _EVENT2_RPC_H_
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /** @file rpc.h
  33. *
  34. * This header files provides basic support for an RPC server and client.
  35. *
  36. * To support RPCs in a server, every supported RPC command needs to be
  37. * defined and registered.
  38. *
  39. * EVRPC_HEADER(SendCommand, Request, Reply);
  40. *
  41. * SendCommand is the name of the RPC command.
  42. * Request is the name of a structure generated by event_rpcgen.py.
  43. * It contains all parameters relating to the SendCommand RPC. The
  44. * server needs to fill in the Reply structure.
  45. * Reply is the name of a structure generated by event_rpcgen.py. It
  46. * contains the answer to the RPC.
  47. *
  48. * To register an RPC with an HTTP server, you need to first create an RPC
  49. * base with:
  50. *
  51. * struct evrpc_base *base = evrpc_init(http);
  52. *
  53. * A specific RPC can then be registered with
  54. *
  55. * EVRPC_REGISTER(base, SendCommand, Request, Reply, FunctionCB, arg);
  56. *
  57. * when the server receives an appropriately formatted RPC, the user callback
  58. * is invoked. The callback needs to fill in the reply structure.
  59. *
  60. * void FunctionCB(EVRPC_STRUCT(SendCommand)* rpc, void *arg);
  61. *
  62. * To send the reply, call EVRPC_REQUEST_DONE(rpc);
  63. *
  64. * See the regression test for an example.
  65. */
  66. /**
  67. Determines if the member has been set in the message
  68. @param msg the message to inspect
  69. @param member the member variable to test for presences
  70. @return 1 if it's present or 0 otherwise.
  71. */
  72. #define EVTAG_HAS(msg, member) \
  73. ((msg)->member##_set == 1)
  74. #ifndef _EVENT2_RPC_COMPAT_H_
  75. /**
  76. Assigns a value to the member in the message.
  77. @param msg the message to which to assign a value
  78. @param member the name of the member variable
  79. @param value the value to assign
  80. */
  81. #define EVTAG_ASSIGN(msg, member, value) \
  82. (*(msg)->base->member##_assign)((msg), (value))
  83. /**
  84. Assigns a value to the member in the message.
  85. @param msg the message to which to assign a value
  86. @param member the name of the member variable
  87. @param value the value to assign
  88. @param len the length of the value
  89. */
  90. #define EVTAG_ASSIGN_WITH_LEN(msg, member, value, len) \
  91. (*(msg)->base->member##_assign)((msg), (value), (len))
  92. /**
  93. Returns the value for a member.
  94. @param msg the message from which to get the value
  95. @param member the name of the member variable
  96. @param pvalue a pointer to the variable to hold the value
  97. @return 0 on success, -1 otherwise.
  98. */
  99. #define EVTAG_GET(msg, member, pvalue) \
  100. (*(msg)->base->member##_get)((msg), (pvalue))
  101. /**
  102. Returns the value for a member.
  103. @param msg the message from which to get the value
  104. @param member the name of the member variable
  105. @param pvalue a pointer to the variable to hold the value
  106. @param plen a pointer to the length of the value
  107. @return 0 on success, -1 otherwise.
  108. */
  109. #define EVTAG_GET_WITH_LEN(msg, member, pvalue, plen) \
  110. (*(msg)->base->member##_get)((msg), (pvalue), (plen))
  111. #endif /* _EVENT2_RPC_COMPAT_H_ */
  112. /**
  113. Adds a value to an array.
  114. */
  115. #define EVTAG_ARRAY_ADD_VALUE(msg, member, value) \
  116. (*(msg)->base->member##_add)((msg), (value))
  117. /**
  118. Allocates a new entry in the array and returns it.
  119. */
  120. #define EVTAG_ARRAY_ADD(msg, member) \
  121. (*(msg)->base->member##_add)(msg)
  122. /**
  123. Gets a variable at the specified offset from the array.
  124. */
  125. #define EVTAG_ARRAY_GET(msg, member, offset, pvalue) \
  126. (*(msg)->base->member##_get)((msg), (offset), (pvalue))
  127. /**
  128. Returns the number of entries in the array.
  129. */
  130. #define EVTAG_ARRAY_LEN(msg, member) ((msg)->member##_length)
  131. struct evbuffer;
  132. struct event_base;
  133. struct evrpc_req_generic;
  134. struct evrpc_request_wrapper;
  135. struct evrpc;
  136. /** The type of a specific RPC Message
  137. *
  138. * @param rpcname the name of the RPC message
  139. */
  140. #define EVRPC_STRUCT(rpcname) struct evrpc_req__##rpcname
  141. struct evhttp_request;
  142. struct evrpc_status;
  143. struct evrpc_hook_meta;
  144. /** Creates the definitions and prototypes for an RPC
  145. *
  146. * You need to use EVRPC_HEADER to create structures and function prototypes
  147. * needed by the server and client implementation. The structures have to be
  148. * defined in an .rpc file and converted to source code via event_rpcgen.py
  149. *
  150. * @param rpcname the name of the RPC
  151. * @param reqstruct the name of the RPC request structure
  152. * @param replystruct the name of the RPC reply structure
  153. * @see EVRPC_GENERATE()
  154. */
  155. #define EVRPC_HEADER(rpcname, reqstruct, rplystruct) \
  156. EVRPC_STRUCT(rpcname) { \
  157. struct evrpc_hook_meta *hook_meta; \
  158. struct reqstruct* request; \
  159. struct rplystruct* reply; \
  160. struct evrpc* rpc; \
  161. struct evhttp_request* http_req; \
  162. struct evbuffer* rpc_data; \
  163. }; \
  164. int evrpc_send_request_##rpcname(struct evrpc_pool *, \
  165. struct reqstruct *, struct rplystruct *, \
  166. void (*)(struct evrpc_status *, \
  167. struct reqstruct *, struct rplystruct *, void *cbarg), \
  168. void *);
  169. struct evrpc_pool;
  170. /** use EVRPC_GENERATE instead */
  171. struct evrpc_request_wrapper *evrpc_make_request_ctx(
  172. struct evrpc_pool *pool, void *request, void *reply,
  173. const char *rpcname,
  174. void (*req_marshal)(struct evbuffer*, void *),
  175. void (*rpl_clear)(void *),
  176. int (*rpl_unmarshal)(void *, struct evbuffer *),
  177. void (*cb)(struct evrpc_status *, void *, void *, void *),
  178. void *cbarg);
  179. /** Creates a context structure that contains rpc specific information.
  180. *
  181. * EVRPC_MAKE_CTX is used to populate a RPC specific context that
  182. * contains information about marshaling the RPC data types.
  183. *
  184. * @param rpcname the name of the RPC
  185. * @param reqstruct the name of the RPC request structure
  186. * @param replystruct the name of the RPC reply structure
  187. * @param pool the evrpc_pool over which to make the request
  188. * @param request a pointer to the RPC request structure object
  189. * @param reply a pointer to the RPC reply structure object
  190. * @param cb the callback function to call when the RPC has completed
  191. * @param cbarg the argument to supply to the callback
  192. */
  193. #define EVRPC_MAKE_CTX(rpcname, reqstruct, rplystruct, \
  194. pool, request, reply, cb, cbarg) \
  195. evrpc_make_request_ctx(pool, request, reply, \
  196. #rpcname, \
  197. (void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
  198. (void (*)(void *))rplystruct##_clear, \
  199. (int (*)(void *, struct evbuffer *))rplystruct##_unmarshal, \
  200. (void (*)(struct evrpc_status *, void *, void *, void *))cb, \
  201. cbarg)
  202. /** Generates the code for receiving and sending an RPC message
  203. *
  204. * EVRPC_GENERATE is used to create the code corresponding to sending
  205. * and receiving a particular RPC message
  206. *
  207. * @param rpcname the name of the RPC
  208. * @param reqstruct the name of the RPC request structure
  209. * @param replystruct the name of the RPC reply structure
  210. * @see EVRPC_HEADER()
  211. */
  212. #define EVRPC_GENERATE(rpcname, reqstruct, rplystruct) \
  213. int evrpc_send_request_##rpcname(struct evrpc_pool *pool, \
  214. struct reqstruct *request, struct rplystruct *reply, \
  215. void (*cb)(struct evrpc_status *, \
  216. struct reqstruct *, struct rplystruct *, void *cbarg), \
  217. void *cbarg) { \
  218. return evrpc_send_request_generic(pool, request, reply, \
  219. (void (*)(struct evrpc_status *, void *, void *, void *))cb, \
  220. cbarg, \
  221. #rpcname, \
  222. (void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
  223. (void (*)(void *))rplystruct##_clear, \
  224. (int (*)(void *, struct evbuffer *))rplystruct##_unmarshal); \
  225. }
  226. /** Provides access to the HTTP request object underlying an RPC
  227. *
  228. * Access to the underlying http object; can be used to look at headers or
  229. * for getting the remote ip address
  230. *
  231. * @param rpc_req the rpc request structure provided to the server callback
  232. * @return an struct evhttp_request object that can be inspected for
  233. * HTTP headers or sender information.
  234. */
  235. #define EVRPC_REQUEST_HTTP(rpc_req) (rpc_req)->http_req
  236. /** completes the server response to an rpc request */
  237. void evrpc_request_done(struct evrpc_req_generic *req);
  238. /** accessors for request and reply */
  239. void *evrpc_get_request(struct evrpc_req_generic *req);
  240. void *evrpc_get_reply(struct evrpc_req_generic *req);
  241. /** Creates the reply to an RPC request
  242. *
  243. * EVRPC_REQUEST_DONE is used to answer a request; the reply is expected
  244. * to have been filled in. The request and reply pointers become invalid
  245. * after this call has finished.
  246. *
  247. * @param rpc_req the rpc request structure provided to the server callback
  248. */
  249. #define EVRPC_REQUEST_DONE(rpc_req) do { \
  250. struct evrpc_req_generic *_req = (struct evrpc_req_generic *)(rpc_req); \
  251. evrpc_request_done(_req); \
  252. } while (0)
  253. struct evrpc_base;
  254. struct evhttp;
  255. /* functions to start up the rpc system */
  256. /** Creates a new rpc base from which RPC requests can be received
  257. *
  258. * @param server a pointer to an existing HTTP server
  259. * @return a newly allocated evrpc_base struct
  260. * @see evrpc_free()
  261. */
  262. struct evrpc_base *evrpc_init(struct evhttp *server);
  263. /**
  264. * Frees the evrpc base
  265. *
  266. * For now, you are responsible for making sure that no rpcs are ongoing.
  267. *
  268. * @param base the evrpc_base object to be freed
  269. * @see evrpc_init
  270. */
  271. void evrpc_free(struct evrpc_base *base);
  272. /** register RPCs with the HTTP Server
  273. *
  274. * registers a new RPC with the HTTP server, each RPC needs to have
  275. * a unique name under which it can be identified.
  276. *
  277. * @param base the evrpc_base structure in which the RPC should be
  278. * registered.
  279. * @param name the name of the RPC
  280. * @param request the name of the RPC request structure
  281. * @param reply the name of the RPC reply structure
  282. * @param callback the callback that should be invoked when the RPC
  283. * is received. The callback has the following prototype
  284. * void (*callback)(EVRPC_STRUCT(Message)* rpc, void *arg)
  285. * @param cbarg an additional parameter that can be passed to the callback.
  286. * The parameter can be used to carry around state.
  287. */
  288. #define EVRPC_REGISTER(base, name, request, reply, callback, cbarg) \
  289. evrpc_register_generic(base, #name, \
  290. (void (*)(struct evrpc_req_generic *, void *))callback, cbarg, \
  291. (void *(*)(void *))request##_new, NULL, \
  292. (void (*)(void *))request##_free, \
  293. (int (*)(void *, struct evbuffer *))request##_unmarshal, \
  294. (void *(*)(void *))reply##_new, NULL, \
  295. (void (*)(void *))reply##_free, \
  296. (int (*)(void *))reply##_complete, \
  297. (void (*)(struct evbuffer *, void *))reply##_marshal)
  298. /**
  299. Low level function for registering an RPC with a server.
  300. Use EVRPC_REGISTER() instead.
  301. @see EVRPC_REGISTER()
  302. */
  303. int evrpc_register_rpc(struct evrpc_base *, struct evrpc *,
  304. void (*)(struct evrpc_req_generic*, void *), void *);
  305. /**
  306. * Unregisters an already registered RPC
  307. *
  308. * @param base the evrpc_base object from which to unregister an RPC
  309. * @param name the name of the rpc to unregister
  310. * @return -1 on error or 0 when successful.
  311. * @see EVRPC_REGISTER()
  312. */
  313. #define EVRPC_UNREGISTER(base, name) evrpc_unregister_rpc((base), #name)
  314. int evrpc_unregister_rpc(struct evrpc_base *base, const char *name);
  315. /*
  316. * Client-side RPC support
  317. */
  318. struct evhttp_connection;
  319. struct evrpc_status;
  320. /** launches an RPC and sends it to the server
  321. *
  322. * EVRPC_MAKE_REQUEST() is used by the client to send an RPC to the server.
  323. *
  324. * @param name the name of the RPC
  325. * @param pool the evrpc_pool that contains the connection objects over which
  326. * the request should be sent.
  327. * @param request a pointer to the RPC request structure - it contains the
  328. * data to be sent to the server.
  329. * @param reply a pointer to the RPC reply structure. It is going to be filled
  330. * if the request was answered successfully
  331. * @param cb the callback to invoke when the RPC request has been answered
  332. * @param cbarg an additional argument to be passed to the client
  333. * @return 0 on success, -1 on failure
  334. */
  335. #define EVRPC_MAKE_REQUEST(name, pool, request, reply, cb, cbarg) \
  336. evrpc_send_request_##name((pool), (request), (reply), (cb), (cbarg))
  337. /**
  338. Makes an RPC request based on the provided context.
  339. This is a low-level function and should not be used directly
  340. unless a custom context object is provided. Use EVRPC_MAKE_REQUEST()
  341. instead.
  342. @param ctx a context from EVRPC_MAKE_CTX()
  343. @returns 0 on success, -1 otherwise.
  344. @see EVRPC_MAKE_REQUEST(), EVRPC_MAKE_CTX()
  345. */
  346. int evrpc_make_request(struct evrpc_request_wrapper *ctx);
  347. /** creates an rpc connection pool
  348. *
  349. * a pool has a number of connections associated with it.
  350. * rpc requests are always made via a pool.
  351. *
  352. * @param base a pointer to an struct event_based object; can be left NULL
  353. * in singled-threaded applications
  354. * @return a newly allocated struct evrpc_pool object
  355. * @see evrpc_pool_free()
  356. */
  357. struct evrpc_pool *evrpc_pool_new(struct event_base *base);
  358. /** frees an rpc connection pool
  359. *
  360. * @param pool a pointer to an evrpc_pool allocated via evrpc_pool_new()
  361. * @see evrpc_pool_new()
  362. */
  363. void evrpc_pool_free(struct evrpc_pool *pool);
  364. /**
  365. * Adds a connection over which rpc can be dispatched to the pool.
  366. *
  367. * The connection object must have been newly created.
  368. *
  369. * @param pool the pool to which to add the connection
  370. * @param evcon the connection to add to the pool.
  371. */
  372. void evrpc_pool_add_connection(struct evrpc_pool *pool,
  373. struct evhttp_connection *evcon);
  374. /**
  375. * Removes a connection from the pool.
  376. *
  377. * The connection object must have been newly created.
  378. *
  379. * @param pool the pool from which to remove the connection
  380. * @param evcon the connection to remove from the pool.
  381. */
  382. void evrpc_pool_remove_connection(struct evrpc_pool *pool,
  383. struct evhttp_connection *evcon);
  384. /**
  385. * Sets the timeout in secs after which a request has to complete. The
  386. * RPC is completely aborted if it does not complete by then. Setting
  387. * the timeout to 0 means that it never timeouts and can be used to
  388. * implement callback type RPCs.
  389. *
  390. * Any connection already in the pool will be updated with the new
  391. * timeout. Connections added to the pool after set_timeout has be
  392. * called receive the pool timeout only if no timeout has been set
  393. * for the connection itself.
  394. *
  395. * @param pool a pointer to a struct evrpc_pool object
  396. * @param timeout_in_secs the number of seconds after which a request should
  397. * timeout and a failure be returned to the callback.
  398. */
  399. void evrpc_pool_set_timeout(struct evrpc_pool *pool, int timeout_in_secs);
  400. /**
  401. * Hooks for changing the input and output of RPCs; this can be used to
  402. * implement compression, authentication, encryption, ...
  403. */
  404. enum EVRPC_HOOK_TYPE {
  405. EVRPC_INPUT, /**< apply the function to an input hook */
  406. EVRPC_OUTPUT /**< apply the function to an output hook */
  407. };
  408. #ifndef WIN32
  409. /** Deprecated alias for EVRPC_INPUT. Not available on windows, where it
  410. * conflicts with platform headers. */
  411. #define INPUT EVRPC_INPUT
  412. /** Deprecated alias for EVRPC_OUTPUT. Not available on windows, where it
  413. * conflicts with platform headers. */
  414. #define OUTPUT EVRPC_OUTPUT
  415. #endif
  416. /**
  417. * Return value from hook processing functions
  418. */
  419. enum EVRPC_HOOK_RESULT {
  420. EVRPC_TERMINATE = -1, /**< indicates the rpc should be terminated */
  421. EVRPC_CONTINUE = 0, /**< continue processing the rpc */
  422. EVRPC_PAUSE = 1 /**< pause processing request until resumed */
  423. };
  424. /** adds a processing hook to either an rpc base or rpc pool
  425. *
  426. * If a hook returns TERMINATE, the processing is aborted. On CONTINUE,
  427. * the request is immediately processed after the hook returns. If the
  428. * hook returns PAUSE, request processing stops until evrpc_resume_request()
  429. * has been called.
  430. *
  431. * The add functions return handles that can be used for removing hooks.
  432. *
  433. * @param vbase a pointer to either struct evrpc_base or struct evrpc_pool
  434. * @param hook_type either INPUT or OUTPUT
  435. * @param cb the callback to call when the hook is activated
  436. * @param cb_arg an additional argument for the callback
  437. * @return a handle to the hook so it can be removed later
  438. * @see evrpc_remove_hook()
  439. */
  440. void *evrpc_add_hook(void *vbase,
  441. enum EVRPC_HOOK_TYPE hook_type,
  442. int (*cb)(void *, struct evhttp_request *, struct evbuffer *, void *),
  443. void *cb_arg);
  444. /** removes a previously added hook
  445. *
  446. * @param vbase a pointer to either struct evrpc_base or struct evrpc_pool
  447. * @param hook_type either INPUT or OUTPUT
  448. * @param handle a handle returned by evrpc_add_hook()
  449. * @return 1 on success or 0 on failure
  450. * @see evrpc_add_hook()
  451. */
  452. int evrpc_remove_hook(void *vbase,
  453. enum EVRPC_HOOK_TYPE hook_type,
  454. void *handle);
  455. /** resume a paused request
  456. *
  457. * @param vbase a pointer to either struct evrpc_base or struct evrpc_pool
  458. * @param ctx the context pointer provided to the original hook call
  459. */
  460. int
  461. evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res);
  462. /** adds meta data to request
  463. *
  464. * evrpc_hook_add_meta() allows hooks to add meta data to a request. for
  465. * a client request, the meta data can be inserted by an outgoing request hook
  466. * and retrieved by the incoming request hook.
  467. *
  468. * @param ctx the context provided to the hook call
  469. * @param key a NUL-terminated c-string
  470. * @param data the data to be associated with the key
  471. * @param data_size the size of the data
  472. */
  473. void evrpc_hook_add_meta(void *ctx, const char *key,
  474. const void *data, size_t data_size);
  475. /** retrieves meta data previously associated
  476. *
  477. * evrpc_hook_find_meta() can be used to retrieve meta data associated to a
  478. * request by a previous hook.
  479. * @param ctx the context provided to the hook call
  480. * @param key a NUL-terminated c-string
  481. * @param data pointer to a data pointer that will contain the retrieved data
  482. * @param data_size pointer to the size of the data
  483. * @return 0 on success or -1 on failure
  484. */
  485. int evrpc_hook_find_meta(void *ctx, const char *key,
  486. void **data, size_t *data_size);
  487. /**
  488. * returns the connection object associated with the request
  489. *
  490. * @param ctx the context provided to the hook call
  491. * @return a pointer to the evhttp_connection object
  492. */
  493. struct evhttp_connection *evrpc_hook_get_connection(void *ctx);
  494. /**
  495. Function for sending a generic RPC request.
  496. Do not call this function directly, use EVRPC_MAKE_REQUEST() instead.
  497. @see EVRPC_MAKE_REQUEST()
  498. */
  499. int evrpc_send_request_generic(struct evrpc_pool *pool,
  500. void *request, void *reply,
  501. void (*cb)(struct evrpc_status *, void *, void *, void *),
  502. void *cb_arg,
  503. const char *rpcname,
  504. void (*req_marshal)(struct evbuffer *, void *),
  505. void (*rpl_clear)(void *),
  506. int (*rpl_unmarshal)(void *, struct evbuffer *));
  507. /**
  508. Function for registering a generic RPC with the RPC base.
  509. Do not call this function directly, use EVRPC_REGISTER() instead.
  510. @see EVRPC_REGISTER()
  511. */
  512. int
  513. evrpc_register_generic(struct evrpc_base *base, const char *name,
  514. void (*callback)(struct evrpc_req_generic *, void *), void *cbarg,
  515. void *(*req_new)(void *), void *req_new_arg, void (*req_free)(void *),
  516. int (*req_unmarshal)(void *, struct evbuffer *),
  517. void *(*rpl_new)(void *), void *rpl_new_arg, void (*rpl_free)(void *),
  518. int (*rpl_complete)(void *),
  519. void (*rpl_marshal)(struct evbuffer *, void *));
  520. /** accessors for obscure and undocumented functionality */
  521. struct evrpc_pool* evrpc_request_get_pool(struct evrpc_request_wrapper *ctx);
  522. void evrpc_request_set_pool(struct evrpc_request_wrapper *ctx,
  523. struct evrpc_pool *pool);
  524. void evrpc_request_set_cb(struct evrpc_request_wrapper *ctx,
  525. void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg),
  526. void *cb_arg);
  527. #ifdef __cplusplus
  528. }
  529. #endif
  530. #endif /* _EVENT2_RPC_H_ */