⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poa.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 5 页
字号:
  if( pd_policy.req_processing != RPP_DEFAULT_SERVANT )    throw WrongPolicy();  omni_tracedmutex_lock sync(pd_lock);  if( !pd_defaultServant )  throw NoServant();  pd_defaultServant->_add_ref();  return pd_defaultServant;}voidomniOrbPOA::set_servant(PortableServer::Servant p_servant){  CHECK_NOT_NIL_OR_DESTROYED();  if( pd_policy.req_processing != RPP_DEFAULT_SERVANT )    throw WrongPolicy();  omni_tracedmutex_lock l(pd_lock);  if( pd_defaultServant )  pd_defaultServant->_remove_ref();  if( p_servant         )  p_servant->_add_ref();  pd_defaultServant = p_servant;}PortableServer::ObjectId*omniOrbPOA::activate_object(PortableServer::Servant p_servant){  CHECK_NOT_NIL();  if( !p_servant )    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidServant, CORBA::COMPLETED_NO);  if( pd_policy.user_assigned_id || !pd_policy.retain_servants )    throw WrongPolicy();  omni_tracedmutex_lock sync(pd_lock);  CHECK_NOT_DYING();  omni_tracedmutex_lock sync2(*omni::internalLock);  if( !pd_policy.multiple_id ) {    // Check the servant's list of activations, to ensure that it    // isn't already active in this POA.    omnivector<omniObjTableEntry*>::const_iterator i, last;    i    = p_servant->_activations().begin();    last = p_servant->_activations().end();    for (; i != last; i++) {      if ((*i)->adapter() == this)	throw ServantAlreadyActive();    }  }  PortableServer::ObjectId* ret = new PortableServer::ObjectId();  omniObjTableEntry* entry = 0;  omniObjKey key;  int idsize;  const CORBA::Octet* oid;  // We have to keep trying here, just in case someone has  // activated an object with a system generated id, using  // activate_object_with_id().  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);  ret->length(idsize);  memcpy(ret->NP_data(), oid, idsize);  return ret;}voidomniOrbPOA::activate_object_with_id(const PortableServer::ObjectId& oid,				    PortableServer::Servant p_servant){  CHECK_NOT_NIL();  if( !pd_policy.retain_servants )  throw WrongPolicy();  if( !p_servant )    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidServant, CORBA::COMPLETED_NO);  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 (oid.length() != length_check)      OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidSystemId, CORBA::COMPLETED_NO);  }  omniObjKey key;  create_key(key, oid.NP_data(), oid.length());  CORBA::ULong hashv = omni::hash(key.key(), key.size());  omniObjTableEntry* entry;  {    // We need to check the object is not already activated. If there    // is an ACTIVATING or ACTIVE entry in the object table, throw    // ObjectAlreadyActive; if there is an entry in another state,    // wait until it's ACTIVE or DEAD, then continue as before.    omni_tracedmutex_lock isync(*omni::internalLock);    entry = omniObjTable::locate(key.key(), key.size(), hashv,				 omniObjTableEntry::ACTIVATING |				 omniObjTableEntry::ACTIVE);    if (entry) {      if (entry->state() == omniObjTableEntry::ACTIVATING &&	  omniORB::trace(5)) {	omniORB::logger l;	l << "Attempt to activate an object while it is already "	  "being activated. Are you calling activate_object_with_id() "	  "inside incarnate()?\n";      }      throw ObjectAlreadyActive();    }    // Put a place-holder in the object table so any other threads    // know we're in the process of activating.    entry = omniObjTable::newEntry(key, hashv);    OMNIORB_ASSERT(entry);  }  omni_tracedmutex_lock sync(pd_lock);  {    omni_tracedmutex_lock isync(*omni::internalLock);    // If we're dying, we have to remove the entry we just put in the    // object table...    if (pd_dying) {      entry->setDead();      OMNIORB_THROW(OBJECT_NOT_EXIST,		    OBJECT_NOT_EXIST_POANotInitialised,		    CORBA::COMPLETED_NO);    }    if( !pd_policy.multiple_id ) {      // Check the servant's list of activations, to ensure that it      // isn't already active in this POA.      omnivector<omniObjTableEntry*>::const_iterator i, last;      i    = p_servant->_activations().begin();      last = p_servant->_activations().end();      for (; i != last; i++) {	if ((*i)->adapter() == this) {	  entry->setDead();	  throw ServantAlreadyActive();	}      }    }    entry->setActive(p_servant, this);  }  p_servant->_add_ref();  entry->insertIntoOAObjList(&pd_activeObjList);}voidomniOrbPOA::deactivate_object(const PortableServer::ObjectId& oid){  // Once an object is targeted for deactivation, things happen in  // this order:  //  //  o wait for requests to complete  //     -- note that new requests can arrive in the mean time, so the  //        deactivation may never actually complete!  This is  //        necessary to prevent deadlocks in objects which do  //        re-entrant calls to themselves.  //  o remove from active object map  //  o etherealise  //  // It is not possible to reactivate the same object until the  // etherealisation stage has happened. Attempts to do so are blocked  // until it is safe to continue.  CHECK_NOT_NIL();  if( !pd_policy.retain_servants )  throw WrongPolicy();  omniObjKey key;  create_key(key, oid.NP_data(), oid.length());  CORBA::ULong hashv = omni::hash(key.key(), key.size());  pd_lock.lock();  if( pd_destroyed ) {    pd_lock.unlock();    OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_POANotInitialised,		  CORBA::COMPLETED_NO);  }  omni::internalLock->lock();  omniObjTableEntry* entry = omniObjTable::locate(key.key(),key.size(),hashv);  if (!entry || entry->state() != omniObjTableEntry::ACTIVE) {    if (omniORB::trace(10) && entry) {      if (entry->state() == omniObjTableEntry::ACTIVATING) {	omniORB::logger l;	l << "deactivate_object() races with a thread activating the "	      "object. ObjectNotActive is thrown.\n";      }      else if (entry->state() != omniObjTableEntry::ACTIVE) {	omniORB::logger l;	l << "deactivate_object() races with another thread deactivating the "	      "object. ObjectNotActive is thrown.\n";      }    }    omni::internalLock->unlock();    pd_lock.unlock();    throw ObjectNotActive();  }  entry->setDeactivating();  entry->removeFromOAObjList();  if( entry->is_idle() ) {    detached_object();    pd_lock.unlock();    lastInvocationHasCompleted(entry);  }  else {    // When outstanding requests have completed the object    // will be etherealised.    omni::internalLock->unlock();    detached_object();    pd_lock.unlock();    omniORB::logs(15, "Object is still busy -- etherealise later.");  }}CORBA::Object_ptromniOrbPOA::create_reference(const char* intf){  CHECK_NOT_NIL_OR_DESTROYED();  if( pd_policy.user_assigned_id )  throw WrongPolicy();  if( !intf )  intf = ""; // Null string is permitted.  omniObjKey key;  omniLocalIdentity* id;  CORBA::ULong hash;  pd_lock.lock();  omni::internalLock->lock();  // We need to be sure we use a new id ...  do {    create_new_key(key);    hash = omni::hash(key.key(), key.size());    id = omniObjTable::locate(key.key(), key.size(), hash);  } while( id );  pd_lock.unlock();  omniObjRef* objref = omni::createLocalObjRef(intf,					       CORBA::Object::_PD_repoId,					       key.key(), key.size());  omni::internalLock->unlock();  OMNIORB_ASSERT(objref);  return (CORBA::Object_ptr) objref->_ptrToObjRef(CORBA::Object::_PD_repoId);}CORBA::Object_ptromniOrbPOA::create_reference_with_id(const PortableServer::ObjectId& oid,				     const char* intf){  CHECK_NOT_NIL_OR_DESTROYED();  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 (oid.length() != length_check)      OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidSystemId, CORBA::COMPLETED_NO);  }  if( !intf )  intf = ""; // Null string is permitted.  omniObjKey key;  create_key(key, oid.NP_data(), oid.length());  omni::internalLock->lock();  omniObjRef* objref = omni::createLocalObjRef(intf,					       CORBA::Object::_PD_repoId,					       key.key(), key.size());  omni::internalLock->unlock();  OMNIORB_ASSERT(objref);  return (CORBA::Object_ptr) objref->_ptrToObjRef(CORBA::Object::_PD_repoId);}PortableServer::ObjectId*omniOrbPOA::localId_to_ObjectId(omniIdentity* id){  OMNIORB_ASSERT(id->inThisAddressSpace());  OMNIORB_ASSERT(pd_poaIdSize == 0 ||		 omni::strMatch((const char*) pd_poaId,				(const char*) id->key()));  int idsize = id->keysize() - pd_poaIdSize;  OMNIORB_ASSERT(idsize >= 0);  PortableServer::ObjectId* ret = new PortableServer::ObjectId(idsize);  ret->length(idsize);  memcpy(ret->NP_data(), id->key() + pd_poaIdSize, idsize);  return ret;}voidomniOrbPOA::localId_to_ObjectId(omniIdentity* id,				PortableServer::ObjectId& oid){  OMNIORB_ASSERT(id->inThisAddressSpace());  OMNIORB_ASSERT(pd_poaIdSize == 0 ||		 omni::strMatch((const char*) pd_poaId,				(const char*) id->key()));  int idsize = id->keysize() - pd_poaIdSize;  OMNIORB_ASSERT(idsize >= 0);  oid.length(idsize);  memcpy(oid.NP_data(), id->key() + pd_poaIdSize, idsize);}PortableServer::ObjectId*omniOrbPOA::servant_to_id(PortableServer::Servant p_servant){  CHECK_NOT_NIL_OR_DESTROYED();  if( !p_servant )    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidServant, CORBA::COMPLETED_NO);  if( !( (pd_policy.req_processing == RPP_DEFAULT_SERVANT) ||	 (pd_policy.retain_servants && (!pd_policy.multiple_id ||					pd_policy.implicit_activation)) ) )    throw WrongPolicy();  omni_tracedmutex_lock sync(pd_lock);  if( pd_policy.req_processing == RPP_DEFAULT_SERVANT ) {    if (p_servant == pd_defaultServant) {      omniCurrent* current = omniCurrent::get();      if (current) {	omniCallDescriptor* call_desc = current->callDescriptor();	if (call_desc &&	    call_desc->poa() == this &&	    call_desc->localId()->servant() == (omniServant*)p_servant) {	  return localId_to_ObjectId(call_desc->localId());	}      }      throw ServantNotActive();    }  }  if (!pd_policy.retain_servants) throw WrongPolicy();  omni_tracedmutex_lock sync2(*omni::internalLock);  if( !pd_policy.multiple_id ) {    // Search the servants activations, to see if it is activated in    // this poa.    omnivector<omniObjTableEntry*>::const_iterator i, last;    i    = p_servant->_activations().begin();    last = p_servant->_activations().end();    for (; i != last; i++) {      if ((*i)->adapter() == this)	return localId_to_ObjectId(*i);    }  }  if( !pd_policy.implicit_activation ) throw ServantNotActive();  CHECK_NOT_DYING();  // If we get here then we need to do an implicit activation.  PortableServer::ObjectId* ret = new PortableServer::ObjectId();  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);  ret->length(idsize);  memcpy(ret->NP_data(), oid, idsize);  return ret;}CORBA::Object_ptromniOrbPOA::servant_to_reference(PortableServer::Servant p_servant){  CHECK_NOT_NIL_OR_DESTROYED();  if( !p_servant )    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_InvalidServant, CORBA::COMPLETED_NO);  omniCurrent* current = omniCurrent::get();  if (current) {    omniCallDescriptor* call_desc = current->callDescriptor();    if (call_desc &&	call_desc->localId()->servant() == (omniServant*)p_servant &&	call_desc->poa() == this) {      // Return reference associated with the current invocation      omniObjRef* objref = omniOrbPOACurrent::real_get_reference(call_desc);      return (CORBA::Object_ptr)	                  objref->_ptrToObjRef(CORBA::Object::_PD_repoId);    }    // It's not clear from the spec what should happen if we're in the    // context of an invocation on the given servant, but not in this    // POA. It seems most sensible to carry on with the code below...  }  if( !( pd_policy.retain_servants &&	 (!pd_policy.multiple_id || pd_policy.implicit_activation) ) )    throw WrongPolicy();  omni_tracedmutex_lock sync(pd_lock);  omni_tracedmutex_lock sync2(*omni::internalLock);  if( !pd_policy.multiple_id ) {    // Search the servants identities, to see if it is    // activated in this poa.    omnivector<omniObjTableEntry*>::const_iterator i, last;    i    = p_servant->_activations().begin();    last = p_servant->_activations().end();    for (; i != last; i++) {      if ((*i)->adapter() == this) {	omniObjTableEntry* entry = *i;	OMNIORB_ASSERT(pd_poaIdSize == 0 ||		       omni::ptrStrMatch(pd_poaId, (const char*)entry->key()));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -