X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/2546a41ad36fdc9ef6471cb35a1d56930ae1b527..5a5c578e2e358a121cdb9234a6cb11c4ecfbf323:/rpc/marshall.h diff --git a/rpc/marshall.h b/rpc/marshall.h index abeaae7..20b9c07 100644 --- a/rpc/marshall.h +++ b/rpc/marshall.h @@ -1,16 +1,10 @@ #ifndef marshall_h #define marshall_h -#include -#include -#include -#include -#include -#include -#include +#include "types.h" +#include #include -#include -#include "lang/verify.h" +#include using proc_t = uint32_t; using status_t = int32_t; @@ -56,7 +50,7 @@ typedef int rpc_sz_t; //size of initial buffer allocation #define DEFAULT_RPC_SZ 1024 -#define RPC_HEADER_SZ (std::max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t)) +#define RPC_HEADER_SZ (max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t)) class marshall { private: @@ -66,7 +60,7 @@ class marshall { inline void reserve(size_t n) { if((index_+n) > capacity_){ - capacity_ += std::max(capacity_, n); + capacity_ += max(capacity_, n); VERIFY (buf_ != NULL); buf_ = (char *)realloc(buf_, capacity_); VERIFY(buf_); @@ -106,12 +100,12 @@ class marshall { } // Return the current content (excluding header) as a string - std::string get_content() { - return std::string(buf_+RPC_HEADER_SZ,index_-RPC_HEADER_SZ); + string get_content() { + return string(buf_+RPC_HEADER_SZ,index_-RPC_HEADER_SZ); } // Return the current content (excluding header) as a string - std::string str() { + string str() { return get_content(); } @@ -135,16 +129,9 @@ marshall& operator<<(marshall &, int8_t); marshall& operator<<(marshall &, uint16_t); marshall& operator<<(marshall &, int16_t); marshall& operator<<(marshall &, uint64_t); -marshall& operator<<(marshall &, const std::string &); +marshall& operator<<(marshall &, const string &); -template -struct is_enumerable : std::false_type {}; - -template struct is_enumerable().cbegin(), std::declval().cend(), void()) -> : std::true_type {}; - -template typename std::enable_if::value, marshall>::type & +template typename enable_if::value, marshall>::type & operator<<(marshall &m, const A &x) { m << (unsigned int) x.size(); for (const auto &a : x) @@ -153,16 +140,16 @@ operator<<(marshall &m, const A &x) { } template marshall & -operator<<(marshall &m, const std::pair &d) { +operator<<(marshall &m, const pair &d) { return m << d.first << d.second; } template -using enum_type_t = typename std::enable_if::value, typename std::underlying_type::type>::type; +using enum_type_t = typename enable_if::value, typename underlying_type::type>::type; template constexpr inline enum_type_t from_enum(E e) noexcept { return (enum_type_t)e; } template constexpr inline E to_enum(enum_type_t value) noexcept { return (E)value; } -template typename std::enable_if::value, marshall>::type & +template typename enable_if::value, marshall>::type & operator<<(marshall &m, E e) { return m << from_enum(e); } @@ -179,8 +166,8 @@ unmarshall& operator>>(unmarshall &, int32_t &); unmarshall& operator>>(unmarshall &, size_t &); unmarshall& operator>>(unmarshall &, uint64_t &); unmarshall& operator>>(unmarshall &, int64_t &); -unmarshall& operator>>(unmarshall &, std::string &); -template typename std::enable_if::value, unmarshall>::type & +unmarshall& operator>>(unmarshall &, string &); +template typename enable_if::value, unmarshall>::type & operator>>(unmarshall &u, E &e); class unmarshall { @@ -194,7 +181,7 @@ class unmarshall { public: unmarshall(): buf_(NULL),sz_(0),index_(0),ok_(false) {} unmarshall(char *b, size_t sz): buf_(b),sz_(sz),index_(),ok_(true) {} - unmarshall(const std::string &s) : buf_(NULL),sz_(0),index_(0),ok_(false) + unmarshall(const string &s) : buf_(NULL),sz_(0),index_(0),ok_(false) { //take the content which does not exclude a RPC header from a string take_content(s); @@ -207,7 +194,7 @@ class unmarshall { void take_in(unmarshall &another); //take the content which does not exclude a RPC header from a string - void take_content(const std::string &s) { + void take_content(const string &s) { sz_ = s.size()+RPC_HEADER_SZ; buf_ = (char *)realloc(buf_,sz_); VERIFY(buf_); @@ -221,7 +208,7 @@ class unmarshall { bool okdone() const { return ok_ && index_ == sz_; } uint8_t rawbyte(); - void rawbytes(std::string &s, size_t n); + void rawbytes(string &s, size_t n); template void rawbytes(T &t); size_t ind() { return index_;} @@ -255,7 +242,7 @@ class unmarshall { } }; -template typename std::enable_if::value, unmarshall>::type & +template typename enable_if::value, unmarshall>::type & operator>>(unmarshall &u, A &x) { unsigned n = u.grab(); x.clear(); @@ -265,26 +252,26 @@ operator>>(unmarshall &u, A &x) { } template unmarshall & -operator>>(unmarshall &u, std::map &x) { +operator>>(unmarshall &u, map &x) { unsigned n = u.grab(); x.clear(); while (n--) - x.emplace(u.grab>()); + x.emplace(u.grab>()); return u; } template unmarshall & -operator>>(unmarshall &u, std::pair &d) { +operator>>(unmarshall &u, pair &d) { return u >> d.first >> d.second; } -template typename std::enable_if::value, unmarshall>::type & +template typename enable_if::value, unmarshall>::type & operator>>(unmarshall &u, E &e) { e = to_enum(u.grab>()); return u; } -typedef std::function handler; +typedef function handler; // // Automatic marshalling wrappers for RPC handlers @@ -294,7 +281,7 @@ typedef std::function handler; // C++11 does neither of these two things for us: // 1) Declare variables using a parameter pack expansion, like so // Args ...args; -// 2) Call a function with a std::tuple of the arguments it expects +// 2) Call a function with a tuple of the arguments it expects // // We implement an 'invoke' function for functions of the RPC handler // signature, i.e. int(R & r, const Args...) @@ -339,17 +326,17 @@ struct VerifyOnFailure { // One for function pointers... template -typename std::enable_if::value, RV>::type +typename enable_if::value, RV>::type invoke(RV, F f, void *, R & r, args_type & t, tuple_indices) { - return f(r, std::move(std::get(t))...); + return f(r, move(get(t))...); } // And one for pointers to member functions... template -typename std::enable_if::value, RV>::type +typename enable_if::value, RV>::type invoke(RV, F f, C *c, R & r, args_type & t, tuple_indices) { - return (c->*f)(r, std::move(std::get(t))...); + return (c->*f)(r, move(get(t))...); } // The class marshalled_func_imp uses partial template specialization to @@ -373,15 +360,15 @@ struct marshalled_func_imp { // template parameters running from 0 up to (# args) - 1. using Indices = typename make_tuple_indices::type; // This type definition represents storage for f's unmarshalled - // arguments. std::decay is (most notably) stripping off const + // arguments. decay is (most notably) stripping off const // qualifiers. - using ArgsStorage = std::tuple::type...>; - // Allocate a handler (i.e. std::function) to hold the lambda + using ArgsStorage = tuple::type...>; + // Allocate a handler (i.e. function) to hold the lambda // which will unmarshall RPCs and call f. return new handler([=](unmarshall &u, marshall &m) -> RV { // Unmarshall each argument with the correct type and store the // result in a tuple. - ArgsStorage t = {u.grab::type>()...}; + ArgsStorage t = {u.grab::type>()...}; // Verify successful unmarshalling of the entire input stream. if (!u.okdone()) return (RV)ErrorHandler::unmarshall_args_failure(); @@ -417,7 +404,7 @@ struct marshalled_func : public marshalled_func_imp {}; template -struct marshalled_func> : +struct marshalled_func> : public marshalled_func_imp {}; #endif