So many changes. Broken.
[invirt/third/libt4.git] / include / rpc / rpc_protocol.h
1 #ifndef rpc_protocol_h
2 #define rpc_protocol_h
3
4 #include "include/types.h"
5
6 namespace rpc_protocol {
7     using proc_id_t = uint32_t;
8
9     using status = int32_t;
10     using rpc_sz_t = uint64_t;
11     using nonce_t = uint32_t;
12     using xid_t = int32_t;
13
14     enum : status {
15         timeout_failure = -1,
16         unmarshall_args_failure = -2,
17         unmarshall_reply_failure = -3,
18         atmostonce_failure = -4,
19         oldsrv_failure = -5,
20         bind_failure = -6,
21         cancel_failure = -7
22     };
23
24     struct request_header {
25         xid_t xid;
26         proc_id_t proc;
27         nonce_t clt_nonce;
28         nonce_t srv_nonce;
29         xid_t xid_rep;
30
31         MEMBERS(xid, proc, clt_nonce, srv_nonce, xid_rep)
32     };
33
34     struct reply_header {
35         xid_t xid;
36         int ret;
37
38         MEMBERS(xid, ret)
39     };
40
41     struct proc_t {
42         proc_id_t id;
43         const char * name;
44     };
45
46     template <typename Signature>
47     struct proc_checked_t : proc_t {
48         using signature = Signature;
49         constexpr inline proc_checked_t(proc_id_t id, const char * name) : proc_t{id, name} {}
50     };
51
52     union header_t { request_header req; reply_header rep; };
53     const size_t RPC_HEADER_SZ = sizeof(header_t) + sizeof(rpc_sz_t);
54     const size_t MAX_PDU = 10<<20; // maximum PDF is 10M
55
56 #define REMOTE_PROCEDURE_BASE(_base_) \
57     static constexpr rpc_protocol::proc_id_t base = _base_
58
59 #define REMOTE_PROCEDURE(_offset_, _name_, _args_) \
60     static constexpr rpc_protocol::proc_checked_t<status _args_> _name_{base + _offset_, #_name_}
61
62     REMOTE_PROCEDURE_BASE(0);
63     REMOTE_PROCEDURE(1, bind, (nonce_t &)); // handler number reserved for bind
64 }
65
66 #endif