diff options
author | Mark Spruiell <mes@zeroc.com> | 2007-11-05 12:19:49 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2007-11-05 12:19:49 -0800 |
commit | 3c8924663df8629b33c2ddd38907c4bf2eeb83cd (patch) | |
tree | 83b63f2396201019163d140555e42d79f82e46d3 /cpp/src/Ice/StreamI.cpp | |
parent | Merge branch 'master' of ssh://cvs.zeroc.com/home/git/ice (diff) | |
download | ice-3c8924663df8629b33c2ddd38907c4bf2eeb83cd.tar.bz2 ice-3c8924663df8629b33c2ddd38907c4bf2eeb83cd.tar.xz ice-3c8924663df8629b33c2ddd38907c4bf2eeb83cd.zip |
- Fixing bug 2522 for Python. This involved adding the C++ class
UserExceptionWriter so that the Python extension can wrap a native
Python user exception into something that the C++ run time can
marshal. Also ported the changes to the servantLocator test.
- Implementing UserExceptionWriter in Java and C#.
- Consolidating the source files for the C# streaming API.
Diffstat (limited to 'cpp/src/Ice/StreamI.cpp')
-rw-r--r-- | cpp/src/Ice/StreamI.cpp | 268 |
1 files changed, 149 insertions, 119 deletions
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(); +} |