2 * Copyright 2015 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <folly/io/async/AsyncTransport.h>
20 #include <folly/futures/Future.h>
21 #include <folly/ExceptionWrapper.h>
23 namespace folly { namespace wangle {
27 template <class In, class Out>
28 class HandlerContext {
30 virtual ~HandlerContext() {}
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;
38 virtual Future<void> fireWrite(Out msg) = 0;
39 virtual Future<void> fireClose() = 0;
41 virtual PipelineBase* getPipeline() = 0;
42 std::shared_ptr<AsyncTransport> getTransport() {
43 return getPipeline()->getTransport();
46 virtual void setWriteFlags(WriteFlags flags) = 0;
47 virtual WriteFlags getWriteFlags() = 0;
49 virtual void setReadBufferSettings(
50 uint64_t minAvailable,
51 uint64_t allocationSize) = 0;
52 virtual std::pair<uint64_t, uint64_t> getReadBufferSettings() = 0;
56 virtual void addHandlerBefore(H&&) {}
58 virtual void addHandlerAfter(H&&) {}
60 virtual void replaceHandler(H&&) {}
61 virtual void removeHandler() {}
66 class InboundHandlerContext {
68 virtual ~InboundHandlerContext() {}
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;
76 virtual PipelineBase* getPipeline() = 0;
77 std::shared_ptr<AsyncTransport> getTransport() {
78 return getPipeline()->getTransport();
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
87 class OutboundHandlerContext {
89 virtual ~OutboundHandlerContext() {}
91 virtual Future<void> fireWrite(Out msg) = 0;
92 virtual Future<void> fireClose() = 0;
94 virtual PipelineBase* getPipeline() = 0;
95 std::shared_ptr<AsyncTransport> getTransport() {
96 return getPipeline()->getTransport();
100 enum class HandlerDir {
108 #include <folly/wangle/channel/HandlerContext-inl.h>