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 | |
| 23 | #include <tr1/functional> |
| 24 | #include <Thrift.h> |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 25 | |
| 26 | namespace apache { namespace thrift { namespace transport { |
| 27 | class TMemoryBuffer; |
| 28 | }}} |
| 29 | |
| 30 | namespace apache { namespace thrift { namespace async { |
| 31 | using apache::thrift::transport::TMemoryBuffer; |
| 32 | |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 33 | class TAsyncChannel { |
| 34 | public: |
| 35 | typedef std::tr1::function<void()> VoidCallback; |
| 36 | |
| 37 | virtual ~TAsyncChannel() {} |
| 38 | |
| 39 | // is the channel in a good state? |
| 40 | virtual bool good() const = 0; |
| 41 | virtual bool error() const = 0; |
| 42 | virtual bool timedOut() const = 0; |
| 43 | |
| 44 | /** |
| 45 | * Send a message over the channel. |
| 46 | * |
| 47 | * @return true iff the cob has been or will be called, else false |
| 48 | */ |
Roger Meier | 285cfaa | 2011-07-28 17:51:36 +0000 | [diff] [blame] | 49 | virtual void sendMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message) = 0; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Receive a message from the channel. |
| 53 | * |
| 54 | * @return true iff the cob has been or will be called, else false |
| 55 | */ |
Roger Meier | 285cfaa | 2011-07-28 17:51:36 +0000 | [diff] [blame] | 56 | virtual void recvMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message) = 0; |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Send a message over the channel and receive a response. |
| 60 | * |
| 61 | * @return true iff the cob has been or will be called, else false |
| 62 | */ |
Roger Meier | 285cfaa | 2011-07-28 17:51:36 +0000 | [diff] [blame] | 63 | virtual void sendAndRecvMessage(const VoidCallback& cob, |
David Reiss | 5ddabb8 | 2010-10-06 17:09:37 +0000 | [diff] [blame] | 64 | apache::thrift::transport::TMemoryBuffer* sendBuf, |
| 65 | apache::thrift::transport::TMemoryBuffer* recvBuf); |
| 66 | }; |
| 67 | |
| 68 | }}} // apache::thrift::async |
| 69 | |
| 70 | #endif // #ifndef _THRIFT_ASYNC_TASYNCCHANNEL_H_ |