diff options
42 files changed, 1076 insertions, 817 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 61922a58a8f..6f0948b395f 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -4,10 +4,11 @@ Changes since version 3.2.X (binary incompatible) - Changed servant locators so both locate() and finished() can throw user exceptions. (See the manual for details.) -- slice2vb has been removed from the distribution and is no longer supported. - To use Visual Basic .NET with Ice, use slice2cs to generate C# code from - Slice definitions, and then use a C# compiler to create a DLL from the - generated code. Then link against that DLL in your Visual Basic project. +- slice2vb has been removed from the distribution and is no longer + supported. To use Visual Basic .NET with Ice, use slice2cs to + generate C# code from Slice definitions, and then use a C# compiler + to create a DLL from the generated code. Then link against that DLL + in your Visual Basic project. See the manual and the Visual Basic demos for more information. @@ -18,8 +19,11 @@ Changes since version 3.2.X (binary incompatible) return a proxy of the same type as the target. This way, you don't need to uncheckedCast the returned proxy. For example, you can now write: - hello = hello.ice_oneway(); + + hello = hello->ice_oneway(); + instead of: + hello = HelloPrx::uncheckedCast(hello->ice_oneway()); - Added a fix to prevent the IceGrid node from printing an annoying @@ -28,11 +32,15 @@ Changes since version 3.2.X (binary incompatible) - Fixed IceGrid bug where updates to IceBox services were not correctly sent to the IceGrid GUI or IceGrid registry slaves. -- Added Ice::createInput(const CommunicatorPtr&, const pair< const Byte*, const Byte*>&); +- Added a new overloading of the Ice::createInputStream method: + + Ice::InputStreamPtr createInputStream( + const CommunicatorPtr&, + const pair< const Byte*, const Byte*>&); - Setting IceBox.ServiceManager.Endpoints is no longer necessary in order to run the IceBox service. If no endpoints are specified - the the ServiceManager interface is not created. + then the ServiceManager interface is not created. - The property Ice.Plugin.Logger is now reserved to allow setting of the communicator's logger from properties. This plugin must @@ -42,8 +50,8 @@ Changes since version 3.2.X (binary incompatible) would be generated when C++ reserved words are used as Slice identifiers. -- It is no longer possible to provide input files on the - command line for icestormadmin nor icegridadmin. +- It is no longer possible to provide input files on the command line + for icestormadmin or icegridadmin. - The thread stack size specified with the IceUtil::Thread::start() method parameter is now adjusted to PTHREAD_STACK_MIN if it's @@ -70,11 +78,12 @@ Changes since version 3.2.X (binary incompatible) present when the adapter was created. - Freeze evictor update: + - the existing evictor was renamed BackgroundSaveEvictor - added new TransactionalEvictor - Fixed a bug in the encoding of user exceptions with a class - attribute and returned by AMD dispatched invocations. An extra byte + attribute and returned by AMD-dispatched invocations. An extra byte was encoded at the end. This fix doesn't affect on the wire compatibility with old Ice clients. diff --git a/cpp/include/Ice/BasicStream.h b/cpp/include/Ice/BasicStream.h index 7cab7da51ef..30edcafb305 100644 --- a/cpp/include/Ice/BasicStream.h +++ b/cpp/include/Ice/BasicStream.h @@ -97,6 +97,9 @@ public: // Instance* instance() const { return _instance; } // Inlined for performance reasons. + void* closure() const; + void* closure(void*); + void swap(BasicStream&); void resize(Container::size_type sz) @@ -594,6 +597,11 @@ private: // Instance* _instance; + // + // The public stream API needs to attach data to a stream. + // + void* _closure; + class ICE_API ReadEncaps : private ::IceUtil::noncopyable { public: diff --git a/cpp/include/Ice/Stream.h b/cpp/include/Ice/Stream.h index 30955233120..526df7e11ad 100644 --- a/cpp/include/Ice/Stream.h +++ b/cpp/include/Ice/Stream.h @@ -198,6 +198,30 @@ private: void* _arg; }; +class ICE_API UserExceptionWriter : public UserException +{ +public: + + UserExceptionWriter(const Ice::CommunicatorPtr&); + ~UserExceptionWriter() throw(); + + virtual void write(const OutputStreamPtr&) const = 0; + virtual bool usesClasses() const = 0; + + virtual std::string ice_name() const = 0; + virtual Ice::Exception* ice_clone() const = 0; + virtual void ice_throw() const = 0; + + virtual void __write(IceInternal::BasicStream*) const; + virtual void __read(IceInternal::BasicStream*, bool); + + virtual bool __usesClasses() const; + +protected: + + Ice::CommunicatorPtr _communicator; +}; + } #endif diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 3ffadc78573..2a94e724f86 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -33,6 +33,7 @@ using namespace IceInternal; IceInternal::BasicStream::BasicStream(Instance* instance, bool unlimited) : IceInternal::Buffer(instance->messageSizeMax()), _instance(instance), + _closure(0), _currentReadEncaps(0), _currentWriteEncaps(0), _traceSlicing(-1), @@ -73,6 +74,20 @@ IceInternal::BasicStream::clear() delete _objectList; } +void* +IceInternal::BasicStream::closure() const +{ + return _closure; +} + +void* +IceInternal::BasicStream::closure(void* p) +{ + void* prev = _closure; + _closure = p; + return prev; +} + void IceInternal::BasicStream::swap(BasicStream& other) { @@ -80,6 +95,8 @@ IceInternal::BasicStream::swap(BasicStream& other) Buffer::swap(other); + std::swap(_closure, other._closure); + // // Swap is never called for BasicStreams that have more than one // encaps. diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp index 989e98a9313..b0458637dfe 100644 --- a/cpp/src/Ice/StreamI.cpp +++ b/cpp/src/Ice/StreamI.cpp @@ -12,42 +12,32 @@ using namespace std; using namespace Ice; - -// -// BasicInputStream -// -IceInternal::BasicInputStream::BasicInputStream(IceInternal::Instance* instance, InputStream* in) : - BasicStream(instance), _in(in) -{ -} - -// -// BasicOutputStream -// -IceInternal::BasicOutputStream::BasicOutputStream(IceInternal::Instance* instance, OutputStream* out) : - BasicStream(instance), _out(out) -{ -} +using namespace IceInternal; // // InputStreamI // Ice::InputStreamI::InputStreamI(const Ice::CommunicatorPtr& communicator, const vector<Byte>& data) : - _communicator(communicator), _is(IceInternal::getInstance(communicator).get(), this) + _communicator(communicator) { - _is.writeBlob(data); - _is.i = _is.b.begin(); + _is = new BasicStream(getInstance(communicator).get()); + _is->closure(this); + _is->writeBlob(data); + _is->i = _is->b.begin(); } Ice::InputStreamI::InputStreamI(const Ice::CommunicatorPtr& communicator, const pair<const Byte*, const Byte*>& data) : - _communicator(communicator), _is(IceInternal::getInstance(communicator).get(), this) + _communicator(communicator) { - _is.writeBlob(data.first, data.second - data.first); - _is.i = _is.b.begin(); + _is = new BasicStream(getInstance(communicator).get()); + _is->closure(this); + _is->writeBlob(data.first, data.second - data.first); + _is->i = _is->b.begin(); } Ice::InputStreamI::~InputStreamI() { + delete _is; } CommunicatorPtr @@ -59,14 +49,14 @@ Ice::InputStreamI::communicator() const void Ice::InputStreamI::sliceObjects(bool b) { - _is.sliceObjects(b); + _is->sliceObjects(b); } bool Ice::InputStreamI::readBool() { bool v; - _is.read(v); + _is->read(v); return v; } @@ -74,21 +64,21 @@ vector<bool> Ice::InputStreamI::readBoolSeq() { vector<bool> v; - _is.read(v); + _is->read(v); return v; } bool* Ice::InputStreamI::readBoolSeq(pair<const bool*, const bool*>& p) { - return _is.read(p); + return _is->read(p); } Byte Ice::InputStreamI::readByte() { Byte v; - _is.read(v); + _is->read(v); return v; } @@ -96,7 +86,7 @@ vector<Byte> Ice::InputStreamI::readByteSeq() { pair<const Byte*, const Byte*> p; - _is.read(p); + _is->read(p); vector<Byte> v(p.first, p.second); return v; } @@ -104,14 +94,14 @@ Ice::InputStreamI::readByteSeq() void Ice::InputStreamI::readByteSeq(pair<const Byte*, const Byte*>& p) { - _is.read(p); + _is->read(p); } Short Ice::InputStreamI::readShort() { Short v; - _is.read(v); + _is->read(v); return v; } @@ -119,21 +109,21 @@ vector<Short> Ice::InputStreamI::readShortSeq() { vector<Short> v; - _is.read(v); + _is->read(v); return v; } Short* Ice::InputStreamI::readShortSeq(pair<const Short*, const Short*>& p) { - return _is.read(p); + return _is->read(p); } Int Ice::InputStreamI::readInt() { Int v; - _is.read(v); + _is->read(v); return v; } @@ -141,21 +131,21 @@ vector<Int> Ice::InputStreamI::readIntSeq() { vector<Int> v; - _is.read(v); + _is->read(v); return v; } Int* Ice::InputStreamI::readIntSeq(pair<const Int*, const Int*>& p) { - return _is.read(p); + return _is->read(p); } Long Ice::InputStreamI::readLong() { Long v; - _is.read(v); + _is->read(v); return v; } @@ -163,21 +153,21 @@ vector<Long> Ice::InputStreamI::readLongSeq() { vector<Long> v; - _is.read(v); + _is->read(v); return v; } Long* Ice::InputStreamI::readLongSeq(pair<const Long*, const Long*>& p) { - return _is.read(p); + return _is->read(p); } Float Ice::InputStreamI::readFloat() { Float v; - _is.read(v); + _is->read(v); return v; } @@ -185,21 +175,21 @@ vector<Float> Ice::InputStreamI::readFloatSeq() { vector<Float> v; - _is.read(v); + _is->read(v); return v; } Float* Ice::InputStreamI::readFloatSeq(pair<const Float*, const Float*>& p) { - return _is.read(p); + return _is->read(p); } Double Ice::InputStreamI::readDouble() { Double v; - _is.read(v); + _is->read(v); return v; } @@ -207,21 +197,21 @@ vector<Double> Ice::InputStreamI::readDoubleSeq() { vector<Double> v; - _is.read(v); + _is->read(v); return v; } Double* Ice::InputStreamI::readDoubleSeq(pair<const Double*, const Double*>& p) { - return _is.read(p); + return _is->read(p); } string Ice::InputStreamI::readString() { string v; - _is.read(v); + _is->read(v); return v; } @@ -229,7 +219,7 @@ vector<string> Ice::InputStreamI::readStringSeq() { vector<string> v; - _is.read(v); + _is->read(v); return v; } @@ -237,7 +227,7 @@ wstring Ice::InputStreamI::readWstring() { wstring v; - _is.read(v); + _is->read(v); return v; } @@ -245,7 +235,7 @@ vector<wstring> Ice::InputStreamI::readWstringSeq() { vector<wstring> v; - _is.read(v); + _is->read(v); return v; } @@ -253,7 +243,7 @@ Int Ice::InputStreamI::readSize() { Int sz; - _is.readSize(sz); + _is->readSize(sz); return sz; } @@ -261,7 +251,7 @@ ObjectPrx Ice::InputStreamI::readProxy() { Ice::ObjectPrx v; - _is.read(v); + _is->read(v); return v; } @@ -277,69 +267,78 @@ void Ice::InputStreamI::readObject(const ReadObjectCallbackPtr& cb) { _callbacks.push_back(cb); // Keep reference to callback. - _is.read(patchObject, cb.get()); + _is->read(patchObject, cb.get()); } string Ice::InputStreamI::readTypeId() { string id; - _is.readTypeId(id); + _is->readTypeId(id); return id; } void Ice::InputStreamI::throwException() { - _is.throwException(); + _is->throwException(); } void Ice::InputStreamI::startSlice() { - _is.startReadSlice(); + _is->startReadSlice(); } void Ice::InputStreamI::endSlice() { - _is.endReadSlice(); + _is->endReadSlice(); } void Ice::InputStreamI::startEncapsulation() { - _is.startReadEncaps(); + _is->startReadEncaps(); } void Ice::InputStreamI::endEncapsulation() { - _is.endReadEncaps(); + _is->endReadEncaps(); } void Ice::InputStreamI::skipSlice() { - _is.skipSlice(); + _is->skipSlice(); } void Ice::InputStreamI::readPendingObjects() { - _is.readPendingObjects(); + _is->readPendingObjects(); } // // OutputStreamI // -Ice::OutputStreamI::OutputStreamI(const Ice::CommunicatorPtr& communicator) : - _communicator(communicator), _os(IceInternal::getInstance(communicator).get(), this) +Ice::OutputStreamI::OutputStreamI(const Ice::CommunicatorPtr& communicator, BasicStream* os) : + _communicator(communicator), _os(os), _own(!os) { + if(!_os) + { + _os = new BasicStream(getInstance(communicator).get()); + } + _os->closure(this); } Ice::OutputStreamI::~OutputStreamI() { + if(_own) + { + delete _os; + } } CommunicatorPtr @@ -351,25 +350,25 @@ Ice::OutputStreamI::communicator() const void Ice::OutputStreamI::writeBool(bool v) { - _os.write(v); + _os->write(v); } void Ice::OutputStreamI::writeBoolSeq(const vector<bool>& v) { - _os.write(v); + _os->write(v); } void Ice::OutputStreamI::writeBoolSeq(const bool* begin, const bool* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeByte(Byte v) { - _os.write(v); + _os->write(v); } void @@ -377,24 +376,24 @@ Ice::OutputStreamI::writeByteSeq(const vector<Byte>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeByteSeq(const Byte* begin, const Byte* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeShort(Short v) { - _os.write(v); + _os->write(v); } void @@ -402,24 +401,24 @@ Ice::OutputStreamI::writeShortSeq(const vector<Short>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeShortSeq(const Short* begin, const Short* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeInt(Int v) { - _os.write(v); + _os->write(v); } void @@ -427,24 +426,24 @@ Ice::OutputStreamI::writeIntSeq(const vector<Int>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeIntSeq(const Int* begin, const Int* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeLong(Long v) { - _os.write(v); + _os->write(v); } void @@ -452,24 +451,24 @@ Ice::OutputStreamI::writeLongSeq(const vector<Long>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeLongSeq(const Long* begin, const Long* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeFloat(Float v) { - _os.write(v); + _os->write(v); } void @@ -477,24 +476,24 @@ Ice::OutputStreamI::writeFloatSeq(const vector<Float>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeFloatSeq(const Float* begin, const Float* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeDouble(Double v) { - _os.write(v); + _os->write(v); } void @@ -502,24 +501,24 @@ Ice::OutputStreamI::writeDoubleSeq(const vector<Double>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeDoubleSeq(const Double* begin, const Double* end) { - _os.write(begin, end); + _os->write(begin, end); } void Ice::OutputStreamI::writeString(const string& v) { - _os.write(v); + _os->write(v); } void @@ -527,18 +526,18 @@ Ice::OutputStreamI::writeStringSeq(const vector<string>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeWstring(const wstring& v) { - _os.write(v); + _os->write(v); } void @@ -546,105 +545,105 @@ Ice::OutputStreamI::writeWstringSeq(const vector<wstring>& v) { if(v.size() == 0) { - _os.writeSize(0); + _os->writeSize(0); } else { - _os.write(&v[0], &v[0] + v.size()); + _os->write(&v[0], &v[0] + v.size()); } } void Ice::OutputStreamI::writeSize(Int sz) { - _os.writeSize(sz); + _os->writeSize(sz); } void Ice::OutputStreamI::writeProxy(const ObjectPrx& v) { - _os.write(v); + _os->write(v); } void Ice::OutputStreamI::writeObject(const ObjectPtr& v) { - _os.write(v); + _os->write(v); } void Ice::OutputStreamI::writeTypeId(const string& id) { - _os.writeTypeId(id); + _os->writeTypeId(id); } void Ice::OutputStreamI::writeException(const UserException& v) { - _os.write(v); + _os->write(v); } void Ice::OutputStreamI::startSlice() { - _os.startWriteSlice(); + _os->startWriteSlice(); } void Ice::OutputStreamI::endSlice() { - _os.endWriteSlice(); + _os->endWriteSlice(); } void Ice::OutputStreamI::startEncapsulation() { - _os.startWriteEncaps(); + _os->startWriteEncaps(); } void Ice::OutputStreamI::endEncapsulation() { - _os.endWriteEncaps(); + _os->endWriteEncaps(); } void Ice::OutputStreamI::writePendingObjects() { - _os.writePendingObjects(); + _os->writePendingObjects(); } void Ice::OutputStreamI::finished(vector<Byte>& bytes) { - vector<Byte>(_os.b.begin(), _os.b.end()).swap(bytes); + vector<Byte>(_os->b.begin(), _os->b.end()).swap(bytes); } // // ObjectReader // void -Ice::ObjectReader::__write(::IceInternal::BasicStream*) const +Ice::ObjectReader::__write(BasicStream*) const { assert(false); } void -Ice::ObjectReader::__read(::IceInternal::BasicStream* is, bool rid) +Ice::ObjectReader::__read(BasicStream* is, bool rid) { - IceInternal::BasicInputStream* bis = dynamic_cast<IceInternal::BasicInputStream*>(is); - assert(bis); - read(bis->_in, rid); + InputStreamI* stream = reinterpret_cast<InputStreamI*>(is->closure()); + assert(stream); + read(stream, rid); } void -Ice::ObjectReader::__write(const ::Ice::OutputStreamPtr&) const +Ice::ObjectReader::__write(const Ice::OutputStreamPtr&) const { assert(false); } void -Ice::ObjectReader::__read(const ::Ice::InputStreamPtr&, bool) +Ice::ObjectReader::__read(const Ice::InputStreamPtr&, bool) { assert(false); } @@ -653,27 +652,58 @@ Ice::ObjectReader::__read(const ::Ice::InputStreamPtr&, bool) // ObjectWriter // void -Ice::ObjectWriter::__write(::IceInternal::BasicStream* os) const +Ice::ObjectWriter::__write(BasicStream* os) const { - IceInternal::BasicOutputStream* bos = dynamic_cast<IceInternal::BasicOutputStream*>(os); - assert(bos); - write(bos->_out); + OutputStreamI* stream = reinterpret_cast<OutputStreamI*>(os->closure()); + assert(stream); + write(stream); } void -Ice::ObjectWriter::__read(::IceInternal::BasicStream*, bool) +Ice::ObjectWriter::__read(BasicStream*, bool) { assert(false); } void -Ice::ObjectWriter::__write(const ::Ice::OutputStreamPtr&) const +Ice::ObjectWriter::__write(const Ice::OutputStreamPtr&) const { assert(false); } void -Ice::ObjectWriter::__read(const ::Ice::InputStreamPtr&, bool) +Ice::ObjectWriter::__read(const Ice::InputStreamPtr&, bool) { assert(false); } + +// +// UserExceptionWriter +// +Ice::UserExceptionWriter::UserExceptionWriter(const Ice::CommunicatorPtr& communicator) : + _communicator(communicator) +{ +} + +Ice::UserExceptionWriter::~UserExceptionWriter() throw() +{ +} + +void +Ice::UserExceptionWriter::__write(BasicStream* os) const +{ + OutputStreamPtr stream = new OutputStreamI(_communicator, os); + write(stream); +} + +void +Ice::UserExceptionWriter::__read(BasicStream*, bool) +{ + assert(false); +} + +bool +Ice::UserExceptionWriter::__usesClasses() const +{ + return usesClasses(); +} diff --git a/cpp/src/Ice/StreamI.h b/cpp/src/Ice/StreamI.h index 70f5e8dd1c3..1f00533612d 100644 --- a/cpp/src/Ice/StreamI.h +++ b/cpp/src/Ice/StreamI.h @@ -13,48 +13,18 @@ #include <Ice/Stream.h> #include <Ice/BasicStream.h> -namespace IceInternal -{ - -// -// Subclass BasicStream in order to associate an InputStream with it. -// -class BasicInputStream : public BasicStream -{ -public: - - BasicInputStream(Instance*, Ice::InputStream*); - - Ice::InputStream* _in; -}; - -// -// Subclass BasicStream in order to associate an OutputStream with it. -// -class BasicOutputStream : public BasicStream -{ -public: - - BasicOutputStream(Instance*, Ice::OutputStream*); - - Ice::OutputStream* _out; -}; - -} - namespace Ice { // -// Implement InputStream as a wrapper around BasicInputStream. +// Implement InputStream as a wrapper around BasicStream. // class InputStreamI : public InputStream { public: - //InputStreamI(const IceInternal::InstancePtr&, const ::std::vector< ::Ice::Byte >&); - InputStreamI(const Ice::CommunicatorPtr&, const ::std::vector< ::Ice::Byte >&); - InputStreamI(const Ice::CommunicatorPtr&, const ::std::pair< const ::Ice::Byte*, const ::Ice::Byte* >&); + InputStreamI(const Ice::CommunicatorPtr&, const std::vector< Ice::Byte >&); + InputStreamI(const Ice::CommunicatorPtr&, const std::pair< const Ice::Byte*, const Ice::Byte* >&); virtual ~InputStreamI(); virtual Ice::CommunicatorPtr communicator() const; @@ -62,46 +32,46 @@ public: virtual void sliceObjects(bool); virtual bool readBool(); - virtual ::std::vector< bool > readBoolSeq(); - virtual bool* readBoolSeq(::std::pair<const bool*, const bool*>&); + virtual std::vector< bool > readBoolSeq(); + virtual bool* readBoolSeq(std::pair<const bool*, const bool*>&); - virtual ::Ice::Byte readByte(); - virtual ::std::vector< ::Ice::Byte > readByteSeq(); - virtual void readByteSeq(::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>&); + virtual Ice::Byte readByte(); + virtual std::vector< Ice::Byte > readByteSeq(); + virtual void readByteSeq(std::pair<const Ice::Byte*, const Ice::Byte*>&); - virtual ::Ice::Short readShort(); - virtual ::std::vector< ::Ice::Short > readShortSeq(); - virtual ::Ice::Short* readShortSeq(::std::pair<const ::Ice::Short*, const ::Ice::Short*>&); + virtual Ice::Short readShort(); + virtual std::vector< Ice::Short > readShortSeq(); + virtual Ice::Short* readShortSeq(std::pair<const Ice::Short*, const Ice::Short*>&); - virtual ::Ice::Int readInt(); - virtual ::std::vector< ::Ice::Int > readIntSeq(); - virtual ::Ice::Int* readIntSeq(::std::pair<const ::Ice::Int*, const ::Ice::Int*>&); + virtual Ice::Int readInt(); + virtual std::vector< Ice::Int > readIntSeq(); + virtual Ice::Int* readIntSeq(std::pair<const Ice::Int*, const Ice::Int*>&); - virtual ::Ice::Long readLong(); - virtual ::std::vector< ::Ice::Long > readLongSeq(); - virtual ::Ice::Long* readLongSeq(::std::pair<const ::Ice::Long*, const ::Ice::Long*>&); + virtual Ice::Long readLong(); + virtual std::vector< Ice::Long > readLongSeq(); + virtual Ice::Long* readLongSeq(std::pair<const Ice::Long*, const Ice::Long*>&); - virtual ::Ice::Float readFloat(); - virtual ::std::vector< ::Ice::Float > readFloatSeq(); - virtual ::Ice::Float* readFloatSeq(::std::pair<const ::Ice::Float*, const ::Ice::Float*>&); + virtual Ice::Float readFloat(); + virtual std::vector< Ice::Float > readFloatSeq(); + virtual Ice::Float* readFloatSeq(std::pair<const Ice::Float*, const Ice::Float*>&); - virtual ::Ice::Double readDouble(); - virtual ::std::vector< ::Ice::Double > readDoubleSeq(); - virtual ::Ice::Double* readDoubleSeq(::std::pair<const ::Ice::Double*, const ::Ice::Double*>&); + virtual Ice::Double readDouble(); + virtual std::vector< Ice::Double > readDoubleSeq(); + virtual Ice::Double* readDoubleSeq(std::pair<const Ice::Double*, const Ice::Double*>&); - virtual ::std::string readString(); - virtual ::std::vector< ::std::string > readStringSeq(); + virtual std::string readString(); + virtual std::vector< std::string > readStringSeq(); - virtual ::std::wstring readWstring(); - virtual ::std::vector< ::std::wstring > readWstringSeq(); + virtual std::wstring readWstring(); + virtual std::vector< std::wstring > readWstringSeq(); - virtual ::Ice::Int readSize(); + virtual Ice::Int readSize(); - virtual ::Ice::ObjectPrx readProxy(); + virtual Ice::ObjectPrx readProxy(); - virtual void readObject(const ::Ice::ReadObjectCallbackPtr&); + virtual void readObject(const Ice::ReadObjectCallbackPtr&); - virtual ::std::string readTypeId(); + virtual std::string readTypeId(); virtual void throwException(); @@ -117,66 +87,65 @@ public: private: Ice::CommunicatorPtr _communicator; - IceInternal::BasicInputStream _is; - ::std::vector< ReadObjectCallbackPtr > _callbacks; + IceInternal::BasicStream* _is; + std::vector< ReadObjectCallbackPtr > _callbacks; }; // -// Implement OutputStream as a wrapper around BasicOutputStream. +// Implement OutputStream as a wrapper around BasicStream. // class OutputStreamI : public OutputStream { public: - //OutputStreamI(const IceInternal::InstancePtr&); - OutputStreamI(const Ice::CommunicatorPtr&); + OutputStreamI(const Ice::CommunicatorPtr&, IceInternal::BasicStream* = 0); virtual ~OutputStreamI(); virtual Ice::CommunicatorPtr communicator() const; virtual void writeBool(bool); - virtual void writeBoolSeq(const ::std::vector< bool >&); + virtual void writeBoolSeq(const std::vector< bool >&); virtual void writeBoolSeq(const bool*, const bool*); - virtual void writeByte(::Ice::Byte); - virtual void writeByteSeq(const ::std::vector< ::Ice::Byte >&); + virtual void writeByte(Ice::Byte); + virtual void writeByteSeq(const std::vector< Ice::Byte >&); virtual void writeByteSeq(const Ice::Byte*, const Ice::Byte*); - virtual void writeShort(::Ice::Short); - virtual void writeShortSeq(const ::std::vector< ::Ice::Short >&); + virtual void writeShort(Ice::Short); + virtual void writeShortSeq(const std::vector< Ice::Short >&); virtual void writeShortSeq(const Ice::Short*, const Ice::Short*); - virtual void writeInt(::Ice::Int); - virtual void writeIntSeq(const ::std::vector< ::Ice::Int >&); + virtual void writeInt(Ice::Int); + virtual void writeIntSeq(const std::vector< Ice::Int >&); virtual void writeIntSeq(const Ice::Int*, const Ice::Int*); - virtual void writeLong(::Ice::Long); - virtual void writeLongSeq(const ::std::vector< ::Ice::Long >&); + virtual void writeLong(Ice::Long); + virtual void writeLongSeq(const std::vector< Ice::Long >&); virtual void writeLongSeq(const Ice::Long*, const Ice::Long*); - virtual void writeFloat(::Ice::Float); - virtual void writeFloatSeq(const ::std::vector< ::Ice::Float >&); + virtual void writeFloat(Ice::Float); + virtual void writeFloatSeq(const std::vector< Ice::Float >&); virtual void writeFloatSeq(const Ice::Float*, const Ice::Float*); - virtual void writeDouble(::Ice::Double); - virtual void writeDoubleSeq(const ::std::vector< ::Ice::Double >&); + virtual void writeDouble(Ice::Double); + virtual void writeDoubleSeq(const std::vector< Ice::Double >&); virtual void writeDoubleSeq(const Ice::Double*, const Ice::Double*); - virtual void writeString(const ::std::string&); - virtual void writeStringSeq(const ::std::vector< ::std::string >&); + virtual void writeString(const std::string&); + virtual void writeStringSeq(const std::vector< std::string >&); - virtual void writeWstring(const ::std::wstring&); - virtual void writeWstringSeq(const ::std::vector< ::std::wstring >&); + virtual void writeWstring(const std::wstring&); + virtual void writeWstringSeq(const std::vector< std::wstring >&); - virtual void writeSize(::Ice::Int); + virtual void writeSize(Ice::Int); - virtual void writeProxy(const ::Ice::ObjectPrx&); + virtual void writeProxy(const Ice::ObjectPrx&); - virtual void writeObject(const ::Ice::ObjectPtr&); + virtual void writeObject(const Ice::ObjectPtr&); - virtual void writeTypeId(const ::std::string&); + virtual void writeTypeId(const std::string&); - virtual void writeException(const ::Ice::UserException&); + virtual void writeException(const Ice::UserException&); virtual void startSlice(); virtual void endSlice(); @@ -186,12 +155,13 @@ public: virtual void writePendingObjects(); - virtual void finished(::std::vector< ::Ice::Byte >&); + virtual void finished(std::vector< Ice::Byte >&); private: Ice::CommunicatorPtr _communicator; - IceInternal::BasicOutputStream _os; + IceInternal::BasicStream* _os; + bool _own; }; } diff --git a/cs/src/Ice/BasicInputStream.cs b/cs/src/Ice/BasicInputStream.cs deleted file mode 100644 index 0a26dfb4339..00000000000 --- a/cs/src/Ice/BasicInputStream.cs +++ /dev/null @@ -1,22 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace IceInternal -{ - public class BasicInputStream : BasicStream - { - public BasicInputStream(Instance instance, Ice.InputStream inStream) - : base(instance) - { - in_ = inStream; - } - - public Ice.InputStream in_; - } -} diff --git a/cs/src/Ice/BasicOutputStream.cs b/cs/src/Ice/BasicOutputStream.cs deleted file mode 100644 index 7c512f633bd..00000000000 --- a/cs/src/Ice/BasicOutputStream.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace IceInternal -{ - - public class BasicOutputStream : BasicStream - { - public BasicOutputStream(Instance instance, Ice.OutputStream outStream) - : base(instance) - { - out_ = outStream; - } - - public Ice.OutputStream out_; - } -} diff --git a/cs/src/Ice/BasicStream.cs b/cs/src/Ice/BasicStream.cs index 6ba70a56aac..0970c6a93ce 100755 --- a/cs/src/Ice/BasicStream.cs +++ b/cs/src/Ice/BasicStream.cs @@ -59,6 +59,7 @@ namespace IceInternal private void initialize(IceInternal.Instance instance, bool unlimited) { instance_ = instance; + _closure = null; _unlimited = unlimited; allocate(1500); _capacity = _buf.capacity(); @@ -109,11 +110,27 @@ namespace IceInternal { return instance_; } - + + public virtual object closure() + { + return _closure; + } + + public virtual object closure(object p) + { + object prev = _closure; + _closure = p; + return prev; + } + public virtual void swap(BasicStream other) { Debug.Assert(instance_ == other.instance_); + object tmpClosure = other._closure; + other._closure = _closure; + _closure = tmpClosure; + ByteBuffer tmpBuf = other._buf; other._buf = _buf; _buf = tmpBuf; @@ -2727,6 +2744,7 @@ namespace IceInternal } private IceInternal.Instance instance_; + private object _closure; private ByteBuffer _buf; private int _capacity; // Cache capacity to avoid excessive method calls. private int _limit; // Cache limit to avoid excessive method calls. diff --git a/cs/src/Ice/InputStream.cs b/cs/src/Ice/InputStream.cs deleted file mode 100644 index 792c200f80c..00000000000 --- a/cs/src/Ice/InputStream.cs +++ /dev/null @@ -1,63 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace Ice -{ - public interface InputStream - { - Communicator communicator(); - - void sliceObjects(bool slice); - - bool readBool(); - bool[] readBoolSeq(); - - byte readByte(); - byte[] readByteSeq(); - - short readShort(); - short[] readShortSeq(); - - int readInt(); - int[] readIntSeq(); - - long readLong(); - long[] readLongSeq(); - - float readFloat(); - float[] readFloatSeq(); - - double readDouble(); - double[] readDoubleSeq(); - - string readString(); - string[] readStringSeq(); - - int readSize(); - - ObjectPrx readProxy(); - - void readObject(ReadObjectCallback cb); - - string readTypeId(); - - void throwException(); - - void startSlice(); - void endSlice(); - void skipSlice(); - - void startEncapsulation(); - void endEncapsulation(); - - void readPendingObjects(); - - void destroy(); - } -} diff --git a/cs/src/Ice/Makefile b/cs/src/Ice/Makefile index a7b7d39de76..0f1213c4742 100644 --- a/cs/src/Ice/Makefile +++ b/cs/src/Ice/Makefile @@ -19,8 +19,6 @@ SRCS = Acceptor.cs \ AssemblyInfo.cs \ AssemblyUtil.cs \ Base64.cs \ - BasicInputStream.cs \ - BasicOutputStream.cs \ BasicStream.cs \ ByteBuffer.cs \ CommunicatorI.cs \ @@ -42,8 +40,6 @@ SRCS = Acceptor.cs \ ImplicitContextI.cs \ IncomingAsync.cs \ Incoming.cs \ - InputStream.cs \ - InputStreamI.cs \ Instance.cs \ LinkedList.cs \ LocalObject.cs \ @@ -54,14 +50,10 @@ SRCS = Acceptor.cs \ ObjectAdapterI.cs \ Object.cs \ ObjectFactoryManager.cs \ - ObjectReader.cs \ - ObjectWriter.cs \ Options.cs \ OutgoingAsync.cs \ Outgoing.cs \ OutputBase.cs \ - OutputStream.cs \ - OutputStreamI.cs \ Patcher.cs \ PluginManagerI.cs \ ProcessI.cs \ @@ -74,7 +66,6 @@ SRCS = Acceptor.cs \ Proxy.cs \ ProxyFactory.cs \ ProxyIdentityKey.cs \ - ReadObjectCallback.cs \ Reference.cs \ ReferenceFactory.cs \ ReplyStatus.cs \ @@ -82,6 +73,8 @@ SRCS = Acceptor.cs \ ServantManager.cs \ Set.cs \ SliceChecksums.cs \ + Stream.cs \ + StreamI.cs \ StringUtil.cs \ SysLoggerI.cs \ TcpAcceptor.cs \ diff --git a/cs/src/Ice/Makefile.mak b/cs/src/Ice/Makefile.mak index 7f61a077204..b0cdf8862db 100644 --- a/cs/src/Ice/Makefile.mak +++ b/cs/src/Ice/Makefile.mak @@ -19,8 +19,6 @@ SRCS = Acceptor.cs \ AssemblyInfo.cs \ AssemblyUtil.cs \ Base64.cs \ - BasicInputStream.cs \ - BasicOutputStream.cs \ BasicStream.cs \ ByteBuffer.cs \ CommunicatorI.cs \ @@ -42,8 +40,6 @@ SRCS = Acceptor.cs \ ImplicitContextI.cs \ IncomingAsync.cs \ Incoming.cs \ - InputStream.cs \ - InputStreamI.cs \ Instance.cs \ LinkedList.cs \ LocalObject.cs \ @@ -54,14 +50,10 @@ SRCS = Acceptor.cs \ ObjectAdapterI.cs \ Object.cs \ ObjectFactoryManager.cs \ - ObjectReader.cs \ - ObjectWriter.cs \ Options.cs \ OutgoingAsync.cs \ Outgoing.cs \ OutputBase.cs \ - OutputStream.cs \ - OutputStreamI.cs \ Patcher.cs \ PluginManagerI.cs \ ProcessI.cs \ @@ -74,7 +66,6 @@ SRCS = Acceptor.cs \ Proxy.cs \ ProxyFactory.cs \ ProxyIdentityKey.cs \ - ReadObjectCallback.cs \ Reference.cs \ ReferenceFactory.cs \ ReplyStatus.cs \ @@ -82,6 +73,8 @@ SRCS = Acceptor.cs \ ServantManager.cs \ Set.cs \ SliceChecksums.cs \ + Stream.cs \ + StreamI.cs \ StringUtil.cs \ SysLoggerI.cs \ TcpAcceptor.cs \ diff --git a/cs/src/Ice/ObjectReader.cs b/cs/src/Ice/ObjectReader.cs deleted file mode 100644 index c96d280ae25..00000000000 --- a/cs/src/Ice/ObjectReader.cs +++ /dev/null @@ -1,29 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System.Diagnostics; - -namespace Ice -{ - public abstract class ObjectReader : ObjectImpl - { - public abstract void read(InputStream inStream, bool rid); - - public override void write__(IceInternal.BasicStream os) - { - Debug.Assert(false); - } - - public override void read__(IceInternal.BasicStream istr, bool rid) - { - IceInternal.BasicInputStream bis = (IceInternal.BasicInputStream)istr; - read(bis.in_, rid); - } - } -} diff --git a/cs/src/Ice/ObjectWriter.cs b/cs/src/Ice/ObjectWriter.cs deleted file mode 100644 index 29991d4a5f7..00000000000 --- a/cs/src/Ice/ObjectWriter.cs +++ /dev/null @@ -1,30 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System.Diagnostics; - -namespace Ice { - - public abstract class ObjectWriter : ObjectImpl - { - public abstract void write(OutputStream outStream); - - public override void write__(IceInternal.BasicStream os) - { - IceInternal.BasicOutputStream bos = (IceInternal.BasicOutputStream)os; - write(bos.out_); - } - - public override void read__(IceInternal.BasicStream istr, bool rid) - { - Debug.Assert(false); - } - } - -} diff --git a/cs/src/Ice/OutputStream.cs b/cs/src/Ice/OutputStream.cs deleted file mode 100644 index efd6bdca19b..00000000000 --- a/cs/src/Ice/OutputStream.cs +++ /dev/null @@ -1,61 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace Ice -{ - public interface OutputStream - { - Communicator communicator(); - - void writeBool(bool v); - void writeBoolSeq(bool[] v); - - void writeByte(byte v); - void writeByteSeq(byte[] v); - - void writeShort(short v); - void writeShortSeq(short[] v); - - void writeInt(int v); - void writeIntSeq(int[] v); - - void writeLong(long v); - void writeLongSeq(long[] v); - - void writeFloat(float v); - void writeFloatSeq(float[] v); - - void writeDouble(double v); - void writeDoubleSeq(double[] v); - - void writeString(string v); - void writeStringSeq(string[] v); - - void writeSize(int sz); - - void writeProxy(ObjectPrx v); - - void writeObject(Ice.Object v); - - void writeTypeId(string id); - - void writeException(UserException ex); - - void startSlice(); - void endSlice(); - - void startEncapsulation(); - void endEncapsulation(); - - void writePendingObjects(); - - byte[] finished(); - void destroy(); - } -} diff --git a/cs/src/Ice/OutputStreamI.cs b/cs/src/Ice/OutputStreamI.cs deleted file mode 100644 index 1286c68495e..00000000000 --- a/cs/src/Ice/OutputStreamI.cs +++ /dev/null @@ -1,175 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace Ice -{ - public class OutputStreamI : OutputStream - { - public OutputStreamI(Communicator communicator) - { - _communicator = communicator; - _os = new IceInternal.BasicOutputStream(Util.getInstance(communicator), this); - } - - public Communicator communicator() - { - return _communicator; - } - - public void writeBool(bool v) - { - _os.writeBool(v); - } - - public void writeBoolSeq(bool[] v) - { - _os.writeBoolSeq(v); - } - - public void writeByte(byte v) - { - _os.writeByte(v); - } - - public void writeByteSeq(byte[] v) - { - _os.writeByteSeq(v); - } - - public void writeShort(short v) - { - _os.writeShort(v); - } - - public void writeShortSeq(short[] v) - { - _os.writeShortSeq(v); - } - - public void writeInt(int v) - { - _os.writeInt(v); - } - - public void writeIntSeq(int[] v) - { - _os.writeIntSeq(v); - } - - public void writeLong(long v) - { - _os.writeLong(v); - } - - public void writeLongSeq(long[] v) - { - _os.writeLongSeq(v); - } - - public void writeFloat(float v) - { - _os.writeFloat(v); - } - - public void writeFloatSeq(float[] v) - { - _os.writeFloatSeq(v); - } - - public void writeDouble(double v) - { - _os.writeDouble(v); - } - - public void writeDoubleSeq(double[] v) - { - _os.writeDoubleSeq(v); - } - - public void writeString(string v) - { - _os.writeString(v); - } - - public void writeStringSeq(string[] v) - { - _os.writeStringSeq(v); - } - - public void writeSize(int sz) - { - _os.writeSize(sz); - } - - public void writeProxy(ObjectPrx v) - { - _os.writeProxy(v); - } - - public void writeObject(Ice.Object v) - { - _os.writeObject(v); - } - - public void writeTypeId(string id) - { - _os.writeTypeId(id); - } - - public void writeException(UserException v) - { - _os.writeUserException(v); - } - - public void startSlice() - { - _os.startWriteSlice(); - } - - public void endSlice() - { - _os.endWriteSlice(); - } - - public void startEncapsulation() - { - _os.startWriteEncaps(); - } - - public void endEncapsulation() - { - _os.endWriteEncaps(); - } - - public void writePendingObjects() - { - _os.writePendingObjects(); - } - - public byte[] finished() - { - IceInternal.ByteBuffer buf = _os.prepareWrite(); - byte[] result = new byte[buf.limit()]; - buf.get(result); - - return result; - } - - public void destroy() - { - if(_os != null) - { - _os = null; - } - } - - private Communicator _communicator; - private IceInternal.BasicOutputStream _os; - } -} diff --git a/cs/src/Ice/ReadObjectCallback.cs b/cs/src/Ice/ReadObjectCallback.cs deleted file mode 100644 index 22664a2a2c5..00000000000 --- a/cs/src/Ice/ReadObjectCallback.cs +++ /dev/null @@ -1,16 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -namespace Ice -{ - public interface ReadObjectCallback - { - void invoke(Ice.Object obj); - } -} diff --git a/cs/src/Ice/Stream.cs b/cs/src/Ice/Stream.cs new file mode 100644 index 00000000000..1ed010ee1e8 --- /dev/null +++ b/cs/src/Ice/Stream.cs @@ -0,0 +1,191 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System.Diagnostics; + +namespace Ice +{ + public interface ReadObjectCallback + { + void invoke(Ice.Object obj); + } + + public interface InputStream + { + Communicator communicator(); + + void sliceObjects(bool slice); + + bool readBool(); + bool[] readBoolSeq(); + + byte readByte(); + byte[] readByteSeq(); + + short readShort(); + short[] readShortSeq(); + + int readInt(); + int[] readIntSeq(); + + long readLong(); + long[] readLongSeq(); + + float readFloat(); + float[] readFloatSeq(); + + double readDouble(); + double[] readDoubleSeq(); + + string readString(); + string[] readStringSeq(); + + int readSize(); + + ObjectPrx readProxy(); + + void readObject(ReadObjectCallback cb); + + string readTypeId(); + + void throwException(); + + void startSlice(); + void endSlice(); + void skipSlice(); + + void startEncapsulation(); + void endEncapsulation(); + + void readPendingObjects(); + + void destroy(); + } + + public interface OutputStream + { + Communicator communicator(); + + void writeBool(bool v); + void writeBoolSeq(bool[] v); + + void writeByte(byte v); + void writeByteSeq(byte[] v); + + void writeShort(short v); + void writeShortSeq(short[] v); + + void writeInt(int v); + void writeIntSeq(int[] v); + + void writeLong(long v); + void writeLongSeq(long[] v); + + void writeFloat(float v); + void writeFloatSeq(float[] v); + + void writeDouble(double v); + void writeDoubleSeq(double[] v); + + void writeString(string v); + void writeStringSeq(string[] v); + + void writeSize(int sz); + + void writeProxy(ObjectPrx v); + + void writeObject(Ice.Object v); + + void writeTypeId(string id); + + void writeException(UserException ex); + + void startSlice(); + void endSlice(); + + void startEncapsulation(); + void endEncapsulation(); + + void writePendingObjects(); + + byte[] finished(); + void destroy(); + } + + public abstract class ObjectReader : ObjectImpl + { + public abstract void read(InputStream inStream, bool rid); + + public override void write__(IceInternal.BasicStream os) + { + Debug.Assert(false); + } + + public override void read__(IceInternal.BasicStream istr, bool rid) + { + InputStream stream = (InputStream)istr.closure(); + read(stream, rid); + } + } + + public abstract class ObjectWriter : ObjectImpl + { + public abstract void write(OutputStream outStream); + + public override void write__(IceInternal.BasicStream os) + { + OutputStream stream = (OutputStream)os.closure(); + write(stream); + } + + public override void read__(IceInternal.BasicStream istr, bool rid) + { + Debug.Assert(false); + } + } + + public abstract class UserExceptionWriter : UserException + { + UserExceptionWriter(Communicator communicator) + { + communicator_ = communicator; + } + + public abstract void write(OutputStream os); + public abstract bool usesClasses(); + + public override void write__(IceInternal.BasicStream ostr) + { + OutputStream stream = new OutputStreamI(communicator_, ostr); + write(stream); + } + + public override void read__(IceInternal.BasicStream istr, bool rid) + { + Debug.Assert(false); + } + + public override void write__(Ice.OutputStream ostr) + { + write(ostr); + } + + public override void read__(Ice.InputStream istr, bool rid) + { + Debug.Assert(false); + } + + public override bool usesClasses__() + { + return usesClasses(); + } + + protected Communicator communicator_; + } +} diff --git a/cs/src/Ice/InputStreamI.cs b/cs/src/Ice/StreamI.cs index a840859743a..2629b5d634f 100644 --- a/cs/src/Ice/InputStreamI.cs +++ b/cs/src/Ice/StreamI.cs @@ -15,7 +15,8 @@ namespace Ice { _communicator = communicator; - _is = new IceInternal.BasicInputStream(Util.getInstance(communicator), this); + _is = new IceInternal.BasicStream(Util.getInstance(communicator)); + _is.closure(this); _is.resize(data.Length, true); IceInternal.ByteBuffer buf = _is.prepareRead(); buf.position(0); @@ -192,6 +193,176 @@ namespace Ice } private Communicator _communicator; - private IceInternal.BasicInputStream _is; + private IceInternal.BasicStream _is; + } + + public class OutputStreamI : OutputStream + { + public OutputStreamI(Communicator communicator) : + this(communicator, new IceInternal.BasicStream(Util.getInstance(communicator))) + { + } + + public OutputStreamI(Communicator communicator, IceInternal.BasicStream os) + { + _communicator = communicator; + _os = os; + _os.closure(this); + } + + public Communicator communicator() + { + return _communicator; + } + + public void writeBool(bool v) + { + _os.writeBool(v); + } + + public void writeBoolSeq(bool[] v) + { + _os.writeBoolSeq(v); + } + + public void writeByte(byte v) + { + _os.writeByte(v); + } + + public void writeByteSeq(byte[] v) + { + _os.writeByteSeq(v); + } + + public void writeShort(short v) + { + _os.writeShort(v); + } + + public void writeShortSeq(short[] v) + { + _os.writeShortSeq(v); + } + + public void writeInt(int v) + { + _os.writeInt(v); + } + + public void writeIntSeq(int[] v) + { + _os.writeIntSeq(v); + } + + public void writeLong(long v) + { + _os.writeLong(v); + } + + public void writeLongSeq(long[] v) + { + _os.writeLongSeq(v); + } + + public void writeFloat(float v) + { + _os.writeFloat(v); + } + + public void writeFloatSeq(float[] v) + { + _os.writeFloatSeq(v); + } + + public void writeDouble(double v) + { + _os.writeDouble(v); + } + + public void writeDoubleSeq(double[] v) + { + _os.writeDoubleSeq(v); + } + + public void writeString(string v) + { + _os.writeString(v); + } + + public void writeStringSeq(string[] v) + { + _os.writeStringSeq(v); + } + + public void writeSize(int sz) + { + _os.writeSize(sz); + } + + public void writeProxy(ObjectPrx v) + { + _os.writeProxy(v); + } + + public void writeObject(Ice.Object v) + { + _os.writeObject(v); + } + + public void writeTypeId(string id) + { + _os.writeTypeId(id); + } + + public void writeException(UserException v) + { + _os.writeUserException(v); + } + + public void startSlice() + { + _os.startWriteSlice(); + } + + public void endSlice() + { + _os.endWriteSlice(); + } + + public void startEncapsulation() + { + _os.startWriteEncaps(); + } + + public void endEncapsulation() + { + _os.endWriteEncaps(); + } + + public void writePendingObjects() + { + _os.writePendingObjects(); + } + + public byte[] finished() + { + IceInternal.ByteBuffer buf = _os.prepareWrite(); + byte[] result = new byte[buf.limit()]; + buf.get(result); + + return result; + } + + public void destroy() + { + if(_os != null) + { + _os = null; + } + } + + private Communicator _communicator; + private IceInternal.BasicStream _os; } } diff --git a/java/CHANGES b/java/CHANGES index 7a3c995a098..dfc91dd86bb 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -8,8 +8,11 @@ Changes since version 3.2.X (binary incompatible) return a proxy of the same type as the target. This allows you to cast the return proxy instead using uncheckedCast on the Helper. For example, you can now write: + hello = (HelloPrx)hello.ice_oneway(); + instead of: + hello = HelloPrxHelper.uncheckedCast(hello.ice_oneway()); - Added support for a password callback in IceSSL. Also added new @@ -18,7 +21,7 @@ Changes since version 3.2.X (binary incompatible) - Setting IceBox.ServiceManager.Endpoints is no longer necessary in order to run the IceBox service. If no endpoints are specified - the the ServiceManager interface is not created. + then the ServiceManager interface is not created. - The property Ice.Plugin.Logger is now reserved to allow setting of the communicator's logger from properties. This plugin must @@ -50,6 +53,7 @@ Changes since version 3.2.X (binary incompatible) present when the adapter was created. - Freeze evictor update: + - the existing evictor was renamed BackgroundSaveEvictor - added new TransactionalEvictor diff --git a/java/src/Ice/InputStreamI.java b/java/src/Ice/InputStreamI.java index b1b1975811a..4cd30cbd4aa 100644 --- a/java/src/Ice/InputStreamI.java +++ b/java/src/Ice/InputStreamI.java @@ -16,7 +16,8 @@ public class InputStreamI implements InputStream { _communicator = communicator; - _is = new IceInternal.BasicInputStream(Util.getInstance(communicator), this); + _is = new IceInternal.BasicStream(Util.getInstance(communicator)); + _is.closure(this); _is.resize(data.length, true); java.nio.ByteBuffer buf = _is.prepareRead(); buf.position(0); @@ -231,5 +232,5 @@ public class InputStreamI implements InputStream } private Communicator _communicator; - private IceInternal.BasicInputStream _is; + private IceInternal.BasicStream _is; } diff --git a/java/src/Ice/ObjectReader.java b/java/src/Ice/ObjectReader.java index f63570f138c..a3c564260e1 100644 --- a/java/src/Ice/ObjectReader.java +++ b/java/src/Ice/ObjectReader.java @@ -22,7 +22,7 @@ public abstract class ObjectReader extends ObjectImpl public void __read(IceInternal.BasicStream is, boolean rid) { - IceInternal.BasicInputStream bis = (IceInternal.BasicInputStream)is; - read(bis._in, rid); + InputStream stream = (InputStream)is.closure(); + read(stream, rid); } } diff --git a/java/src/Ice/ObjectWriter.java b/java/src/Ice/ObjectWriter.java index fc5afeca4f4..1d8e57fa2d4 100644 --- a/java/src/Ice/ObjectWriter.java +++ b/java/src/Ice/ObjectWriter.java @@ -16,8 +16,8 @@ public abstract class ObjectWriter extends ObjectImpl public void __write(IceInternal.BasicStream os) { - IceInternal.BasicOutputStream bos = (IceInternal.BasicOutputStream)os; - write(bos._out); + OutputStream stream = (OutputStream)os.closure(); + write(stream); } public void diff --git a/java/src/Ice/OutputStreamI.java b/java/src/Ice/OutputStreamI.java index 188080d4f9c..2a0884014ef 100644 --- a/java/src/Ice/OutputStreamI.java +++ b/java/src/Ice/OutputStreamI.java @@ -14,8 +14,15 @@ public class OutputStreamI implements OutputStream public OutputStreamI(Communicator communicator) { + this(communicator, new IceInternal.BasicStream(Util.getInstance(communicator))); + } + + public + OutputStreamI(Communicator communicator, IceInternal.BasicStream os) + { _communicator = communicator; - _os = new IceInternal.BasicOutputStream(Util.getInstance(communicator), this); + _os = os; + _os.closure(this); } public Communicator @@ -200,5 +207,5 @@ public class OutputStreamI implements OutputStream } private Communicator _communicator; - private IceInternal.BasicOutputStream _os; + private IceInternal.BasicStream _os; } diff --git a/java/src/Ice/UserExceptionWriter.java b/java/src/Ice/UserExceptionWriter.java new file mode 100644 index 00000000000..a1d57e59573 --- /dev/null +++ b/java/src/Ice/UserExceptionWriter.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public abstract class UserExceptionWriter extends UserException +{ + public UserExceptionWriter(Communicator communicator) + { + _communicator = communicator; + } + + public abstract void + write(Ice.OutputStream os); + + public abstract boolean + usesClasses(); + + public void + __write(IceInternal.BasicStream os) + { + OutputStream stream = new OutputStreamI(_communicator, os); + write(stream); + } + + public void + __read(IceInternal.BasicStream is, boolean rid) + { + assert(false); + } + + public void + __write(Ice.OutputStream os) + { + write(os); + } + + public void + __read(Ice.InputStream is, boolean rid) + { + assert(false); + } + + public boolean + __usesClasses() + { + return usesClasses(); + } + + protected Communicator _communicator; +} diff --git a/java/src/IceInternal/BasicInputStream.java b/java/src/IceInternal/BasicInputStream.java deleted file mode 100644 index 188f321fa90..00000000000 --- a/java/src/IceInternal/BasicInputStream.java +++ /dev/null @@ -1,22 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package IceInternal; - -public class BasicInputStream extends BasicStream -{ - public - BasicInputStream(Instance instance, Ice.InputStream in) - { - super(instance); - _in = in; - } - - public Ice.InputStream _in; -} diff --git a/java/src/IceInternal/BasicOutputStream.java b/java/src/IceInternal/BasicOutputStream.java deleted file mode 100644 index a96ec64927b..00000000000 --- a/java/src/IceInternal/BasicOutputStream.java +++ /dev/null @@ -1,22 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package IceInternal; - -public class BasicOutputStream extends BasicStream -{ - public - BasicOutputStream(Instance instance, Ice.OutputStream out) - { - super(instance); - _out = out; - } - - public Ice.OutputStream _out; -} diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 372b9875f33..2b15bdd6897 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -27,6 +27,7 @@ public class BasicStream initialize(IceInternal.Instance instance, boolean unlimited) { _instance = instance; + _closure = null; _unlimited = unlimited; allocate(1500); _capacity = _buf.capacity(); @@ -80,11 +81,29 @@ public class BasicStream return _instance; } + public Object + closure() + { + return _closure; + } + + public Object + closure(Object p) + { + Object prev = _closure; + _closure = p; + return prev; + } + public void swap(BasicStream other) { assert(_instance == other._instance); + Object tmpClosure = other._closure; + other._closure = _closure; + _closure = tmpClosure; + java.nio.ByteBuffer tmpBuf = other._buf; other._buf = _buf; _buf = tmpBuf; @@ -2294,6 +2313,7 @@ public class BasicStream } private IceInternal.Instance _instance; + private Object _closure; private java.nio.ByteBuffer _buf; private int _capacity; // Cache capacity to avoid excessive method calls. private int _limit; // Cache limit to avoid excessive method calls. diff --git a/py/CHANGES b/py/CHANGES index 4d6f439b6fa..087f5667a96 100644 --- a/py/CHANGES +++ b/py/CHANGES @@ -1,13 +1,16 @@ Changes since version 3.2.X (binary incompatible) ------------------------------------------------- +- Changed servant locators so both locate() and finished() can + throw user exceptions. (See the manual for details.) + - Fixed a bug where returning an AMD servant from a ServantLocator would cause a deadlock in the IcePy extension. - Added support for blobjects. - Fixed a code generation bug with slice2py where the proxy type - for a python reserved word would be incorrectly named. For example, + for a Python reserved word would be incorrectly named. For example, interface def would generate a proxy class named _defPrx, not the correct class name defPrx. diff --git a/py/modules/IcePy/.depend b/py/modules/IcePy/.depend index 179c835a866..b9acb575b09 100644 --- a/py/modules/IcePy/.depend +++ b/py/modules/IcePy/.depend @@ -4,7 +4,7 @@ Current$(OBJEXT): Current.cpp ./Current.h ./Config.h ./Connection.h ./ObjectAdap ImplicitContext$(OBJEXT): ImplicitContext.cpp ./ImplicitContext.h ./Config.h ./ObjectAdapter.h ./Proxy.h ./Util.h Init$(OBJEXT): Init.cpp ./Communicator.h ./Config.h ./Connection.h ./Current.h ./ImplicitContext.h ./Logger.h ./Util.h ./ObjectAdapter.h ./Operation.h ./Properties.h ./Proxy.h ./Slice.h ./Types.h Logger$(OBJEXT): Logger.cpp ./Logger.h ./Config.h ./Util.h -ObjectAdapter$(OBJEXT): ObjectAdapter.cpp ./ObjectAdapter.h ./Config.h ./Communicator.h ./Current.h ./Operation.h ./Proxy.h ./Util.h +ObjectAdapter$(OBJEXT): ObjectAdapter.cpp ./ObjectAdapter.h ./Config.h ./Communicator.h ./Current.h ./Operation.h ./Proxy.h ./Types.h ./Util.h ObjectFactory$(OBJEXT): ObjectFactory.cpp ./ObjectFactory.h ./Config.h ./Types.h ./Util.h Operation$(OBJEXT): Operation.cpp ./Operation.h ./Config.h ./Current.h ./Proxy.h ./Types.h ./Util.h Properties$(OBJEXT): Properties.cpp ./Properties.h ./Config.h ./Util.h diff --git a/py/modules/IcePy/ObjectAdapter.cpp b/py/modules/IcePy/ObjectAdapter.cpp index 0416b6a3a89..b96820c3f1e 100644 --- a/py/modules/IcePy/ObjectAdapter.cpp +++ b/py/modules/IcePy/ObjectAdapter.cpp @@ -15,6 +15,7 @@ #include <Current.h> #include <Operation.h> #include <Proxy.h> +#include <Types.h> #include <Util.h> #include <Ice/Communicator.h> #include <Ice/LocalException.h> @@ -120,7 +121,23 @@ IcePy::ServantLocatorWrapper::locate(const Ice::Current& current, Ice::LocalObje PyObjectHandle res = PyObject_CallMethod(_locator, STRCAST("locate"), STRCAST("O"), c->current); if(PyErr_Occurred()) { - throwPythonException(); + PyException ex; // Retrieve the exception before another Python API call clears it. + + // + // A locator that calls sys.exit() will raise the SystemExit exception. + // This is normally caught by the interpreter, causing it to exit. + // However, we have no way to pass this exception to the interpreter, + // so we act on it directly. + // + ex.checkSystemExit(); + + PyObject* userExceptionType = lookupType("Ice.UserException"); + if(PyObject_IsInstance(ex.ex.get(), userExceptionType)) + { + throw ExceptionWriter(current.adapter->getCommunicator(), ex.ex); + } + + ex.raise(); } if(res.get() == Py_None) @@ -168,7 +185,8 @@ IcePy::ServantLocatorWrapper::locate(const Ice::Current& current, Ice::LocalObje } void -IcePy::ServantLocatorWrapper::finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr& cookie) +IcePy::ServantLocatorWrapper::finished(const Ice::Current& current, const Ice::ObjectPtr&, + const Ice::LocalObjectPtr& cookie) { AdoptThread adoptThread; // Ensure the current thread is able to call into Python. @@ -182,7 +200,23 @@ IcePy::ServantLocatorWrapper::finished(const Ice::Current&, const Ice::ObjectPtr servantObj.get(), c->cookie); if(PyErr_Occurred()) { - throwPythonException(); + PyException ex; // Retrieve the exception before another Python API call clears it. + + // + // A locator that calls sys.exit() will raise the SystemExit exception. + // This is normally caught by the interpreter, causing it to exit. + // However, we have no way to pass this exception to the interpreter, + // so we act on it directly. + // + ex.checkSystemExit(); + + PyObject* userExceptionType = lookupType("Ice.UserException"); + if(PyObject_IsInstance(ex.ex.get(), userExceptionType)) + { + throw ExceptionWriter(current.adapter->getCommunicator(), ex.ex); + } + + ex.raise(); } } @@ -194,7 +228,17 @@ IcePy::ServantLocatorWrapper::deactivate(const string& category) PyObjectHandle res = PyObject_CallMethod(_locator, STRCAST("deactivate"), STRCAST("s"), category.c_str()); if(PyErr_Occurred()) { - throwPythonException(); + PyException ex; // Retrieve the exception before another Python API call clears it. + + // + // A locator that calls sys.exit() will raise the SystemExit exception. + // This is normally caught by the interpreter, causing it to exit. + // However, we have no way to pass this exception to the interpreter, + // so we act on it directly. + // + ex.checkSystemExit(); + + ex.raise(); } Py_DECREF(_locator); diff --git a/py/modules/IcePy/Operation.cpp b/py/modules/IcePy/Operation.cpp index b6ec94283b1..19ae001c952 100644 --- a/py/modules/IcePy/Operation.cpp +++ b/py/modules/IcePy/Operation.cpp @@ -1799,10 +1799,7 @@ IcePy::TypedUpcall::exception(PyException& ex) // However, we have no way to pass this exception to the interpreter, // so we act on it directly. // - if(PyObject_IsInstance(ex.ex.get(), PyExc_SystemExit)) - { - handleSystemExit(ex.ex.get()); // Does not return. - } + ex.checkSystemExit(); PyObject* userExceptionType = lookupType("Ice.UserException"); @@ -1822,6 +1819,9 @@ IcePy::TypedUpcall::exception(PyException& ex) else { Ice::OutputStreamPtr os = Ice::createOutputStream(_communicator); + + os->writeBool(info->usesClasses); + ObjectMap objectMap; info->marshal(ex.ex.get(), os, &objectMap); @@ -2058,10 +2058,7 @@ IcePy::BlobjectUpcall::exception(PyException& ex) // However, we have no way to pass this exception to the interpreter, // so we act on it directly. // - if(PyObject_IsInstance(ex.ex.get(), PyExc_SystemExit)) - { - handleSystemExit(ex.ex.get()); // Does not return. - } + ex.checkSystemExit(); ex.raise(); } diff --git a/py/modules/IcePy/Types.cpp b/py/modules/IcePy/Types.cpp index eff2703fec6..422e8a9358a 100644 --- a/py/modules/IcePy/Types.cpp +++ b/py/modules/IcePy/Types.cpp @@ -2308,8 +2308,6 @@ IcePy::ExceptionInfo::marshal(PyObject* p, const Ice::OutputStreamPtr& os, Objec throw AbortMarshaling(); } - os->writeBool(usesClasses); - ExceptionInfoPtr info = this; while(info) { @@ -2418,6 +2416,53 @@ IcePy::ExceptionInfo::printMembers(PyObject* value, IceUtil::Output& out, PrintO } // +// ExceptionWriter implementation. +// +IcePy::ExceptionWriter::ExceptionWriter(const Ice::CommunicatorPtr& communicator, const PyObjectHandle& ex) : + Ice::UserExceptionWriter(communicator), _ex(ex) +{ + PyObjectHandle iceType = PyObject_GetAttrString(ex.get(), STRCAST("ice_type")); + assert(iceType.get()); + _info = ExceptionInfoPtr::dynamicCast(getException(iceType.get())); + assert(_info); +} + +IcePy::ExceptionWriter::~ExceptionWriter() throw() +{ +} + +void +IcePy::ExceptionWriter::write(const Ice::OutputStreamPtr& os) const +{ + ObjectMap objectMap; + _info->marshal(_ex.get(), os, &objectMap); +} + +bool +IcePy::ExceptionWriter::usesClasses() const +{ + return _info->usesClasses; +} + +string +IcePy::ExceptionWriter::ice_name() const +{ + return _info->id; +} + +Ice::Exception* +IcePy::ExceptionWriter::ice_clone() const +{ + return new ExceptionWriter(*this); +} + +void +IcePy::ExceptionWriter::ice_throw() const +{ + throw *this; +} + +// // lookupClassInfo() // IcePy::ClassInfoPtr diff --git a/py/modules/IcePy/Types.h b/py/modules/IcePy/Types.h index 4decb6741ef..0194cb5db28 100644 --- a/py/modules/IcePy/Types.h +++ b/py/modules/IcePy/Types.h @@ -409,6 +409,29 @@ private: }; typedef IceUtil::Handle<ObjectReader> ObjectReaderPtr; +// +// ExceptionWriter wraps a Python user exception for marshaling. +// +class ExceptionWriter : public Ice::UserExceptionWriter +{ +public: + + ExceptionWriter(const Ice::CommunicatorPtr&, const PyObjectHandle&); + ~ExceptionWriter() throw(); + + virtual void write(const Ice::OutputStreamPtr&) const; + virtual bool usesClasses() const; + + virtual std::string ice_name() const; + virtual Ice::Exception* ice_clone() const; + virtual void ice_throw() const; + +private: + + PyObjectHandle _ex; + ExceptionInfoPtr _info; +}; + ClassInfoPtr lookupClassInfo(const std::string&); ExceptionInfoPtr lookupExceptionInfo(const std::string&); diff --git a/py/modules/IcePy/Util.cpp b/py/modules/IcePy/Util.cpp index edf92dc2c14..98f51a460e0 100644 --- a/py/modules/IcePy/Util.cpp +++ b/py/modules/IcePy/Util.cpp @@ -58,7 +58,7 @@ IcePy::PyObjectHandle::operator=(const PyObjectHandle& p) } PyObject* -IcePy::PyObjectHandle::get() +IcePy::PyObjectHandle::get() const { return _p; } @@ -153,6 +153,15 @@ IcePy::PyException::raise() } void +IcePy::PyException::checkSystemExit() +{ + if(PyObject_IsInstance(ex.get(), PyExc_SystemExit)) + { + handleSystemExit(ex.get()); // Does not return. + } +} + +void IcePy::PyException::raiseLocalException() { string typeName = getTypeName(); diff --git a/py/modules/IcePy/Util.h b/py/modules/IcePy/Util.h index ea246c1f461..7e191ce81ca 100644 --- a/py/modules/IcePy/Util.h +++ b/py/modules/IcePy/Util.h @@ -61,7 +61,7 @@ public: void operator=(PyObject*); void operator=(const PyObjectHandle&); - PyObject* get(); + PyObject* get() const; PyObject* release(); private: @@ -91,6 +91,11 @@ public: // void raise(); + // + // If the Python exception is SystemExit, act on it. May not return. + // + void checkSystemExit(); + PyObjectHandle ex; private: diff --git a/py/test/Ice/exceptions/AllTests.py b/py/test/Ice/exceptions/AllTests.py index e3c1c2c248e..41af433ae5a 100644 --- a/py/test/Ice/exceptions/AllTests.py +++ b/py/test/Ice/exceptions/AllTests.py @@ -288,7 +288,7 @@ class AMI_WrongOperation_noSuchOperationI(CallbackBase): self.called() def allTests(communicator): - print "testing servant registration exceptions... ", + print "testing servant registration exceptions...", communicator.getProperties().setProperty("TestAdapter1.Endpoints", "default") adapter = communicator.createObjectAdapter("TestAdapter1") obj = EmptyI() @@ -309,7 +309,7 @@ def allTests(communicator): adapter.deactivate() print "ok" - print "testing servant locator registrations exceptions... ", + print "testing servant locator registrations exceptions...", communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default") adapter = communicator.createObjectAdapter("TestAdapter2") loc = ServantLocatorI() @@ -323,7 +323,7 @@ def allTests(communicator): adapter.deactivate() print "ok" - print "testing object factory registration exception... ", + print "testing object factory registration exception...", of = ObjectFactoryI() communicator.addObjectFactory(of, "x") try: @@ -333,19 +333,19 @@ def allTests(communicator): pass print "ok" - print "testing stringToProxy... ", + print "testing stringToProxy...", ref = "thrower:default -p 12010 -t 10000" base = communicator.stringToProxy(ref) test(base) print "ok" - print "testing checked cast... ", + print "testing checked cast...", thrower = Test.ThrowerPrx.checkedCast(base) test(thrower) test(thrower == base) print "ok" - print "catching exact types... ", + print "catching exact types...", try: thrower.throwAasA(1) @@ -412,7 +412,7 @@ def allTests(communicator): print "ok" - print "catching base types... ", + print "catching base types...", try: thrower.throwBasB(1, 2) @@ -449,7 +449,7 @@ def allTests(communicator): print "ok" - print "catching derived types... ", + print "catching derived types...", try: thrower.throwBasA(1, 2) @@ -486,16 +486,12 @@ def allTests(communicator): print "ok" if thrower.supportsUndeclaredExceptions(): - print "catching unknown user exception... ", + print "catching unknown user exception...", try: thrower.throwUndeclaredA(1) test(False) except Ice.UnknownUserException: - # - # We get an unknown user exception without collocation - # optimization. - # pass except: print sys.exc_info() @@ -505,10 +501,6 @@ def allTests(communicator): thrower.throwUndeclaredB(1, 2) test(False) except Ice.UnknownUserException: - # - # We get an unknown user exception without collocation - # optimization. - # pass except: print sys.exc_info() @@ -518,10 +510,6 @@ def allTests(communicator): thrower.throwUndeclaredC(1, 2, 3) test(False) except Ice.UnknownUserException: - # - # We get an unknown user exception without - # collocation optimization. - # pass except: print sys.exc_info() @@ -529,7 +517,7 @@ def allTests(communicator): print "ok" - print "catching object not exist exception... ", + print "catching object not exist exception...", id = communicator.stringToIdentity("does not exist") try: @@ -545,7 +533,7 @@ def allTests(communicator): print "ok" - print "catching facet not exist exception... ", + print "catching facet not exist exception...", try: thrower2 = Test.ThrowerPrx.uncheckedCast(thrower, "no such facet") @@ -560,7 +548,7 @@ def allTests(communicator): print "ok" - print "catching operation not exist exception... ", + print "catching operation not exist exception...", try: thrower2 = Test.WrongOperationPrx.uncheckedCast(thrower) @@ -574,16 +562,12 @@ def allTests(communicator): print "ok" - print "catching unknown local exception... ", + print "catching unknown local exception...", try: thrower.throwLocalException() test(False) except Ice.UnknownLocalException: - # - # We get an unknown local exception without collocation - # optimization. - # pass except: print sys.exc_info() @@ -591,16 +575,12 @@ def allTests(communicator): print "ok" - print "catching unknown non-Ice exception... ", + print "catching unknown non-Ice exception...", try: thrower.throwNonIceException() test(False) except Ice.UnknownException: - # - # We get an unknown exception without collocation - # optimization. - # pass except: print sys.exc_info() @@ -608,7 +588,7 @@ def allTests(communicator): print "ok" - print "catching exact types with AMI... ", + print "catching exact types with AMI...", cb = AMI_Thrower_throwAasAI() thrower.throwAasA_async(cb, 1) @@ -642,7 +622,7 @@ def allTests(communicator): print "ok" - print "catching derived types... ", + print "catching derived types...", cb = AMI_Thrower_throwBasAI() thrower.throwBasA_async(cb, 1, 2) @@ -659,7 +639,7 @@ def allTests(communicator): print "ok" if thrower.supportsUndeclaredExceptions(): - print "catching unknown user exception with AMI... ", + print "catching unknown user exception with AMI...", cb = AMI_Thrower_throwUndeclaredAI() thrower.throwUndeclaredA_async(cb, 1) @@ -675,7 +655,7 @@ def allTests(communicator): print "ok" - print "catching object not exist exception with AMI... ", + print "catching object not exist exception with AMI...", id = communicator.stringToIdentity("does not exist") thrower2 = Test.ThrowerPrx.uncheckedCast(thrower.ice_identity(id)) @@ -685,7 +665,7 @@ def allTests(communicator): print "ok" - print "catching facet not exist exception with AMI... ", + print "catching facet not exist exception with AMI...", thrower2 = Test.ThrowerPrx.uncheckedCast(thrower, "no such facet") cb = AMI_Thrower_throwAasAFacetNotExistI() @@ -694,7 +674,7 @@ def allTests(communicator): print "ok" - print "catching operation not exist exception with AMI... ", + print "catching operation not exist exception with AMI...", cb = AMI_WrongOperation_noSuchOperationI() thrower4 = Test.WrongOperationPrx.uncheckedCast(thrower) @@ -703,7 +683,7 @@ def allTests(communicator): print "ok" - print "catching unknown local exception with AMI... ", + print "catching unknown local exception with AMI...", cb = AMI_Thrower_throwLocalExceptionI() thrower.throwLocalException_async(cb) @@ -711,7 +691,7 @@ def allTests(communicator): print "ok" - print "catching unknown non-Ice exception with AMI... ", + print "catching unknown non-Ice exception with AMI...", cb = AMI_Thrower_throwNonIceExceptionI() thrower.throwNonIceException_async(cb) diff --git a/py/test/Ice/servantLocator/AllTests.py b/py/test/Ice/servantLocator/AllTests.py index fcc9c33342f..fb8434769bf 100644 --- a/py/test/Ice/servantLocator/AllTests.py +++ b/py/test/Ice/servantLocator/AllTests.py @@ -18,72 +18,117 @@ def testExceptions(obj, collocated): try: obj.requestFailedException() - test(false) + test(False) except Ice.ObjectNotExistException, ex: if not collocated: test(ex.id == obj.ice_getIdentity()) test(ex.facet == obj.ice_getFacet()) test(ex.operation == "requestFailedException") + except: + test(False) try: obj.unknownUserException() - test(false) + test(False) except Ice.UnknownUserException, ex: test(ex.unknown == "reason") pass + except: + test(False) try: obj.unknownLocalException() - test(false) + test(False) except Ice.UnknownLocalException, ex: test(ex.unknown == "reason") pass try: obj.unknownException() - test(false) + test(False) except Ice.UnknownException, ex: test(ex.unknown == "reason") pass try: obj.userException() - test(false) + test(False) except Ice.UnknownUserException, ex: - #print ex.unknown - test(not collocated) - test(ex.unknown.find("Test.TestIntfUserException") >= 0) - except Test.TestIntfUserException: - test(collocated) + test(ex.unknown.find("Test::TestIntfUserException") >= 0) + except: + test(False) try: obj.localException() - test(false) + test(False) except Ice.UnknownLocalException, ex: - #print ex.unknown test(not collocated) test(ex.unknown.find("Ice.SocketException") >= 0) except SocketException: test(collocated) + except: + test(False) try: obj.pythonException() - test(false) + test(False) except Ice.UnknownException, ex: - #print ex.unknown - test(not collocated) test(ex.unknown.find("RuntimeError: message") >= 0) - except RuntimeError: - test(collocated) + except: + test(False) + + try: + obj.unknownExceptionWithServantException() + test(False) + except Ice.UnknownException, ex: + test(ex.unknown == "reason") + except: + test(False) + + try: + obj.impossibleException(False) + test(False) + except Ice.UnknownUserException: + # Operation doesn't throw, but locate() and finshed() throw TestIntfUserException. + pass + except: + test(False) + + try: + obj.impossibleException(True) + test(False) + except Ice.UnknownUserException: + # Operation doesn't throw, but locate() and finshed() throw TestIntfUserException. + pass + except: + test(False) + + try: + obj.intfUserException(False) + test(False) + except Test.TestImpossibleException: + # Operation doesn't throw, but locate() and finshed() throw TestIntfUserException. + pass + except: + test(False) + + try: + obj.intfUserException(True) + test(False) + except Test.TestImpossibleException: + # Operation doesn't throw, but locate() and finshed() throw TestIntfUserException. + pass + except: + test(False) def allTests(communicator, collocated): - print "testing stringToProxy... ", + print "testing stringToProxy...", sys.stdout.flush() base = communicator.stringToProxy("asm:default -p 12010 -t 10000") test(base) print "ok" - print "testing checked cast... ", + print "testing checked cast...", sys.stdout.flush() obj = Test.TestIntfPrx.checkedCast(base) test(obj) @@ -116,14 +161,14 @@ def allTests(communicator, collocated): pass print "ok" - print "testing locate exceptions... ", + print "testing locate exceptions...", sys.stdout.flush() base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000") obj = Test.TestIntfPrx.checkedCast(base) testExceptions(obj, collocated) print "ok" - print "testing finished exceptions... ", + print "testing finished exceptions...", sys.stdout.flush() base = communicator.stringToProxy("category/finished:default -p 12010 -t 10000") obj = Test.TestIntfPrx.checkedCast(base) diff --git a/py/test/Ice/servantLocator/Test.ice b/py/test/Ice/servantLocator/Test.ice index a0ecf41df1d..b0157771ffd 100644 --- a/py/test/Ice/servantLocator/Test.ice +++ b/py/test/Ice/servantLocator/Test.ice @@ -17,6 +17,10 @@ exception TestIntfUserException { }; +exception TestImpossibleException +{ +}; + interface TestIntf { void requestFailedException(); @@ -27,6 +31,11 @@ interface TestIntf void userException(); void pythonException(); + void unknownExceptionWithServantException(); + + string impossibleException(bool throw) throws TestImpossibleException; + string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + void shutdown(); }; diff --git a/py/test/Ice/servantLocator/TestAMD.ice b/py/test/Ice/servantLocator/TestAMD.ice index fa62d346ffe..14747d48c84 100644 --- a/py/test/Ice/servantLocator/TestAMD.ice +++ b/py/test/Ice/servantLocator/TestAMD.ice @@ -17,6 +17,10 @@ exception TestIntfUserException { }; +exception TestImpossibleException +{ +}; + ["amd"] interface TestIntf { void requestFailedException(); @@ -27,6 +31,11 @@ exception TestIntfUserException void userException(); void pythonException(); + void unknownExceptionWithServantException(); + + string impossibleException(bool throw) throws TestImpossibleException; + string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + void shutdown(); }; diff --git a/py/test/Ice/servantLocator/TestAMDI.py b/py/test/Ice/servantLocator/TestAMDI.py index b19211b0b57..189702a4225 100644 --- a/py/test/Ice/servantLocator/TestAMDI.py +++ b/py/test/Ice/servantLocator/TestAMDI.py @@ -38,6 +38,29 @@ class TestI(Test.TestIntf): def pythonException_async(self, cb, current=None): cb.ice_response() + def unknownExceptionWithServantException_async(self, cb, current=None): + cb.ice_exception(Ice.ObjectNotExistException()) + + def impossibleException_async(self, cb, throw, current=None): + if throw: + cb.ice_exception(Test.TestImpossibleException()) + else: + # + # Return a value so we can be sure that the stream position + # is reset correctly if finished() throws. + # + cb.ice_response("Hello") + + def intfUserException_async(self, cb, throw, current=None): + if throw: + cb.ice_exception(Test.TestIntfUserException()) + else: + # + # Return a value so we can be sure that the stream position + # is reset correctly if finished() throws. + # + cb.ice_response("Hello") + def shutdown_async(self, cb, current=None): current.adapter.deactivate() cb.ice_response() @@ -89,22 +112,20 @@ class ServantLocatorI(Ice.ServantLocator): if current.operation == "requestFailedException": raise Ice.ObjectNotExistException() elif current.operation == "unknownUserException": - ex = Ice.UnknownUserException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownUserException("reason") elif current.operation == "unknownLocalException": - ex = Ice.UnknownLocalException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownLocalException("reason") elif current.operation == "unknownException": - ex = Ice.UnknownException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownException("reason") elif current.operation == "userException": raise Test.TestIntfUserException() elif current.operation == "localException": - ex = Ice.SocketException() - ex.error = 0 - raise ex + raise Ice.SocketException(0) elif current.operation == "pythonException": raise RuntimeError("message") + elif current.operation == "unknownExceptionWithServantException": + raise Ice.UnknownException("reason") + elif current.operation == "impossibleException": + raise Test.TestIntfUserException() # Yes, it really is meant to be TestIntfUserException. + elif current.operation == "intfUserException": + raise Test.TestImpossibleException() # Yes, it really is meant to be TestImpossibleException. diff --git a/py/test/Ice/servantLocator/TestI.py b/py/test/Ice/servantLocator/TestI.py index b79c7e9b337..52b367308ea 100644 --- a/py/test/Ice/servantLocator/TestI.py +++ b/py/test/Ice/servantLocator/TestI.py @@ -38,6 +38,27 @@ class TestI(Test.TestIntf): def pythonException(self, current=None): pass + def unknownExceptionWithServantException(self, current=None): + raise Ice.ObjectNotExistException() + + def impossibleException(self, throw, current=None): + if throw: + raise Test.TestImpossibleException() + # + # Return a value so we can be sure that the stream position + # is reset correctly if finished() throws. + # + return "Hello" + + def intfUserException(self, throw, current=None): + if throw: + raise Test.TestIntfUserException() + # + # Return a value so we can be sure that the stream position + # is reset correctly if finished() throws. + # + return "Hello" + def shutdown(self, current=None): current.adapter.deactivate() @@ -88,22 +109,20 @@ class ServantLocatorI(Ice.ServantLocator): if current.operation == "requestFailedException": raise Ice.ObjectNotExistException() elif current.operation == "unknownUserException": - ex = Ice.UnknownUserException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownUserException("reason") elif current.operation == "unknownLocalException": - ex = Ice.UnknownLocalException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownLocalException("reason") elif current.operation == "unknownException": - ex = Ice.UnknownException() - ex.unknown = "reason" - raise ex + raise Ice.UnknownException("reason") elif current.operation == "userException": raise Test.TestIntfUserException() elif current.operation == "localException": - ex = Ice.SocketException() - ex.error = 0 - raise ex + raise Ice.SocketException(0) elif current.operation == "pythonException": raise RuntimeError("message") + elif current.operation == "unknownExceptionWithServantException": + raise Ice.UnknownException("reason") + elif current.operation == "impossibleException": + raise Test.TestIntfUserException() # Yes, it really is meant to be TestIntfUserException. + elif current.operation == "intfUserException": + raise Test.TestImpossibleException() # Yes, it really is meant to be TestImpossibleException. |