Roger Meier | 7699b40 | 2012-04-08 18:18:44 +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 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 20 | #ifndef _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_ |
| 21 | #define _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_ 1 |
| 22 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 23 | #include <boost/shared_ptr.hpp> |
| 24 | |
| 25 | #include <transport/TVirtualTransport.h> |
| 26 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 27 | class QIODevice; |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 28 | |
| 29 | namespace apache { namespace thrift { namespace transport { |
| 30 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 31 | /** |
| 32 | * Transport that operates on a QIODevice (socket, file, etc). |
| 33 | */ |
| 34 | class TQIODeviceTransport : public apache::thrift::transport::TVirtualTransport<TQIODeviceTransport> { |
| 35 | public: |
| 36 | explicit TQIODeviceTransport(boost::shared_ptr<QIODevice> dev); |
| 37 | virtual ~TQIODeviceTransport(); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 38 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 39 | void open(); |
| 40 | bool isOpen(); |
| 41 | bool peek(); |
| 42 | void close(); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 43 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 44 | uint32_t readAll(uint8_t *buf, uint32_t len); |
| 45 | uint32_t read(uint8_t* buf, uint32_t len); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 46 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 47 | void write(const uint8_t* buf, uint32_t len); |
| 48 | uint32_t write_partial(const uint8_t* buf, uint32_t len); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 49 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 50 | void flush(); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 51 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 52 | uint8_t* borrow(uint8_t* buf, uint32_t* len); |
| 53 | void consume(uint32_t len); |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 54 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 55 | private: |
| 56 | TQIODeviceTransport(const TQIODeviceTransport&); |
| 57 | TQIODeviceTransport& operator=(const TQIODeviceTransport&); |
| 58 | |
| 59 | boost::shared_ptr<QIODevice> dev_; |
| 60 | }; |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 61 | }}} // apache::thrift::transport |
| 62 | |
| 63 | #endif // #ifndef _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_ |
| 64 | |