blob: d497edb9e01f2dac80394feb3df74908e9bf0083 [file] [log] [blame]
David Reiss5ddabb82010-10-06 17:09:37 +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
20#ifndef _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_
21#define _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_ 1
22
23#include <string>
24#include <boost/shared_ptr.hpp>
25#include "TAsyncChannel.h"
26
27struct event_base;
28struct evhttp_connection;
29struct evhttp_request;
30
31namespace apache { namespace thrift { namespace transport {
32class TMemoryBuffer;
33}}}
34
35namespace apache { namespace thrift { namespace async {
36
37class TEvhttpClientChannel : public TAsyncChannel {
38 public:
39 using TAsyncChannel::VoidCallback;
40
41 TEvhttpClientChannel(
42 const std::string& host,
43 const std::string& path,
44 const char* address,
45 int port,
46 struct event_base* eb);
47 ~TEvhttpClientChannel();
48
Roger Meier285cfaa2011-07-28 17:51:36 +000049 virtual void sendAndRecvMessage(const VoidCallback& cob,
David Reiss5ddabb82010-10-06 17:09:37 +000050 apache::thrift::transport::TMemoryBuffer* sendBuf,
51 apache::thrift::transport::TMemoryBuffer* recvBuf);
52
Roger Meier285cfaa2011-07-28 17:51:36 +000053 virtual void sendMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message);
54 virtual void recvMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message);
David Reiss5ddabb82010-10-06 17:09:37 +000055
56 void finish(struct evhttp_request* req);
57
58 //XXX
59 virtual bool good() const { return true; }
60 virtual bool error() const { return false; }
61 virtual bool timedOut() const { return false; }
62
63 private:
64 static void response(struct evhttp_request* req, void* arg);
65
66 std::string host_;
67 std::string path_;
68 VoidCallback cob_;
69 apache::thrift::transport::TMemoryBuffer* recvBuf_;
70 struct evhttp_connection* conn_;
71
72};
73
74}}} // apache::thrift::async
75
76#endif // #ifndef _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_