mirror of
https://github.com/zap-proto/ocaml-rpc.git
synced 2026-10-30 15:04:28 +00:00
The original idea was to allow different async libraries to be used, but with effects we should only ever need one library, so it makes sense to use the shorter `Capnp_rpc` name for this. The core protocol is now a sub-library of the same package (`capnp-rpc.proto`). The protocol modules that are generally useful are now re-exported by the new `Capnp_rpc`. This change is useful on its own, but the main aim is to reduce the diff when switching from Lwt to Eio.
41 lines
1.2 KiB
OCaml
41 lines
1.2 KiB
OCaml
module Api = Api.MakeRPC(Capnp_rpc)
|
|
|
|
open Capnp_rpc.Std
|
|
|
|
let rec local label =
|
|
let module Logger = Api.Service.Logger in
|
|
Logger.local @@ object
|
|
inherit Logger.service
|
|
|
|
method log_impl params release_param_caps =
|
|
let open Logger.Log in
|
|
let msg = Params.msg_get params in
|
|
release_param_caps ();
|
|
Printf.printf "[server] %S says %S\n%!" label msg;
|
|
Service.return_empty ()
|
|
|
|
method sub_impl params release_param_caps =
|
|
let open Logger.Sub in
|
|
let sub_label = Params.label_get params in
|
|
release_param_caps ();
|
|
let sub = local (Printf.sprintf "%s/%s" label sub_label) in
|
|
let response, results = Service.Response.create Results.init_pointer in
|
|
Results.logger_set results (Some sub);
|
|
Capability.dec_ref sub;
|
|
Service.return response
|
|
end
|
|
|
|
module Logger = Api.Client.Logger
|
|
|
|
let log t msg =
|
|
let open Logger.Log in
|
|
let request, params = Capability.Request.create Params.init_pointer in
|
|
Params.msg_set params msg;
|
|
Capability.call_for_unit_exn t method_id request
|
|
|
|
let sub t label =
|
|
let open Logger.Sub in
|
|
let request, params = Capability.Request.create Params.init_pointer in
|
|
Params.label_set params label;
|
|
Capability.call_for_caps t method_id request Results.logger_get_pipelined
|