]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/TDispatchProcessor.h
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
19 #ifndef _THRIFT_TDISPATCHPROCESSOR_H_
20 #define _THRIFT_TDISPATCHPROCESSOR_H_ 1
22 #include <thrift/TProcessor.h>
28 * TDispatchProcessor is a helper class to parse the message header then call
29 * another function to dispatch based on the function name.
31 * Subclasses must implement dispatchCall() to dispatch on the function name.
33 template <class Protocol_
>
34 class TDispatchProcessorT
: public TProcessor
{
36 bool process(std::shared_ptr
<protocol::TProtocol
> in
,
37 std::shared_ptr
<protocol::TProtocol
> out
,
38 void* connectionContext
) override
{
39 protocol::TProtocol
* inRaw
= in
.get();
40 protocol::TProtocol
* outRaw
= out
.get();
42 // Try to dynamic cast to the template protocol type
43 auto* specificIn
= dynamic_cast<Protocol_
*>(inRaw
);
44 auto* specificOut
= dynamic_cast<Protocol_
*>(outRaw
);
45 if (specificIn
&& specificOut
) {
46 return processFast(specificIn
, specificOut
, connectionContext
);
49 // Log the fact that we have to use the slow path
50 T_GENERIC_PROTOCOL(this, inRaw
, specificIn
);
51 T_GENERIC_PROTOCOL(this, outRaw
, specificOut
);
54 protocol::TMessageType mtype
;
56 inRaw
->readMessageBegin(fname
, mtype
, seqid
);
58 // If this doesn't look like a valid call, log an error and return false so
59 // that the server will close the connection.
61 // (The old generated processor code used to try to skip a T_STRUCT and
62 // continue. However, that seems unsafe.)
63 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
64 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
68 return this->dispatchCall(inRaw
, outRaw
, fname
, seqid
, connectionContext
);
72 bool processFast(Protocol_
* in
, Protocol_
* out
, void* connectionContext
) {
74 protocol::TMessageType mtype
;
76 in
->readMessageBegin(fname
, mtype
, seqid
);
78 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
79 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
83 return this->dispatchCallTemplated(in
, out
, fname
, seqid
, connectionContext
);
87 * dispatchCall() methods must be implemented by subclasses
89 virtual bool dispatchCall(apache::thrift::protocol::TProtocol
* in
,
90 apache::thrift::protocol::TProtocol
* out
,
91 const std::string
& fname
,
93 void* callContext
) = 0;
95 virtual bool dispatchCallTemplated(Protocol_
* in
,
97 const std::string
& fname
,
99 void* callContext
) = 0;
103 * Non-templatized version of TDispatchProcessor, that doesn't bother trying to
104 * perform a dynamic_cast.
106 class TDispatchProcessor
: public TProcessor
{
108 bool process(std::shared_ptr
<protocol::TProtocol
> in
,
109 std::shared_ptr
<protocol::TProtocol
> out
,
110 void* connectionContext
) override
{
112 protocol::TMessageType mtype
;
114 in
->readMessageBegin(fname
, mtype
, seqid
);
116 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
117 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
121 return dispatchCall(in
.get(), out
.get(), fname
, seqid
, connectionContext
);
125 virtual bool dispatchCall(apache::thrift::protocol::TProtocol
* in
,
126 apache::thrift::protocol::TProtocol
* out
,
127 const std::string
& fname
,
129 void* callContext
) = 0;
132 // Specialize TDispatchProcessorT for TProtocol and TDummyProtocol just to use
133 // the generic TDispatchProcessor.
135 class TDispatchProcessorT
<protocol::TDummyProtocol
> : public TDispatchProcessor
{};
137 class TDispatchProcessorT
<protocol::TProtocol
> : public TDispatchProcessor
{};
141 #endif // _THRIFT_TDISPATCHPROCESSOR_H_