Exemple #1
0
void CNamingTreeCtrl::OnContextPopupBindobject()
{
  // TODO: Add your command handler code here
  CBindDialog Dialog(false, m_pORB);
  if(Dialog.DoModal() != IDOK)
  {
    return;
  }
  try
  {
    HTREEITEM hItem = GetSelectedItem();
    CNamingObject* pObject = GetTreeObject(hItem);
    CosNaming::NamingContext_var Context = pObject->NamingContext();
    if(CORBA::is_nil(Context.in ()))
    {
      return;
    }
    Context->bind(Dialog.GetName(), Dialog.GetObject());
    OnContextPopupRefresh();
  }
  catch(CORBA::Exception& ex)
  {
    MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
  }
}
  /*!
   * @if jp
   * @brief 途中のコンテキストを再帰的に bind しながら Object を bind する
   * @else
   * @brief Bind intermediate context recursively and bind object
   * @endif
   */
  void CorbaNaming::bindRecursive(CosNaming::NamingContext_ptr context,
				  const CosNaming::Name& name,
				  CORBA::Object_ptr obj)
    throw (SystemException, CannotProceed, InvalidName, AlreadyBound)
  {
    CORBA::ULong len(name.length());
    CosNaming::NamingContext_var cxt;
    cxt = CosNaming::NamingContext::_duplicate(context);
    
    for (CORBA::ULong i = 0; i < len; ++i)
      {
	if (i == (len - 1))
	  { // this operation may throw AlreadyBound, 
	    cxt->bind(subName(name, i, i), obj);
	    return;
	  }
	else
	  { // If the context is not a NamingContext, CannotProceed is thrown
	    if (isNamingContext(cxt))
	      cxt = bindOrResolveContext(cxt, subName(name, i, i));
	    else
	      throw CannotProceed(cxt, subName(name, i));
	  }
      }
    return;
  }
