📄 request.cc
字号:
// -*- Mode: C++; -*-// Package : omniORB// request.cc Created on: 9/1998// Author : David Riddoch (djr)//// Copyright (C) 1996-1999 AT&T Laboratories Cambridge//// This file is part of the omniORB library//// The omniORB library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA////// Description:// Implementation of CORBA::Request.//#include <omniORB4/CORBA.h>#include <omniORB4/objTracker.h>#ifdef HAS_pch#pragma hdrstop#endif#include <request.h>#include <deferredRequest.h>#include <context.h>#include <string.h>#include <omniORB4/callDescriptor.h>#include <remoteIdentity.h>#include <exceptiondefs.h>#include <omniORB4/IOP_C.h>#include <orbParameters.h>#include <invoker.h>OMNI_NAMESPACE_BEGIN(omni)#define INVOKE_DONE() if( pd_state == RS_READY ) pd_state = RS_DONE;RequestImpl::RequestImpl(CORBA::Object_ptr target, const char* operation){ pd_target = CORBA::Object::_duplicate(target); pd_operation = CORBA::string_dup(operation); pd_arguments = new NVListImpl(); pd_result = new NamedValueImpl(CORBA::Flags(0)); pd_result->value()->replace(CORBA::_tc_void, (void*)0); pd_environment = new EnvironmentImpl; pd_state = RS_READY; pd_deferredRequest = 0; pd_sysExceptionToThrow = 0; if( CORBA::is_nil(target) ) throw omniORB::fatalException(__FILE__,__LINE__, "CORBA::RequestImpl::RequestImpl()"); if( !operation || !*operation ) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_NullStringUnexpected, CORBA::COMPLETED_NO);}RequestImpl::RequestImpl(CORBA::Object_ptr target, const char* operation, CORBA::Context_ptr context, CORBA::NVList_ptr arguments, CORBA::NamedValue_ptr result){ pd_target = CORBA::Object::_duplicate(target); pd_operation = CORBA::string_dup(operation); if( CORBA::is_nil(arguments) ) pd_arguments = new NVListImpl(); else pd_arguments = CORBA::NVList::_duplicate(arguments); if( CORBA::is_nil(result) ){ pd_result = new NamedValueImpl(CORBA::Flags(0)); pd_result->value()->replace(CORBA::_tc_void, (void*) 0); } else pd_result = CORBA::NamedValue::_duplicate(result); pd_environment = new EnvironmentImpl; pd_context = CORBA::Context::_duplicate(context); pd_state = RS_READY; pd_deferredRequest = 0; pd_sysExceptionToThrow = 0; if( CORBA::is_nil(target) ) throw omniORB::fatalException(__FILE__,__LINE__, "CORBA::RequestImpl::RequestImpl()"); if( !operation || !*operation ) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_NullStringUnexpected, CORBA::COMPLETED_NO);}RequestImpl::RequestImpl(CORBA::Object_ptr target, const char* operation, CORBA::Context_ptr context, CORBA::NVList_ptr arguments, CORBA::NamedValue_ptr result, CORBA::ExceptionList_ptr exceptions, CORBA::ContextList_ptr contexts){ pd_target = CORBA::Object::_duplicate(target); pd_operation = CORBA::string_dup(operation); if( CORBA::is_nil(arguments) ) pd_arguments = new NVListImpl(); else pd_arguments = CORBA::NVList::_duplicate(arguments); if( CORBA::is_nil(result) ){ pd_result = new NamedValueImpl(CORBA::Flags(0)); pd_result->value()->replace(CORBA::_tc_void, (void*) 0); } else pd_result = CORBA::NamedValue::_duplicate(result); pd_environment = new EnvironmentImpl; pd_exceptions = CORBA::ExceptionList::_duplicate(exceptions); pd_contexts = CORBA::ContextList::_duplicate(contexts); pd_context = CORBA::Context::_duplicate(context); pd_state = RS_READY; pd_deferredRequest = 0; pd_sysExceptionToThrow = 0; if( CORBA::is_nil(target) ) throw omniORB::fatalException(__FILE__,__LINE__, "CORBA::RequestImpl::RequestImpl()"); if( !operation || !*operation ) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_NullStringUnexpected, CORBA::COMPLETED_NO);}RequestImpl::~RequestImpl(){ if( (pd_state == RS_DEFERRED) && omniORB::traceLevel > 0 ){ omniORB::logger log; log << "omniORB: WARNING -- The application has not collected the reponse of\n" " a deferred DII request. Use Request::get_response() or\n" " poll_response().\n"; } if( pd_sysExceptionToThrow ) delete pd_sysExceptionToThrow;}CORBA::Object_ptrRequestImpl::target() const{ return pd_target;}const char*RequestImpl::operation() const{ return pd_operation;}CORBA::NVList_ptrRequestImpl::arguments(){ if( pd_sysExceptionToThrow ) pd_sysExceptionToThrow->_raise(); return pd_arguments;}CORBA::NamedValue_ptrRequestImpl::result(){ if( pd_sysExceptionToThrow ) pd_sysExceptionToThrow->_raise(); return pd_result;}CORBA::Environment_ptrRequestImpl::env(){ if( pd_sysExceptionToThrow ) pd_sysExceptionToThrow->_raise(); return pd_environment;}CORBA::ExceptionList_ptrRequestImpl::exceptions(){ if( CORBA::is_nil(pd_exceptions) ) pd_exceptions = new ExceptionListImpl(); return pd_exceptions;}CORBA::ContextList_ptrRequestImpl::contexts(){ if( CORBA::is_nil(pd_contexts) ) pd_contexts = new ContextListImpl(); return pd_contexts;}CORBA::Context_ptrRequestImpl::ctx() const{ return pd_context;}voidRequestImpl::ctx(CORBA::Context_ptr context){ if (!CORBA::Context::PR_is_valid(context)) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidContext, CORBA::COMPLETED_NO); if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); pd_context = CORBA::Context::_duplicate(context);}CORBA::Any&RequestImpl::add_in_arg(){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add(CORBA::ARG_IN)->value());}CORBA::Any&RequestImpl::add_in_arg(const char* name){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add_item(name, CORBA::ARG_IN)->value());}CORBA::Any&RequestImpl::add_inout_arg(){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add(CORBA::ARG_INOUT)->value());}CORBA::Any&RequestImpl::add_inout_arg(const char* name){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add_item(name, CORBA::ARG_INOUT)->value());}CORBA::Any&RequestImpl::add_out_arg(){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add(CORBA::ARG_OUT)->value());}CORBA::Any&RequestImpl::add_out_arg(const char* name){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); return *(pd_arguments->add_item(name, CORBA::ARG_OUT)->value());}voidRequestImpl::set_return_type(CORBA::TypeCode_ptr tc){ if (!CORBA::TypeCode::PR_is_valid(tc)) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidTypeCode, CORBA::COMPLETED_NO); if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestConfiguredOutOfOrder, CORBA::COMPLETED_NO); pd_result->value()->replace(tc, (void*)0);}CORBA::Any&RequestImpl::return_value(){ if( pd_sysExceptionToThrow ) pd_sysExceptionToThrow->_raise(); return *(pd_result->value());}class omni_RequestImpl_callDesc : public omniCallDescriptor{public: inline omni_RequestImpl_callDesc(const char* op, size_t oplen, _CORBA_Boolean oneway, RequestImpl& impl) : omniCallDescriptor(0,op,oplen,oneway,0,0,0), pd_impl(impl) {} void marshalArguments(cdrStream& s) { pd_impl.marshalArgs(s); } void unmarshalReturnedValues(cdrStream& s) { pd_impl.unmarshalResults(s); } void userException(cdrStream& stream, IOP_C* iop_c, const char* repoId) { CORBA::Boolean rc = pd_impl.unmarshalUserException(stream, repoId); if (iop_c) iop_c->RequestCompleted(!rc); if (!rc) { OMNIORB_THROW(UNKNOWN, UNKNOWN_UserException, CORBA::COMPLETED_MAYBE); } }private: RequestImpl& pd_impl;}; voidRequestImpl::invoke(){ if( pd_state != RS_READY ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_RequestAlreadySent, CORBA::COMPLETED_NO); try { CORBA::ULong operation_len = strlen(pd_operation) + 1; omniObjRef* o = pd_target->_PR_getobj(); omni_RequestImpl_callDesc call_desc(pd_operation,operation_len,0,*this); o->_invoke(call_desc); } // Either throw system exceptions, or store in pd_environment. catch(CORBA::SystemException& ex){ INVOKE_DONE(); if( orbParameters::diiThrowsSysExceptions ) { pd_sysExceptionToThrow = CORBA::Exception::_duplicate(&ex); throw; } else pd_environment->exception(CORBA::Exception::_duplicate(&ex)); } INVOKE_DONE();}voidRequestImpl::deferred_invoke(){ OMNIORB_ASSERT(pd_state == RS_DEFERRED); try { CORBA::ULong operation_len = strlen(pd_operation) + 1; omniObjRef* o = pd_target->_PR_getobj(); omni_RequestImpl_callDesc call_desc(pd_operation,operation_len,0,*this); o->_invoke(call_desc); } // Either throw system exceptions, or store in pd_environment. catch(CORBA::SystemException& ex){ INVOKE_DONE(); if( orbParameters::diiThrowsSysExceptions ) { pd_sysExceptionToThrow = CORBA::Exception::_duplicate(&ex); throw; } else pd_environment->exception(CORBA::Exception::_duplicate(&ex)); } INVOKE_DONE();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -