コード例 #1
0
TAO_BEGIN_VERSIONED_NAMESPACE_DECL

PortableServer::POA_var create_persistent_poa(PortableServer::POA_var root_poa,
                                              PortableServer::POAManager_var mgr,
                                              const char* name,
                                              CORBA::PolicyList& policy_list)
{
  PortableServer::POA_var result;
    PortableServer::LifespanPolicy_var lifespan =
    root_poa->create_lifespan_policy(PortableServer::PERSISTENT);

  // create a USER_ID IdAssignmentPolicy object
  PortableServer::IdAssignmentPolicy_var assign =
    root_poa->create_id_assignment_policy(PortableServer::USER_ID);

  // create PolicyList.
  size_t orig_len =  policy_list.length();
  policy_list.length(orig_len+2);
  policy_list[orig_len+0]=
    PortableServer::LifespanPolicy::_duplicate(lifespan.in());
  policy_list[orig_len+1]=
    PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  // create the child POA
  result = root_poa->create_POA(name, mgr.in(), policy_list);


  return result;
}
コード例 #2
0
ファイル: server.cpp プロジェクト: asdlei00/ACE
PortableServer::POA_ptr
createPOA (PortableServer::POA_ptr root_poa,
           bool share_mgr,
           const char* poa_name)
{
  PortableServer::LifespanPolicy_var life =
    root_poa->create_lifespan_policy(PortableServer::PERSISTENT);

  PortableServer::IdAssignmentPolicy_var assign =
    root_poa->create_id_assignment_policy(PortableServer::USER_ID);

  CORBA::PolicyList pols;
  pols.length(2);
  pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in());
  pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  PortableServer::POAManager_var mgr = PortableServer::POAManager::_nil();
  if (share_mgr)
    {
      mgr = root_poa->the_POAManager();
    }
  PortableServer::POA_var poa =
    root_poa->create_POA(poa_name, mgr.in(), pols);

  life->destroy();
  assign->destroy();

  return poa._retn();
}
コード例 #3
0
PortableServer::POA_ptr 
VOmniORBHelper::poaGetOrCreatePoa(const char* program, const char* object,
				  int telescopenumber)
  throw(CORBA::SystemException)
{
  ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex);

  // Munge the path name into a unique POA name
  char* poa_name = poaPathToPoaName(program, object, telescopenumber);

  // Check to see if we created this one already, if so then return it now
  std::map<std::string,PortableServer::POA_var>::iterator poaFound = 
    m_poaMap.find(poa_name);
  
  if(poaFound != m_poaMap.end())
    return PortableServer::POA::_duplicate(poaFound->second);

  // Grab the root POA
  PortableServer::POA_var root_poa = poaRootPoa();

  // Must create the POA, use the PERSISTENT and USER_ID policies
  PortableServer::LifespanPolicy_var lifespan = 
    root_poa -> create_lifespan_policy(PortableServer::PERSISTENT);
  PortableServer::IdAssignmentPolicy_var assign =
    root_poa -> create_id_assignment_policy(PortableServer::USER_ID);

  CORBA::PolicyList policy_list;
  policy_list.length(2);
  policy_list[0] = PortableServer::LifespanPolicy::_duplicate(lifespan);
  policy_list[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign);

  // Root POA manager
  PortableServer::POAManager_var root_poa_manager = 
    PortableServer::POAManager::_duplicate(m_rootPoaManager);

  // Create the POA
  PortableServer::POA_var poa = 
    root_poa -> create_POA(poa_name, root_poa_manager, policy_list);

  // Make a copy of the POA object and remember it in case we are asked
  // for it again some time
  m_poaMap[poa_name] = PortableServer::POA::_duplicate(poa);

  CORBA::string_free(poa_name);

  lifespan->destroy();
  assign->destroy();

  return poa._retn();
}
コード例 #4
0
int
TAO_CosEventChannelFactory_i::init (PortableServer::POA_ptr poa,
                                    const char* child_poa_name,
                                    CosNaming::NamingContext_ptr naming)
{
  // Check if we have a parent poa.
  if (CORBA::is_nil (poa))
    return -1;

  this->naming_ = CosNaming::NamingContext::_duplicate (naming);
  // Save the naming context.

  // Create a UNIQUE_ID and USER_ID policy because we want the POA
  // to detect duplicates for us.
  PortableServer::IdUniquenessPolicy_var idpolicy =
    poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID);

  PortableServer::IdAssignmentPolicy_var assignpolicy =
    poa->create_id_assignment_policy (PortableServer::USER_ID);

  // Create a PolicyList
  CORBA::PolicyList policy_list;
  policy_list.length (2);
  policy_list [0] =
    PortableServer::IdUniquenessPolicy::_duplicate (idpolicy.in ());
  policy_list [1] =
    PortableServer::IdAssignmentPolicy::_duplicate (assignpolicy.in ());

  PortableServer::POAManager_ptr manager =
    poa->the_POAManager ();
  // @@ Pradeep : TODO - find a way to destroy the policy_list if we return here.

  // Create the child POA.
  this->poa_ = poa->create_POA (child_poa_name,
                                manager,
                                policy_list);


  idpolicy->destroy ();

  assignpolicy->destroy ();

  //this->poa_ =  PortableServer::POA::_duplicate (poa);
  // uncomment this if we want to use the parent poa for some reason.
   return 0;
}
コード例 #5
0
ファイル: server.cpp プロジェクト: CCJY/ATCD
void
createPOAs(ACE_CString &base)
{
  PortableServer::LifespanPolicy_var life =
    root_poa->create_lifespan_policy(PortableServer::PERSISTENT);

  PortableServer::IdAssignmentPolicy_var assign =
    root_poa->create_id_assignment_policy(PortableServer::USER_ID);

  CORBA::PolicyList pols;
  pols.length(2);
  pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in());
  pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  PortableServer::POAManager_var mgr = PortableServer::POAManager::_nil();
  ACE_CString poa_name = base + ACE_CString ("_a");
  poa_a = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
  poa_name = base + ACE_CString ("_b");
  poa_b = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
}
コード例 #6
0
ファイル: consumer.C プロジェクト: AlvaroVega/TIDNotifC
int main(int argc, char* argv[]){

  char aux1[1000];


  try{
    //
    // Inicializacion del ORB 
    //
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "");

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
    PortableServer::POAManager_var manager = root_poa->the_POAManager();


    //
    // Obtain NamincContext reference ...
    //
    CORBA::Object_var naming_context_object;
    CosNaming::NamingContext_ptr naming_context;
    try {
       naming_context_object = 
         orb->string_to_object("corbaloc:iiop:[email protected]:2809/NameService");
       naming_context =
          CosNaming::NamingContext::_narrow (naming_context_object.in ());
    } catch (...) {
       cerr << "Error: cannot obtain naming service initial reference" << endl;
       throw; 
    }

    //
    // Crea un POA para el supplier: PERSISTENT LifespanPolicy, USER_ID policy
    // 

    PortableServer::LifespanPolicy_var lifespan =
      root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
    
    PortableServer::IdAssignmentPolicy_var idAssignment =
      root_poa->create_id_assignment_policy(PortableServer::USER_ID);
    
    CORBA::PolicyList policies(2);  
    policies.length(2);
    policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idAssignment);
    policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan);
    
    PortableServer::POA_var consumer_poa =
      root_poa->create_POA("consumerPOA", manager.in(), policies);

    PortableServer::POAManager_var consumer_poa_manager = 
      consumer_poa->the_POAManager();

    idAssignment->destroy();
    lifespan->destroy();

    // Activa el POAManager
    manager->activate();


    //
    // Crea y activa el servant del consumer
    // 

    PortableServer::ObjectId_var oid = 
      PortableServer::string_to_ObjectId("MyConsumer");

    MyConsumerImpl servant_consumer;

    try{
      consumer_poa->activate_object_with_id(oid.in(), &servant_consumer);
    }
    catch(...){
      cerr << "[supplier] ERROR: activating servant_supplier " << endl;
    }
    CORBA::Object_var consumer_obj = consumer_poa->id_to_reference(oid.in());


    CosEventComm::PushConsumer_var consumer =
      CosEventComm::PushConsumer::_narrow(consumer_obj);


    //
    // Recoge la referencia al canal
    //
    // readChannelIOR();
    // obj = orb->string_to_object(ChannelIOR);
    CosNaming::NamingContext_var naming_context_notif = NULL;
    CosNaming::Name name_notif(2);
    name_notif.length (2);
    name_notif[0].id = CORBA::string_dup ("MyNotif");
    name_notif[0].kind = CORBA::string_dup ("");
    name_notif[1].id = CORBA::string_dup ("channel");
    name_notif[1].kind = CORBA::string_dup ("");
    obj = naming_context->resolve(name_notif);

    CosNotifyChannelAdmin::EventChannel_var channel;
    channel = CosNotifyChannelAdmin::EventChannel::_narrow(obj);
    if (CORBA::is_nil(channel)) { 
      cerr << "[consumer] ERROR: canal nulo " << endl;
      return -1; 
    } 
    // cerr << "[consumer] ChannelId " << channel->get_channelID() << endl;


    // 
    // Obtenemos el manager 
    // 
    CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin;
    CosNotifyChannelAdmin::AdminID adminid;
    
    try{
      consumerAdmin = channel->default_consumer_admin();   
    }
    catch(CORBA::Exception &ce){
      fprintf(stderr,"(%s)%i CORBA::Exception - %s\n",
              __FILE__,__LINE__,ce._name());
    }
    catch(...){
      fprintf(stderr,"(%s)%i - Unexpected exception!",
              __FILE__,__LINE__);
    }


    //
    // Obtenemos el proxy
    // 
    CosNotifyChannelAdmin::ProxyPushSupplier_var pushSupplier;
    CosNotifyChannelAdmin::ProxyID proxy_id;
    CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::ANY_EVENT;

    try{
      CosNotifyChannelAdmin::ProxySupplier_var obj =
        consumerAdmin->obtain_notification_push_supplier(ctype, proxy_id);
      
      pushSupplier = CosNotifyChannelAdmin::ProxyPushSupplier::_narrow(obj);
      
      // Conecta proxy
      pushSupplier->connect_any_push_consumer(consumer);

    }
    catch(CosEventChannelAdmin::AlreadyConnected &ac){
      fprintf(stderr,"(%s)%i CosEventChannelAdmin::AlreadyConnected\n",
              __FILE__,__LINE__);
    }
    catch(CORBA::SystemException& se){
      fprintf(stderr,"(%s)%i CORBA::SystemException\n",
              __FILE__,__LINE__);
    }
    catch(CosNotifyChannelAdmin::AdminLimitExceeded err){
      fprintf(stderr,"(%s)%i CosNotifyChannelAdmin::AdminLimitExceeded\n",
              __FILE__,__LINE__);
    }
    catch(CORBA::Exception &ce){
      fprintf(stderr,"(%s)%i CORBA::Exception - %s\n",
              __FILE__,__LINE__,ce._name());
    }
    catch(...){
      fprintf(stderr,"Unexpected exception!\n");
    }

