Split HandlerContext and Pipeline into inl headers
[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 template <class In, class Out>
26 class HandlerContext {
27  public:
28   virtual ~HandlerContext() {}
29
30   virtual void fireRead(In msg) = 0;
31   virtual void fireReadEOF() = 0;
32   virtual void fireReadException(exception_wrapper e) = 0;
33
34   virtual Future<void> fireWrite(Out msg) = 0;
35   virtual Future<void> fireClose() = 0;
36
37   virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
38
39   virtual void setWriteFlags(WriteFlags flags) = 0;
40   virtual WriteFlags getWriteFlags() = 0;
41
42   virtual void setReadBufferSettings(
43       uint64_t minAvailable,
44       uint64_t allocationSize) = 0;
45   virtual std::pair<uint64_t, uint64_t> getReadBufferSettings() = 0;
46
47   /* TODO
48   template <class H>
49   virtual void addHandlerBefore(H&&) {}
50   template <class H>
51   virtual void addHandlerAfter(H&&) {}
52   template <class H>
53   virtual void replaceHandler(H&&) {}
54   virtual void removeHandler() {}
55   */
56 };
57
58 template <class In>
59 class InboundHandlerContext {
60  public:
61   virtual ~InboundHandlerContext() {}
62
63   virtual void fireRead(In msg) = 0;
64   virtual void fireReadEOF() = 0;
65   virtual void fireReadException(exception_wrapper e) = 0;
66
67   virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
68
69   // TODO Need get/set writeFlags, readBufferSettings? Probably not.
70   // Do we even really need them stored in the pipeline at all?
71   // Could just always delegate to the socket impl
72 };
73
74 template <class Out>
75 class OutboundHandlerContext {
76  public:
77   virtual ~OutboundHandlerContext() {}
78
79   virtual Future<void> fireWrite(Out msg) = 0;
80   virtual Future<void> fireClose() = 0;
81
82   virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
83 };
84
85 enum class HandlerDir {
86   IN,
87   OUT,
88   BOTH
89 };
90
91 }} // folly::wangle
92
93 #include <folly/wangle/channel/HandlerContext-inl.h>