Get *=default*ed default constructors
[folly.git] / folly / wangle / channel / HandlerContext.h
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/io/async/AsyncTransport.h>
20 #include <folly/futures/Future.h>
21 #include <folly/ExceptionWrapper.h>
22
23 namespace folly { namespace wangle {
24
25 class PipelineBase;
26
27 template <class In, class Out>
28 class HandlerContext {
29  public:
30   virtual ~HandlerContext() = default;
31
32   virtual void fireRead(In msg) = 0;
33   virtual void fireReadEOF() = 0;
34   virtual void fireReadException(exception_wrapper e) = 0;
35   virtual void fireTransportActive() = 0;
36   virtual void fireTransportInactive() = 0;
37
38   virtual Future<void> fireWrite(Out msg) = 0;
39   virtual Future<void> fireClose() = 0;
40
41   virtual PipelineBase* getPipeline() = 0;
42   std::shared_ptr<AsyncTransport> getTransport() {
43     return getPipeline()->getTransport();
44   }
45
46   virtual void setWriteFlags(WriteFlags flags) = 0;
47   virtual WriteFlags getWriteFlags() = 0;
48
49   virtual void setReadBufferSettings(
50       uint64_t minAvailable,
51       uint64_t allocationSize) = 0;
52   virtual std::pair<uint64_t, uint64_t> getReadBufferSettings() = 0;
53
54   /* TODO
55   template <class H>
56   virtual void addHandlerBefore(H&&) {}
57   template <class H>
58   virtual void addHandlerAfter(H&&) {}
59   template <class H>
60   virtual void replaceHandler(H&&) {}
61   virtual void removeHandler() {}
62   */
63 };
64
65 template <class In>
66 class InboundHandlerContext {
67  public:
68   virtual ~InboundHandlerContext() = default;
69
70   virtual void fireRead(In msg) = 0;
71   virtual void fireReadEOF() = 0;
72   virtual void fireReadException(exception_wrapper e) = 0;
73   virtual void fireTransportActive() = 0;
74   virtual void fireTransportInactive() = 0;
75
76   virtual PipelineBase* getPipeline() = 0;
77   std::shared_ptr<AsyncTransport> getTransport() {
78     return getPipeline()->getTransport();
79   }
80
81   // TODO Need get/set writeFlags, readBufferSettings? Probably not.
82   // Do we even really need them stored in the pipeline at all?
83   // Could just always delegate to the socket impl
84 };
85
86 template <class Out>
87 class OutboundHandlerContext {
88  public:
89   virtual ~OutboundHandlerContext() = default;
90
91   virtual Future<void> fireWrite(Out msg) = 0;
92   virtual Future<void> fireClose() = 0;
93
94   virtual PipelineBase* getPipeline() = 0;
95   std::shared_ptr<AsyncTransport> getTransport() {
96     return getPipeline()->getTransport();
97   }
98 };
99
100 enum class HandlerDir {
101   IN,
102   OUT,
103   BOTH
104 };
105
106 }} // folly::wangle
107
108 #include <folly/wangle/channel/HandlerContext-inl.h>