//     // 
//     // Guarda la referencia en el Servicio de Nombres
//     // 

//     CosNaming::NamingContext_var naming_context_notif = NULL;
//     CosNaming::Name name_notif(1);
//     name_notif.length (1);
//     name_notif[0].id = CORBA::string_dup ("MyNotif");
//     name_notif[0].kind = CORBA::string_dup ("");

//     naming_context_notif = naming_context->bind_new_context(name_notif);

//     CosNaming::Name name_consumer(1);
//     name_consumer.length (1);
//     name_consumer[0].id = CORBA::string_dup ("consumer");
//     name_consumer[0].kind = CORBA::string_dup ("");
//     naming_context_notif->bind(name_consumer, consumer_obj);



    cerr << "[consumer] Esperando eventos.... " << endl;


    orb->run();  

    cerr << "[consumer] disconnect .... " << endl;
//     supplier->disconnect_push_supplier();
//     consumeradmin->destroy();

    cerr << "[consumer] Terminando " << endl;
    orb->shutdown(true);
    orb->destroy();



  } catch(CORBA::Exception& exc) {
    cerr << "[consumer] Excepcion: " << exc << endl;
    return 1;
  }

}
コード例 #7
0
void
TAO_POA_Default_Policy_Validator::validate_impl (TAO_Policy_Set &policies)
{
#if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
  CORBA::Policy_var policy =
    policies.get_cached_policy (TAO_CACHED_POLICY_SERVANT_RETENTION);

  PortableServer::ServantRetentionPolicy_var srp =
    PortableServer::ServantRetentionPolicy::_narrow (policy.in ());
  PortableServer::ServantRetentionPolicyValue servant_retention =
    srp->value ();

  policy = policies.get_cached_policy (TAO_CACHED_POLICY_REQUEST_PROCESSING);

  PortableServer::RequestProcessingPolicy_var rpp =
    PortableServer::RequestProcessingPolicy::_narrow (policy.in ());
  PortableServer::RequestProcessingPolicyValue request_processing =
    rpp->value ();

  // The NON_RETAIN policy requires either the USE_DEFAULT_SERVANT or
  // USE_SERVANT_MANAGER policies.
  if (servant_retention == PortableServer::NON_RETAIN)
    if (request_processing != PortableServer::USE_SERVANT_MANAGER &&
        request_processing  != PortableServer::USE_DEFAULT_SERVANT)
      throw PortableServer::POA::InvalidPolicy ();

  // USE_ACTIVE_OBJECT_MAP_ONLY requires the RETAIN policy.
  if (request_processing == PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY)
    if (servant_retention != PortableServer::RETAIN)
      throw PortableServer::POA::InvalidPolicy ();

  policy = policies.get_cached_policy (TAO_CACHED_POLICY_ID_UNIQUENESS);

  PortableServer::IdUniquenessPolicy_var iup =
    PortableServer::IdUniquenessPolicy::_narrow (policy.in ());
  PortableServer::IdUniquenessPolicyValue id_uniqueness =
    iup->value ();

  policy =
    policies.get_cached_policy (TAO_CACHED_POLICY_IMPLICIT_ACTIVATION);

  PortableServer::ImplicitActivationPolicy_var iap =
    PortableServer::ImplicitActivationPolicy::_narrow (policy.in ());
  PortableServer::ImplicitActivationPolicyValue implicit_activation =
    iap->value ();

  policy = policies.get_cached_policy (TAO_CACHED_POLICY_ID_ASSIGNMENT);

  PortableServer::IdAssignmentPolicy_var idap =
    PortableServer::IdAssignmentPolicy::_narrow (policy.in ());
  PortableServer::IdAssignmentPolicyValue id_assignment =
    idap->value ();

  // USE_DEFAULT_SERVANT requires the MULTIPLE_ID policy.
  if (request_processing == PortableServer::USE_DEFAULT_SERVANT)
    if (id_uniqueness != PortableServer::MULTIPLE_ID)
      throw PortableServer::POA::InvalidPolicy ();

  // IMPLICIT_ACTIVATION requires the SYSTEM_ID and RETAIN policies.
  if (implicit_activation == PortableServer::IMPLICIT_ACTIVATION)
    if (servant_retention != PortableServer::RETAIN ||
        id_assignment != PortableServer::SYSTEM_ID)
      throw PortableServer::POA::InvalidPolicy ();
#else /* TAO_HAS_MINIMUM_POA == 0 */
  ACE_UNUSED_ARG (policies);
#endif /* TAO_HAS_MINIMUM_POA == 0 */
}
コード例 #8
0
ファイル: server.cpp プロジェクト: CCJY/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1);

      PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();

      PortableServer::LifespanPolicy_var life =
        root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

      PortableServer::IdAssignmentPolicy_var assign =
        root_poa->create_id_assignment_policy (PortableServer::USER_ID);

      CORBA::PolicyList pols;
      pols.length (2);
      pols[0] = PortableServer::LifespanPolicy::_duplicate (life.in ());
      pols[1] = PortableServer::IdAssignmentPolicy::_duplicate (assign.in ());

      PortableServer::POA_var poa =
        root_poa->create_POA ("ImRified POA", poa_manager.in (), pols);
      life->destroy ();
      assign->destroy ();

      Hello *hello_impl = 0;
      ACE_NEW_RETURN (hello_impl, Hello, 1);
      PortableServer::ServantBase_var owner_transfer (hello_impl);

      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("Test 3891 Object");

      poa->activate_object_with_id (id.in (), hello_impl);

      CORBA::Object_var obj = poa->id_to_reference (id.in ());

      if (!obj->_stubobj ()->type_id.in () ||
          ACE_OS::strcmp (obj->_stubobj ()->type_id.in (),
                          hello_impl->_repository_id ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR, "ERROR: type_id is incorrect\n"), 1);
        }

      root_poa->destroy (1, 1);
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
コード例 #9
0
ファイル: FTEC_Gateway.cpp プロジェクト: OspreyHub/ATCD
RtecEventChannelAdmin::EventChannel_ptr
FTEC_Gateway::activate(PortableServer::POA_ptr root_poa)
{
  PortableServer::POA_var poa;
  PortableServer::POAManager_var mgr;

  if (impl_->local_orb) {
    int argc = 0;
    char** argv = 0;
    impl_->orb = CORBA::ORB_init(argc, argv, "FTEC_GatewayORB");

    Interceptor_Destoryer::execute(impl_->orb.in());

    poa = resolve_init<PortableServer::POA>(impl_->orb.in(), "RootPOA");

    mgr = poa->the_POAManager();

    mgr->activate();
  }
  else {
    poa = PortableServer::POA::_duplicate(root_poa);
    mgr = poa->the_POAManager();
  }

  PortableServer::IdUniquenessPolicy_var id_uniqueness_policy =
    poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID);

  PortableServer::LifespanPolicy_var lifespan =
    poa->create_lifespan_policy(PortableServer::PERSISTENT);

  // create a USER_ID IdAssignmentPolicy object
  PortableServer::IdAssignmentPolicy_var assign =
    poa->create_id_assignment_policy(PortableServer::USER_ID);

  CORBA::PolicyList policy_list;
  policy_list.length(3);

  policy_list[0] = PortableServer::IdUniquenessPolicy::_duplicate(
    id_uniqueness_policy.in());
  policy_list[1]=
    PortableServer::LifespanPolicy::_duplicate(lifespan.in());
  policy_list[2]=
    PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  impl_->poa = poa->create_POA("gateway_poa", mgr.in(), policy_list);

  id_uniqueness_policy->destroy();
  lifespan->destroy();
  assign->destroy();

  FtRtecEventComm::ObjectId oid;
  oid.length(16);
  TAO_FtRt::UUID::create(oid.get_buffer());

  RtecEventChannelAdmin::EventChannel_var gateway;

  activate_object_with_id(gateway.out(), impl_->poa.in(), this, oid);
  ++oid[9];
  activate_object_with_id(impl_->consumer_admin.out(),
    impl_->poa.in(),
    &impl_->consumer_admin_servant,
    oid);
  ++oid[9];
  activate_object_with_id(impl_->supplier_admin.out(),
    impl_->poa.in(),
    &impl_->supplier_admin_servant,
    oid);

  return gateway._retn();
}
コード例 #10
0
ファイル: server.cpp プロジェクト: chenbk85/ACE-Middleware
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {

    // Initialze the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

    // Get a reference to the RootPOA.
    CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");

    // Get the POA_var object from Object_var.
    PortableServer::POA_var root_poa =
      PortableServer::POA::_narrow (obj.in ());

    // Get the POAManager of the RootPOA.
    PortableServer::POAManager_var poa_manager =
      root_poa->the_POAManager ();

    poa_manager->activate ();

    // Create a USER_ID IdAssignmentpolicy object.
    PortableServer::IdAssignmentPolicy_var idassignment =
      root_poa->create_id_assignment_policy (PortableServer::USER_ID);

    // Create a PERSISTENT LifespanPolicy object.
    PortableServer::LifespanPolicy_var lifespan =
      root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

    // Policies for the childPOA to be created.
    CORBA::PolicyList policies;
    policies.length (2);

    policies[0] =
      PortableServer::IdAssignmentPolicy::_duplicate (idassignment.in ());

    policies[1] =
      PortableServer::LifespanPolicy::_duplicate (lifespan.in ());

    // Create the childPOA under the RootPOA.
    PortableServer::POA_var child_poa =
      root_poa->create_POA ("childPOA",
                            poa_manager.in (),
                            policies);

    // Destroy policy objects.
    idassignment->destroy ();
    lifespan->destroy ();

    // Create an instance of class Quoter_Stock_Factory_i.
    Quoter_Stock_Factory_i stock_factory_i;

    // Get the Object ID.
    PortableServer::ObjectId_var oid =
      PortableServer::string_to_ObjectId ("Stock_Factory");

    // Activate the Stock_Factory object.
    child_poa->activate_object_with_id (oid.in (),
                                        &stock_factory_i);

    // Get the object reference.
    CORBA::Object_var stock_factory =
      child_poa->id_to_reference (oid.in ());

    // Stringify all the object referencs.
    CORBA::String_var ior = orb->object_to_string (stock_factory.in ());
    // Print them out !
    cout << ior.in () << endl;

    orb-> run ();

    // Destroy POA, waiting until the destruction terminates.
    root_poa->destroy (1, 1);
    orb->destroy ();
  }
  catch (CORBA::Exception &) {
    cerr << "CORBA exception raised !" << endl;
  }
  return 0;
}