diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-12-09 15:18:08 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-12-09 15:18:08 -0800 |
commit | 3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5 (patch) | |
tree | a8edbf5d1043527cc50880b34ee83458ed7e4855 /cpp | |
parent | Merge remote-tracking branch 'origin/3.6' (diff) | |
download | ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.tar.bz2 ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.tar.xz ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.zip |
ICE-7138 - new Python AMI mapping based on futures and modified AMD mapping
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/AsyncResult.h | 10 | ||||
-rw-r--r-- | cpp/include/Ice/OutgoingAsync.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/OutgoingAsync.cpp | 37 | ||||
-rw-r--r-- | cpp/src/Slice/Python.cpp | 16 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.cpp | 48 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.h | 2 |
6 files changed, 89 insertions, 26 deletions
diff --git a/cpp/include/Ice/AsyncResult.h b/cpp/include/Ice/AsyncResult.h index e2c1d53d53b..639a44ed278 100644 --- a/cpp/include/Ice/AsyncResult.h +++ b/cpp/include/Ice/AsyncResult.h @@ -62,6 +62,16 @@ public: static void check(const AsyncResultPtr&, const Connection*, const ::std::string&); static void check(const AsyncResultPtr&, const Communicator*, const ::std::string&); + class Callback : public IceUtil::Shared + { + public: + + virtual void run() = 0; + }; + typedef IceUtil::Handle<Callback> CallbackPtr; + + virtual void scheduleCallback(const CallbackPtr&) = 0; + protected: static void check(const AsyncResultPtr&, const ::std::string&); diff --git a/cpp/include/Ice/OutgoingAsync.h b/cpp/include/Ice/OutgoingAsync.h index 86d017dbfe1..cb83850a048 100644 --- a/cpp/include/Ice/OutgoingAsync.h +++ b/cpp/include/Ice/OutgoingAsync.h @@ -107,6 +107,8 @@ public: virtual void readEmptyParams(); virtual void readParamEncaps(const ::Ice::Byte*&, ::Ice::Int&); virtual void throwUserException(); + + virtual void scheduleCallback(const CallbackPtr&); #endif void attachRemoteObserver(const Ice::ConnectionInfoPtr& c, const Ice::EndpointPtr& endpt, Ice::Int requestId) diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 060f9019e72..40c753fe656 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -124,8 +124,7 @@ OutgoingAsyncBase::invokeExceptionAsync() }; // - // CommunicatorDestroyedCompleted is the only exception that can propagate directly - // from this method. + // CommunicatorDestroyedException is the only exception that can propagate directly from this method. // _instance->clientThreadPool()->dispatch(new AsynchronousException(_cachedConnection, ICE_SHARED_FROM_THIS)); } @@ -154,8 +153,7 @@ OutgoingAsyncBase::invokeResponseAsync() }; // - // CommunicatorDestroyedCompleted is the only exception that can propagate directly - // from this method. + // CommunicatorDestroyedException is the only exception that can propagate directly from this method. // _instance->clientThreadPool()->dispatch(new AsynchronousResponse(_cachedConnection, ICE_SHARED_FROM_THIS)); } @@ -534,6 +532,37 @@ OutgoingAsyncBase::throwUserException() } } +void +OutgoingAsyncBase::scheduleCallback(const CallbackPtr& cb) +{ + class WorkItem : public DispatchWorkItem + { + public: + + WorkItem(const CallbackPtr& cb) : _cb(cb) {} + + virtual void run() + { + try + { + _cb->run(); + } + catch(...) + { + } + } + + private: + + CallbackPtr _cb; + }; + + // + // CommunicatorDestroyedException is the only exception that can propagate directly from this method. + // + _instance->clientThreadPool()->dispatch(new WorkItem(cb)); +} + #endif void diff --git a/cpp/src/Slice/Python.cpp b/cpp/src/Slice/Python.cpp index cf46117d345..b602b09a1c0 100644 --- a/cpp/src/Slice/Python.cpp +++ b/cpp/src/Slice/Python.cpp @@ -401,10 +401,7 @@ usage(const string& n) "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" "--prefix PREFIX Prepend filenames of Python modules with PREFIX.\n" - "--ice Allow reserved Ice prefix in Slice identifiers\n" - " deprecated: use instead [[\"ice-prefix\"]] metadata.\n" - "--underscore Allow underscores in Slice identifiers\n" - " deprecated: use instead [[\"underscore\"]] metadata.\n" + "--python3 Generate code for the Python 3 mapping.\n" ; } @@ -432,6 +429,7 @@ Slice::Python::compile(const vector<string>& argv) opts.addOpt("", "build-package"); opts.addOpt("", "checksum"); opts.addOpt("", "prefix", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "python3"); vector<string> args; try @@ -502,6 +500,8 @@ Slice::Python::compile(const vector<string>& argv) string prefix = opts.optArg("prefix"); + bool python3 = opts.isSet("python3"); + if(args.empty()) { getErrorStream() << argv[0] << ": error: no input file" << endl; @@ -661,15 +661,17 @@ Slice::Python::compile(const vector<string>& argv) FileTracker::instance()->addFile(file); // - // Python magic comment to set the file encoding, it must be first or second line + // Emit a Python magic comment to set the file encoding. + // It must be the first or second line. // out << "# -*- coding: utf-8 -*-\n"; printHeader(out); printGeneratedHeader(out, base + ".ice", "#"); + // - // Generate the Python mapping. + // Generate Python code. // - generate(u, all, checksum, includePaths, out); + generate(u, all, checksum, python3, includePaths, out); out.close(); } diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index b07e605a1ed..c8759a6124c 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -87,7 +87,7 @@ class CodeVisitor : public ParserVisitor { public: - CodeVisitor(IceUtilInternal::Output&, set<string>&); + CodeVisitor(IceUtilInternal::Output&, set<string>&, bool); virtual bool visitModuleStart(const ModulePtr&); virtual void visitModuleEnd(const ModulePtr&); @@ -181,12 +181,13 @@ private: }; bool parseOpComment(const string&, OpComment&); - enum DocstringMode { DocSync, DocAsyncBegin, DocAsyncEnd, DocDispatch, DocAsyncDispatch }; + enum DocstringMode { DocSync, DocAsync, DocAsyncBegin, DocAsyncEnd, DocDispatch, DocAsyncDispatch }; void writeDocstring(const OperationPtr&, DocstringMode, bool); Output& _out; set<string>& _moduleHistory; + const bool _python3; list<string> _moduleStack; set<string> _classHistory; }; @@ -315,8 +316,8 @@ Slice::Python::ModuleVisitor::visitModuleStart(const ModulePtr& p) // // CodeVisitor implementation. // -Slice::Python::CodeVisitor::CodeVisitor(Output& out, set<string>& moduleHistory) : - _out(out), _moduleHistory(moduleHistory) +Slice::Python::CodeVisitor::CodeVisitor(Output& out, set<string>& moduleHistory, bool python3) : + _out(out), _moduleHistory(moduleHistory), _python3(python3) { } @@ -563,9 +564,9 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) { string fixedOpName = fixIdent((*oli)->name()); - if(!p->isLocal() && (p->hasMetaData("amd") || (*oli)->hasMetaData("amd"))) + if(!p->isLocal()) { - _out << sp << nl << "def " << (*oli)->name() << "_async(self, _cb"; + _out << sp << nl << "def " << fixedOpName << "(self"; ParamDeclList params = (*oli)->parameters(); @@ -695,6 +696,23 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // Async operations. // _out << sp; + writeDocstring(*oli, DocAsync, false); + _out << nl << "def " << (*oli)->name() << "Async(self"; + if(!inParams.empty()) + { + _out << ", " << inParams; + } + _out << ", _ctx=None):"; + _out.inc(); + _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".invokeAsync(self, ((" << inParams; + if(!inParams.empty() && inParams.find(',') == string::npos) + { + _out << ", "; + } + _out << "), _ctx))"; + _out.dec(); + + _out << sp; writeDocstring(*oli, DocAsyncBegin, false); _out << nl << "def begin_" << (*oli)->name() << "(self"; if(!inParams.empty()) @@ -2486,7 +2504,7 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode { return; } - else if(mode == DocAsyncBegin && inParams.empty()) + else if((mode == DocAsync || mode == DocAsyncBegin) && inParams.empty()) { return; } @@ -2519,6 +2537,7 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode switch(mode) { case DocSync: + case DocAsync: case DocAsyncBegin: case DocDispatch: needArgs = !local || !inParams.empty(); @@ -2532,10 +2551,6 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode if(needArgs) { _out << nl << "Arguments:"; - if(mode == DocAsyncDispatch) - { - _out << nl << "_cb -- The asynchronous callback object."; - } for(vector<string>::iterator q = inParams.begin(); q != inParams.end(); ++q) { string fixed = fixIdent(*q); @@ -2556,7 +2571,7 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode << nl << "_ex -- The asynchronous exception callback." << nl << "_sent -- The asynchronous sent callback."; } - if(!local && (mode == DocSync || mode == DocAsyncBegin)) + if(!local && (mode == DocSync || mode == DocAsync || mode == DocAsyncBegin)) { _out << nl << "_ctx -- The request context for the invocation."; } @@ -2574,6 +2589,10 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode // // Emit return value(s). // + if(mode == DocAsync || mode == DocAsyncDispatch) + { + _out << nl << "Returns: A future object for the invocation."; + } if(mode == DocAsyncBegin) { _out << nl << "Returns: An asynchronous result object for the invocation."; @@ -2641,7 +2660,8 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode } void -Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out) +Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, bool python3, const vector<string>& includePaths, + Output& out) { Slice::Python::MetaDataVisitor visitor; un->visit(&visitor, false); @@ -2671,7 +2691,7 @@ Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector ModuleVisitor moduleVisitor(out, moduleHistory); un->visit(&moduleVisitor, true); - CodeVisitor codeVisitor(out, moduleHistory); + CodeVisitor codeVisitor(out, moduleHistory, python3); un->visit(&codeVisitor, false); if(checksum) diff --git a/cpp/src/Slice/PythonUtil.h b/cpp/src/Slice/PythonUtil.h index 9d48b3d3871..0966d4ba6a9 100644 --- a/cpp/src/Slice/PythonUtil.h +++ b/cpp/src/Slice/PythonUtil.h @@ -21,7 +21,7 @@ namespace Python // // Generate Python code for a translation unit. // -void generate(const Slice::UnitPtr&, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&); +void generate(const Slice::UnitPtr&, bool, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&); // // Convert a scoped name into a Python name. |