]>
git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/Protocol.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef _MSG_ASYNC_PROTOCOL_
5 #define _MSG_ASYNC_PROTOCOL_
10 #include "AsyncConnection.h"
11 #include "include/buffer.h"
12 #include "include/msgr.h"
15 * Continuation Helper Classes
25 virtual Ct
<C
> *call(C
*foo
) const = 0;
28 template <class C
, typename
... Args
>
29 class CtFun
: public Ct
<C
> {
31 using fn_t
= Ct
<C
> *(C::*)(Args
...);
33 std::tuple
<Args
...> _params
;
35 template <std::size_t... Is
>
36 inline Ct
<C
> *_call(C
*foo
, std::index_sequence
<Is
...>) const {
37 return (foo
->*_f
)(std::get
<Is
>(_params
)...);
41 CtFun(fn_t f
) : _f(f
) {}
43 inline void setParams(Args
... args
) { _params
= std::make_tuple(args
...); }
44 inline Ct
<C
> *call(C
*foo
) const override
{
45 return _call(foo
, std::index_sequence_for
<Args
...>());
50 std::unique_ptr
<ceph::buffer::ptr_node
, ceph::buffer::ptr_node::disposer
>;
53 class CtRxNode
: public Ct
<C
> {
54 using fn_t
= Ct
<C
> *(C::*)(rx_buffer_t
&&, int r
);
58 mutable rx_buffer_t node
;
61 CtRxNode(fn_t f
) : _f(f
) {}
62 void setParams(rx_buffer_t
&&node
, int r
) {
63 this->node
= std::move(node
);
66 inline Ct
<C
> *call(C
*foo
) const override
{
67 return (foo
->*_f
)(std::move(node
), r
);
71 template <class C
> using CONTINUATION_TYPE
= CtFun
<C
>;
72 template <class C
> using CONTINUATION_TX_TYPE
= CtFun
<C
, int>;
73 template <class C
> using CONTINUATION_RX_TYPE
= CtFun
<C
, char*, int>;
74 template <class C
> using CONTINUATION_RXBPTR_TYPE
= CtRxNode
<C
>;
76 #define CONTINUATION_DECL(C, F, ...) \
77 CtFun<C, ##__VA_ARGS__> F##_cont { (&C::F) };
79 #define CONTINUATION(F) F##_cont
80 #define CONTINUE(F, ...) (F##_cont.setParams(__VA_ARGS__), &F##_cont)
82 #define CONTINUATION_RUN(CT) \
84 Ct<std::remove_reference<decltype(*this)>::type> *_cont = &CT;\
86 _cont = _cont->call(this); \
90 #define READ_HANDLER_CONTINUATION_DECL(C, F) \
91 CONTINUATION_DECL(C, F, char *, int)
93 #define READ_BPTR_HANDLER_CONTINUATION_DECL(C, F) \
94 CtRxNode<C> F##_cont { (&C::F) };
96 #define WRITE_HANDLER_CONTINUATION_DECL(C, F) CONTINUATION_DECL(C, F, int)
98 //////////////////////////////////////////////////////////////////////
100 class AsyncMessenger
;
104 const int proto_type
;
106 AsyncConnection
*connection
;
107 AsyncMessenger
*messenger
;
110 std::shared_ptr
<AuthConnectionMeta
> auth_meta
;
113 Protocol(int type
, AsyncConnection
*connection
);
116 // prepare protocol for connecting to peer
117 virtual void connect() = 0;
118 // prepare protocol for accepting peer connections
119 virtual void accept() = 0;
120 // true -> protocol is ready for sending messages
121 virtual bool is_connected() = 0;
123 virtual void stop() = 0;
124 // signal and handle connection failure
125 virtual void fault() = 0;
127 virtual void send_message(Message
*m
) = 0;
129 virtual void send_keepalive() = 0;
131 virtual void read_event() = 0;
132 virtual void write_event() = 0;
133 virtual bool is_queued() = 0;
135 int get_con_mode() const {
136 return auth_meta
->con_mode
;
140 #endif /* _MSG_ASYNC_PROTOCOL_ */