X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..5a5c578e2e358a121cdb9234a6cb11c4ecfbf323:/rsm_client.h diff --git a/rsm_client.h b/rsm_client.h index 3219179..bb21f24 100644 --- a/rsm_client.h +++ b/rsm_client.h @@ -1,11 +1,8 @@ #ifndef rsm_client_h #define rsm_client_h -#include "rpc.h" +#include "types.h" #include "rsm_protocol.h" -#include -#include - // // rsm client interface. @@ -19,113 +16,52 @@ class rsm_client { protected: std::string primary; std::vector known_mems; - pthread_mutex_t rsm_client_mutex; - void primary_failure(); - bool init_members(); + std::mutex rsm_client_mutex; + void primary_failure(lock & rsm_client_mutex_lock); + bool init_members(lock & rsm_client_mutex_lock); public: rsm_client(std::string dst); - rsm_protocol::status invoke(int proc, std::string req, std::string &rep); - - template - int call(unsigned int proc, const A1 & a1, R &r); - - template - int call(unsigned int proc, const A1 & a1, const A2 & a2, R &r); - - template - int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, - R &r); - - template - int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, - const A4 & a4, R &r); + rsm_protocol::status invoke(unsigned int proc, std::string &rep, const std::string &req); - template - int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, - const A4 & a4, const A5 & a5, R &r); + template + int call(unsigned int proc, R & r, const Args & ...a1); private: - template int call_m(unsigned int proc, marshall &req, R &r); + template int call_m(unsigned int proc, R & r, const marshall & req); }; template -int rsm_client::call_m(unsigned int proc, marshall &req, R &r) { - std::string rep; - std::string res; - int intret = invoke(proc, req.str(), rep); - VERIFY( intret == rsm_client_protocol::OK ); - unmarshall u(rep); - u >> intret; - if (intret < 0) return intret; - u >> res; - if (!u.okdone()) { - fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" - "You probably forgot to set the reply string in " - "rsm::client_invoke, or you may call RPC 0x%x with wrong return " - "type\n", proc); - VERIFY(0); - return rpc_const::unmarshal_reply_failure; - } - unmarshall u1(res); - u1 >> r; - if(!u1.okdone()) { - fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" - "You are probably calling RPC 0x%x with wrong return " - "type.\n", proc); - VERIFY(0); - return rpc_const::unmarshal_reply_failure; - } - return intret; -} - -template -int rsm_client::call(unsigned int proc, const A1 & a1, R & r) { - marshall m; - m << a1; - return call_m(proc, m, r); -} - -template -int rsm_client::call(unsigned int proc, const A1 & a1, const A2 & a2, R & r) { - marshall m; - m << a1; - m << a2; - return call_m(proc, m, r); -} - -template -int rsm_client::call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, R & r) { - marshall m; - std::string rep; - std::string res; - m << a1; - m << a2; - m << a3; - return call_m(proc, m, r); -} - -template -int rsm_client::call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, const A4 & a4, R & r) { - marshall m; +int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) { std::string rep; std::string res; - m << a1; - m << a2; - m << a3; - m << a4; - return call_m(proc, m, r); + int intret = invoke(proc, rep, req.cstr()); + VERIFY( intret == rsm_client_protocol::OK ); + unmarshall u(rep); + u >> intret; + if (intret < 0) return intret; + u >> res; + if (!u.okdone()) { + fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" + "You probably forgot to set the reply string in " + "rsm::client_invoke, or you may call RPC 0x%x with wrong return " + "type\n", proc); + VERIFY(0); + return rpc_const::unmarshal_reply_failure; + } + unmarshall u1(res); + u1 >> r; + if(!u1.okdone()) { + fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" + "You are probably calling RPC 0x%x with wrong return " + "type.\n", proc); + VERIFY(0); + return rpc_const::unmarshal_reply_failure; + } + return intret; } -template -int rsm_client::call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3, const A4 & a4, const A5 & a5, R & r) { - marshall m; - std::string rep; - std::string res; - m << a1; - m << a2; - m << a3; - m << a4; - m << a5; - return call_m(proc, m, r); +template +int rsm_client::call(unsigned int proc, R & r, const Args & ...a1) { + return call_m(proc, r, marshall{a1...}); } #endif