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 {
25 template <class In, class Out>
26 class HandlerContext {
28 virtual ~HandlerContext() {}
30 virtual void fireRead(In msg) = 0;
31 virtual void fireReadEOF() = 0;
32 virtual void fireReadException(exception_wrapper e) = 0;
34 virtual Future<void> fireWrite(Out msg) = 0;
35 virtual Future<void> fireClose() = 0;
37 virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
39 virtual void setWriteFlags(WriteFlags flags) = 0;
40 virtual WriteFlags getWriteFlags() = 0;
42 virtual void setReadBufferSettings(
43 uint64_t minAvailable,
44 uint64_t allocationSize) = 0;
45 virtual std::pair<uint64_t, uint64_t> getReadBufferSettings() = 0;
49 virtual void addHandlerBefore(H&&) {}
51 virtual void addHandlerAfter(H&&) {}
53 virtual void replaceHandler(H&&) {}
54 virtual void removeHandler() {}
59 class InboundHandlerContext {
61 virtual ~InboundHandlerContext() {}
63 virtual void fireRead(In msg) = 0;
64 virtual void fireReadEOF() = 0;
65 virtual void fireReadException(exception_wrapper e) = 0;
67 virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
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
75 class OutboundHandlerContext {
77 virtual ~OutboundHandlerContext() {}
79 virtual Future<void> fireWrite(Out msg) = 0;
80 virtual Future<void> fireClose() = 0;
82 virtual std::shared_ptr<AsyncTransport> getTransport() = 0;
85 enum class HandlerDir {
93 #include <folly/wangle/channel/HandlerContext-inl.h>