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);
23 rsm_client(string dst);
24 rsm_protocol::status invoke(unsigned int proc, string &rep, const string &req);
26 template<class R, class ...Args>
27 int call(unsigned int proc, R & r, const Args & ...a1);
29 template<class R> int call_m(unsigned int proc, R & r, const marshall & req);
32 inline string hexify(const string & s) {
35 bytes.push_back("0123456789abcdef"[(uint8_t)ch >> 4]);
36 bytes.push_back("0123456789abcdef"[(uint8_t)ch & 15]);
42 int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) {
45 int intret = invoke(proc, rep, req.content());
46 VERIFY( intret == rsm_client_protocol::OK );
47 unmarshall u(rep, false);
49 if (intret < 0) return intret;
52 LOG("failed to unmarshall the reply.");
53 LOG("You probably forgot to set the reply string in " <<
54 "rsm::client_invoke, or you may have called RPC " <<
55 "0x" << hex << proc << " with the wrong return type");
56 LOG("here's what I got: \"" << hexify(rep) << "\"");
58 return rpc_const::unmarshal_reply_failure;
60 unmarshall u1(res, false);
63 LOG("failed to unmarshall the reply.");
64 LOG("You are probably calling RPC 0x" << hex << proc <<
65 " with the wrong return type.");
66 LOG("here's what I got: \"" << hexify(res) << "\"");
68 return rpc_const::unmarshal_reply_failure;
73 template<class R, class ...Args>
74 int rsm_client::call(unsigned int proc, R & r, const Args & ...a1) {
75 return call_m(proc, r, marshall{a1...});