Exemple #3
0
void
TAO_Hash_Naming_Context::bind (const CosNaming::Name& n, CORBA::Object_ptr obj)
{
  // Check to make sure this object didn't have <destroy> method
  // invoked on it.
  if (this->destroyed_)
    throw CORBA::OBJECT_NOT_EXIST ();

  // Get the length of the name.
  CORBA::ULong const name_len = n.length ();

  // Check for invalid name.
  if (name_len == 0)
    throw CosNaming::NamingContext::InvalidName();

  // If we received compound name, resolve it to get the context in
  // which the binding should take place, then perform the binding on
  // target context.
  if (name_len > 1)
    {
      CosNaming::NamingContext_var context = this->get_context (n);

      CosNaming::Name simple_name;
      simple_name.length (1);
      simple_name[0] = n[name_len - 1];
      try
        {
          context->bind (simple_name, obj);
        }
      catch (const CORBA::SystemException&)
        {
          throw CosNaming::NamingContext::CannotProceed(
            context.in (), simple_name);
        }
    }
  // If we received a simple name, we need to bind it in this context.
  else
    {
      ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX,
                                ace_mon, this->lock_,
                                CORBA::INTERNAL ());

      // Try binding the name.
      int result = this->context_->bind (n[0].id,
                                        n[0].kind,
                                        obj,
                                        CosNaming::nobject);
      if (result == 1)
        throw CosNaming::NamingContext::AlreadyBound();

      // Something went wrong with the internal structure
      else if (result == -1)
        throw CORBA::INTERNAL ();
    }
}
Exemple #4
0
CORBA::Object_ptr
join_object_group (CORBA::ORB_ptr orb,
                   CosLoadBalancing::LoadManager_ptr lm,
                   const PortableGroup::Location & location)
{
  CORBA::Object_var ns_object =
    orb->resolve_initial_references ("NameService");

  CosNaming::NamingContext_var nc =
    CosNaming::NamingContext::_narrow (ns_object.in ());

  CosNaming::Name name (1);
  name.length (1);

  name[0].id = "RoundtripObjectGroup";
  name[0].kind = "Object Group";

  CORBA::Object_var group;

  try
    {
      group = nc->resolve (name);
    }
  catch (const CosNaming::NamingContext::NotFound& )
    {
      // Object group not created.  Create one.
      const char repository_id[] = "IDL:Test/Roundtrip:1.0";

      PortableGroup::Criteria criteria (1);
      criteria.length (1);

      PortableGroup::Property & property = criteria[0];
      property.nam.length (1);

      property.nam[0].id =
        CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle");

      PortableGroup::MembershipStyleValue msv =
        PortableGroup::MEMB_APP_CTRL;
      property.val <<= msv;

      PortableGroup::GenericFactory::FactoryCreationId_var fcid;

      group = lm->create_object (repository_id,
                                 criteria,
                                 fcid.out ());

      try
        {
          nc->bind (name,
                    group.in ());

          PortableGroup::Properties props (1);
          props.length (1);
          props[0].nam.length (1);
          props[0].nam[0].id =
            CORBA::string_dup ("org.omg.CosLoadBalancing.StrategyInfo");

          CosLoadBalancing::StrategyInfo strategy_info;

          strategy_info.name = CORBA::string_dup (strategy);

          if (ACE_OS::strcasecmp (strategy, "LeastLoaded") == 0
              && (reject_threshold != 0
                  || critical_threshold != 0
                  || dampening != 0))
            {
              CORBA::ULong len = 1;

              PortableGroup::Properties & props =
                strategy_info.props;

              if (reject_threshold != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.RejectThreshold");
                  props[i].val <<= reject_threshold;
                }

              if (critical_threshold != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.CriticalThreshold");
                  props[i].val <<= critical_threshold;
                }

              if (dampening != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.Dampening");
                  props[i].val <<= dampening;
                }

            }

          props[0].val <<= strategy_info;

          lm->set_default_properties (props);
        }
      catch (const CosNaming::NamingContext::AlreadyBound& )
        {
          // Somebody beat us to creating the object group.  Clean up
          // the one we created.
          lm->delete_object (fcid.in ());

          group = nc->resolve (name);
        }
    }

  Roundtrip * roundtrip_impl;
  ACE_NEW_THROW_EX (roundtrip_impl,
                    Roundtrip (orb),
                    CORBA::NO_MEMORY ());

  PortableServer::ServantBase_var owner_transfer (roundtrip_impl);

  Test::Roundtrip_var roundtrip =
    roundtrip_impl->_this ();

  group = lm->add_member (group.in (),
                          location,
                          roundtrip.in ());

  return group._retn ();
}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - no root POA available." << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << std::endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	//
	// register in name service
	//

	CosNaming::NamingContext_var nameService;

	//
	// try to get naming service from config values
	//
	CORBA::Object_var obj;
	std::string ns = Qedo::ConfigurationReader::instance()->lookup_config_value( "/General/NameService" );
	if( !ns.empty() )
	{
		try
		{
			obj = orb_->string_to_object( ns.c_str() );
		}
		catch(...)
		{
			std::cerr << "ServerActivatorImpl: can't resolve NameService " << ns << std::endl;
			throw CannotInitialize();
		}

		std::cout <<  "ServerActivatorImpl: NameService is " <<  ns << std::endl;
	}
	//
	// try to get naming service from orb
	//
	else
	{
		try
		{
			obj = orb_->resolve_initial_references( "NameService" );
		}
		catch (const CORBA::ORB::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: can't resolve NameService" << std::endl;
			throw CannotInitialize();
		}

		if (CORBA::is_nil(obj.in()))
		{
			std::cerr << "ServerActivatorImpl: NameService is a nil object reference" << std::endl;
			throw CannotInitialize();
		}
	}

	try
	{
		nameService = CosNaming::NamingContext::_narrow( obj.in() );
	}
	catch (const CORBA::Exception&)
	{
		std::cerr << "ServerActivatorImpl: NameService is not running" << std::endl;
		throw CannotInitialize();
	}

	if( CORBA::is_nil(nameService.in()) )
	{
		std::cerr << "NameService is not a NamingContext object reference" << std::endl;
		throw CannotInitialize();
	}

	CORBA::ULong context_offset;
	if (global_context_used_)
	{
		context_offset = 1;
	} else 
	{
		context_offset= 0;
	};


	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;

	current_name.length (1);
	if (global_context_used_)
	{
		current_name[0].id = CORBA::string_dup(global_context_.c_str());
		current_name[0].kind = CORBA::string_dup("");
		try 
		{
			nameService->bind_new_context (current_name);
		}
		catch (CosNaming::NamingContext::AlreadyBound&)
		{
			// ignore this exception
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
			throw CannotInitialize();
		}

	} 
	current_name.length (1 + context_offset);
	current_name[0 + context_offset].id = CORBA::string_dup ("Qedo");
	current_name[0 + context_offset].kind = CORBA::string_dup ("");
	try
	{
		nameService->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
		throw CannotInitialize();
	}

	current_name.length(2 + context_offset);
	current_name[1+context_offset].id = CORBA::string_dup ("Activators");
	current_name[1+context_offset].kind = CORBA::string_dup ("");

	try
	{
		nameService->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << std::endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		std::cerr << "ServerActivatorImpl: Cannot determine my hostname" << std::endl;
		throw CannotInitialize();
	}

	std::cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << std::endl;

	current_name.length (3 + context_offset);
	current_name[2+context_offset].id = CORBA::string_dup (hostname);
	current_name[2+context_offset].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		nameService->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			nameService->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << std::endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during bind()" << std::endl;
		throw CannotInitialize();
	}

}
Exemple #6
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            "Mighty ORB");

      // Get the Root POA.
      CORBA::Object_var obj =
        orb->resolve_initial_references ("RootPOA");

      PortableServer::POA_var poa =
        PortableServer::POA::_narrow (obj.in ());

      // Activate the POA manager.
      PortableServer::POAManager_var mgr = poa->the_POAManager ();
      mgr->activate ();

      // Create the Iterator_Factory servant and object.
      // It activates and deactivates the Content_Iterator object.
      Iterator_Factory_i factory_servant;
      Web_Server::Iterator_Factory_var factory =
        factory_servant._this ();

      // Get a reference to the Name Service.
      obj = orb->resolve_initial_references ("NameService");

      // Narrow to a Naming Context
      CosNaming::NamingContext_var nc;
      nc = CosNaming::NamingContext::_narrow (obj.in ());

      // Create a name.
      CosNaming::Name name;
      name.length (1);
      name[0].id = CORBA::string_dup ("Iterator_Factory");
      name[0].kind = CORBA::string_dup ("");

      nc->bind (name, factory.in ());

      // Some debugging output.
      CORBA::String_var IOR = orb->object_to_string (factory.in ());
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Bound <%s> to <%s> in Name Service.\n"),
                  name[0].id.in (),
                  IOR.in ()));

      ACE_DEBUG ((LM_INFO,
                  ACE_TEXT ("Accepting requests.\n")));

      // Accept requests.
      orb->run ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (ACE_TEXT ("Caught unexpected exception:"));

      return -1;
    }

  return 0;
}
Exemple #7
0
static CORBA::Boolean
bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref)
{
  CosNaming::NamingContext_var rootContext;

  try {
    // Obtain a reference to the root context of the Name service:
    CORBA::Object_var obj;
    obj = orb->resolve_initial_references("NameService");

    // Narrow the reference returned.
    rootContext = CosNaming::NamingContext::_narrow(obj);
    if( CORBA::is_nil(rootContext) ) {
      cerr << "Failed to narrow the root naming context." << endl;
      return 0;
    }
  }
  catch (CORBA::NO_RESOURCES&) {
    cerr << "Caught NO_RESOURCES exception. You must configure omniORB "
	 << "with the location" << endl
	 << "of the naming service." << endl;
    return 0;
  }
  catch (CORBA::ORB::InvalidName&) {
    // This should not happen!
    cerr << "Service required is invalid [does not exist]." << endl;
    return 0;
  }

  try {
    // Bind a context called "test" to the root context:

    CosNaming::Name contextName;
    contextName.length(1);
    contextName[0].id   = (const char*) "test";       // string copied
    contextName[0].kind = (const char*) "my_context"; // string copied
    // Note on kind: The kind field is used to indicate the type
    // of the object. This is to avoid conventions such as that used
    // by files (name.type -- e.g. test.ps = postscript etc.)

    CosNaming::NamingContext_var testContext;
    try {
      // Bind the context to root.
      testContext = rootContext->bind_new_context(contextName);
    }
    catch(CosNaming::NamingContext::AlreadyBound& ex) {
      // If the context already exists, this exception will be raised.
      // In this case, just resolve the name and assign testContext
      // to the object returned:
      CORBA::Object_var obj;
      obj = rootContext->resolve(contextName);
      testContext = CosNaming::NamingContext::_narrow(obj);
      if( CORBA::is_nil(testContext) ) {
        cerr << "Failed to narrow naming context." << endl;
        return 0;
      }
    }

    // Bind objref with name Echo to the testContext:
    CosNaming::Name objectName;
    objectName.length(1);
    objectName[0].id   = (const char*) "Echo";   // string copied
    objectName[0].kind = (const char*) "Object"; // string copied

    try {
      testContext->bind(objectName, objref);
    }
    catch(CosNaming::NamingContext::AlreadyBound& ex) {
      testContext->rebind(objectName, objref);
    }
    // Note: Using rebind() will overwrite any Object previously bound
    //       to /test/Echo with obj.
    //       Alternatively, bind() can be used, which will raise a
    //       CosNaming::NamingContext::AlreadyBound exception if the name
    //       supplied is already bound to an object.

    // Amendment: When using OrbixNames, it is necessary to first try bind
    // and then rebind, as rebind on it's own will throw a NotFoundexception if
    // the Name has not already been bound. [This is incorrect behaviour -
    // it should just bind].
  }
  catch(CORBA::TRANSIENT& ex) {
    cerr << "Caught system exception TRANSIENT -- unable to contact the "
         << "naming service." << endl
	 << "Make sure the naming server is running and that omniORB is "
	 << "configured correctly." << endl;

    return 0;
  }
  catch(CORBA::SystemException& ex) {
    cerr << "Caught a CORBA::" << ex._name()
	 << " while using the naming service." << endl;
    return 0;
  }
  return 1;
}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Fatal error - no root POA available." << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	CosNaming::NamingContext_var ns;

	// Now try to bind with the Name Service
	try
	{
		CORBA::Object_var ns_obj = orb_->resolve_initial_references ("NameService");
		ns = CosNaming::NamingContext::_narrow (ns_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Name Service not found" << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: Cannot narrow object reference of Name Service" << endl;
		throw CannotInitialize();
	}

	if (CORBA::is_nil (ns))
	{
		cerr << "ServerActivatorImpl: Name Service is nil" << endl;
		throw CannotInitialize();
	}

	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;
	current_name.length (1);
	current_name[0].id = CORBA::string_dup ("Qedo");
	current_name[0].kind = CORBA::string_dup ("");
	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << endl;
		throw CannotInitialize();
	}

	current_name.length(2);
	current_name[1].id = CORBA::string_dup ("Activators");
	current_name[1].kind = CORBA::string_dup ("");

	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		cerr << "ServerActivatorImpl: Cannot determine my hostname" << endl;
		throw CannotInitialize();
	}

	cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << endl;

	current_name.length (3);
	current_name[2].id = CORBA::string_dup (hostname);
	current_name[2].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		ns->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			ns->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during bind()" << endl;
		throw CannotInitialize();
	}

