diff options
author | Joe George <joe@zeroc.com> | 2015-12-18 14:48:29 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2015-12-18 14:48:29 -0500 |
commit | 3c07e69ea17223c7d5a8449ec9bb75d9bba40e07 (patch) | |
tree | 6101376459c3f62f9fe4dcbb7819729667209191 /cpp/src | |
parent | C++11 Ice/ami test hangs on OS X (diff) | |
download | ice-3c07e69ea17223c7d5a8449ec9bb75d9bba40e07.tar.bz2 ice-3c07e69ea17223c7d5a8449ec9bb75d9bba40e07.tar.xz ice-3c07e69ea17223c7d5a8449ec9bb75d9bba40e07.zip |
ICE-6903 - "async" metadata changes
- Rename "async" metadata to "async-oneway"
- Update C++11 mapping for "async-oneway".
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.h | 6 | ||||
-rw-r--r-- | cpp/src/Ice/ConnectionI.cpp | 20 | ||||
-rw-r--r-- | cpp/src/Ice/ConnectionI.h | 11 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 4 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 68 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 6 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 4 | ||||
-rw-r--r-- | cpp/src/slice2objc/Gen.cpp | 4 |
9 files changed, 65 insertions, 60 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 25c8d8f7d97..13d082a1af1 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -235,7 +235,6 @@ Ice::CommunicatorI::flushBatchRequests() { promise<bool> promise; flushBatchRequests_async( - nullptr, [&](exception_ptr ex) { promise.set_exception(move(ex)); @@ -249,7 +248,6 @@ Ice::CommunicatorI::flushBatchRequests() ::std::function<void ()> Ice::CommunicatorI::flushBatchRequests_async( - function<void ()> completed, function<void (exception_ptr)> exception, function<void (bool)> sent) { diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index 277d573b04b..173effb3beb 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -75,10 +75,8 @@ public: #ifdef ICE_CPP11_MAPPING virtual ::std::function<void ()> - flushBatchRequests_async( - ::std::function<void ()> completed, - ::std::function<void (std::exception_ptr)> exception = nullptr, - ::std::function<void (bool)> sent = nullptr); + flushBatchRequests_async(::std::function<void (::std::exception_ptr)> exception, + ::std::function<void (bool)> sent); #else virtual AsyncResultPtr begin_flushBatchRequests(); virtual AsyncResultPtr begin_flushBatchRequests(const CallbackPtr&, const LocalObjectPtr& = 0); diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index a824fbf0107..f8b9475fd1b 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -815,22 +815,22 @@ Ice::ConnectionI::flushBatchRequests() #ifdef ICE_CPP11_MAPPING function<void ()> -Ice::ConnectionI::flushBatchRequests_async(function<void ()>, function<void (exception_ptr)> exception, - function<void (bool)> sent) +Ice::ConnectionI::flushBatchRequests_async(function<void (exception_ptr)> exception, + function<void (bool)> sent) { class FlushBatchRequestsCallback : public CallbackBase { public: - + FlushBatchRequestsCallback(function<void (exception_ptr)> exception, - function<void (bool)> sent, + function<void (bool)> sent, shared_ptr<Connection> connection) : _exception(move(exception)), _sent(move(sent)), _connection(move(connection)) { } - + virtual void sent(const AsyncResultPtr& result) const { try @@ -842,19 +842,19 @@ Ice::ConnectionI::flushBatchRequests_async(function<void ()>, function<void (exc { _exception(current_exception()); } - + if(_sent) { _sent(result->sentSynchronously()); } } - + virtual bool hasSentCallback() const { return true; } - + virtual void completed(const ::Ice::AsyncResultPtr& result) const { @@ -875,9 +875,9 @@ Ice::ConnectionI::flushBatchRequests_async(function<void ()>, function<void (exc function<void (bool)> _sent; shared_ptr<Connection> _connection; }; - + auto self = dynamic_pointer_cast<ConnectionI>(shared_from_this()); - + auto result = make_shared<ConnectionFlushBatchAsync>(self, _communicator, _instance, __flushBatchRequests_name, make_shared<FlushBatchRequestsCallback>(move(exception), move(sent), self)); result->invoke(); diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h index c3b4c270311..6e7227f6bdf 100644 --- a/cpp/src/Ice/ConnectionI.h +++ b/cpp/src/Ice/ConnectionI.h @@ -134,7 +134,7 @@ public: #endif }; - + #ifdef ICE_CPP11_MAPPING class StartCallback { @@ -154,7 +154,7 @@ public: }; typedef IceUtil::Handle<StartCallback> StartCallbackPtr; #endif - + enum DestructionReason { ObjectAdapterDeactivated, @@ -187,10 +187,9 @@ public: virtual void flushBatchRequests(); // From Connection. #ifdef ICE_CPP11_MAPPING - virtual std::function<void ()> - flushBatchRequests_async(::std::function<void ()> completed, - ::std::function<void (::std::exception_ptr)> exception = nullptr, - ::std::function<void (bool)> sent = nullptr); + virtual ::std::function<void ()> + flushBatchRequests_async(::std::function<void (::std::exception_ptr)> exception, + ::std::function<void (bool)> sent); #else virtual AsyncResultPtr begin_flushBatchRequests(); virtual AsyncResultPtr begin_flushBatchRequests(const CallbackPtr&, const LocalObjectPtr& = 0); diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 02a26d39551..26658b3509a 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1582,7 +1582,7 @@ Slice::Container::hasLocalClassDefsWithAsync() const ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); if(cl && cl->isLocal()) { - if(cl->hasMetaData("async")) + if(cl->hasMetaData("async-oneway")) { return true; } @@ -1590,7 +1590,7 @@ Slice::Container::hasLocalClassDefsWithAsync() const OperationList ol = cl->operations(); for(OperationList::const_iterator q = ol.begin(); q != ol.end(); ++q) { - if((*q)->hasMetaData("async")) + if((*q)->hasMetaData("async-oneway")) { return true; } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index e34d25b5361..9b52d739bf2 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -662,7 +662,7 @@ Slice::Gen::generate(const UnitPtr& p) ImplVisitor implVisitor(implH, implC, _dllExport); p->visit(&implVisitor, false); } - + generateChecksumMap(p); } H << sp; @@ -726,7 +726,7 @@ Slice::Gen::generate(const UnitPtr& p) }*/ generateChecksumMap(p); - + H << sp; H.zeroIndent(); H << nl << "#endif"; @@ -3797,7 +3797,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) C << eb; } - if(cl->isLocal() && (cl->hasMetaData("async") || p->hasMetaData("async"))) + if(cl->isLocal() && (cl->hasMetaData("async-oneway") || p->hasMetaData("async-oneway"))) { vector<string> paramsDeclAMI; vector<string> outParamsDeclAMI; @@ -4121,7 +4121,7 @@ Slice::Gen::AsyncCallbackVisitor::AsyncCallbackVisitor(Output& h, Output&, const bool Slice::Gen::AsyncCallbackVisitor::visitModuleStart(const ModulePtr& p) { - if(!p->hasNonLocalClassDefs() && !p->hasContentsWithMetaData("async")) + if(!p->hasNonLocalClassDefs() && !p->hasContentsWithMetaData("async-oneway")) { return false; } @@ -4159,7 +4159,7 @@ Slice::Gen::AsyncCallbackVisitor::visitOperation(const OperationPtr& p) { ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); - if(cl->isLocal() && !(cl->hasMetaData("async") || p->hasMetaData("async"))) + if(cl->isLocal() && !(cl->hasMetaData("async-oneway") || p->hasMetaData("async-oneway"))) { return; } @@ -7677,7 +7677,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p) H << nl << deprecateSymbol << "virtual " << retS << ' ' << fixKwd(name) << params << (isConst ? " const" : "") << " = 0;"; - if(cl->hasMetaData("async") || p->hasMetaData("async")) + if(cl->hasMetaData("async-oneway") || p->hasMetaData("async-oneway")) { vector<string> paramsDeclAMI; vector<string> outParamsDeclAMI; @@ -7689,24 +7689,11 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p) StringList metaData = (*r)->getMetaData(); string typeString; - if((*r)->isOutParam()) - { - typeString = outputTypeToString((*r)->type(), (*r)->optional(), metaData, - _useWstring | TypeContextAMIEnd | TypeContextLocalOperation, true); - } - else - { - typeString = inputTypeToString((*r)->type(), (*r)->optional(), metaData, _useWstring | TypeContextLocalOperation, true); - } - if(!(*r)->isOutParam()) { + typeString = inputTypeToString((*r)->type(), (*r)->optional(), metaData, _useWstring | TypeContextLocalOperation, true); paramsDeclAMI.push_back(typeString + ' ' + paramName); } - else - { - outParamsDeclAMI.push_back(typeString + ' ' + paramName); - } } H << sp; @@ -7721,19 +7708,42 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p) { H << nl; } - H << "::std::function<void ("; - for(vector<string>::const_iterator i = outParamsDeclAMI.begin(); i != outParamsDeclAMI.end();) + H << "::std::function<void (::std::exception_ptr)> exception,"; + H << nl << "::std::function<void (bool)> sent) = 0;"; + H.restoreIndent(); + + H << sp; + H << nl << "template<template<typename> class P = ::std::promise>"; + H << nl << deprecateSymbol << "auto " << name << "_async" << spar << paramsDeclAMI << epar; + H.inc(); + H << nl << "-> decltype(::std::declval<P<bool>>().get_future())"; + H.dec(); + H << sb; + H << nl << "using Promise = P<bool>;"; + H << nl << "auto __promise = ::std::make_shared<Promise>();"; + + H << nl << name << "_async("; + H.useCurrentPosAsIndent(); + for(vector<string>::const_iterator i = paramsDeclAMI.begin(); i != paramsDeclAMI.end(); ++i) { H << *i << ","; - if(++i != outParamsDeclAMI.end()) - { - H << " "; - } } - H << ")>,"; - H << nl << "::std::function<void (::std::exception_ptr)> exception = nullptr,"; - H << nl << "::std::function<void (bool)> sent = nullptr) = 0;"; + if(!paramsDeclAMI.empty()) + { + H << nl; + } + H << "[__promise](::std::exception_ptr __ex)"; + H << sb; + H << nl << "__promise->set_exception(::std::move(__ex));"; + H << eb << ","; + H << nl << "[__promise](bool __b)"; + H << sb; + H << nl << "__promise->set_value(__b);"; + H << eb << ");"; H.restoreIndent(); + + H << nl << "return __promise->get_future();"; + H << eb; } } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index e5288b6d1e7..2b6e736795f 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -3352,7 +3352,7 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p) << spar << params << "Ice.Current current__" << epar << ';'; } - if(isLocal && (classDef->hasMetaData("async") || p->hasMetaData("async"))) + if(isLocal && (classDef->hasMetaData("async-oneway") || p->hasMetaData("async-oneway"))) { vector<string> paramsNewAsync = getParamsAsync(p, false); @@ -5063,9 +5063,9 @@ Slice::Gen::AsyncDelegateVisitor::visitOperation(const OperationPtr& p) ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); // - // We also generate delegates for local twoway-style operations marked with "async" metadata. + // We also generate delegates for local twoway-style operations marked with "async-oneway" metadata. // - if(cl->isLocal() && (!(cl->hasMetaData("async") || p->hasMetaData("async")) || !p->returnsData())) + if(cl->isLocal() && (!(cl->hasMetaData("async-oneway") || p->hasMetaData("async-oneway")) || !p->returnsData())) { return; } diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index d0397e9cb41..354b0ce37f1 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -3073,9 +3073,9 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) out << ';'; // - // Generate asynchronous API for local operations marked with "async" metadata. + // Generate asynchronous API for local operations marked with "async-oneway" metadata. // - if(p->hasMetaData("async") || op->hasMetaData("async")) + if(p->hasMetaData("async-oneway") || op->hasMetaData("async-oneway")) { vector<string> inParams = getInOutParams(op, package, InParam, true, true); diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp index 4e39a68dd3b..eae190d4a5f 100644 --- a/cpp/src/slice2objc/Gen.cpp +++ b/cpp/src/slice2objc/Gen.cpp @@ -1135,9 +1135,9 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p) _H << ";"; } - if(cl->isLocal() && (cl->hasMetaData("async") || p->hasMetaData("async"))) + if(cl->isLocal() && (cl->hasMetaData("async-oneway") || p->hasMetaData("async-oneway"))) { - // TODO: add supports for parameters when needed. + // TODO: add support for parameters when needed. _H << nl << "-(id<ICEAsyncResult>) begin_" << name << ";"; _H << nl << "-(id<ICEAsyncResult>) begin_" << name << ":(void(^)(ICEException*))exception;"; _H << nl << "-(id<ICEAsyncResult>) begin_" << name |