blob: 3d152f47ed482ec7d75da709d1bb6e33e3c33156 [file] [log] [blame]
Roger Meier7699b402012-04-08 18:18:44 +00001/*
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 Meier86e89862012-02-10 19:53:20 +000020#ifndef _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_
21#define _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_ 1
22
Roger Meier86e89862012-02-10 19:53:20 +000023#include <boost/shared_ptr.hpp>
24
25#include <transport/TVirtualTransport.h>
26
Roger Meier19a99152012-02-11 19:09:30 +000027class QIODevice;
Roger Meier86e89862012-02-10 19:53:20 +000028
29namespace apache { namespace thrift { namespace transport {
30
Roger Meier19a99152012-02-11 19:09:30 +000031/**
32 * Transport that operates on a QIODevice (socket, file, etc).
33 */
34class TQIODeviceTransport : public apache::thrift::transport::TVirtualTransport<TQIODeviceTransport> {
35 public:
36 explicit TQIODeviceTransport(boost::shared_ptr<QIODevice> dev);
37 virtual ~TQIODeviceTransport();
Roger Meier86e89862012-02-10 19:53:20 +000038
Roger Meier19a99152012-02-11 19:09:30 +000039 void open();
40 bool isOpen();
41 bool peek();
42 void close();
Roger Meier86e89862012-02-10 19:53:20 +000043
Roger Meier19a99152012-02-11 19:09:30 +000044 uint32_t readAll(uint8_t *buf, uint32_t len);
45 uint32_t read(uint8_t* buf, uint32_t len);
Roger Meier86e89862012-02-10 19:53:20 +000046
Roger Meier19a99152012-02-11 19:09:30 +000047 void write(const uint8_t* buf, uint32_t len);
48 uint32_t write_partial(const uint8_t* buf, uint32_t len);
Roger Meier86e89862012-02-10 19:53:20 +000049
Roger Meier19a99152012-02-11 19:09:30 +000050 void flush();
Roger Meier86e89862012-02-10 19:53:20 +000051
Roger Meier19a99152012-02-11 19:09:30 +000052 uint8_t* borrow(uint8_t* buf, uint32_t* len);
53 void consume(uint32_t len);
Roger Meier86e89862012-02-10 19:53:20 +000054
Roger Meier19a99152012-02-11 19:09:30 +000055 private:
56 TQIODeviceTransport(const TQIODeviceTransport&);
57 TQIODeviceTransport& operator=(const TQIODeviceTransport&);
58
59 boost::shared_ptr<QIODevice> dev_;
60};
Roger Meier86e89862012-02-10 19:53:20 +000061}}} // apache::thrift::transport
62
63#endif // #ifndef _THRIFT_ASYNC_TQIODEVICE_TRANSPORT_H_
64