Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 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
 
20
#ifndef PEEKPROCESSOR_H
21
#define PEEKPROCESSOR_H
22
 
23
#include <string>
24
#include <TProcessor.h>
25
#include <transport/TTransport.h>
26
#include <transport/TTransportUtils.h>
27
#include <transport/TBufferTransports.h>
28
#include <boost/shared_ptr.hpp>
29
 
30
namespace apache { namespace thrift { namespace processor {
31
 
32
/*
33
 * Class for peeking at the raw data that is being processed by another processor
34
 * and gives the derived class a chance to change behavior accordingly
35
 *
36
 */
37
class PeekProcessor : public apache::thrift::TProcessor {
38
 
39
 public:
40
  PeekProcessor();
41
  virtual ~PeekProcessor();
42
 
43
  // Input here: actualProcessor  - the underlying processor
44
  //             protocolFactory  - the protocol factory used to wrap the memory buffer
45
  //             transportFactory - this TPipedTransportFactory is used to wrap the source transport
46
  //                                via a call to getPipedTransport
47
  void initialize(boost::shared_ptr<apache::thrift::TProcessor> actualProcessor,
48
                  boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory,
49
                  boost::shared_ptr<apache::thrift::transport::TPipedTransportFactory> transportFactory);
50
 
51
  boost::shared_ptr<apache::thrift::transport::TTransport> getPipedTransport(boost::shared_ptr<apache::thrift::transport::TTransport> in);
52
 
53
  void setTargetTransport(boost::shared_ptr<apache::thrift::transport::TTransport> targetTransport);
54
 
55
  virtual bool process(boost::shared_ptr<apache::thrift::protocol::TProtocol> in,
56
                       boost::shared_ptr<apache::thrift::protocol::TProtocol> out);
57
 
58
  // The following three functions can be overloaded by child classes to
59
  // achieve desired peeking behavior
60
  virtual void peekName(const std::string& fname);
61
  virtual void peekBuffer(uint8_t* buffer, uint32_t size);
62
  virtual void peek(boost::shared_ptr<apache::thrift::protocol::TProtocol> in,
63
                    apache::thrift::protocol::TType ftype,
64
                    int16_t fid);
65
  virtual void peekEnd();
66
 
67
 private:
68
  boost::shared_ptr<apache::thrift::TProcessor> actualProcessor_;
69
  boost::shared_ptr<apache::thrift::protocol::TProtocol> pipedProtocol_;
70
  boost::shared_ptr<apache::thrift::transport::TPipedTransportFactory> transportFactory_;
71
  boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> memoryBuffer_;
72
  boost::shared_ptr<apache::thrift::transport::TTransport> targetTransport_;
73
};
74
 
75
}}} // apache::thrift::processor
76
 
77
#endif