4 #include "include/types.h"
5 #include "include/rsm_protocol.h"
8 // rsm client interface.
10 // The client stubs package up an rpc, and then call the invoke procedure
11 // on the replicated state machine passing the RPC as an argument. This way
12 // the replicated state machine isn't service specific; any server can use it.
18 std::vector<string> known_mems;
19 std::mutex rsm_client_mutex;
20 bool init_members(lock & rsm_client_mutex_lock);
21 rsm_protocol::status invoke(rpc_protocol::proc_id_t proc, string & rep, const string & req);
22 template<class R> int call_marshalled(rpc_protocol::proc_t & proc, R & r, const marshall & req);
24 rsm_client(string dst);
26 template<class P, class R, class ...Args>
27 inline int call(rpc_protocol::proc_checked_t<P> proc, R & r, const Args & ...a1) {
28 static_assert(is_valid_call<P, R, Args...>::value, "RSM method invoked with incorrect argument types");
29 return call_marshalled(proc, r, marshall(a1...));
34 int rsm_client::call_marshalled(rpc_protocol::proc_t & proc, R & r, const marshall & req) {
36 int intret = invoke(proc.id, rep, req);
37 VERIFY( intret == rsm_client_protocol::OK );
38 auto u = unmarshall(rep, intret);
39 if (intret < 0) return intret;
40 if ((u >> res).okdone() && unmarshall(res, r).okdone())
42 LOG << "failed to unmarshall reply \"" << hex_string(rep) << "\" for proceduce "
43 << proc.name << " (0x" << std::hex << proc.id << ").";
44 return rpc_protocol::unmarshall_reply_failure;