corbaboa.cc
来自「编译工具」· CC 代码 · 共 1,378 行 · 第 1/3 页
CC
1,378 行
// -*- Mode: C++; -*-// Package : omniORB// corbaBoa.cc Created on: 23/7/99// 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 the BOA interface.// /* $Log: corbaBoa.cc,v $ Revision 1.16.2.19 2003/07/25 16:05:42 dgrisby BOA locking bug. Revision 1.16.2.18 2003/07/02 11:01:05 dgrisby Race condition in POA destruction. Revision 1.16.2.17 2003/02/17 02:03:08 dgrisby vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH). Revision 1.16.2.16 2002/05/29 14:28:45 dgrisby Bug using identity after deletion in BOA. Reported by Tihomir Sokcevic. Revision 1.16.2.15 2002/01/16 11:31:58 dpg1 Race condition in use of registerNilCorbaObject/registerTrackedObject. (Reported by Teemu Torma). Revision 1.16.2.14 2002/01/15 16:38:12 dpg1 On the road to autoconf. Dependencies refactored, configure.ac written. No makefiles yet. Revision 1.16.2.13 2001/10/19 11:06:44 dpg1 Principal support for GIOP 1.0. Correct some spelling mistakes. Revision 1.16.2.12 2001/09/20 09:27:43 dpg1 Remove assertion failure on exit if not all POAs are deleted. Revision 1.16.2.11 2001/09/19 17:26:47 dpg1 Full clean-up after orb->destroy(). Revision 1.16.2.10 2001/08/17 17:14:09 sll Relocated old omniORB API implementation to this file. Revision 1.16.2.9 2001/08/15 10:26:12 dpg1 New object table behaviour, correct POA semantics. Revision 1.16.2.8 2001/08/03 17:41:18 sll System exception minor code overhaul. When a system exeception is raised, a meaning minor code is provided. Revision 1.16.2.7 2001/06/08 17:12:21 dpg1 Merge all the bug fixes from omni3_develop. Revision 1.16.2.6 2001/05/31 16:18:12 dpg1 inline string matching functions, re-ordered string matching in _ptrToInterface/_ptrToObjRef Revision 1.16.2.5 2001/05/29 17:03:51 dpg1 In process identity. Revision 1.16.2.4 2001/04/18 18:18:10 sll Big checkin with the brand new internal APIs. Revision 1.16.2.3 2000/11/09 12:27:56 dpg1 Huge merge from omni3_develop, plus full long long from omni3_1_develop. Revision 1.16.2.2 2000/09/27 17:53:27 sll Updated to identify the ORB as omniORB4. Revision 1.16.2.1 2000/07/17 10:35:51 sll Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0. Revision 1.17 2000/07/13 15:25:58 dpg1 Merge from omni3_develop for 3.0 release. Revision 1.13.6.14 2000/06/22 10:40:13 dpg1 exception.h renamed to exceptiondefs.h to avoid name clash on some platforms. Revision 1.13.6.13 2000/06/22 09:01:29 djr Fixed assertion failure (locking bug). Revision 1.13.6.12 2000/06/02 14:20:15 dpg1 Using boa_lock for the nil BOA's condition variable caused an assertion failure on exit. Revision 1.13.6.11 2000/04/27 10:42:08 dpg1 Interoperable Naming Service omniInitialReferences::get() renamed to omniInitialReferences::resolve(). Revision 1.13.6.10 2000/01/27 10:55:45 djr Mods needed for powerpc_aix. New macro OMNIORB_BASE_CTOR to provide fqname for base class constructor for some compilers. Revision 1.13.6.9 1999/10/29 13:18:15 djr Changes to ensure mutexes are constructed when accessed. Revision 1.13.6.8 1999/10/27 17:32:10 djr omni::internalLock and objref_rc_lock are now pointers. Revision 1.13.6.7 1999/10/14 16:22:05 djr Implemented logging when system exceptions are thrown. Revision 1.13.6.6 1999/10/04 17:08:31 djr Some more fixes/MSVC work-arounds. Revision 1.13.6.5 1999/09/30 12:24:48 djr Implemented the '_interface' operation for BOA servants. Revision 1.13.6.4 1999/09/28 10:54:32 djr Removed pretty-printing of object keys from object adapters. Revision 1.13.6.3 1999/09/24 17:11:11 djr New option -ORBtraceInvocations and omniORB::traceInvocations. Revision 1.13.6.2 1999/09/24 10:27:30 djr Improvements to ORB and BOA options. Revision 1.13.6.1 1999/09/22 14:26:44 djr Major rewrite of orbcore to support POA.*/#define ENABLE_CLIENT_IR_SUPPORT#include <omniORB4/CORBA.h>#include <omniORB4/IOP_S.h>#include <corbaBoa.h>#include <omniORB4/callDescriptor.h>#include <omniORB4/callHandle.h>#include <omniORB4/objTracker.h>#include <objectTable.h>#include <initRefs.h>#include <dynamicLib.h>#include <exceptiondefs.h>#include <orbParameters.h>#include <stdio.h>#include <stdlib.h>#if defined(UnixArchitecture) || defined(__VMS)# ifdef __vxWorks__# include <time.h># else# include <sys/time.h># endif# include <unistd.h>#elif defined(NTArchitecture)# include <sys/types.h># include <sys/timeb.h># include <process.h>#endifOMNI_USING_NAMESPACE(omni)static const char* boa_ids[] = { "omniORB4_BOA", "omniORB3_BOA", "omniORB2_BOA", 0 };static omniOrbBOA* the_boa = 0;static omni_tracedmutex boa_lock;static omniORB::loader::mapKeyToObject_t MapKeyToObjectFunction = 0;staticCORBA::Booleanparse_BOA_args(int &argc,char **argv,const char *boa_identifier);/////////////////////////////////////////////////////////////////////////////////////////////////// CORBA::BOA ///////////////////////////////////////////////////////////////////////////////////////////////////CORBA::BOA::~BOA() {}CORBA::BOA_ptrCORBA::ORB::BOA_init(int& argc, char** argv, const char* boa_identifier){ omni_tracedmutex_lock sync(boa_lock); if( the_boa ) { the_boa->incrRefCount_locked(); return the_boa; } if( !parse_BOA_args(argc, argv, boa_identifier) ) OMNIORB_THROW(INITIALIZE,INITIALIZE_InvalidORBInitArgs, CORBA::COMPLETED_NO); try { omniObjAdapter::initialise(); } catch(...) { OMNIORB_THROW(INITIALIZE,INITIALIZE_FailedBOAInit, CORBA::COMPLETED_NO); } the_boa = new omniOrbBOA(0 /* not nil */); the_boa->incrRefCount_locked(); return the_boa;}CORBA::BOA_ptrCORBA::BOA::getBOA(){ boa_lock.lock(); omniOrbBOA* boa = the_boa; if( boa ) boa->incrRefCount_locked(); boa_lock.unlock(); if( !boa ) OMNIORB_THROW(OBJ_ADAPTER,OBJ_ADAPTER_BOANotInitialised, CORBA::COMPLETED_NO); return boa;}CORBA::BOA_ptr CORBA::BOA::_duplicate(CORBA::BOA_ptr obj){ if( !CORBA::is_nil(obj) ) obj->_NP_incrRefCount(); return obj;}CORBA::BOA_ptrCORBA::BOA::_narrow(CORBA::Object_ptr obj){ if( CORBA::is_nil(obj) || !obj->_NP_is_pseudo() ) return _nil(); BOA_ptr p = (BOA_ptr) obj->_ptrToObjRef(_PD_repoId); if( p ) p->_NP_incrRefCount(); return p ? p : _nil();}CORBA::BOA_ptrCORBA::BOA::_nil(){ static omniOrbBOA* _the_nil_ptr = 0; if( !_the_nil_ptr ) { omni::nilRefLock().lock(); if( !_the_nil_ptr ) { _the_nil_ptr = new omniOrbBOA(1 /* is nil */); registerNilCorbaObject(_the_nil_ptr); } omni::nilRefLock().unlock(); } return _the_nil_ptr;}const char* CORBA::BOA::_PD_repoId = "IDL:omg.org/CORBA/BOA:1.0";/////////////////////////////////////////////////////////////////////////////////////////////////// omniOrbBOA ///////////////////////////////////////////////////////////////////////////////////////////////////#define CHECK_NOT_NIL_OR_DESTROYED() \ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); \ if( pd_state == DESTROYED ) \ OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_BOANotInitialised, \ CORBA::COMPLETED_NO); \omniOrbBOA::~omniOrbBOA(){ if (pd_state_signal) delete pd_state_signal;}omniOrbBOA::omniOrbBOA(int nil) : OMNIORB_BASE_CTOR(CORBA::)BOA(nil), omniObjAdapter(nil), pd_state(IDLE), pd_refCount(1), pd_activeObjList(0), pd_nblocked(0), pd_nwaiting(0), pd_state_signal(0){ if (!nil) pd_state_signal = new omni_tracedcondition(omni::internalLock); // NB. If nil, then omni::internalLock may be zero, so we cannot use // it to initialise the condition variable. However, since the // condition variable will never be used, we don't bother to create // it.}voidomniOrbBOA::impl_is_ready(CORBA::ImplementationDef_ptr, CORBA::Boolean dont_block){ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); int state_changed = 0; boa_lock.lock(); { omni::internalLock->lock(); switch( pd_state ) { case IDLE: state_changed = 1; pd_state = ACTIVE; break; case ACTIVE: break; case DESTROYED: omni::internalLock->unlock(); boa_lock.unlock(); OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_BOANotInitialised, CORBA::COMPLETED_NO); break; } omni::internalLock->unlock(); } if( state_changed ) { try { adapterActive(); } catch(...) { boa_lock.unlock(); throw; } // Wake-up anyone stuck in synchronise_request(). if( /* anyone stuck */ 1 ) pd_state_signal->broadcast(); } if( !dont_block ) { pd_nblocked++; omni::internalLock->lock(); boa_lock.unlock(); pd_state_signal->wait(); omni::internalLock->unlock(); boa_lock.lock(); --pd_nblocked; boa_lock.unlock(); } else boa_lock.unlock();}voidomniOrbBOA::impl_shutdown(){ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); int wake_blockers = 0; { omni_tracedmutex_lock sync(boa_lock); int state_changed = 0; omni::internalLock->lock(); switch( pd_state ) { case IDLE: break; case ACTIVE: state_changed = 1; pd_state = IDLE; break; case DESTROYED: omni::internalLock->unlock(); OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_BOANotInitialised, CORBA::COMPLETED_NO); break; } omni::internalLock->unlock(); wake_blockers = state_changed && pd_nblocked > 0; if( state_changed ) { try { adapterInactive(); } catch(...) { if( wake_blockers ) pd_state_signal->broadcast(); throw; } } } // We cannot wait for request completion -- since if this is // called from a CORBA operation we would block forever. // However, if the application is using the BOA only, then // adapterInactive will give us the behaviour we desire. // There is only a problem if using both POA and BOA. // Wake-up anyone stuck in impl_is_ready(). if( wake_blockers ) pd_state_signal->broadcast();}voidomniOrbBOA::destroy(){ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); omniOrbBOA* boa = 0; omniObjTableEntry* obj_list = 0; int do_inactive = 0; { boa_lock.lock(); { omni::internalLock->lock(); switch( pd_state ) { case IDLE: pd_state = DESTROYED; break; case ACTIVE: do_inactive = 1; pd_state = DESTROYED; break; case DESTROYED: omni::internalLock->unlock(); boa_lock.unlock(); OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_BOANotInitialised, CORBA::COMPLETED_NO); break; } omni::internalLock->unlock(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?