#ifdef HAVE_JTC
#else
#if _WIN32
	// Create an event handle to be used for the notification from the created component server
	event_handle_ = CreateEvent (NULL, TRUE /*auto-reset*/, FALSE /*initial: non-signaled*/, "QEDO_NOTIFY_EVENT");
	    
	if (event_handle_ == NULL)
	{
		cerr << "ServerActivatorImpl: ServerActivatorImpl: Cannot create event object for notify_component_server() operation"<< endl;
		throw CannotInitialize();
	}
#endif
#endif
}
Exemple #9
0
bool ServiceOptions::bindServiceObject(CORBA::ORB_ptr orb, 
                                       CORBA::Object_ptr object,
                                       PortableServer::Servant p_servant,
                                       const char* objName,
                                       bool rebind)
{
 if(is_set("with-naming")) {
     CosNaming::Name name;
     name.length(1);
     name[0].id=CORBA::string_dup(objName);
     name[0].kind=CORBA::string_dup("");
     CORBA::Object_var obj ;
     try {
        obj = orb->resolve_initial_references("NameService");
     }catch(const CORBA::ORB::InvalidName& ex){
        std::cerr << argv()[0] << ": can't resolve `NameService'" << std::endl;
        return false;
     }
     CosNaming::NamingContext_var nc;
     try {
        nc = CosNaming::NamingContext::_narrow(obj.in());
     }catch(const CORBA::SystemException& ex){
        std::cerr << argv()[0] << ": can't narrow naming service" << std::endl;
        return false;
     }
     try {
        if(rebind){
          nc->rebind(name,object);
        }else{
          try{
            nc->bind(name,object);
          }catch(const CosNaming::NamingContext::AlreadyBound&){
            std::cerr<<argv()[0]<<":can't bind "<<objName<<" (AlreadyBound)"<< std::endl;
            return false;
          }
        }
     }catch(const CosNaming::NamingContext::CannotProceed&){
        std::cerr<<argv()[0]<<": can't bind "<<objName<<" (CannotProceed)"<< std::endl;
        return false;
     }catch(const CosNaming::NamingContext::InvalidName&){
        std::cerr<<argv()[0]<<":can't bind "<<objName<<" (InvalidName)"<< std::endl;
        return false;
     }
     std::cout<<argv()[0]<<": binding completed successfully"<<std::endl;
 }
 CORBA::String_var ior ;
 try {
   ior = orb->object_to_string(object);
 }catch(const CORBA::SystemException& ex){
#ifdef CORBA_SYSTEM_EXCEPTION_IS_STREAMBLE
   std::cerr << ex << std::endl;
#else
   std::cerr << "CORBA::SystemException" << std::endl; 
#endif
   return false;
 }
 const char* fname = get_ior_fname(objName);
 if (fname!=NULL && strcmp(fname,"")!=0) {
    std::ofstream ofs (fname);
    if (ofs.bad()) {
       std::cerr << argv()[0] << ": can't open file " << fname <<  std::endl;
       perror(argv()[0]);
       return false;
    }
    ofs << ior.in();
    ofs.close();
 }
 if (is_set("ior-stdout")) {
    std::cout << ior << std::flush;
 }
#ifdef ORBACUS
 CORBA::Object_var bmgrObj = orb->resolve_initial_references("BootManager");
 OB::BootManager_var bootManager = OB::BootManager::_narrow(bmgrObj);
 PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName);
 bootManager -> add_binding(oid.in(),object);
