File indexing completed on 2026-04-17 08:35:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef _THRIFT_ASYNC_TASYNCDISPATCHPROCESSOR_H_
0020 #define _THRIFT_ASYNC_TASYNCDISPATCHPROCESSOR_H_ 1
0021
0022 #include <thrift/async/TAsyncProcessor.h>
0023
0024 namespace apache {
0025 namespace thrift {
0026 namespace async {
0027
0028
0029
0030
0031
0032
0033
0034 template <class Protocol_>
0035 class TAsyncDispatchProcessorT : public TAsyncProcessor {
0036 public:
0037 void process(std::function<void(bool success)> _return,
0038 std::shared_ptr<protocol::TProtocol> in,
0039 std::shared_ptr<protocol::TProtocol> out) override {
0040 protocol::TProtocol* inRaw = in.get();
0041 protocol::TProtocol* outRaw = out.get();
0042
0043
0044 auto* specificIn = dynamic_cast<Protocol_*>(inRaw);
0045 auto* specificOut = dynamic_cast<Protocol_*>(outRaw);
0046 if (specificIn && specificOut) {
0047 return processFast(_return, specificIn, specificOut);
0048 }
0049
0050
0051 T_GENERIC_PROTOCOL(this, inRaw, specificIn);
0052 T_GENERIC_PROTOCOL(this, outRaw, specificOut);
0053
0054 std::string fname;
0055 protocol::TMessageType mtype;
0056 int32_t seqid;
0057 inRaw->readMessageBegin(fname, mtype, seqid);
0058
0059
0060
0061
0062
0063
0064 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0065 GlobalOutput.printf("received invalid message type %d from client", mtype);
0066 _return(false);
0067 return;
0068 }
0069
0070 return this->dispatchCall(_return, inRaw, outRaw, fname, seqid);
0071 }
0072
0073 void processFast(std::function<void(bool success)> _return,
0074 Protocol_* in,
0075 Protocol_* out) {
0076 std::string fname;
0077 protocol::TMessageType mtype;
0078 int32_t seqid;
0079 in->readMessageBegin(fname, mtype, seqid);
0080
0081 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0082 GlobalOutput.printf("received invalid message type %d from client", mtype);
0083 _return(false);
0084 return;
0085 }
0086
0087 return this->dispatchCallTemplated(_return, in, out, fname, seqid);
0088 }
0089
0090 virtual void dispatchCall(std::function<void(bool ok)> _return,
0091 apache::thrift::protocol::TProtocol* in,
0092 apache::thrift::protocol::TProtocol* out,
0093 const std::string& fname,
0094 int32_t seqid) = 0;
0095
0096 virtual void dispatchCallTemplated(std::function<void(bool ok)> _return,
0097 Protocol_* in,
0098 Protocol_* out,
0099 const std::string& fname,
0100 int32_t seqid) = 0;
0101 };
0102
0103
0104
0105
0106
0107 class TAsyncDispatchProcessor : public TAsyncProcessor {
0108 public:
0109 void process(std::function<void(bool success)> _return,
0110 std::shared_ptr<protocol::TProtocol> in,
0111 std::shared_ptr<protocol::TProtocol> out) override {
0112 protocol::TProtocol* inRaw = in.get();
0113 protocol::TProtocol* outRaw = out.get();
0114
0115 std::string fname;
0116 protocol::TMessageType mtype;
0117 int32_t seqid;
0118 inRaw->readMessageBegin(fname, mtype, seqid);
0119
0120
0121
0122
0123
0124
0125 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0126 GlobalOutput.printf("received invalid message type %d from client", mtype);
0127 _return(false);
0128 return;
0129 }
0130
0131 return dispatchCall(_return, inRaw, outRaw, fname, seqid);
0132 }
0133
0134 virtual void dispatchCall(std::function<void(bool ok)> _return,
0135 apache::thrift::protocol::TProtocol* in,
0136 apache::thrift::protocol::TProtocol* out,
0137 const std::string& fname,
0138 int32_t seqid) = 0;
0139 };
0140
0141
0142
0143 template <>
0144 class TAsyncDispatchProcessorT<protocol::TDummyProtocol> : public TAsyncDispatchProcessor {};
0145 template <>
0146 class TAsyncDispatchProcessorT<protocol::TProtocol> : public TAsyncDispatchProcessor {};
0147 }
0148 }
0149 }
0150
0151 #endif