David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #ifndef _THRIFT_ASYNC_TASYNCCHANNEL_H_ |
| 21 | #define _THRIFT_ASYNC_TASYNCCHANNEL_H_ 1 |
| 22 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 23 | #include <functional> |
| 24 | #include <memory> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 25 | #include <thrift/Thrift.h> |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 26 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 27 | namespace apache { |
| 28 | namespace thrift { |
| 29 | namespace transport { |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 30 | class TMemoryBuffer; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | } |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 34 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 35 | namespace apache { |
| 36 | namespace thrift { |
| 37 | namespace async { |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 38 | using apache::thrift::transport::TMemoryBuffer; |
| 39 | |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 40 | class TAsyncChannel { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 41 | public: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 42 | typedef std::function<void()> VoidCallback; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 43 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 44 | virtual ~TAsyncChannel() = default; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 45 | |
| 46 | // is the channel in a good state? |
| 47 | virtual bool good() const = 0; |
| 48 | virtual bool error() const = 0; |
| 49 | virtual bool timedOut() const = 0; |
| 50 | |
| 51 | /** |
| 52 | * Send a message over the channel. |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 53 | */ |
Jake Farrell | 2cb3913 | 2011-08-29 18:34:41 +0000 | [diff] [blame] | 54 | virtual void sendMessage(const VoidCallback& cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 55 | apache::thrift::transport::TMemoryBuffer* message) = 0; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Receive a message from the channel. |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 59 | */ |
Jake Farrell | 2cb3913 | 2011-08-29 18:34:41 +0000 | [diff] [blame] | 60 | virtual void recvMessage(const VoidCallback& cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 61 | apache::thrift::transport::TMemoryBuffer* message) = 0; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Send a message over the channel and receive a response. |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 65 | */ |
Roger Meier | 285cfaa | 2011-07-28 17:51:36 +0000 | [diff] [blame] | 66 | virtual void sendAndRecvMessage(const VoidCallback& cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 67 | apache::thrift::transport::TMemoryBuffer* sendBuf, |
| 68 | apache::thrift::transport::TMemoryBuffer* recvBuf); |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 69 | }; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } // apache::thrift::async |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 73 | |
| 74 | #endif // #ifndef _THRIFT_ASYNC_TASYNCCHANNEL_H_ |