]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.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_ASYNC_TASYNCDISPATCHPROCESSOR_H_
20 #define _THRIFT_ASYNC_TASYNCDISPATCHPROCESSOR_H_ 1
22 #include <thrift/async/TAsyncProcessor.h>
29 * TAsyncDispatchProcessor is a helper class to parse the message header then
30 * call another function to dispatch based on the function name.
32 * Subclasses must implement dispatchCall() to dispatch on the function name.
34 template <class Protocol_
>
35 class TAsyncDispatchProcessorT
: public TAsyncProcessor
{
37 void process(std::function
<void(bool success
)> _return
,
38 std::shared_ptr
<protocol::TProtocol
> in
,
39 std::shared_ptr
<protocol::TProtocol
> out
) override
{
40 protocol::TProtocol
* inRaw
= in
.get();
41 protocol::TProtocol
* outRaw
= out
.get();
43 // Try to dynamic cast to the template protocol type
44 auto* specificIn
= dynamic_cast<Protocol_
*>(inRaw
);
45 auto* specificOut
= dynamic_cast<Protocol_
*>(outRaw
);
46 if (specificIn
&& specificOut
) {
47 return processFast(_return
, specificIn
, specificOut
);
50 // Log the fact that we have to use the slow path
51 T_GENERIC_PROTOCOL(this, inRaw
, specificIn
);
52 T_GENERIC_PROTOCOL(this, outRaw
, specificOut
);
55 protocol::TMessageType mtype
;
57 inRaw
->readMessageBegin(fname
, mtype
, seqid
);
59 // If this doesn't look like a valid call, log an error and return false so
60 // that the server will close the connection.
62 // (The old generated processor code used to try to skip a T_STRUCT and
63 // continue. However, that seems unsafe.)
64 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
65 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
70 return this->dispatchCall(_return
, inRaw
, outRaw
, fname
, seqid
);
73 void processFast(std::function
<void(bool success
)> _return
,
77 protocol::TMessageType mtype
;
79 in
->readMessageBegin(fname
, mtype
, seqid
);
81 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
82 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
87 return this->dispatchCallTemplated(_return
, in
, out
, fname
, seqid
);
90 virtual void dispatchCall(std::function
<void(bool ok
)> _return
,
91 apache::thrift::protocol::TProtocol
* in
,
92 apache::thrift::protocol::TProtocol
* out
,
93 const std::string
& fname
,
96 virtual void dispatchCallTemplated(std::function
<void(bool ok
)> _return
,
99 const std::string
& fname
,
104 * Non-templatized version of TAsyncDispatchProcessor,
105 * that doesn't bother trying to perform a dynamic_cast.
107 class TAsyncDispatchProcessor
: public TAsyncProcessor
{
109 void process(std::function
<void(bool success
)> _return
,
110 std::shared_ptr
<protocol::TProtocol
> in
,
111 std::shared_ptr
<protocol::TProtocol
> out
) override
{
112 protocol::TProtocol
* inRaw
= in
.get();
113 protocol::TProtocol
* outRaw
= out
.get();
116 protocol::TMessageType mtype
;
118 inRaw
->readMessageBegin(fname
, mtype
, seqid
);
120 // If this doesn't look like a valid call, log an error and return false so
121 // that the server will close the connection.
123 // (The old generated processor code used to try to skip a T_STRUCT and
124 // continue. However, that seems unsafe.)
125 if (mtype
!= protocol::T_CALL
&& mtype
!= protocol::T_ONEWAY
) {
126 GlobalOutput
.printf("received invalid message type %d from client", mtype
);
131 return dispatchCall(_return
, inRaw
, outRaw
, fname
, seqid
);
134 virtual void dispatchCall(std::function
<void(bool ok
)> _return
,
135 apache::thrift::protocol::TProtocol
* in
,
136 apache::thrift::protocol::TProtocol
* out
,
137 const std::string
& fname
,
141 // Specialize TAsyncDispatchProcessorT for TProtocol and TDummyProtocol just to
142 // use the generic TDispatchProcessor.
144 class TAsyncDispatchProcessorT
<protocol::TDummyProtocol
> : public TAsyncDispatchProcessor
{};
146 class TAsyncDispatchProcessorT
<protocol::TProtocol
> : public TAsyncDispatchProcessor
{};
149 } // apache::thrift::async
151 #endif // _THRIFT_ASYNC_TASYNCDISPATCHPROCESSOR_H_