diff options
author | Reece Humphreys <reecewh@icloud.com> | 2019-07-18 11:22:59 -0400 |
---|---|---|
committer | Jose <pepone@users.noreply.github.com> | 2019-07-18 17:22:59 +0200 |
commit | b804b8d141c0f4243e9b27d02cdee184da2ee628 (patch) | |
tree | 073729c29aaaed080b3caa5f987927c3b0c4d295 /cpp | |
parent | Add support for forward declarations (diff) | |
download | ice-b804b8d141c0f4243e9b27d02cdee184da2ee628.tar.bz2 ice-b804b8d141c0f4243e9b27d02cdee184da2ee628.tar.xz ice-b804b8d141c0f4243e9b27d02cdee184da2ee628.zip |
Dispatch fixes for #421 (#440)
* Dispatch fixes for #421
* Add interceptor test
* Updated test to add test interceptor exceptions
* Dispatch fixes and add ability to retry
* Fixed comments
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/slice2swift/Gen.cpp | 8 | ||||
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.cpp | 85 | ||||
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.h | 1 |
3 files changed, 52 insertions, 42 deletions
diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index 2215503dea9..1d8ff20d595 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -1593,9 +1593,11 @@ Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) out << ("request: " + getUnqualified("Ice.Request", swiftModule)); out << ("current: " + getUnqualified("Ice.Current", swiftModule)); out << epar; - out << " throws"; + out << " throws -> PromiseKit.Promise<" << getUnqualified("Ice.OutputStream", swiftModule) << ">?"; out << sb; + // Call startOver() so that dispatch interceptors can retry requests + out << nl << "request.startOver()"; out << nl << "switch current.operation"; out << sb; out.dec(); // to align case with switch @@ -1606,12 +1608,12 @@ Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) out.inc(); if(opName == "ice_id" || opName == "ice_ids" || opName == "ice_isA" || opName == "ice_ping") { - out << nl << "try (servant as? Object ?? " << disp << ".defaultObject)._iceD_" + out << nl << "return try (servant as? Object ?? " << disp << ".defaultObject)._iceD_" << opName << "(incoming: request, current: current)"; } else { - out << nl << "try servant._iceD_" << opName << "(incoming: request, current: current)"; + out << nl << "return try servant._iceD_" << opName << "(incoming: request, current: current)"; } out.dec(); } diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 78a1e37e263..626b43847bc 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -2263,6 +2263,38 @@ SwiftGenerator::writeMarshalOutParams(::IceUtilInternal::Output& out, const Oper } void +SwiftGenerator::writeMarshalAsyncOutParams(::IceUtilInternal::Output& out, const OperationPtr& op) +{ + ParamInfoList requiredOutParams, optionalOutParams; + getOutParams(op, requiredOutParams, optionalOutParams); + + out << sb << " (ostr, retVals) in"; + out << nl << "let " << operationReturnDeclaration(op) << " = retVals"; + // + // Marshal parameters + // 1. required + // 2. optional (including optional return) + // + + for(ParamInfoList::const_iterator q = requiredOutParams.begin(); q != requiredOutParams.end(); ++q) + { + writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true); + } + + for(ParamInfoList::const_iterator q = optionalOutParams.begin(); q != optionalOutParams.end(); ++q) + { + writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true, q->tag); + } + + if(op->returnsClasses(false)) + { + out << nl << "ostr.writePendingValues()"; + } + + out << eb; +} + +void SwiftGenerator::writeUnmarshalOutParams(::IceUtilInternal::Output& out, const OperationPtr& op) { TypePtr returnType = op->returnType(); @@ -2645,7 +2677,7 @@ SwiftGenerator::writeDispatchOperation(::IceUtilInternal::Output& out, const Ope out << ("current: " + getUnqualified("Ice.Current", swiftModule)); out << epar; - out << " throws"; + out << " throws -> PromiseKit.Promise<" << getUnqualified("Ice.OutputStream", swiftModule) << ">?"; out << sb; if(allInParams.empty()) @@ -2660,7 +2692,7 @@ SwiftGenerator::writeDispatchOperation(::IceUtilInternal::Output& out, const Ope if(op->format() != DefaultFormat) { - out << nl << "inS.setFormat(" << opFormatTypeToString(op) << ");"; + out << nl << "inS.setFormat(" << opFormatTypeToString(op) << ")"; } out << sp; @@ -2679,17 +2711,16 @@ SwiftGenerator::writeDispatchOperation(::IceUtilInternal::Output& out, const Ope out << "current: current"; out << epar; - out << sp; - if(allOutParams.empty()) + out << sp << nl; + out << "return inS.setResult"; + if (allOutParams.empty()) { - out << nl << "inS.writeEmptyParams()"; + out << "()"; } else { - out << nl << "inS.write "; writeMarshalOutParams(out, op); } - out << eb; } @@ -2708,8 +2739,7 @@ SwiftGenerator::writeDispatchAsyncOperation(::IceUtilInternal::Output& out, cons out << ("current: " + getUnqualified("Ice.Current", swiftModule)); out << epar; - out << " throws"; - + out << " throws -> PromiseKit.Promise<" << getUnqualified("Ice.OutputStream", swiftModule) << ">?"; out << sb; if(allInParams.empty()) { @@ -2723,44 +2753,21 @@ SwiftGenerator::writeDispatchAsyncOperation(::IceUtilInternal::Output& out, cons if(op->format() != DefaultFormat) { - out << nl << "inS.setFormat(" << opFormatTypeToString(op) << ");"; + out << nl << "inS.setFormat(" << opFormatTypeToString(op) << ")"; } - out << sp; - out << nl; - out << "firstly"; - out << sb; - out << nl << fixIdent(op->name() + (operationIsAmd(op) ? "Async" : "")); - - out << spar; + out << sp << nl; + out << "return inS.setResultPromise(" << fixIdent(op->name() + (operationIsAmd(op) ? "Async" : "")) << spar; for(ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q) { out << (q->name + ": iceP_" + q->name); } - out << "current: current"; - out << epar; - out << eb; - - out << ".done(on: nil)"; - out << sb; - if(allOutParams.empty()) + out << "current: current" << epar; + out << ")"; + if (!allOutParams.empty()) { - out << nl << "inS.writeEmptyParams()"; + writeMarshalAsyncOutParams(out, op); } - else - { - out << " " << operationReturnDeclaration(op) << " in"; - out << nl << "inS.write "; - writeMarshalOutParams(out, op); - } - out << eb; - - out << ".catch(on: nil)"; - out << sb; - out << " err in"; - out << nl << "inS.exception(err)"; - out << eb; - out << eb; } diff --git a/cpp/src/slice2swift/SwiftUtil.h b/cpp/src/slice2swift/SwiftUtil.h index 3a4b338fba3..2265ba15ae6 100644 --- a/cpp/src/slice2swift/SwiftUtil.h +++ b/cpp/src/slice2swift/SwiftUtil.h @@ -134,6 +134,7 @@ protected: bool usesMarshalHelper(const TypePtr&); void writeMarshalInParams(::IceUtilInternal::Output&, const OperationPtr&); void writeMarshalOutParams(::IceUtilInternal::Output&, const OperationPtr&); + void writeMarshalAsyncOutParams(::IceUtilInternal::Output&, const OperationPtr&); void writeUnmarshalInParams(::IceUtilInternal::Output&, const OperationPtr&); void writeUnmarshalOutParams(::IceUtilInternal::Output&, const OperationPtr&); void writeUnmarshalUserException(::IceUtilInternal::Output& out, const OperationPtr&); |