Skip to content
Browse files

p4_idl: functorise generated Client module

This avoids having to pass in an "rpc" argument on every call; instead
one can write

  let module M = Client(struct let rpc = ... end) in
  M.just_do_it ()

Patch originally written by: Rob Hoes <rob.hoes@citrix.com>

Patch ported from xen-org/xen-api-libs c/s 66476cba733fde295aa433092632556111cfa4a5
  • Loading branch information...
1 parent 0a4d1de commit 47eb42f08fc38200682c90be37e5056dfa8d6fed David Scott committed
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/p4_idl.ml
View
12 lib/p4_idl.ml
@@ -137,7 +137,7 @@ struct
let arg_path = MyRpc.arg_path rpc.loc (rpc.namespace @ [cap_name]) in
<:expr<
let call = $create_call rpc$ in
- let response = rpc call in
+ let response = R.rpc call in
if response.Rpc.success
then Args.$arg_path$.response_of_rpc response.Rpc.contents
else
@@ -147,7 +147,7 @@ struct
let gen_client_fun rpc =
let n = List.length rpc.args - 1 in
- <:str_item< value $lid:rpc.fname$ = fun rpc ->
+ <:str_item< value $lid:rpc.fname$ =
$MyRpc.list_foldi (fun accu arg i ->
let lid = MyRpc.argi (n-i) in
match arg.MyRpc.kind with
@@ -170,7 +170,7 @@ struct
end >>
else <:str_item< >>) items
in
- <:str_item< module Client = struct $list: gen_str_items rpcs$ end >>
+ <:str_item< module Client = functor(R: RPC) -> struct $list: gen_str_items rpcs$ end >>
(* Generates a signature for a server module - again, very similar to the original
idl module, but in this one a 'context' is defined - a way of passing in any
@@ -319,11 +319,17 @@ struct
exception RpcFailure of (string * list (string * string))
>>
in
+ let rpc_type =
+ let t = <:ctyp< Rpc.call -> Rpc.response >> in
+ let s = <:sig_item< value rpc: $typ:t$ >> in
+ <:str_item< module type RPC = sig $sigi:s$ end >>
+ in
let flat_rpcs = flatten_rpcs rpcs in
let sis = Ast.list_of_str_item si [] in
<:str_item< $list: (List.map filter_types sis) @
[ failure_bits;
make_args rpcs;
+ rpc_type;
make_client rpcs;
make_server_sig rpcs;
make_server_functor flat_rpcs ] $ >>

0 comments on commit 47eb42f

Please sign in to comment.
Something went wrong with that request. Please try again.