expose a way to create the rpc context manually

svn:r754
This commit is contained in:
Niels Provos 2008-05-01 02:08:26 +00:00
parent 85c4904bc5
commit e8f450f232
3 changed files with 47 additions and 5 deletions

View File

@ -784,7 +784,7 @@ evrpc_make_request(struct evrpc_request_wrapper *ctx)
struct evrpc_request_wrapper *
evrpc_send_request_generic(
evrpc_make_request_ctx(
struct evrpc_pool *pool, void *request, void *reply,
const char *rpcname,
void (*req_marshal)(struct evbuffer*, void *),

28
evrpc.h
View File

@ -183,7 +183,7 @@ int evrpc_send_request_##rpcname(struct evrpc_pool *, \
struct evrpc_pool;
/** use EVRPC_GENERATE instead */
struct evrpc_request_wrapper *evrpc_send_request_generic(
struct evrpc_request_wrapper *evrpc_make_request_ctx(
struct evrpc_pool *pool, void *request, void *reply,
const char *rpcname,
void (*req_marshal)(struct evbuffer*, void *),
@ -192,6 +192,30 @@ struct evrpc_request_wrapper *evrpc_send_request_generic(
void (*cb)(struct evrpc_status *, void *, void *, void *),
void *cbarg);
/** Creates a context structure that contains rpc specific information.
*
* EVRPC_MAKE_CTX is used to populate a RPC specific context that
* contains information about marshaling the RPC data types.
*
* @param rpcname the name of the RPC
* @param reqstruct the name of the RPC request structure
* @param replystruct the name of the RPC reply structure
* @param pool the evrpc_pool over which to make the request
* @param request a pointer to the RPC request structure object
* @param reply a pointer to the RPC reply structure object
* @param cb the callback function to call when the RPC has completed
* @param cbarg the argument to supply to the callback
*/
#define EVRPC_MAKE_CTX(rpcname, reqstruct, rplystruct, \
pool, request, reply, cb, cbarg) \
evrpc_make_request_ctx(pool, request, reply, \
#rpcname, \
(void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
(void (*)(void *))rplystruct##_clear, \
(int (*)(void *, struct evbuffer *))rplystruct##_unmarshal, \
(void (*)(struct evrpc_status *, void *, void *, void *))cb, \
cbarg)
/** Generates the code for receiving and sending an RPC message
*
* EVRPC_GENERATE is used to create the code corresponding to sending
@ -210,7 +234,7 @@ int evrpc_send_request_##rpcname(struct evrpc_pool *pool, \
void *cbarg) { \
struct evrpc_status status; \
struct evrpc_request_wrapper *ctx; \
ctx = evrpc_send_request_generic(pool, request, reply, \
ctx = evrpc_make_request_ctx(pool, request, reply, \
#rpcname, \
(void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
(void (*)(void *))rplystruct##_clear, \

View File

@ -509,13 +509,31 @@ rpc_basic_client(void)
event_dispatch();
rpc_teardown(base);
if (test_ok != 2) {
fprintf(stdout, "FAILED (2)\n");
exit(1);
}
/* we do it trice to make sure other stuff works, too */
kill_clear(kill);
{
struct evrpc_request_wrapper *ctx =
EVRPC_MAKE_CTX(Message, msg, kill,
pool, msg, kill, GotKillCb, NULL);
evrpc_make_request(ctx);
}
event_dispatch();
rpc_teardown(base);
if (test_ok != 3) {
fprintf(stdout, "FAILED (3)\n");
exit(1);
}
fprintf(stdout, "OK\n");
msg_free(msg);