blob: a0b54281dacf12a78c4954430b5b4bd64a3d45ea [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_TASYNCPROCESSOR_H_
21#define _THRIFT_TASYNCPROCESSOR_H_ 1
22
23#include <tr1/functional>
24#include <boost/shared_ptr.hpp>
25#include <protocol/TProtocol.h>
26#include <TProcessor.h>
27
28namespace apache { namespace thrift { namespace async {
29
30/**
31 * Async version of a TProcessor. It is not expected to complete by the time
32 * the call to process returns. Instead, it calls a cob to signal completion.
33 */
David Reiss18cd0f02010-10-06 17:09:39 +000034
35class TEventServer; // forward declaration
36
David Reiss5ddabb82010-10-06 17:09:37 +000037class TAsyncProcessor {
38 public:
39 virtual ~TAsyncProcessor() {}
40
41 virtual void process(std::tr1::function<void(bool success)> _return,
42 boost::shared_ptr<protocol::TProtocol> in,
43 boost::shared_ptr<protocol::TProtocol> out) = 0;
44
45 void process(std::tr1::function<void(bool success)> _return,
46 boost::shared_ptr<apache::thrift::protocol::TProtocol> io) {
47 return process(_return, io, io);
48 }
49
David Reiss18cd0f02010-10-06 17:09:39 +000050 boost::shared_ptr<TProcessorEventHandler> getEventHandler() {
51 return eventHandler_;
52 }
53
54 void setEventHandler(boost::shared_ptr<TProcessorEventHandler> eventHandler) {
55 eventHandler_ = eventHandler;
56 }
57
58 const TEventServer* getAsyncServer() {
59 return asyncServer_;
60 }
David Reiss5ddabb82010-10-06 17:09:37 +000061 protected:
62 TAsyncProcessor() {}
David Reiss18cd0f02010-10-06 17:09:39 +000063
64 boost::shared_ptr<TProcessorEventHandler> eventHandler_;
65 const TEventServer* asyncServer_;
66 private:
67 friend class TEventServer;
68 void setAsyncServer(const TEventServer* server) {
69 asyncServer_ = server;
70 }
David Reiss5ddabb82010-10-06 17:09:37 +000071};
72
73}}} // apache::thrift::async
74
75// XXX I'm lazy for now
76namespace apache { namespace thrift {
77using apache::thrift::async::TAsyncProcessor;
78}}
79
80#endif // #ifndef _THRIFT_TASYNCPROCESSOR_H_