~rpadovani/reminders-app/fixForReload

« back to all changes in this revision

Viewing changes to 3rdParty/libthrift/processor/PeekProcessor.cpp

  • Committer: Michael Zanetti
  • Date: 2013-11-21 23:30:15 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: michael.zanetti@canonical.com-20131121233015-fnbjnzcb6chdtdzm
add libthrift, evernote-sdk and a Evernote qml plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "PeekProcessor.h"
 
21
 
 
22
using namespace apache::thrift::transport;
 
23
using namespace apache::thrift::protocol;
 
24
using namespace apache::thrift;
 
25
 
 
26
namespace apache { namespace thrift { namespace processor {
 
27
 
 
28
PeekProcessor::PeekProcessor() {
 
29
  memoryBuffer_.reset(new TMemoryBuffer());
 
30
  targetTransport_ = memoryBuffer_;
 
31
}
 
32
PeekProcessor::~PeekProcessor() {}
 
33
 
 
34
void PeekProcessor::initialize(boost::shared_ptr<TProcessor> actualProcessor,
 
35
                               boost::shared_ptr<TProtocolFactory> protocolFactory,
 
36
                               boost::shared_ptr<TPipedTransportFactory> transportFactory) {
 
37
  actualProcessor_ = actualProcessor;
 
38
  pipedProtocol_ = protocolFactory->getProtocol(targetTransport_);
 
39
  transportFactory_ = transportFactory;
 
40
  transportFactory_->initializeTargetTransport(targetTransport_);
 
41
}
 
42
 
 
43
boost::shared_ptr<TTransport> PeekProcessor::getPipedTransport(boost::shared_ptr<TTransport> in) {
 
44
  return transportFactory_->getTransport(in);
 
45
}
 
46
 
 
47
void PeekProcessor::setTargetTransport(boost::shared_ptr<TTransport> targetTransport) {
 
48
  targetTransport_ = targetTransport;
 
49
  if (boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport_)) {
 
50
    memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport);
 
51
  } else if (boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)) {
 
52
    memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)->getTargetTransport());
 
53
  }
 
54
 
 
55
  if (!memoryBuffer_) {
 
56
    throw TException("Target transport must be a TMemoryBuffer or a TPipedTransport with TMemoryBuffer");
 
57
  }
 
58
}
 
59
 
 
60
bool PeekProcessor::process(boost::shared_ptr<TProtocol> in,
 
61
                            boost::shared_ptr<TProtocol> out,
 
62
                            void* connectionContext) {
 
63
 
 
64
  std::string fname;
 
65
  TMessageType mtype;
 
66
  int32_t seqid;
 
67
  in->readMessageBegin(fname, mtype, seqid);
 
68
 
 
69
  if (mtype != T_CALL) {
 
70
    throw TException("Unexpected message type");
 
71
  }
 
72
 
 
73
  // Peek at the name
 
74
  peekName(fname);
 
75
 
 
76
  TType ftype;
 
77
  int16_t fid;
 
78
  while (true) {
 
79
    in->readFieldBegin(fname, ftype, fid);
 
80
    if (ftype == T_STOP) {
 
81
      break;
 
82
    }
 
83
 
 
84
    // Peek at the variable
 
85
    peek(in, ftype, fid);
 
86
    in->readFieldEnd();
 
87
  }
 
88
  in->readMessageEnd();
 
89
  in->getTransport()->readEnd();
 
90
 
 
91
  //
 
92
  // All the data is now in memoryBuffer_ and ready to be processed
 
93
  //
 
94
 
 
95
  // Let's first take a peek at the full data in memory
 
96
  uint8_t* buffer;
 
97
  uint32_t size;
 
98
  memoryBuffer_->getBuffer(&buffer, &size);
 
99
  peekBuffer(buffer, size);
 
100
 
 
101
  // Done peeking at variables
 
102
  peekEnd();
 
103
 
 
104
  bool ret = actualProcessor_->process(pipedProtocol_, out, connectionContext);
 
105
  memoryBuffer_->resetBuffer();
 
106
  return ret;
 
107
}
 
108
 
 
109
void PeekProcessor::peekName(const std::string& fname) {
 
110
  (void) fname;
 
111
}
 
112
 
 
113
void PeekProcessor::peekBuffer(uint8_t* buffer, uint32_t size) {
 
114
  (void) buffer;
 
115
  (void) size;
 
116
}
 
117
 
 
118
void PeekProcessor::peek(boost::shared_ptr<TProtocol> in,
 
119
                         TType ftype,
 
120
                         int16_t fid) {
 
121
  (void) fid;
 
122
  in->skip(ftype);
 
123
}
 
124
 
 
125
void PeekProcessor::peekEnd() {}
 
126
 
 
127
}}}