// ********************************************************************** // // Copyright (c) 2003 - 2004 // ZeroC, Inc. // North Palm Beach, FL, USA // // All Rights Reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #include #include #include #include #include #include #include #include using namespace std; using namespace Ice; using namespace IceInternal; void IceInternal::incRef(IncomingAsync* p) { p->__incRef(); } void IceInternal::decRef(IncomingAsync* p) { p->__decRef(); } void IceInternal::incRef(AMD_Object_ice_invoke* p) { p->__incRef(); } void IceInternal::decRef(AMD_Object_ice_invoke* p) { p->__decRef(); } IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : IncomingBase(in), _finished(false), _instanceCopy(_os.instance()), _connectionCopy(_connection) { } void IceInternal::IncomingAsync::__response(bool ok) { assert(!_finished); _finished = true; if(_response) { _os.endWriteEncaps(); if(ok) { *(_os.b.begin() + headerSize + 4) = static_cast(DispatchOK); // Dispatch status position. } else { *(_os.b.begin() + headerSize + 4) = static_cast(DispatchUserException); // Dispatch status position. } } // // Must be called last, so that if an exception is raised, // this function is definitely *not* called. // __finishInvoke(); } void IceInternal::IncomingAsync::__exception(const Exception& exc) { assert(!_finished); _finished = true; try { exc.ice_throw(); } catch(RequestFailedException& ex) { if(ex.id.name.empty()) { ex.id = _current.id; } if(ex.facet.empty() && !_current.facet.empty()) { ex.facet = _current.facet; } if(ex.operation.empty() && !_current.operation.empty()) { ex.operation = _current.operation; } if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) { __warning(ex); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. if(dynamic_cast(&ex)) { _os.write(static_cast(DispatchObjectNotExist)); } else if(dynamic_cast(&ex)) { _os.write(static_cast(DispatchFacetNotExist)); } else if(dynamic_cast(&ex)) { _os.write(static_cast(DispatchOperationNotExist)); } else { assert(false); } ex.id.__write(&_os); // // For compatibility with the old FacetPath. // if(ex.facet.empty()) { _os.write(vector()); } else { vector facetPath; facetPath.push_back(ex.facet); _os.write(facetPath); } _os.write(ex.operation); } } catch(const LocalException& ex) { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { __warning(ex); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast(DispatchUnknownLocalException)); ostringstream str; str << ex; _os.write(str.str()); } } catch(const UserException& ex) { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { __warning(ex); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast(DispatchUnknownUserException)); ostringstream str; str << ex; _os.write(str.str()); } } catch(const Exception& ex) { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { __warning(ex); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast(DispatchUnknownException)); ostringstream str; str << ex; _os.write(str.str()); } } // // Must be called last, so that if an exception is raised, // this function is definitely *not* called. // __finishInvoke(); } void IceInternal::IncomingAsync::__exception(const std::exception& ex) { assert(!_finished); _finished = true; if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { __warning(string("std::exception: ") + ex.what()); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast(DispatchUnknownException)); ostringstream str; str << "std::exception: " << ex.what(); _os.write(str.str()); } // // Must be called last, so that if an exception is raised, // this function is definitely *not* called. // __finishInvoke(); } void IceInternal::IncomingAsync::__exception() { assert(!_finished); _finished = true; if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { __warning("unknown c++ exception"); } if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast(DispatchUnknownException)); string reason = "unknown c++ exception"; _os.write(reason); } // // Must be called last, so that if an exception is raised, // this function is definitely *not* called. // __finishInvoke(); } IceAsync::Ice::AMD_Object_ice_invoke::AMD_Object_ice_invoke(Incoming& in) : IncomingAsync(in) { } void IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const ::std::vector< ::Ice::Byte>& outParams) { try { __os()->writeBlob(outParams); } catch(const LocalException& ex) { __exception(ex); return; } __response(ok); } void IceAsync::Ice::AMD_Object_ice_invoke::ice_exception(const Exception& ex) { __exception(ex); } void IceAsync::Ice::AMD_Object_ice_invoke::ice_exception(const std::exception& ex) { __exception(ex); } void IceAsync::Ice::AMD_Object_ice_invoke::ice_exception() { __exception(); }