📄 poa.cc
字号:
omniObjRef* objref = omni::createLocalObjRef(p_servant->_mostDerivedRepoId(), CORBA::Object::_PD_repoId, entry); OMNIORB_ASSERT(objref); return (CORBA::Object_ptr) objref->_ptrToObjRef(CORBA::Object ::_PD_repoId); } } } if( !pd_policy.implicit_activation ) throw ServantNotActive(); CHECK_NOT_DYING(); // If we get here, then either the servant is not activated in // this POA, or we have the multiple id policy. So do an // implicit activation. omniObjTableEntry* entry = 0; omniObjKey key; int idsize; const CORBA::Octet* oid; do { create_new_key(key, &oid, &idsize); entry = omniObjTable::newEntry(key); } while( !entry ); entry->setActive(p_servant, this); // *** FIXME: Move into setActive() ? p_servant->_add_ref(); entry->insertIntoOAObjList(&pd_activeObjList); omniObjRef* objref = omni::createLocalObjRef(p_servant->_mostDerivedRepoId(), CORBA::Object::_PD_repoId, entry); OMNIORB_ASSERT(objref); return (CORBA::Object_ptr) objref->_ptrToObjRef(CORBA::Object::_PD_repoId);}PortableServer::ServantomniOrbPOA::reference_to_servant(CORBA::Object_ptr reference){ CHECK_NOT_NIL_OR_DESTROYED(); if( CORBA::is_nil(reference) ) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidObjectRef, CORBA::COMPLETED_NO); if( reference->_NP_is_pseudo() ) throw WrongAdapter(); if( !pd_policy.retain_servants && pd_policy.req_processing != RPP_DEFAULT_SERVANT ) throw WrongPolicy(); omni_tracedmutex_lock sync(pd_lock); omni_tracedmutex_lock sync2(*omni::internalLock); omniObjRef* objref = reference->_PR_getobj(); omniIdentity* id = objref->_identity(); if (!id->inThisAddressSpace() || id->keysize() < pd_poaIdSize || memcmp(id->key(), (const char*) pd_poaId, pd_poaIdSize)) throw WrongAdapter(); if( pd_policy.retain_servants ) { omniObjTableEntry* entry = omniObjTableEntry::downcast(id); if (!entry) { omniInProcessIdentity* ipid = omniInProcessIdentity::downcast(id); if (ipid) { // The objref has an inProcessIdentity. The servant might have // been activated since the reference was created, so check // the object table. CORBA::ULong hashv = omni::hash(id->key(), id->keysize()); entry = omniObjTable::locate(id->key(), id->keysize(), hashv); } } if (entry && (entry->state() == omniObjTableEntry::ACTIVE || entry->state() & omniObjTableEntry::DEACTIVATING)) { omniServant* servant = entry->servant(); OMNIORB_ASSERT(servant); PortableServer::Servant s = DOWNCAST(servant); s->_add_ref(); return s; } } if( pd_policy.req_processing == RPP_DEFAULT_SERVANT && pd_defaultServant ) { pd_defaultServant->_add_ref(); return pd_defaultServant; } throw ObjectNotActive();#ifdef NEED_DUMMY_RETURN return 0;#endif}PortableServer::ObjectId*omniOrbPOA::reference_to_id(CORBA::Object_ptr reference){ CHECK_NOT_NIL_OR_DESTROYED(); if( CORBA::is_nil(reference) ) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidObjectRef, CORBA::COMPLETED_NO); if( reference->_NP_is_pseudo() ) throw WrongAdapter(); omni_tracedmutex_lock sync(*omni::internalLock); omniObjRef* objref = reference->_PR_getobj(); omniIdentity* id = objref->_identity(); if (!id->inThisAddressSpace() || id->keysize() < pd_poaIdSize || memcmp(id->key(), (const char*) pd_poaId, pd_poaIdSize)) throw WrongAdapter(); return localId_to_ObjectId(id);}PortableServer::ServantomniOrbPOA::id_to_servant(const PortableServer::ObjectId& oid){ CHECK_NOT_NIL_OR_DESTROYED(); if( !pd_policy.retain_servants && pd_policy.req_processing != RPP_DEFAULT_SERVANT ) throw WrongPolicy(); if( pd_policy.retain_servants ) { omniObjKey key; create_key(key, oid.NP_data(), oid.length()); CORBA::ULong hash = omni::hash(key.key(), key.size()); omni::internalLock->lock(); omniObjTableEntry* entry = omniObjTable::locateActive(key.key(), key.size(), hash, 0); PortableServer::Servant s = 0; if( entry ) { OMNIORB_ASSERT(entry->servant()); s = DOWNCAST(entry->servant()); s->_add_ref(); } omni::internalLock->unlock(); if( s ) return s; } omni_tracedmutex_lock sync(pd_lock); if( pd_policy.req_processing == RPP_DEFAULT_SERVANT && pd_defaultServant != 0 ) { pd_defaultServant->_add_ref(); return pd_defaultServant; } throw ObjectNotActive();#ifdef NEED_DUMMY_RETURN return 0;#endif}CORBA::Object_ptromniOrbPOA::id_to_reference(const PortableServer::ObjectId& oid){ CHECK_NOT_NIL_OR_DESTROYED(); if( !pd_policy.retain_servants ) throw WrongPolicy(); omniObjKey key; create_key(key, oid.NP_data(), oid.length()); CORBA::ULong hash = omni::hash(key.key(), key.size()); omni::internalLock->lock(); omniObjTableEntry* entry = omniObjTable::locateActive(key.key(), key.size(), hash, 0); if (!entry) { omni::internalLock->unlock(); throw ObjectNotActive(); } OMNIORB_ASSERT(entry->servant()); omniObjRef* objref = omni::createLocalObjRef(entry->servant()->_mostDerivedRepoId(), CORBA::Object::_PD_repoId, entry); omni::internalLock->unlock(); OMNIORB_ASSERT(objref); return (CORBA::Object_ptr) objref->_ptrToObjRef(CORBA::Object::_PD_repoId);}CORBA::OctetSeq*omniOrbPOA::id(){ CHECK_NOT_NIL_OR_DESTROYED(); CORBA::OctetSeq* seq = new CORBA::OctetSeq(pd_poaIdSize); seq->length(pd_poaIdSize); const char* ids = (const char*)pd_poaId; for (int i=0; i<pd_poaIdSize; i++) (*seq)[i] = ids[i]; return seq;}///////////////////// CORBA::Object /////////////////////_CORBA_BooleanomniOrbPOA::_non_existent(){ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); omni_tracedmutex_lock sync(pd_lock); return pd_destroyed ? 1 : 0;}void*omniOrbPOA::_ptrToObjRef(const char* repoId){ OMNIORB_ASSERT(repoId); if( omni::ptrStrMatch(repoId, PortableServer::POA::_PD_repoId) ) return (PortableServer::POA_ptr) this; if( omni::ptrStrMatch(repoId, CORBA::Object::_PD_repoId) ) return (CORBA::Object_ptr) this; return 0;}voidomniOrbPOA::_NP_incrRefCount(){ // Identical to incrRefCount(). omni::poRcLock->lock(); pd_refCount++; omni::poRcLock->unlock();}voidomniOrbPOA::_NP_decrRefCount(){ decrRefCount();}/////////////////////////////// Override omniObjAdapter ///////////////////////////////voidomniOrbPOA::incrRefCount(){ omni::poRcLock->lock(); pd_refCount++; omni::poRcLock->unlock();}voidomniOrbPOA::decrRefCount(){ omni::poRcLock->lock(); int done = --pd_refCount > 0; omni::poRcLock->unlock(); if( done ) return; OMNIORB_USER_CHECK(pd_destroyed == 2); OMNIORB_USER_CHECK(pd_refCount == 0); // If either of these fails then the application has released the // POA reference too many times. CORBA::release(pd_manager); if( pd_adapterActivator ) CORBA::release(pd_adapterActivator); if( pd_servantActivator ) CORBA::release(pd_servantActivator); if( pd_servantLocator ) CORBA::release(pd_servantLocator); delete this;}voidomniOrbPOA::dispatch(omniCallHandle& handle, omniLocalIdentity* id){ ASSERT_OMNI_TRACEDMUTEX_HELD(*omni::internalLock, 1); OMNIORB_ASSERT(id); OMNIORB_ASSERT(id->servant()); OMNIORB_ASSERT(id->adapter() == this); handle.poa(this); enterAdapter(); if( pd_rq_state != (int) PortableServer::POAManager::ACTIVE ) synchronise_request(id); startRequest(); omni::internalLock->unlock(); omni_optional_rlock sync(pd_call_lock, pd_policy.threading != TP_SINGLE_THREAD, pd_policy.threading != TP_SINGLE_THREAD); if (pd_policy.threading == TP_MAIN_THREAD) { omni_thread* self = omni_thread::self(); if (!(self && self->id() == omni::mainThreadId)) handle.mainThread(pd_main_thread_sync.mu, pd_main_thread_sync.cond); } if( omniORB::traceInvocations ) { omniORB::logger l; l << "Dispatching " << (handle.call_desc() ? "in process" : "remote") << " call '" << handle.operation_name() << "' to: " << id << '\n'; } // Can we do a direct upcall? if (handle.call_desc() && handle.try_direct() && handle.call_desc()->haslocalCallFn() && id->servant()-> _ptrToInterface(handle.call_desc()->objref()->_localServantTarget())) { handle.upcall(id->servant(), *handle.call_desc()); return; } // Dispatch through the servant's _dispatch() function. if( !id->servant()->_dispatch(handle) ) { if( !id->servant()->omniServant::_dispatch(handle) ) { handle.SkipRequestBody(); OMNIORB_THROW(BAD_OPERATION, BAD_OPERATION_UnRecognisedOperationName, CORBA::COMPLETED_NO); } }}voidomniOrbPOA::dispatch(omniCallHandle& handle, const CORBA::Octet* key, int keysize){ ASSERT_OMNI_TRACEDMUTEX_HELD(*omni::internalLock, 0); OMNIORB_ASSERT(key); OMNIORB_ASSERT(keysize >= pd_poaIdSize); //OMNIORB_ASSERT(!memcmp(key, (const char*) pd_poaId, pd_poaIdSize)); handle.poa(this); // Check that the key is the right size (if system generated). if( !pd_policy.user_assigned_id ) { CORBA::ULong length_check; if (!pd_policy.transient && poaUniquePersistentSystemIds) length_check = SYS_ASSIGNED_ID_SIZE + TRANSIENT_SUFFIX_SIZE; else length_check = SYS_ASSIGNED_ID_SIZE; if (keysize - pd_poaIdSize != length_check) { OMNIORB_THROW(OBJECT_NOT_EXIST, OBJECT_NOT_EXIST_NoMatch, CORBA::COMPLETED_NO); } } switch( pd_policy.req_processing ) { case RPP_ACTIVE_OBJ_MAP: { omni_tracedmutex_lock sync(*omni::internalLock); switch (pd_rq_state) { case (int) PortableServer::POAManager::HOLDING: // *** We should block here until we leave the HOLDING state, // then check if the object now exists. For now we fall // through as if ACTIVE... case (int) PortableServer::POAManager::ACTIVE: OMNIORB_THROW(OBJECT_NOT_EXIST, OBJECT_NOT_EXIST_NoMatch, CORBA::COMPLETED_NO); case (int) PortableServer::POAManager::DISCARDING: OMNIORB_THROW(TRANSIENT, TRANSIENT_POANoResource, CORBA::COMPLETED_NO); case (int) PortableServer::POAManager::INACTIVE: OMNIORB_THROW(OBJ_ADAPTER, OBJ_ADAPTER_POAUnknownAdapter, CORBA::COMPLETED_NO); } } break; case RPP_DEFAULT_SERVANT: dispatch_to_ds(handle, key, keysize); break; case RPP_SERVANT_MANAGER: if( pd_policy.retain_servants ) dispatch_to_sa(handle, key, keysize); else dispatch_to_sl(handle, key, keysize); break; };}voidomniOrbPOA::dispatch(omniCallDescriptor& call_desc, omniLocalIdentity* id){ ASSERT_OMNI_TRACEDMUTEX_HELD(*omni::internalLock, 1); OMNIORB_ASSERT(id); OMNIORB_ASSERT(id->servant()); OMNIORB_ASSERT(id->adapter() == this); enterAdapter(); if( pd_rq_state != (int) PortableServer::POAManager::ACTIVE ) synchronise_request(id); startRequest(); omni::internalLock->unlock(); omni_optional_rlock sync(pd_call_lock, pd_policy.threading != TP_SINGLE_THREAD, pd_policy.threading != TP_SINGLE_THREAD); if( omniORB::traceInvocations ) { omniORB::logger l; l << "Dispatching local call \'" << call_desc.op() << "\' to " << id << '\n'; } if (pd_policy.threading == TP_MAIN_THREAD) { omni_thread* self = omni_thread::self(); if (!(self && self->id() == omni::mainThreadId)) { // Have to mess with thread switching. Leave it to // omniCallHandle::upcall() omniCallHandle handle(&call_desc,1); handle.poa(this); handle.localId(id); handle.mainThread(pd_main_thread_sync.mu, pd_main_thread_sync.cond); handle.upcall(id->servant(), call_desc); return; } } if (pd_policy.local_shortcut) { if (omniORB::trace(10)) { omniORB::logger l; l << "Enabling local shortcut for " << id << "\n"; } call_desc.objref()->_enableShortcut(id->servant(), id->p_deactivated()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -