5 #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 vector<string> known_mems;
19 mutex rsm_client_mutex;
20 void primary_failure(lock & rsm_client_mutex_lock);
21 bool init_members(lock & rsm_client_mutex_lock);
22 rsm_protocol::status invoke(unsigned int proc, string &rep, const string &req);
23 template<class R> int call_m(unsigned int proc, R & r, const marshall & req);
25 rsm_client(string dst);
27 template<class P, class R, class ...Args>
28 int call(rpc_protocol::proc_t<P> proc, R & r, const Args & ...a1) {
29 static_assert(is_valid_call<P, R, Args...>::value, "RSM method invoked with incorrect argument types");
30 return call_m(proc.id, r, marshall{a1...});
34 inline string hexify(const string & s) {
37 bytes.push_back("0123456789abcdef"[(uint8_t)ch >> 4]);
38 bytes.push_back("0123456789abcdef"[(uint8_t)ch & 15]);
44 int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) {
47 int intret = invoke(proc, rep, req.content());
48 VERIFY( intret == rsm_client_protocol::OK );
49 unmarshall u(rep, false);
51 if (intret < 0) return intret;
54 LOG("failed to unmarshall the reply.");
55 LOG("You probably forgot to set the reply string in " <<
56 "rsm::client_invoke, or you may have called RPC " <<
57 "0x" << hex << proc << " with the wrong return type");
58 LOG("here's what I got: \"" << hexify(rep) << "\"");
60 return rpc_protocol::unmarshal_reply_failure;
62 unmarshall u1(res, false);
65 LOG("failed to unmarshall the reply.");
66 LOG("You are probably calling RPC 0x" << hex << proc <<
67 " with the wrong return type.");
68 LOG("here's what I got: \"" << hexify(res) << "\"");
70 return rpc_protocol::unmarshal_reply_failure;