blob: 72ed40fff509606e588477178f6d4f17b2407427 [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>
Roger Meier4285ba22013-06-10 21:17:23 +020025#include <thrift/async/TAsyncChannel.h>
David Reiss5ddabb82010-10-06 17:09:37 +000026
27struct event_base;
28struct evhttp_connection;
29struct evhttp_request;
30
Konrad Grochowski16a23a62014-11-13 15:33:38 +010031namespace apache {
32namespace thrift {
33namespace transport {
David Reiss5ddabb82010-10-06 17:09:37 +000034class TMemoryBuffer;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010035}
36}
37}
David Reiss5ddabb82010-10-06 17:09:37 +000038
Konrad Grochowski16a23a62014-11-13 15:33:38 +010039namespace apache {
40namespace thrift {
41namespace async {
David Reiss5ddabb82010-10-06 17:09:37 +000042
43class TEvhttpClientChannel : public TAsyncChannel {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010044public:
David Reiss5ddabb82010-10-06 17:09:37 +000045 using TAsyncChannel::VoidCallback;
46
Konrad Grochowski16a23a62014-11-13 15:33:38 +010047 TEvhttpClientChannel(const std::string& host,
48 const std::string& path,
49 const char* address,
50 int port,
51 struct event_base* eb);
David Reiss5ddabb82010-10-06 17:09:37 +000052 ~TEvhttpClientChannel();
53
Roger Meier285cfaa2011-07-28 17:51:36 +000054 virtual void sendAndRecvMessage(const VoidCallback& cob,
David Reiss5ddabb82010-10-06 17:09:37 +000055 apache::thrift::transport::TMemoryBuffer* sendBuf,
56 apache::thrift::transport::TMemoryBuffer* recvBuf);
57
Konrad Grochowski16a23a62014-11-13 15:33:38 +010058 virtual void sendMessage(const VoidCallback& cob,
59 apache::thrift::transport::TMemoryBuffer* message);
60 virtual void recvMessage(const VoidCallback& cob,
61 apache::thrift::transport::TMemoryBuffer* message);
David Reiss5ddabb82010-10-06 17:09:37 +000062
63 void finish(struct evhttp_request* req);
64
Konrad Grochowski16a23a62014-11-13 15:33:38 +010065 // XXX
David Reiss5ddabb82010-10-06 17:09:37 +000066 virtual bool good() const { return true; }
67 virtual bool error() const { return false; }
68 virtual bool timedOut() const { return false; }
69
Konrad Grochowski16a23a62014-11-13 15:33:38 +010070private:
David Reiss5ddabb82010-10-06 17:09:37 +000071 static void response(struct evhttp_request* req, void* arg);
72
73 std::string host_;
74 std::string path_;
75 VoidCallback cob_;
76 apache::thrift::transport::TMemoryBuffer* recvBuf_;
77 struct evhttp_connection* conn_;
David Reiss5ddabb82010-10-06 17:09:37 +000078};
Konrad Grochowski16a23a62014-11-13 15:33:38 +010079}
80}
81} // apache::thrift::async
David Reiss5ddabb82010-10-06 17:09:37 +000082
83#endif // #ifndef _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_