#elif defined(OMNIORB)
 PortableServer::POA_var objPOA = p_servant->_default_POA();
 CORBA::String_var objPOAName = objPOA->the_name();
 if (strcmp(objPOAName.in(),"omniINSPOA")!=0) {
   CORBA::Object_var insPOAObj = orb->resolve_initial_references("omniINSPOA");
   PortableServer::POA_var insPOA = PortableServer::POA::_narrow(insPOAObj);
   PortableServer::POAManager_var insPOAManager=insPOA->the_POAManager();
   insPOAManager->activate();
   PortableServer::ObjectId_var oid = 
                          PortableServer::string_to_ObjectId(objName);
   insPOA->activate_object_with_id(oid.in(),p_servant);
 }
#elif defined(RSSH_TAO)
#ifdef TAO_HAVE_IORTABLE_ADAPTER
 CORBA::Object_var table = orb->resolve_initial_references ("IORTable");
 IORTable::Table_var adapter = IORTable::Table::_narrow (table.in());
 if (CORBA::is_nil(adapter.in())) {
   cerr<<argv()[0]<<": nil IORTable reference"<<endl;
 } else {
   adapter->bind (objName, ior.in ());
 }
#else
 ACE_CString ins(objName);
 if (orb->_tao_add_to_IOR_table(ins,object)!=0) {
   return false;
 }
