From: Marc Slemko Date: Fri, 11 Aug 2006 23:58:57 +0000 (+0000) Subject: Added function name to read/writeMessageBegin args X-Git-Tag: 0.2.0~1720 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=91f674823a80031962265f559c9b3d3ef5bcb1df;p=common%2Fthrift.git Added function name to read/writeMessageBegin args Added cpp generator for master server message processor git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664752 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/src/cpp_generator.py b/compiler/src/cpp_generator.py index 92636c5a..06c253da 100644 --- a/compiler/src/cpp_generator.py +++ b/compiler/src/cpp_generator.py @@ -256,6 +256,37 @@ CPP_TRANSPORT_NS = CPP_THRIFT_NS+"::transport" CPP_TRANSPORT = CPP_TRANSPORT_NS+"::TTransport" CPP_TRANSPORTP = CPP_SP.substitute(klass=CPP_TRANSPORT) +CPP_PROTOCOL_TSTOP = CPP_PROTOCOL_NS+"::T_STOP" +CPP_PROTOCOL_TTYPE = CPP_PROTOCOL_NS+"::TType" +CPP_PROTOCOL_MESSAGE_TYPE = CPP_PROTOCOL_NS+"::TMessageType" +CPP_PROTOCOL_CALL = CPP_PROTOCOL_NS+"::T_CALL" +CPP_PROTOCOL_REPLY = CPP_PROTOCOL_NS+"::T_REPLY" + +CPP_TTYPE_MAP = { + STOP_TYPE : CPP_PROTOCOL_NS+"::T_STOP", + VOID_TYPE : CPP_PROTOCOL_NS+"::T_VOID", + BOOL_TYPE : CPP_PROTOCOL_NS+"::T_BOOL", + UTF7_TYPE : CPP_PROTOCOL_NS+"::T_UTF7", + UTF7_TYPE : CPP_PROTOCOL_NS+"::T_UTF7", + UTF8_TYPE : CPP_PROTOCOL_NS+"::T_UTF8", + UTF16_TYPE : CPP_PROTOCOL_NS+"::T_UTF16", + U08_TYPE : CPP_PROTOCOL_NS+"::T_U08", + I08_TYPE : CPP_PROTOCOL_NS+"::T_I08", + I16_TYPE : CPP_PROTOCOL_NS+"::T_I16", + I32_TYPE : CPP_PROTOCOL_NS+"::T_I32", + I64_TYPE : CPP_PROTOCOL_NS+"::T_I64", + U08_TYPE : CPP_PROTOCOL_NS+"::T_U08", + U16_TYPE : CPP_PROTOCOL_NS+"::T_U16", + U32_TYPE : CPP_PROTOCOL_NS+"::T_U32", + U64_TYPE : CPP_PROTOCOL_NS+"::T_U64", + FLOAT_TYPE : CPP_PROTOCOL_NS+"::T_FLOAT", + StructType : CPP_PROTOCOL_NS+"::T_STRUCT", + ListType : CPP_PROTOCOL_NS+"::T_LIST", + MapType : CPP_PROTOCOL_NS+"::T_MAP", + SetType : CPP_PROTOCOL_NS+"::T_SET" +} + + CPP_SERVER_FUNCTION_DECLARATION = Template(""" void process_${function}(uint32_t seqid, """+CPP_TRANSPORTP+""" itrans, """+CPP_TRANSPORTP+""" otrans); """) @@ -268,7 +299,7 @@ void ${service}ServerIf::process_${function}(uint32_t seqid, """+CPP_TRANSPORTP+ ${argsStructReader}; - iprot->readMessageEnd(itrans); + _iprot->readMessageEnd(itrans); ${returnValueDeclaration}; @@ -278,11 +309,11 @@ void ${service}ServerIf::process_${function}(uint32_t seqid, """+CPP_TRANSPORTP+ ${returnToResult}; - oprot->writeMessageBegin(otrans, """+CPP_PROTOCOL_REPLY+""", seqid); + _oprot->writeMessageBegin(otrans, \"${function}\", """+CPP_PROTOCOL_REPLY+""", seqid); ${resultStructWriter}; - oprot->writeMessaeEnd(otrans); + _oprot->writeMessageEnd(otrans); otrans->flush(); } @@ -295,11 +326,11 @@ bool ${service}ServerIf::process("""+CPP_TRANSPORTP+""" itrans, """+CPP_TRANSPOR std::string name; - """+CPP_MESSAGE_TYPE+""" messageType; + """+CPP_PROTOCOL_MESSAGE_TYPE+""" messageType; uint32_t seqid; - _iprot->readMessageBegin(_itrans, name, messageType, cseqid); + _iprot->readMessageBegin(itrans, name, messageType, seqid); if(messageType == """+CPP_PROTOCOL_CALL+""") { ${callProcessSwitch} @@ -309,36 +340,6 @@ ${callProcessSwitch} } """) -CPP_PROTOCOL_TSTOP = CPP_PROTOCOL_NS+"::T_STOP" -CPP_PROTOCOL_TTYPE = CPP_PROTOCOL_NS+"::TType" -CPP_PROTOCOL_MESSAGE_TYPE = CPP_PROTOCOL_NS+"::TMessageType" -CPP_PROTOCOL_CALL = CPP_PROTOCOL_NS+"::T_CALL" -CPP_PROTOCOL_REPLY = CPP_PROTOCOL_NS+"::T_REPLY" - -CPP_TTYPE_MAP = { - STOP_TYPE : CPP_PROTOCOL_NS+"::T_STOP", - VOID_TYPE : CPP_PROTOCOL_NS+"::T_VOID", - BOOL_TYPE : CPP_PROTOCOL_NS+"::T_BOOL", - UTF7_TYPE : CPP_PROTOCOL_NS+"::T_UTF7", - UTF7_TYPE : CPP_PROTOCOL_NS+"::T_UTF7", - UTF8_TYPE : CPP_PROTOCOL_NS+"::T_UTF8", - UTF16_TYPE : CPP_PROTOCOL_NS+"::T_UTF16", - U08_TYPE : CPP_PROTOCOL_NS+"::T_U08", - I08_TYPE : CPP_PROTOCOL_NS+"::T_I08", - I16_TYPE : CPP_PROTOCOL_NS+"::T_I16", - I32_TYPE : CPP_PROTOCOL_NS+"::T_I32", - I64_TYPE : CPP_PROTOCOL_NS+"::T_I64", - U08_TYPE : CPP_PROTOCOL_NS+"::T_U08", - U16_TYPE : CPP_PROTOCOL_NS+"::T_U16", - U32_TYPE : CPP_PROTOCOL_NS+"::T_U32", - U64_TYPE : CPP_PROTOCOL_NS+"::T_U64", - FLOAT_TYPE : CPP_PROTOCOL_NS+"::T_FLOAT", - StructType : CPP_PROTOCOL_NS+"::T_STRUCT", - ListType : CPP_PROTOCOL_NS+"::T_LIST", - MapType : CPP_PROTOCOL_NS+"::T_MAP", - SetType : CPP_PROTOCOL_NS+"::T_SET" -} - def toWireType(ttype): if isinstance(ttype, PrimitiveType): @@ -384,11 +385,12 @@ CPP_CLIENT_FUNCTION_DEFINITION = Template(""" ${returnDeclaration} ${service}Client::${function}(${argsDeclaration}) { uint32_t xfer = 0; + std::string name; """+CPP_PROTOCOL_MESSAGE_TYPE+""" messageType; uint32_t cseqid = 0; uint32_t rseqid = 0; - _oprot->writeMessageBegin(_otrans, """+CPP_PROTOCOL_CALL+""", cseqid); + _oprot->writeMessageBegin(_otrans, \"${function}\", """+CPP_PROTOCOL_CALL+""", cseqid); ${argsStructDeclaration}; @@ -398,7 +400,7 @@ ${argsToStruct}; _otrans->flush(); - _iprot->readMessageBegin(_itrans, messageType, rseqid); + _iprot->readMessageBegin(_itrans, name, messageType, rseqid); if(messageType != """+CPP_PROTOCOL_REPLY+""" || rseqid != cseqid) { @@ -478,11 +480,10 @@ def toServerServiceDefinition(service, debugp=None): for function in service.functionList: result+= toServerFunctionDefinition(service.name, function, debugp) - - callProcessSwitch = "if"+string.join(["(name.compare(\""+function.name+"\") == 0) {"+toServerProcessFunctionCall(function)+";}" for function in service.functionList], "\n else if") + callProcessSwitch = " if"+string.join(["(name.compare(\""+function.name+"\") == 0) { process_"+function.name+"(seqid, itrans, otrans);}" for function in service.functionList], "\n else if")+"\n else {throw "+CPP_EXCEPTION+"(\"Unknown function name \\\"\"+name+\"\\\"\");}" - result+= CPP_SERVER_PROCESS_DEFINITION(service=service.name, callProcessSwitch=callProcessSwitch) + result+= CPP_SERVER_PROCESS_DEFINITION.substitute(service=service.name, callProcessSwitch=callProcessSwitch) return result diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cc b/lib/cpp/src/protocol/TBinaryProtocol.cc index f1e4ec9a..7ad3b2bf 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.cc +++ b/lib/cpp/src/protocol/TBinaryProtocol.cc @@ -5,9 +5,11 @@ using std::string; namespace facebook { namespace thrift { namespace protocol { uint32_t TBinaryProtocol::writeMessageBegin(shared_ptr out, + const std::string name, const TMessageType messageType, const uint32_t seqid) const { return + writeString(out, name) + writeByte(out, (uint8_t)messageType) + writeU32(out, seqid); } @@ -134,11 +136,13 @@ uint32_t TBinaryProtocol::writeString(shared_ptr out, */ uint32_t TBinaryProtocol::readMessasgeBegin(shared_ptr in, + std::string& name, TMessageType& messageType, uint32_t& seqid) const { uint32_t result = 0; uint8_t type; + result+= readString(in, name); result+= readByte(in, type); messageType = (TMessageType)type; result+= readU32(in, seqid); diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h index 89f4d4ab..e70f687f 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.h +++ b/lib/cpp/src/protocol/TBinaryProtocol.h @@ -25,6 +25,7 @@ using namespace boost; */ virtual uint32_t writeMessageBegin(shared_ptr out, + const std::string name, const TMessageType messageType, const uint32_t seqid) const; @@ -97,8 +98,9 @@ using namespace boost; uint32_t readMessasgeBegin(shared_ptr in, - TMessageType& messageType, - uint32_t& seqid) const; + std::string& name, + TMessageType& messageType, + uint32_t& seqid) const; uint32_t readMessageEnd(shared_ptr in) const; diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h index 329b7bf6..7dbb4a09 100644 --- a/lib/cpp/src/protocol/TProtocol.h +++ b/lib/cpp/src/protocol/TProtocol.h @@ -79,6 +79,7 @@ class TProtocol { */ virtual uint32_t writeMessageBegin(shared_ptr out, + const std::string name, const TMessageType messageType, const uint32_t seqid) const = 0; @@ -150,8 +151,9 @@ class TProtocol { */ virtual uint32_t readMessageBegin(shared_ptr in, - TMessageType& messageType, - uint32_t& seqid) const = 0; + std::string& name, + TMessageType& messageType, + uint32_t& seqid) const = 0; virtual uint32_t readMessageEnd(shared_ptr in) const = 0;