From 9f5da0f7bfc52f3bfa984c344e8943c8ed951576 Mon Sep 17 00:00:00 2001 From: jarodruan Date: Mon, 10 Feb 2020 16:23:17 +0800 Subject: [PATCH] support http2 succ --- examples/CustomDemo/CustomClient/main.cpp | 19 +- .../HelloServer/Client/main.cpp | 38 +- servant/libservant/AdapterProxy.cpp | 7 - servant/libservant/AppProtocol.cpp | 10 +- servant/libservant/ObjectProxy.cpp | 9 +- servant/libservant/ServantProxy.cpp | 18 +- servant/libservant/Transceiver.cpp | 48 -- servant/servant/AppProtocol.h | 10 - servant/servant/ObjectProxy.h | 33 +- servant/servant/ServantProxy.h | 26 +- servant/servant/Transceiver.h | 12 - tools/tars2cpp/tars2cpp.cpp | 707 ++++-------------- tools/tars2cpp/tars2cpp.h | 27 +- 13 files changed, 193 insertions(+), 771 deletions(-) diff --git a/examples/CustomDemo/CustomClient/main.cpp b/examples/CustomDemo/CustomClient/main.cpp index df20569..bb70d40 100644 --- a/examples/CustomDemo/CustomClient/main.cpp +++ b/examples/CustomDemo/CustomClient/main.cpp @@ -77,17 +77,20 @@ static vector customRequest(RequestPacket& request, Transceiver *) class CustomCallBack : public ServantProxyCallback { public: - virtual int onDispatchResponse(const RequestPacket &req, const ResponsePacket &rsp) + virtual int onDispatch(ReqMessagePtr msg) { - cout << "async response:" << rsp.sBuffer.data() << endl; - return 0; + if(msg->response->iRet != tars::TARSSERVERSUCCESS) + { + cout << "ret error:" << msg->response->iRet << endl; + } + else + { + cout << "succ:" << msg->response->sBuffer.data() << endl; + } + + return msg->response->iRet; } - virtual int onDispatchException(const RequestPacket &req, const ResponsePacket &rsp) - { - cout << "async exception:" << rsp.iRet << endl; - return 0; - } }; typedef tars::TC_AutoPtr CustomCallBackPtr; diff --git a/examples/QuickStartDemo/HelloServer/Client/main.cpp b/examples/QuickStartDemo/HelloServer/Client/main.cpp index 87bf574..216df3c 100644 --- a/examples/QuickStartDemo/HelloServer/Client/main.cpp +++ b/examples/QuickStartDemo/HelloServer/Client/main.cpp @@ -189,29 +189,33 @@ struct TupCallback : public ServantProxyCallback } - virtual int onDispatchResponse(const RequestPacket &request, const ResponsePacket &response) + virtual int onDispatch(ReqMessagePtr msg) { - callback_count++; + if(msg->response->iRet != tars::TARSSERVERSUCCESS) + { + cout << "ret error:" << msg->response->iRet << endl; + } + else + { + callback_count++; - TarsUniPacket<> rsp; + TarsUniPacket<> rsp; - rsp.decode(response.sBuffer.data(), response.sBuffer.size()); + rsp.decode(msg->response->sBuffer.data(), msg->response->sBuffer.size()); - int ret = rsp.get(""); - string sRsp = rsp.get("sRsp"); - if(cur == count-1) - { - int64_t cost = TC_Common::now2us() - start; - cout << "TupCallback count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl; - } + int ret = rsp.get(""); + string sRsp = rsp.get("sRsp"); - return 0; - } + if(cur == count-1) + { + int64_t cost = TC_Common::now2us() - start; + cout << "TupCallback count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl; + } - virtual int onDispatchException(const RequestPacket &req, const ResponsePacket &rsp) - { - cout << "onDispatchException" << endl; - return 0; + return 0; + } + + return msg->response->iRet; } int64_t start; diff --git a/servant/libservant/AdapterProxy.cpp b/servant/libservant/AdapterProxy.cpp index 6e2a013..34b7251 100755 --- a/servant/libservant/AdapterProxy.cpp +++ b/servant/libservant/AdapterProxy.cpp @@ -158,13 +158,6 @@ int AdapterProxy::invoke(ReqMessage * msg) msg->request.iRequestId = _timeoutQueue->generateId(); } -// #if TARS_HTTP2 -// if (getObjProxy()->getProtoName() == HTTP2) -// { -// msg->request.iRequestId = getId(); // session Id -// } -// #endif - #ifdef _USE_OPENTRACKING startTrack(msg); #endif diff --git a/servant/libservant/AppProtocol.cpp b/servant/libservant/AppProtocol.cpp index 48d1dda..faa5056 100644 --- a/servant/libservant/AppProtocol.cpp +++ b/servant/libservant/AppProtocol.cpp @@ -31,11 +31,11 @@ namespace tars { -//TAFServer的协议解析器 -TC_NetWorkBuffer::PACKET_TYPE AppProtocol::parseAdmin(TC_NetWorkBuffer &in, shared_ptr &out) -{ - return parse(in, out->getBuffer()); -} +// //TAFServer的协议解析器 +// TC_NetWorkBuffer::PACKET_TYPE AppProtocol::parseAdmin(TC_NetWorkBuffer &in, shared_ptr &out) +// { +// return parse(in, out->getBuffer()); +// } vector ProxyProtocol::tarsRequest(RequestPacket& request, Transceiver *) { diff --git a/servant/libservant/ObjectProxy.cpp b/servant/libservant/ObjectProxy.cpp index c0f30dd..a9cb149 100755 --- a/servant/libservant/ObjectProxy.cpp +++ b/servant/libservant/ObjectProxy.cpp @@ -55,7 +55,6 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll * pCommunicatorEpoll, const string & _proxyProtocol.requestFunc = ProxyProtocol::tarsRequest; _proxyProtocol.responseFunc = ProxyProtocol::tarsResponse; - _protoName = "tars"; _endpointManger.reset(new EndpointManager(this, _communicatorEpoll->getCommunicator(), sObjectProxyName, pCommunicatorEpoll->isFirstNetThread(), setName)); @@ -93,7 +92,7 @@ int ObjectProxy::loadLocator() return 0; } -void ObjectProxy::setProxyProtocol(const ProxyProtocol& protocol, const std::string& name) +void ObjectProxy::setProxyProtocol(const ProxyProtocol& protocol) { if(_hasSetProtocol) { @@ -102,7 +101,6 @@ void ObjectProxy::setProxyProtocol(const ProxyProtocol& protocol, const std::str _hasSetProtocol = true; _proxyProtocol = protocol; - _protoName = name; } ProxyProtocol& ObjectProxy::getProxyProtocol() @@ -110,11 +108,6 @@ ProxyProtocol& ObjectProxy::getProxyProtocol() return _proxyProtocol; } -const std::string& ObjectProxy::getProtoName() const -{ - return _protoName; -} - void ObjectProxy::setSocketOpt(int level, int optname, const void *optval, socklen_t optlen) { SocketOpt socketOpt; diff --git a/servant/libservant/ServantProxy.cpp b/servant/libservant/ServantProxy.cpp index aac8902..d6a4a20 100644 --- a/servant/libservant/ServantProxy.cpp +++ b/servant/libservant/ServantProxy.cpp @@ -161,7 +161,7 @@ ServantProxyCallback::ServantProxyCallback() { } -int ServantProxyCallback::onDispatch(ReqMessagePtr msg) +int HttpServantProxyCallback::onDispatch(ReqMessagePtr msg) { if (msg->response->iRet != tars::TARSSERVERSUCCESS) { @@ -171,18 +171,6 @@ int ServantProxyCallback::onDispatch(ReqMessagePtr msg) return onDispatchResponse(msg->request, *msg->response); } -int ServantProxyCallback::onDispatchResponse(const RequestPacket &req, const ResponsePacket &rsp) -{ - TLOGERROR("[TARS][ServantProxyCallback::onDispatchResponse not be implemented]"< lock(*this); for(size_t i = 0;i < _objectProxyNum; ++i) { - (*(_objectProxy + i))->setProxyProtocol(protocol, protoName); + (*(_objectProxy + i))->setProxyProtocol(protocol); } } diff --git a/servant/libservant/Transceiver.cpp b/servant/libservant/Transceiver.cpp index 6c496f3..13e26c3 100755 --- a/servant/libservant/Transceiver.cpp +++ b/servant/libservant/Transceiver.cpp @@ -310,7 +310,6 @@ TC_Http2Client* Transceiver::getHttp2Client() if(_http2Client == NULL) { _http2Client = new TC_Http2Client(); - // _http2Client->Init(); _http2Client->settings(); } @@ -318,56 +317,12 @@ TC_Http2Client* Transceiver::getHttp2Client() } #endif -// int Transceiver::doRequest() -// { -// if(!isValid()) -// { -// return -1; -// } - -// int iRet = 0; - -// //buf不为空,先发生buffer的内容 -// if(!_sendBuffer.IsEmpty()) -// { -// size_t length = 0; -// void* data = NULL; -// _sendBuffer.PeekData(data, length); - -// iRet = this->send(data, length, 0); - -// //失败,直接返回 -// if(iRet < 0) -// { -// return iRet; -// } - -// if(iRet > 0) -// { -// _sendBuffer.Consume(iRet); -// if (_sendBuffer.IsEmpty()) -// _sendBuffer.Shrink(); -// else -// return 0; -// } -// } - -// //取adapter里面积攒的数据 -// _adapterProxy->doInvoke(); - -// //object里面应该是空的 -// assert(_adapterProxy->getObjProxy()->timeoutQSize() == 0); - -// return 0; -// } int Transceiver::doRequest() { if(!isValid()) return -1; -// int64_t s = TC_Common::now2us(); - //buf不为空,先发送buffer的内容 if(_sendBuffer && !_sendBuffer->empty()) { @@ -386,15 +341,12 @@ int Transceiver::doRequest() _adapterProxy->doInvoke(); } -// cout << "doRequest:" << std::this_thread::get_id() << ", us:" << TC_Common::now2us() - s << ", invoke:" << voke << endl; - //object里面应该是空的 // assert(_adapterProxy->getObjProxy()->timeQEmpty()); return 0; } -// int Transceiver::sendRequest(const char * pData, size_t iSize, bool forceSend) int Transceiver::sendRequest(const shared_ptr &buff, bool forceSend) { //空数据 直接返回成功 diff --git a/servant/servant/AppProtocol.h b/servant/servant/AppProtocol.h index 248e7e1..e1ab3b3 100644 --- a/servant/servant/AppProtocol.h +++ b/servant/servant/AppProtocol.h @@ -69,16 +69,6 @@ public: return TC_NetWorkBuffer::parseBinary4(in, out); } - /** - * 解析协议 - * @param in, 目前的buffer - * @param out, 一个完整的包 - * - * @return int, 0表示没有接收完全, 1表示收到一个完整包 - */ - static TC_NetWorkBuffer::PACKET_TYPE parseAdmin(TC_NetWorkBuffer &in, shared_ptr &out); - - /** * * @param T diff --git a/servant/servant/ObjectProxy.h b/servant/servant/ObjectProxy.h index 641cca2..2dffcfb 100644 --- a/servant/servant/ObjectProxy.h +++ b/servant/servant/ObjectProxy.h @@ -91,19 +91,14 @@ public: * 设置协议解析器 * @return UserProtocol& */ - void setProxyProtocol(const ProxyProtocol& protocol, const std::string& name = "tars"); + void setProxyProtocol(const ProxyProtocol& protocol); + /** * 获取协议解析器 * @return ProxyProtocol& */ ProxyProtocol& getProxyProtocol(); - /** - * 获取协议名字 - * @return ProxyProtocol& - */ - const std::string& getProtoName() const; - /** * 设置套接口选项 */ @@ -178,21 +173,6 @@ public: return _invokeSetId; } - /** - * 生成唯一Id - */ - // inline uint32_t generateId() - // { - // _id++; - - // if(_id == 0) - // { - // ++_id; - // } - - // return _id; - // } - /** * 获取连接超时时间 * @return int @@ -280,11 +260,6 @@ private: */ bool _isInvokeBySet; - /* - * 生成请求的唯一id - */ - // uint32_t _id; - /* * 是否调用了tars_set_protocol设置过proxy的协议函数, * 设置过了就不在设置 @@ -295,10 +270,6 @@ private: * 请求和响应的协议解析器 */ ProxyProtocol _proxyProtocol; - /* - * 协议名称 - */ - std::string _protoName; /* * 连接超时的时间 diff --git a/servant/servant/ServantProxy.h b/servant/servant/ServantProxy.h index d27d3a8..88c111b 100644 --- a/servant/servant/ServantProxy.h +++ b/servant/servant/ServantProxy.h @@ -298,21 +298,7 @@ public: * @param msg * @return int */ - virtual int onDispatch(ReqMessagePtr ptr); - - /** - * 异步回调对象实现该方法,进行业务逻辑处理 - * @param msg - * @return int - */ - virtual int onDispatchResponse(const RequestPacket &req, const ResponsePacket &rsp); - - /** - * 异步回调对象实现该方法(异常),进行业务逻辑处理 - * @param msg - * @return int - */ - virtual int onDispatchException(const RequestPacket &req, const ResponsePacket &rsp); + virtual int onDispatch(ReqMessagePtr ptr) = 0; protected: @@ -351,6 +337,13 @@ class HttpServantProxyCallback : virtual public ServantProxyCallback public: explicit HttpServantProxyCallback(const HttpCallbackPtr& cb); + /** + * 异步回调对象实现该方法,进行业务逻辑处理 + * @param msg + * @return int + */ + virtual int onDispatch(ReqMessagePtr ptr); + /** * 异步回调对象实现该方法,进行业务逻辑处理 * @param msg @@ -519,7 +512,7 @@ public: * 设置用户自定义协议 * @param protocol */ - void tars_set_protocol(const ProxyProtocol& protocol, const std::string& protoName = "tars"); + void tars_set_protocol(const ProxyProtocol& protocol); /** *设置套接字选项 @@ -600,7 +593,6 @@ public: tars::TarsOutputStream& buf, const map& context, const map& status); - // ResponsePacket& rep); /** * TARS协议异步方法调用 diff --git a/servant/servant/Transceiver.h b/servant/servant/Transceiver.h index 93b06ae..3219d64 100755 --- a/servant/servant/Transceiver.h +++ b/servant/servant/Transceiver.h @@ -119,7 +119,6 @@ public: * 如果fd缓冲区已满,返回错误 * 如果数据发送一半,缓冲区满了,返回成功 */ - // int sendRequest(const char * pData,size_t iSize, bool forceSend = false); int sendRequest(const shared_ptr &pData, bool forceSend = false); /* @@ -292,17 +291,6 @@ protected: * 接收buffer */ TC_NetWorkBuffer _recvBuffer; - - // /* - // * 发送缓存buff - // */ - // TC_Buffer _sendBuffer; - - // /* - // * 接收缓存buff - // */ - // TC_Buffer _recvBuffer; - }; ////////////////////////////////////////////////////////// diff --git a/tools/tars2cpp/tars2cpp.cpp b/tools/tars2cpp/tars2cpp.cpp index 44aabea..94fdd98 100644 --- a/tools/tars2cpp/tars2cpp.cpp +++ b/tools/tars2cpp/tars2cpp.cpp @@ -973,86 +973,25 @@ string Tars2Cpp::generateParamDecl(const ParamDeclPtr& pPtr) const return s.str(); } -// string Tars2Cpp::generateDispatchResponseAsync(const OperationPtr& pPtr, const string& cn) const -// { -// ostringstream s; -// s << TAB << "if (msg->response->iRet != tars::TARSSERVERSUCCESS)" << endl -// << TAB << "{" << endl; - -// INC_TAB; -// s << TAB << "callback_" << pPtr->getId() << "_exception(msg->response->iRet);" << endl; -// s << endl; - -// s << TAB << "return msg->response->iRet;" << endl; -// DEL_TAB; -// s << TAB << "}" << endl; - -// s << TAB << _namespace + "::TarsInputStream<" + _namespace + "::BufferReader> _is;" << endl; -// s << endl; -// vector& vParamDecl = pPtr->getAllParamDeclPtr(); - -// s << TAB << "_is.setBuffer(msg->response->sBuffer);" << endl; - -// //对输出参数编码 -// if (pPtr->getReturnPtr()->getTypePtr()) -// { -// s << TAB << tostr(pPtr->getReturnPtr()->getTypePtr()) << " " << pPtr->getReturnPtr()->getId() << generateInitValue(pPtr->getReturnPtr()) << ";" << endl; -// s << readFrom(pPtr->getReturnPtr()) << endl; -// } - -// for (size_t i = 0; i < vParamDecl.size(); i++) -// { -// if (vParamDecl[i]->isOut()) -// { -// s << TAB << tostr(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << " " -// << vParamDecl[i]->getTypeIdPtr()->getId() << generateInitValue(vParamDecl[i]->getTypeIdPtr()) << ";" << endl; -// s << readFrom(vParamDecl[i]->getTypeIdPtr()); -// } -// } - -// //处理线程私有数据 -// s << TAB << "CallbackThreadData * pCbtd = CallbackThreadData::getData();" << endl; -// s << TAB << "assert(pCbtd != NULL);" << endl; -// s << endl; -// s << TAB << "pCbtd->setResponseContext(msg->response->context);" << endl; -// s << endl; - -// //异步回调都无返回值 -// s << TAB << "callback_" << pPtr->getId() << "("; -// string sParams; -// if (pPtr->getReturnPtr()->getTypePtr()) -// { -// sParams = pPtr->getReturnPtr()->getId() + ", "; -// } -// for (size_t i = 0; i < vParamDecl.size(); i++) -// { -// if (vParamDecl[i]->isOut()) -// { -// sParams += vParamDecl[i]->getTypeIdPtr()->getId() + ", "; -// } -// } -// s << tars::TC_Common::trimright(sParams, ", ", false) << ");" << endl; - -// s << endl; -// s << TAB << "pCbtd->delResponseContext();" << endl; -// s << endl; - - -// s << TAB << "return tars::TARSSERVERSUCCESS;" << endl; - -// return s.str(); -// } - - -string Tars2Cpp::generateDispatchResponseAsync(const OperationPtr& pPtr, const string& cn) const +string Tars2Cpp::generateDispatchAsync(const OperationPtr& pPtr, const string& cn) const { ostringstream s; + s << TAB << "if (msg->response->iRet != tars::TARSSERVERSUCCESS)" << endl + << TAB << "{" << endl; + + INC_TAB; + s << TAB << "callback_" << pPtr->getId() << "_exception(msg->response->iRet);" << endl; + s << endl; + + s << TAB << "return msg->response->iRet;" << endl; + DEL_TAB; + s << TAB << "}" << endl; s << TAB << _namespace + "::TarsInputStream<" + _namespace + "::BufferReader> _is;" << endl; s << endl; vector& vParamDecl = pPtr->getAllParamDeclPtr(); - s << TAB << "_is.setBuffer(response.sBuffer);" << endl; + s << TAB << "_is.setBuffer(msg->response->sBuffer);" << endl; //对输出参数编码 if (pPtr->getReturnPtr()->getTypePtr()) @@ -1075,7 +1014,7 @@ string Tars2Cpp::generateDispatchResponseAsync(const OperationPtr& pPtr, const s s << TAB << "CallbackThreadData * pCbtd = CallbackThreadData::getData();" << endl; s << TAB << "assert(pCbtd != NULL);" << endl; s << endl; - s << TAB << "pCbtd->setResponseContext(response.context);" << endl; + s << TAB << "pCbtd->setResponseContext(msg->response->context);" << endl; s << endl; //异步回调都无返回值 @@ -1104,143 +1043,26 @@ string Tars2Cpp::generateDispatchResponseAsync(const OperationPtr& pPtr, const s return s.str(); } -string Tars2Cpp::generateDispatchExceptionAsync(const OperationPtr& pPtr, const string& cn) const -{ - ostringstream s; - INC_TAB; - s << TAB << "callback_" << pPtr->getId() << "_exception(response.iRet);" << endl; - s << endl; - - s << TAB << "return response.iRet;" << endl; - DEL_TAB; - - return s.str(); -} - /////////////////////////////////////////////////////////////////////////////////////////////// -// string Tars2Cpp::generateDispatchCoroAsync(const OperationPtr& pPtr, const string& cn) const -// { -// ostringstream s; -// s << TAB << "if (msg->response->iRet != tars::TARSSERVERSUCCESS)" << endl -// << TAB << "{" << endl; - -// INC_TAB; -// s << TAB << "callback_" << pPtr->getId() << "_exception(msg->response->iRet);" << endl; -// s << endl; - -// s << TAB << "return msg->response->iRet;" << endl; -// DEL_TAB; -// s << TAB << "}" << endl; - -// s << TAB << _namespace + "::TarsInputStream<" + _namespace + "::BufferReader> _is;" << endl; -// s << endl; -// vector& vParamDecl = pPtr->getAllParamDeclPtr(); - -// s << TAB << "_is.setBuffer(msg->response->sBuffer);" << endl; - -// if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) -// { -// s << TAB << "try" << endl; -// s << TAB << "{" << endl; - -// INC_TAB; -// } - -// //对输出参数编码 -// if (pPtr->getReturnPtr()->getTypePtr()) -// { -// s << TAB << tostr(pPtr->getReturnPtr()->getTypePtr()) << " " << pPtr->getReturnPtr()->getId() << generateInitValue(pPtr->getReturnPtr()) << ";" << endl; -// s << readFrom(pPtr->getReturnPtr()) << endl; -// } - -// for (size_t i = 0; i < vParamDecl.size(); i++) -// { -// if (vParamDecl[i]->isOut()) -// { -// s << TAB << tostr(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << " " -// << vParamDecl[i]->getTypeIdPtr()->getId() << generateInitValue(vParamDecl[i]->getTypeIdPtr()) << ";" << endl; -// s << readFrom(vParamDecl[i]->getTypeIdPtr()); -// } -// } - -// s << TAB << "setResponseContext(msg->response->context);" << endl; -// s << endl; - -// //异步回调都无返回值 -// s << TAB << "callback_" << pPtr->getId() << "("; -// string sParams; -// if (pPtr->getReturnPtr()->getTypePtr()) -// { -// sParams = pPtr->getReturnPtr()->getId() + ", "; -// } -// for (size_t i = 0; i < vParamDecl.size(); i++) -// { -// if (vParamDecl[i]->isOut()) -// { -// sParams += vParamDecl[i]->getTypeIdPtr()->getId() + ", "; -// } -// } -// s << tars::TC_Common::trimright(sParams, ", ", false) << ");" << endl; - -// s << endl; - -// if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) -// { -// DEL_TAB; - -// s << TAB << "}" << endl; -// s << TAB << "catch(std::exception &ex)" << endl; -// s << TAB << "{" << endl; - -// INC_TAB; -// s << TAB << "callback_" << pPtr->getId() << "_exception(tars::TARSCLIENTDECODEERR);" << endl; -// s << endl; -// s << TAB << "return tars::TARSCLIENTDECODEERR;" << endl; -// DEL_TAB; - -// s << TAB << "}" << endl; -// s << TAB << "catch(...)" << endl; -// s << TAB << "{" << endl; - -// INC_TAB; -// s << TAB << "callback_" << pPtr->getId() << "_exception(tars::TARSCLIENTDECODEERR);" << endl; -// s << endl; -// s << TAB << "return tars::TARSCLIENTDECODEERR;" << endl; -// DEL_TAB; - -// s << TAB << "}" << endl; -// s << endl; -// } - -// s << TAB << "return tars::TARSSERVERSUCCESS;" << endl; - -// return s.str(); -// } - -string Tars2Cpp::generateDispatchCoroExceptionAsync(const OperationPtr& pPtr, const string& cn) const +string Tars2Cpp::generateDispatchCoroAsync(const OperationPtr& pPtr, const string& cn) const { ostringstream s; + s << TAB << "if (msg->response->iRet != tars::TARSSERVERSUCCESS)" << endl + << TAB << "{" << endl; INC_TAB; - s << TAB << "callback_" << pPtr->getId() << "_exception(response.iRet);" << endl; + s << TAB << "callback_" << pPtr->getId() << "_exception(msg->response->iRet);" << endl; s << endl; - s << TAB << "return response.iRet;" << endl; + s << TAB << "return msg->response->iRet;" << endl; DEL_TAB; - - return s.str(); -} - - -string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, const string& cn) const -{ - ostringstream s; + s << TAB << "}" << endl; s << TAB << _namespace + "::TarsInputStream<" + _namespace + "::BufferReader> _is;" << endl; s << endl; vector& vParamDecl = pPtr->getAllParamDeclPtr(); - s << TAB << "_is.setBuffer(response.sBuffer);" << endl; + s << TAB << "_is.setBuffer(msg->response->sBuffer);" << endl; if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) { @@ -1267,7 +1089,7 @@ string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, con } } - s << TAB << "setResponseContext(response.context);" << endl; + s << TAB << "setResponseContext(msg->response->context);" << endl; s << endl; //异步回调都无返回值 @@ -1320,7 +1142,6 @@ string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, con return s.str(); } - /////////////////////////////////////////////////////////////////////////////////////////////////////// string Tars2Cpp::generateHAsync(const OperationPtr& pPtr) const { @@ -1563,7 +1384,6 @@ string Tars2Cpp::promiseReadFrom(const TypeIdPtr &pPtr, bool bIsRequire) const { //枚举强制类型转换在O2编译选项情况下会告警 string tmp = _namespace + "::Int32 eTemp" + TC_Common::tostr(pPtr->getTag()) + generateInitValue(pPtr); - s << TAB << tmp <getTag()); } @@ -1580,20 +1400,15 @@ string Tars2Cpp::promiseReadFrom(const TypeIdPtr &pPtr, bool bIsRequire) const { s << TAB << "_is.read(ptr->"<< pPtr->getId(); } - s << ", " << pPtr->getTag() << ", " << ((pPtr->isRequire() && bIsRequire)?"true":"false") << ");" << endl; - if(EnumPtr::dynamicCast(pPtr->getTypePtr())) { s << TAB << "ptr->" << pPtr->getId() << " = (" <getTypePtr()) <<")eTemp"<getTag())<<";"<getTypePtr()->isPointer()) s << TAB <<"_is.mapBufferSkip("<getId() << "Len);"<getTypePtr()); @@ -1602,7 +1417,6 @@ bool Tars2Cpp::isPromiseDispatchInitValue(const TypeIdPtr &pPtr) const { return true; } - //枚举强制类型转换在O2编译选项情况下会告警 EnumPtr ePtr = EnumPtr::dynamicCast(pPtr->getTypePtr()); if(ePtr) @@ -1686,9 +1500,7 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons /* //promise异步的函数声明 string sStruct = pPtr->getId(); - s << TAB << "tars::Future< " << cn <<"PrxCallbackPromise::Promise" << sStruct << "Ptr > promise_async_" << pPtr->getId() << "("; - for(size_t i = 0; i < vParamDecl.size(); i++) { if (!vParamDecl[i]->isOut()) @@ -1697,21 +1509,16 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons } } s << "const map& context)" << endl; - s << TAB << "{" << endl; INC_TAB; - if (_tarsMaster) { s << TAB << "this->tars_setMasterFlag(true);" << endl; } - s << TAB << "tars::Promise< " << cn <<"PrxCallbackPromise::Promise" << sStruct << "Ptr > promise;" << endl; s << TAB << cn << "PrxCallbackPromisePtr callback = new " << cn << "PrxCallbackPromise(promise);" << endl; s << endl; - s << TAB << _namespace + "::TarsOutputStream<" + _namespace + "::BufferWriterVector> _os;" << endl; - for(size_t i = 0; i < vParamDecl.size(); i++) { if(vParamDecl[i]->isOut()) @@ -1720,23 +1527,16 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons } s << writeTo(vParamDecl[i]->getTypeIdPtr()); } - s << TAB << "std::map _mStatus;" << endl; - if (!routekey.empty()) { ostringstream os; - os << routekey; - s << TAB << "_mStatus.insert(std::make_pair(ServantProxy::STATUS_GRID_KEY, " << os.str() << "));" << endl; } - s << TAB << "tars_invoke_async(tars::TARSNORMAL,\"" << pPtr->getId() << "\", _os, context, _mStatus, callback);" << endl; - s << endl; s << TAB << "return promise.getFuture();" << endl; - DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -1996,7 +1796,6 @@ struct SortOperation { string Tars2Cpp::generateHPromiseAsync(const InterfacePtr &pInter, const OperationPtr &pPtr) const { ostringstream s; - string sStruct = pPtr->getId(); vector& vParamDecl = pPtr->getAllParamDeclPtr(); //////// @@ -2007,12 +1806,10 @@ string Tars2Cpp::generateHPromiseAsync(const InterfacePtr &pInter, const Operati s << TAB << "{" << endl; s << TAB << "public:" << endl; INC_TAB; - if (pPtr->getReturnPtr()->getTypePtr()) { s << TAB << tostr(pPtr->getReturnPtr()->getTypePtr()) << " _ret;" << endl; } - for(size_t i = 0; i < vParamDecl.size(); i++) { ParamDeclPtr& pPtr = vParamDecl[i]; @@ -2021,82 +1818,63 @@ string Tars2Cpp::generateHPromiseAsync(const InterfacePtr &pInter, const Operati s << TAB << tostr(pPtr->getTypeIdPtr()->getTypePtr()) << " " << pPtr->getTypeIdPtr()->getId() << ";" << endl; } } - s << TAB << "map _mRspContext;" << endl; - DEL_TAB; s << TAB << "};" << endl; s << TAB << endl; s << TAB << "typedef tars::TC_AutoPtr< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << " > Promise" << sStruct << "Ptr;" << endl; s << endl; - s << TAB << pInter->getId() << "PrxCallbackPromise(const tars::Promise< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << "Ptr > &promise)" << endl; s << TAB << ": _promise_" << sStruct << "(promise)" << endl; s << TAB << "{}" << endl; s << TAB << endl; - s << TAB << "virtual void " << "callback_" << pPtr->getId() << "(const " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << "Ptr &ptr)" << endl; s << TAB << "{" << endl; INC_TAB; s << TAB << "_promise_" << sStruct << ".setValue(ptr);" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "virtual void " << "callback_" << pPtr->getId() << "_exception(" + _namespace + "::Int32 ret)" << endl; s << TAB << "{" << endl; INC_TAB; - s << TAB << "std::string str(\"\");" << endl; s << TAB << "str += \"Function:" << pPtr->getId() << "_exception|Ret:\";" << endl; s << TAB << "str += TC_Common::tostr(ret);" << endl; s << TAB << "_promise_" << sStruct << ".setException(tars::copyException(str, ret));" << endl; - DEL_TAB; s << TAB << "}" << endl; - s << endl; DEL_TAB; s << TAB << "protected:" << endl; INC_TAB; s << TAB << "tars::Promise< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << "Ptr > _promise_" << sStruct << ";" << endl; - return s.str(); } - string Tars2Cpp::generateDispatchPromiseAsync(const OperationPtr &pPtr, const string &cn) const { ostringstream s; s << TAB << "if (msg->response->iRet != tars::TARSSERVERSUCCESS)" << endl << TAB << "{" << endl; - INC_TAB; s << TAB << "callback_" << pPtr->getId() << "_exception(msg->response->iRet);" << endl; s << endl; - s << TAB << "return msg->response->iRet;" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << _namespace + "::TarsInputStream<" + _namespace + "::BufferReader> _is;" << endl; s << endl; vector& vParamDecl = pPtr->getAllParamDeclPtr(); - s << TAB << "_is.setBuffer(msg->response->sBuffer);" << endl; s << endl; - string sStruct = pPtr->getId(); - s << TAB << cn << "PrxCallbackPromise::Promise" << sStruct << "Ptr ptr = new "<< cn << "PrxCallbackPromise::Promise" << sStruct << "();" << endl; s << endl; - if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) { s << TAB << "try" << endl; s << TAB << "{" << endl; - INC_TAB; } - //对输出参数编码 if(pPtr->getReturnPtr()->getTypePtr()) { @@ -2104,7 +1882,6 @@ string Tars2Cpp::generateDispatchPromiseAsync(const OperationPtr &pPtr, const st s << TAB << "ptr->_ret " << generateInitValue(pPtr->getReturnPtr())<< ";"<< endl; s << promiseReadFrom(pPtr->getReturnPtr()) << endl; } - for(size_t i = 0; i < vParamDecl.size(); i++) { if(vParamDecl[i]->isOut()) @@ -2114,44 +1891,33 @@ string Tars2Cpp::generateDispatchPromiseAsync(const OperationPtr &pPtr, const st s << promiseReadFrom(vParamDecl[i]->getTypeIdPtr()); } } - if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) { DEL_TAB; - s << TAB << "}" << endl; s << TAB << "catch(std::exception &ex)" << endl; s << TAB << "{" << endl; - INC_TAB; s << TAB << "callback_" << pPtr->getId() << "_exception(tars::TARSCLIENTDECODEERR);" << endl; s << endl; s << TAB << "return tars::TARSCLIENTDECODEERR;" << endl; DEL_TAB; - s << TAB << "}" << endl; s << TAB << "catch(...)" << endl; s << TAB << "{" << endl; - INC_TAB; s << TAB << "callback_" << pPtr->getId() << "_exception(tars::TARSCLIENTDECODEERR);" << endl; s << endl; s << TAB << "return tars::TARSCLIENTDECODEERR;" << endl; DEL_TAB; - s << TAB << "}" << endl; s << endl; } - s << TAB << "ptr->_mRspContext = msg->response->context;" << endl; s << endl; - s << TAB << "callback_" << pPtr->getId() << "(ptr);" << endl; s << endl; - - s << TAB << "return tars::TARSSERVERSUCCESS;" << endl; - return s.str(); } */ @@ -2202,125 +1968,64 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << TAB << "public:" << endl; INC_TAB; - //生成异步回调接口 onDispatchException + s << TAB << "virtual int onDispatch(tars::ReqMessagePtr msg)" << endl; + + //生成异步回调接口 + s << TAB << "{" << endl; + INC_TAB; + string dname = "__" + pPtr->getId() + "_all"; + string dispatch = "static ::std::string " + dname; + s << TAB << dispatch << "[]=" << endl; + s << TAB << "{" << endl; + INC_TAB; + + for (size_t i = 0; i < vOperation.size(); i++) { - s << TAB << "virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)" << endl; - - s << TAB << "{" << endl; - INC_TAB; - string dname = "__" + pPtr->getId() + "_all"; - string dispatch = "static ::std::string " + dname; - s << TAB << dispatch << "[]=" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) + s << TAB << "\"" << vOperation[i]->getId() << "\""; + if (i != vOperation.size() - 1) { - s << TAB << "\"" << vOperation[i]->getId() << "\""; - if (i != vOperation.size() - 1) - { - s << ","; - } - s << endl; - + s << ","; } - DEL_TAB; - s << TAB << "};" << endl; - - s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", request.sFuncName);" << endl; - - s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; - - s << TAB << "switch(r.first - " << dname << ")" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "case " << i << ":" << endl; - s << TAB << "{" << endl; - INC_TAB; - - s << generateDispatchExceptionAsync(vOperation[i], pPtr->getId()) << endl; - - DEL_TAB; - s << TAB << "}" << endl; - } - - DEL_TAB; - s << TAB << "}" << endl; - - s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; - DEL_TAB; - s << TAB << "}" << endl; - s << endl; - // DEL_TAB; - // s << TAB << "};" << endl; + } + DEL_TAB; + s << TAB << "};" << endl; + + s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", string(msg->request.sFuncName));" << endl; + + s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; + + s << TAB << "switch(r.first - " << dname << ")" << endl; + s << TAB << "{" << endl; + INC_TAB; + + for (size_t i = 0; i < vOperation.size(); i++) + { + s << TAB << "case " << i << ":" << endl; + s << TAB << "{" << endl; + INC_TAB; + + s << generateDispatchAsync(vOperation[i], pPtr->getId()) << endl; + + DEL_TAB; + s << TAB << "}" << endl; } - //生成异步回调接口 onDispatchResponse - { - s << TAB << "virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)" << endl; + DEL_TAB; + s << TAB << "}" << endl; - s << TAB << "{" << endl; - INC_TAB; - string dname = "__" + pPtr->getId() + "_all"; - string dispatch = "static ::std::string " + dname; - s << TAB << dispatch << "[]=" << endl; - s << TAB << "{" << endl; - INC_TAB; + s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; + DEL_TAB; + s << TAB << "}" << endl; - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "\"" << vOperation[i]->getId() << "\""; - if (i != vOperation.size() - 1) - { - s << ","; - } - s << endl; + s << endl; - } - DEL_TAB; - s << TAB << "};" << endl; + DEL_TAB; + s << TAB << "};" << endl; - s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", request.sFuncName);" << endl; - - s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; - - s << TAB << "switch(r.first - " << dname << ")" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "case " << i << ":" << endl; - s << TAB << "{" << endl; - INC_TAB; - - s << generateDispatchResponseAsync(vOperation[i], pPtr->getId()) << endl; - - DEL_TAB; - s << TAB << "}" << endl; - } - - DEL_TAB; - s << TAB << "}" << endl; - - s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; - DEL_TAB; - s << TAB << "}" << endl; - - s << endl; - - DEL_TAB; - s << TAB << "};" << endl; - - - s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallback> " << pPtr->getId() << "PrxCallbackPtr;" << endl; - s << endl; - } + s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallback> " << pPtr->getId() << "PrxCallbackPtr;" << endl; + s << endl; /* //生成promise异步回调Proxy s << TAB << "//callback of promise async proxy for client" << endl; @@ -2329,21 +2034,82 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << TAB << "public:" << endl; INC_TAB; s << TAB << "virtual ~" << pPtr->getId() << "PrxCallbackPromise(){}" << endl; - for(size_t i = 0; i < vOperation.size(); i++) { s << generateHPromiseAsync(pPtr, vOperation[i]) << endl; } - DEL_TAB; - s << TAB << "public:" << endl; INC_TAB; s << TAB << "virtual int onDispatch(tars::ReqMessagePtr msg)" << endl; - s << TAB << "{" << endl; INC_TAB; + dname = "__" + pPtr->getId() + "_all"; + dispatch = "static ::std::string " + dname; + s << TAB << dispatch << "[]=" << endl; + s << TAB << "{" << endl; + INC_TAB; + for (size_t i = 0; i < vOperation.size(); i++) + { + s << TAB << "\"" << vOperation[i]->getId() << "\""; + if (i != vOperation.size() - 1) + { + s << ","; + } + s << endl; + } + DEL_TAB; + s << TAB << "};" << endl; + s << endl; + s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", string(msg->request.sFuncName));" << endl; + s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; + s << TAB << "switch(r.first - " << dname << ")" << endl; + s << TAB << "{" << endl; + INC_TAB; + for(size_t i = 0; i < vOperation.size(); i++) + { + s << TAB << "case " << i << ":" << endl; + s << TAB << "{" << endl; + INC_TAB; + s << generateDispatchPromiseAsync(vOperation[i], pPtr->getId()) << endl; + DEL_TAB; + s << TAB << "}" << endl; + } + DEL_TAB; + s << TAB << "}" << endl; + s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; + DEL_TAB; + s << TAB << "}" << endl; + s << endl; + DEL_TAB; + s << TAB << "};" << endl; + s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallbackPromise> " << pPtr->getId() << "PrxCallbackPromisePtr;" << endl; + s << endl; +*/ + //生成协程异步回调类,用于并发请求 + s << TAB << "/* callback of coroutine async proxy for client */" << endl; + s << TAB << "class " << pPtr->getId() << "CoroPrxCallback: public " << pPtr->getId() << "PrxCallback" << endl; + s << TAB << "{" << endl; + s << TAB << "public:" << endl; + INC_TAB; + s << TAB << "virtual ~" << pPtr->getId() << "CoroPrxCallback(){}" << endl; + DEL_TAB; + s << TAB << "public:" << endl; + + INC_TAB; + s << TAB << "virtual const map & getResponseContext() const { return _mRspContext; }" << endl; + s << endl; + s << TAB << "virtual void setResponseContext(const map &mContext) { _mRspContext = mContext; }" << endl; + s << endl; + DEL_TAB; + + s << TAB << "public:" << endl; + INC_TAB; + //生成协程异步回调接口 + s << TAB << "int onDispatch(tars::ReqMessagePtr msg)" << endl; + s << TAB << "{" << endl; + INC_TAB; dname = "__" + pPtr->getId() + "_all"; dispatch = "static ::std::string " + dname; s << TAB << dispatch << "[]=" << endl; @@ -2373,13 +2139,13 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << TAB << "{" << endl; INC_TAB; - for(size_t i = 0; i < vOperation.size(); i++) + for (size_t i = 0; i < vOperation.size(); i++) { s << TAB << "case " << i << ":" << endl; s << TAB << "{" << endl; INC_TAB; - s << generateDispatchPromiseAsync(vOperation[i], pPtr->getId()) << endl; + s << generateDispatchCoroAsync(vOperation[i], pPtr->getId()) << endl; DEL_TAB; s << TAB << "}" << endl; @@ -2394,199 +2160,6 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << endl; - DEL_TAB; - - s << TAB << "};" << endl; - - s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallbackPromise> " << pPtr->getId() << "PrxCallbackPromisePtr;" << endl; - s << endl; -*/ - //生成协程异步回调类,用于并发请求 - s << TAB << "/* callback of coroutine async proxy for client */" << endl; - s << TAB << "class " << pPtr->getId() << "CoroPrxCallback: public " << pPtr->getId() << "PrxCallback" << endl; - s << TAB << "{" << endl; - s << TAB << "public:" << endl; - INC_TAB; - s << TAB << "virtual ~" << pPtr->getId() << "CoroPrxCallback(){}" << endl; - DEL_TAB; - - s << TAB << "public:" << endl; - - INC_TAB; - s << TAB << "virtual const map & getResponseContext() const { return _mRspContext; }" << endl; - s << endl; - s << TAB << "virtual void setResponseContext(const map &mContext) { _mRspContext = mContext; }" << endl; - s << endl; - DEL_TAB; - - s << TAB << "public:" << endl; - INC_TAB; - - //生成协程异步回调接口 - { - s << TAB << "virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)" << endl; - s << TAB << "{" << endl; - INC_TAB; - string dname = "__" + pPtr->getId() + "_all"; - string dispatch = "static ::std::string " + dname; - s << TAB << dispatch << "[]=" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "\"" << vOperation[i]->getId() << "\""; - if (i != vOperation.size() - 1) - { - s << ","; - } - s << endl; - } - - DEL_TAB; - s << TAB << "};" << endl; - - s << endl; - - s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", request.sFuncName);" << endl; - - s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; - - s << TAB << "switch(r.first - " << dname << ")" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "case " << i << ":" << endl; - s << TAB << "{" << endl; - INC_TAB; - - s << generateDispatchCoroResponseAsync(vOperation[i], pPtr->getId()) << endl; - - DEL_TAB; - s << TAB << "}" << endl; - } - - DEL_TAB; - s << TAB << "}" << endl; - - s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; - DEL_TAB; - s << TAB << "}" << endl; - - s << endl; - } - - - { - //生成协程异步回调接口 - s << TAB << "virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)" << endl; - s << TAB << "{" << endl; - INC_TAB; - string dname = "__" + pPtr->getId() + "_all"; - string dispatch = "static ::std::string " + dname; - s << TAB << dispatch << "[]=" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "\"" << vOperation[i]->getId() << "\""; - if (i != vOperation.size() - 1) - { - s << ","; - } - s << endl; - } - - DEL_TAB; - s << TAB << "};" << endl; - - s << endl; - - s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", request.sFuncName);" << endl; - - s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; - - s << TAB << "switch(r.first - " << dname << ")" << endl; - s << TAB << "{" << endl; - INC_TAB; - - for (size_t i = 0; i < vOperation.size(); i++) - { - s << TAB << "case " << i << ":" << endl; - s << TAB << "{" << endl; - INC_TAB; - - s << generateDispatchCoroExceptionAsync(vOperation[i], pPtr->getId()) << endl; - - DEL_TAB; - s << TAB << "}" << endl; - } - - DEL_TAB; - s << TAB << "}" << endl; - - s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; - DEL_TAB; - s << TAB << "}" << endl; - - s << endl; - } - // s << TAB << "int onDispatch(tars::ReqMessagePtr msg)" << endl; - // s << TAB << "{" << endl; - // INC_TAB; - // dname = "__" + pPtr->getId() + "_all"; - // dispatch = "static ::std::string " + dname; - // s << TAB << dispatch << "[]=" << endl; - // s << TAB << "{" << endl; - // INC_TAB; - - // for (size_t i = 0; i < vOperation.size(); i++) - // { - // s << TAB << "\"" << vOperation[i]->getId() << "\""; - // if (i != vOperation.size() - 1) - // { - // s << ","; - // } - // s << endl; - // } - - // DEL_TAB; - // s << TAB << "};" << endl; - - // s << endl; - - // s << TAB << "pair r = equal_range(" << dname << ", " << dname << "+" << vOperation.size() << ", string(msg->request.sFuncName));" << endl; - - // s << TAB << "if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;" << endl; - - // s << TAB << "switch(r.first - " << dname << ")" << endl; - // s << TAB << "{" << endl; - // INC_TAB; - - // for (size_t i = 0; i < vOperation.size(); i++) - // { - // s << TAB << "case " << i << ":" << endl; - // s << TAB << "{" << endl; - // INC_TAB; - - // s << generateDispatchCoroAsync(vOperation[i], pPtr->getId()) << endl; - - // DEL_TAB; - // s << TAB << "}" << endl; - // } - - // DEL_TAB; - // s << TAB << "}" << endl; - - // s << TAB << "return tars::TARSSERVERNOFUNCERR;" << endl; - // DEL_TAB; - // s << TAB << "}" << endl; - - // s << endl; - //////////////////////////////////////////////////////////////////// DEL_TAB; @@ -2669,8 +2242,8 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << TAB << "{" << endl; INC_TAB; - string dname = "__" + nPtr->getId() + "__" + pPtr->getId() + "_all"; - string dispatch = "static ::std::string " + dname; + dname = "__" + nPtr->getId() + "__" + pPtr->getId() + "_all"; + dispatch = "static ::std::string " + dname; s << TAB << dispatch << "[]=" << endl; s << TAB << "{" << endl; INC_TAB; @@ -3286,8 +2859,4 @@ StructPtr Tars2Cpp::findStruct(const ContextPtr& pPtr, const string& id) // s << endl; // s << "#endif" << endl; -// tars::TC_File::makeDirRecursive(_baseDir, 0755); -// tars::TC_File::save2file(fileH, s.str()); - -// return; -// } +// \ No newline at end of file diff --git a/tools/tars2cpp/tars2cpp.h b/tools/tars2cpp/tars2cpp.h index dffe182..3cfccd6 100644 --- a/tools/tars2cpp/tars2cpp.h +++ b/tools/tars2cpp/tars2cpp.h @@ -309,16 +309,7 @@ protected: * * @return string */ - string generateDispatchResponseAsync(const OperationPtr &pPtr, const string &cn) const; - - /** - * 生成onDispatchException - * @param pPtr - * @param cn - * - * @return string - */ - string generateDispatchExceptionAsync(const OperationPtr& pPtr, const string& cn) const; + string generateDispatchAsync(const OperationPtr &pPtr, const string &cn) const; /** * 生成操作函数调用分发的源码 @@ -327,17 +318,7 @@ protected: * * @return string */ - string generateDispatchCoroResponseAsync(const OperationPtr &pPtr, const string &cn) const; - - /** - * 生成操作函数调用分发的源码 - * @param pPtr - * @param cn - * - * @return string - */ - string generateDispatchCoroExceptionAsync(const OperationPtr &pPtr, const string &cn) const; - + string generateDispatchCoroAsync(const OperationPtr &pPtr, const string &cn) const; /** * 生成servant操作函数调用的源码 @@ -477,6 +458,4 @@ private: bool _tarsMaster; }; -#endif - - +#endif \ No newline at end of file