#endif
#elif defined(MICO)
  // create persistent POA with name as service name if we have no one.
 PortableServer::POA_var objPOA = p_servant->_default_POA();
 CORBA::String_var objPOAName = objPOA->the_name();
 std::cerr << "existent OBJPOAName=" << objPOAName.in() << std::endl;
 std::cerr << "objName=" << objName << std::endl;
 if (strcmp(objPOAName.in(),objName)!=0) {
   CORBA::Object_var rootPOAObj = orb->resolve_initial_references ("RootPOA");
   PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj);
   CORBA::PolicyList pl;
   pl.length (2);                              
   pl[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);
   pl[1] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID);
   PortableServer::POA_var objPOA = rootPOA->create_POA(objName,
			                  PortableServer::POAManager::_nil (),
			                  pl);
   PortableServer::POAManager_var objPOAManager = objPOA->the_POAManager ();   
   PortableServer::ObjectId_var objId =
                           PortableServer::string_to_ObjectId (objName);
   objPOA->activate_object_with_id (objId.in(), p_servant);
   objPOAManager->activate();
 }else{
   //PortbaobjPOA
 }  
#endif
 return true;
}
bool
NameServiceBase::registerName(std::string name, CORBA::Object_ptr obj, bool rebind)
{
    if (name.empty())
    {
        return false;
    }
    
    // extract name without contexts
    std::string pure_name = name;
    std::string contexts = "";
    std::string::size_type delimiter_pos = name.find_last_of("/");
    if (delimiter_pos != std::string::npos)
    {
        pure_name = pure_name.replace(0, delimiter_pos + 1, "");
        contexts = name.replace(delimiter_pos, std::string::npos, "");
    }

    CosNaming::Name aName;
    aName.length(1);
    aName[0].id = CORBA::string_dup(pure_name.c_str());
    aName[0].kind = CORBA::string_dup("");

    // make sure each context is bound
    CosNaming::NamingContext_var context = nameService_;
    while (contexts.length())
    {
        std::string ctx = contexts;
        delimiter_pos = contexts.find_first_of("/");
        if (delimiter_pos != std::string::npos)
        {
            ctx = ctx.replace(delimiter_pos, std::string::npos, "");
            contexts = contexts.replace(0, delimiter_pos + 1, "");
        }
        else
        {
            contexts = "";
        }

	    CosNaming::Name contextName;
        contextName.length(1);
        contextName[0].id = CORBA::string_dup(ctx.c_str());
        contextName[0].kind = CORBA::string_dup("");

        try
        {
            context = context->bind_new_context(contextName);
	    }
	    catch (const CosNaming::NamingContext::AlreadyBound&)
        {
            try
            {
		        // already bound -> take it
                CORBA::Object_var dummy;
                context = CosNaming::NamingContext::_narrow(dummy = context->resolve(contextName));
            }
            catch (...)
            {
                std::cerr << ctx << " is probably no context?" << std::endl;
                return false;
            }
        }
	    catch (const CosNaming::NamingContext::NotFound&)
        {
            std::cerr << "Got a `NotFound' exception : " << std::endl;
    		return false;
        }
        catch (const CosNaming::NamingContext::CannotProceed&)
        {
            std::cerr << "Got a `CannotProceed' exception : " << std::endl;
    		return false;
        }
        catch (const CosNaming::NamingContext::InvalidName&)
        {
            std::cerr << "Got a `InvalidName' exception : " << std::endl;
		    return false;
        }
    }

    //  bind the name
    try
	{
        context->bind(aName, obj);
	}
	catch(const CosNaming::NamingContext::AlreadyBound&)
    {
		// rebind the name if intended
        if (rebind)
        {
		    try
		    {
			    context->rebind(aName, obj);
		    }
		    catch (const CosNaming::NamingContext::NotFound&)
	        {
	            std::cerr << "Got a `NotFound' exception : " << std::endl;
			    return false;
	        }
	        catch (const CosNaming::NamingContext::CannotProceed&)
		    {
		        std::cerr << "Got a `CannotProceed' exception : " << std::endl;
			    return false;
		    }
		    catch (const CosNaming::NamingContext::InvalidName&)
	        {
			    std::cerr << "Got a `InvalidName' exception : " << std::endl;
			    return false;
		    }
        }
        else
        {
            std::cerr << "Got a `InvalidName' exception" << std::endl;
            return false;
        }
    }
	catch (const CosNaming::NamingContext::NotFound&)
    {
        std::cerr << "Got a `NotFound' exception : " << std::endl;
		return false;
    }
    catch (const CosNaming::NamingContext::CannotProceed&)
    {
        std::cerr << "Got a `CannotProceed' exception : " << std::endl;
		return false;
    }
    catch (const CosNaming::NamingContext::InvalidName&)
    {
        std::cerr << "Got a `InvalidName' exception : " << std::endl;
		return false;
    }

    return true;
}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - no root POA available." << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << std::endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	CosNaming::NamingContext_var ns;

	// Now try to bind with the Name Service
	try
	{
		CORBA::Object_var ns_obj = orb_->resolve_initial_references ("NameService");
		ns = CosNaming::NamingContext::_narrow (ns_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service not found" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Cannot narrow object reference of Name Service" << std::endl;
		throw CannotInitialize();
	}

	if (CORBA::is_nil (ns))
	{
		std::cerr << "ServerActivatorImpl: Name Service is nil" << std::endl;
		throw CannotInitialize();
	}

	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;
	current_name.length (1);
	current_name[0].id = CORBA::string_dup ("Qedo");
	current_name[0].kind = CORBA::string_dup ("");
	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
		throw CannotInitialize();
	}

	current_name.length(2);
	current_name[1].id = CORBA::string_dup ("Activators");
	current_name[1].kind = CORBA::string_dup ("");

	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << std::endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		std::cerr << "ServerActivatorImpl: Cannot determine my hostname" << std::endl;
		throw CannotInitialize();
	}

	std::cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << std::endl;

	current_name.length (3);
	current_name[2].id = CORBA::string_dup (hostname);
	current_name[2].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		ns->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			ns->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << std::endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during bind()" << std::endl;
		throw CannotInitialize();
	}



}
Exemple #12
0
static void bindObjectToName(CORBA::ORB_ptr orb, const char name[], CORBA::Object_ptr objref)
{
   CosNaming::NamingContext_var rootContext;

   try 
   {
      // Obtain a reference to the root context of the name service:
      CORBA::Object_var obj;
      obj = orb->resolve_initial_references("NameService");
      
      // Narrow the reference returned.
      rootContext = CosNaming::NamingContext::_narrow(obj);
      if(CORBA::is_nil(rootContext)) 
      {
         cerr << "Failed to narrow the root naming context." << endl;
         return;
      }
   }
   catch (CORBA::ORB::InvalidName& ex) 
   {
      // This should not happen!
      cerr << "Service required is invalid [does not exist]." << endl;
      return;
   }

   try 
   {
      CosNaming::Name contextName;
      contextName.length(1);
      contextName[0].id   = (const char*) "corejava"; 
      contextName[0].kind = (const char*) "Context"; 

      CosNaming::NamingContext_var corejavaContext;
      try 
      {
         // Bind the context to root.
         corejavaContext = rootContext->bind_new_context(contextName);
      }
      catch (CosNaming::NamingContext::AlreadyBound& ex) 
      {
         // If the context already exists, this exception will be raised. In this case, just 
         // resolve the name and assign the context to the object returned:
         CORBA::Object_var obj;
         obj = rootContext->resolve(contextName);
         corejavaContext = CosNaming::NamingContext::_narrow(obj);
         if( CORBA::is_nil(corejavaContext) ) 
         {
            cerr << "Failed to narrow naming context." << endl;
            return;
         }
      }

      // Bind objref with given name to the context:
      CosNaming::Name objectName;
      objectName.length(1);
      objectName[0].id = name;
      objectName[0].kind = (const char*) "Object"; 

      try 
      {      
         corejavaContext->bind(objectName, objref);
      }
      catch (CosNaming::NamingContext::AlreadyBound& ex) 
      {
         corejavaContext->rebind(objectName, objref);
      }
   }
   catch (CORBA::COMM_FAILURE& ex) 
   {
      cerr << "Caught system exception COMM_FAILURE--unable to contact the naming service." 
         << endl;
   }
   catch (CORBA::SystemException&) 
   {
      cerr << "Caught a CORBA::SystemException while using the naming service." << endl;
   }
}