Пример #1
0
  /*!
   * @if jp
   * @brief 与えられた NamingContext の Binding を取得する
   * @else
   * @brief Get Binding on the given NamingContext
   * @endif
   */
  void CorbaNaming::list(CosNaming::NamingContext_ptr name_cxt,
			 CORBA::ULong how_many,
			 CosNaming::BindingList_var& bl,
			 CosNaming::BindingIterator_var& bi)
  {
#ifndef ORB_IS_RTORB
    name_cxt->list(how_many, bl.out(), bi.out());
#else // ORB_IS_RTORB
    name_cxt->list(how_many, (CosNaming::BindingList_out)bl,
                   (CosNaming::BindingIterator_ptr)bi);
#endif // ORB_IS_RTORB

  }
Пример #2
0
void main(int argc,char **argv){
	try {
		//Crear ORB
		CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

		//Crear POA
		CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
		PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj);
		PortableServer::POAManager_var manager = poa->the_POAManager();

		//Crear servidor
		Servidor *service = NULL;
		service = new Servidor();
		service->orb = &orb;

		//Subir servidor a servicio de nombres
		try {
			CORBA::Object_var ns_obj = orb->resolve_initial_references("NameService");
			if (!CORBA::is_nil(ns_obj)) {
				CosNaming::NamingContext_ptr nc = CosNaming::NamingContext::_narrow(ns_obj);
				service->nc = &nc;
				CosNaming::Name name;
				name.length(1);
				name[0].id = CORBA::string_dup("Server");
				name[0].kind = CORBA::string_dup("");
				nc->bind(name, service->_this());
				cout << "Server is running ..." << endl;
			}
		}
		catch (CosNaming::NamingContext::NotFound &) {
			cerr << "not found" << endl;
		}catch (CosNaming::NamingContext::InvalidName &) {
			cerr << "invalid name" << endl;
		}catch (CosNaming::NamingContext::CannotProceed &) {
			cerr << "cannot proceed" << endl;
		}

		manager->activate();
		orb->run();

		delete service;
		orb->destroy();
	}
	catch (CORBA::UNKNOWN) {
		cerr << "unknown exception" << endl;
	}catch (CORBA::SystemException &) {
		cerr << "system exception" << endl;
	}
	getchar();
	//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
Пример #3
0
int main(int argc, char ** argv)
{
    try {
        // init ORB
        CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
 
        // init POA
        CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj);
        PortableServer::POAManager_var manager = poa->the_POAManager();
 
        // create service
        Math_operation * service = new Math_operation;
 
        // register within the naming service
        try {
            CORBA::Object_var ns_obj = orb->resolve_initial_references("NameService");
            if (!CORBA::is_nil(ns_obj)) {
                CosNaming::NamingContext_ptr nc = CosNaming::NamingContext::_narrow(ns_obj);
                CosNaming::Name name;
                name.length(1);
                name[0].id = CORBA::string_dup("TestServer");
                name[0].kind = CORBA::string_dup("");
                nc->rebind(name, service->_this());
                cout << argv[0] << ": server 'TestServer' bound" << endl;
            }
        } catch (CosNaming::NamingContext::NotFound &) {
            cerr << "not found" << endl;
        } catch (CosNaming::NamingContext::InvalidName &) {
            cerr << "invalid name" << endl;
        } catch (CosNaming::NamingContext::CannotProceed &) {
            cerr << "cannot proceed" << endl;
        }
 
        // run
        manager->activate();
        orb->run();
 
        // clean up
        delete service;
 
        // quit
        orb->destroy();
    } catch (CORBA::UNKNOWN) {
        cerr << "unknown exception" << endl;
    } catch (CORBA::SystemException &) {
        cerr << "system exception" << endl;
    }
}
Пример #4
0
CORBA::Boolean TestDestroy::test(CosNaming::NamingContext_ptr context, 
                                 CORBA::Exception* expected_exception,
                                 const char* id, CORBA::Boolean print)
{
  if (print)
    cerr << "(" << id << ") TestDestroy " << endl; 
  
  if (context == NULL) {
    cerr << "Error: given context is null" << endl;
    return false;
  }
  
  try {
    
    context->destroy(); 
      
    
  } catch (const CORBA::Exception & e) {
    // TODO: check if cp and expected_exception RTTI types matches
  }

  if(print) {
    cerr << "(" << id << ") TestDestroy: OK!!" << endl;
  }
    
  return true;
}
Пример #5
0
    bool
    unbind_object (const char *name,
                   CosNaming::NamingContext_ptr ctx)
    {
      CIAO_TRACE ("Name_Utilities::unbind_object");

      if (CORBA::is_nil (ctx))
        {
          CIAO_ERROR (1, (LM_WARNING, CLINFO
                          "Name_Utilities::unbind_object - "
                          "Provided naming context is nil, instance <%C> will not be unbound\n",
                          name));
          return false;
        }

      CosNaming::Name nm;
      Name_Utilities::build_name (name, nm);

      try
        {
          ctx->unbind (nm);
        }
      catch (CORBA::Exception &e)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                          "Name_Utilities::unbind_object - "
                          "Caught CORBA exception whilst unbinding name <%C>: <%C>\n",
                          name, e._info ().c_str ()));
          return false;
        }
      return true;
    }
Пример #6
0
void
FT_EventService::setup_scheduler(CosNaming::NamingContext_ptr naming_context)
{
    RtecScheduler::Scheduler_var scheduler;
    if (CORBA::is_nil(naming_context)) {
        ACE_NEW_THROW_EX (this->sched_impl_,
            ACE_Config_Scheduler,
            CORBA::NO_MEMORY());

        scheduler = this->sched_impl_->_this ();

        if (ACE_Scheduler_Factory::server(scheduler.in()) == -1)
            ORBSVCS_ERROR((LM_ERROR,"Unable to install scheduler\n"));
    }
    else {
        // This is the name we (potentially) register the Scheduling
        // Service in the Naming Service.
        CosNaming::Name schedule_name (1);
        schedule_name.length (1);
        schedule_name[0].id = CORBA::string_dup ("ScheduleService");


        if (1)
        {
            // We must find the scheduler object reference...

            if (this->global_scheduler_ == 0)
            {
                ACE_NEW_THROW_EX (this->sched_impl_,
                    ACE_Config_Scheduler,
                    CORBA::NO_MEMORY());

                scheduler = this->sched_impl_->_this ();

                // Register the servant with the Naming Context....
                naming_context->rebind (schedule_name, scheduler.in ());
            }
            else
            {
                CORBA::Object_var tmp =
                    naming_context->resolve (schedule_name);

                scheduler = RtecScheduler::Scheduler::_narrow (tmp.in ());
            }
        }
    }
}
Пример #7
0
  /*!
   * @if jp
   * @brief NamingContext を再帰的に下って非アクティブ化する
   * @else
   * @brief Destroy the naming context recursively
   * @endif
   */
  void CorbaNaming::destroyRecursive(CosNaming::NamingContext_ptr context)
    throw (SystemException, NotEmpty, NotFound, CannotProceed, InvalidName)
  {
    CosNaming::BindingList_var     bl;
    CosNaming::BindingIterator_var bi;
    CORBA::Boolean cont(true);
    
#ifndef ORB_IS_RTORB
    context->list(m_blLength, bl.out(), bi.out());
#else // ORB_IS_RTORB
    //    context->list(m_blLength, bl, bi);
    context->list(m_blLength, (CosNaming::BindingList_out)bl,
                  (CosNaming::BindingIterator_ptr)bi);
#endif // ORB_IS_RTORB
    
    while (cont)
      {
	CORBA::ULong len(bl->length());
	
	for (CORBA::ULong i = 0; i < len; ++i)
	  {
	    if (bl[i].binding_type == CosNaming::ncontext)
	      {	// If Object is context, destroy recursive.
		CosNaming::NamingContext_var next_context;
		next_context = CosNaming::NamingContext::
		  _narrow(context->resolve(bl[i].binding_name));
		
		// Recursive function call
		destroyRecursive(next_context); // +++ Recursive call +++
		context->unbind(bl[i].binding_name);
		next_context->destroy();
	      }
	    else if (bl[i].binding_type == CosNaming::nobject)
	      {	// If Object is object, unbind it.
		context->unbind(bl[i].binding_name);
	      }
	    else assert(0); // never comes here
	  }
	
	// no more binding -> do-while loop will be finished
	if (CORBA::is_nil(bi)) cont = false;
	else bi->next_n(m_blLength, bl);
      }
    
    if (!CORBA::is_nil(bi)) bi->destroy();
    return;
  }
Пример #8
0
  /*!
   * @if jp
   * @brief オブジェクトの名前をバインドまたは解決する
   * @else
   * @brief Bind or resolve the given name component
   * @endif
   */
  CORBA::Object_ptr
  CorbaNaming::bindOrResolve(CosNaming::NamingContext_ptr context,
			     const CosNaming::Name& name,
			     CORBA::Object_ptr obj)
  {
    try
      {
	context->bind(name, obj);
	return obj;
      }
    catch (AlreadyBound& e)
      {
	(void)(e);
	return context->resolve(name);
      }
    return CORBA::Object::_nil();
  }
Пример #9
0
Components::Deployment::ServerActivator_ptr
get_server_activator (CORBA::ORB_ptr orb, CosNaming::NamingContext_ptr ns, const char* hostname)
{
	cout << "Getting Component Server Activator from Qedo/Activators/" << hostname << endl;

	CosNaming::Name server_activator_name;
	server_activator_name.length (3);
	server_activator_name[0].id = CORBA::string_dup ("Qedo");
	server_activator_name[0].kind = CORBA::string_dup ("");
	server_activator_name[1].id = CORBA::string_dup ("Activators");
	server_activator_name[1].kind = CORBA::string_dup ("");
	server_activator_name[2].id = CORBA::string_dup (hostname);
	server_activator_name[2].kind = CORBA::string_dup ("");

	Components::Deployment::ServerActivator_var server_activator;
	CORBA::Object_var server_activator_obj;

	try
	{
		server_activator_obj = ns->resolve (server_activator_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		cerr << "Component Server Activator not found in Name Service" << endl;
		orb->destroy();
		exit (1);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "CORBA system exception during resolve()" << endl;
		orb->destroy();
		exit (1);
	}

	try
	{
		server_activator = Components::Deployment::ServerActivator::_narrow (server_activator_obj);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "Cannot narrow Component Server Activator" << endl;
		orb->destroy();
		exit (1);
	}

	return server_activator._retn();
}
CosEventChannelAdmin::EventChannel_ptr connectToEventChannel (CosNaming::NamingContext_ptr context, const std::string& name)
{
    TRACE_ENTER(EventChannelSupport);
    CosNaming::Name_var boundName = ossie::corba::stringToName(name);
    try {
        CORBA::Object_var obj = context->resolve(boundName);
        LOG_TRACE(EventChannelSupport, "Existing event channel " << name << " found");
        return CosEventChannelAdmin::EventChannel::_narrow(obj);
    } catch (const CosNaming::NamingContext::NotFound&) {
        // The channel does not exist and can be safely created.
    } catch (const CORBA::Exception& e) {
        LOG_WARN(EventChannelSupport, "CORBA (" << e._name() << ") exception connecting to event channel " << name <<". Continue without connecting to the channel (the event service might not be running)");
    }

    TRACE_EXIT(EventChannelSupport);
    return CosEventChannelAdmin::EventChannel::_nil();
}
Пример #11
0
void CNamingTreeCtrl::ListBindingList(HTREEITEM hItem, CosNaming::NamingContext_ptr pContext, CosNaming::BindingList_var& bl)
{
  try
  {
    for(unsigned int i=0; i < bl->length(); i++)
    {
      // Add each entry into the tree control
      CORBA::Object_var Object = pContext->resolve(bl[i].binding_name);
      bool Context = (bl[i].binding_type == CosNaming::ncontext);
      CNamingObject* pNewObject = new CNamingObject(bl[i].binding_name, Object, Context);
      CString Name;
      const char* pKind = (bl[i].binding_name[0]).kind;
      if(*pKind)
      {
        Name.Format(ACE_TEXT ("%s | %s"), (bl[i].binding_name[0]).id, pKind);
      }
      else
      {
        Name.Format(ACE_TEXT ("%s"), (bl[i].binding_name[0]).id);
      }
      HTREEITEM hContext = InsertItem(Name, hItem);
      SetItemData(hContext, (DWORD)pNewObject);
      switch(bl[i].binding_type)
      {
      case CosNaming::ncontext:
        {
          // Set the children flag so the + button is displayed
          TV_ITEM Item;
          Item.mask = TVIF_CHILDREN | TVIF_HANDLE;
          Item.cChildren = 1;
          Item.hItem = hContext;
          SetItem(&Item);
        }
        break;
      case CosNaming::nobject:
        break;
      }
    }
  }
  catch(CORBA::Exception& ex)
  {
    MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
  }
}
Пример #12
0
typename T::_ptr_type
resolve_name(
    CosNaming::NamingContext_ptr    nc,
    const CosNaming::Name &         name)
{
    CORBA::Object_var obj;
    try {
        obj = nc->resolve(name);
    }
    catch (const CosNaming::NamingContext::NotFound &) {
        throw;
    }
    catch (const CORBA::Exception & e) {
        std::cerr << "Cannot resolve binding: "
                  << e
                  << std::endl;
        throw 0;
    }
    if (CORBA::is_nil(obj.in())) {
        std::cerr << "Nil binding in Naming Service" << std::endl;
        throw 0;
    }

    typename T::_var_type ref;
    try {
        ref = T::_narrow(obj.in());
    }
    catch (const CORBA::Exception & e) {
        std::cerr << "Cannot narrow reference: "
                  << e
                  << std::endl;
        throw 0;
    }
    if (CORBA::is_nil(ref.in())) {
        std::cerr << "Reference has incorrect type" << std::endl;
        throw 0;
    }
    return ref._retn();
}
Пример #13
0
    void
    bind_context (CosNaming::Name &nm,
                  CosNaming::NamingContext_ptr ctx)
    {
      CIAO_TRACE ("Name_Utilities::bind_context");

      if (CORBA::is_nil (ctx))
        {
          CIAO_ERROR (1, (LM_WARNING, CLINFO
                          "Name_Utilities::bind_context - "
                          "Provided naming context is nil, the naming context will not be bound."));
          return;
        }

      CosNaming::Name newname (nm.length ());

      for (CORBA::ULong i = 0;
           i < (nm.length () - 1); ++i)
        {
          newname.length (i + 1);
          newname[i] = nm[i];

          try
            {
              ctx->bind_new_context (newname);
              CIAO_DEBUG (9, (LM_TRACE, CLINFO
                              "Name_Utilities::bind_context - "
                              "Bound new context <%C>\n",
                              newname[i].id.in ()));
            }
          catch (CosNaming::NamingContext::AlreadyBound &)
            {
              CIAO_DEBUG (9, (LM_TRACE, CLINFO
                              "Name_Utilities::bind_context - "
                              "Context <%C> already bound.\n",
                              newname[i].id.in ()));
            }
        }
    }
Пример #14
0
 /*!
  * @if jp
  * @brief NamingContext を非アクティブ化する
  * @else
  * @brief Destroy the naming context
  * @endif
  */
 void CorbaNaming::destroy(CosNaming::NamingContext_ptr context)
   throw (SystemException, NotEmpty)
 {
   context->destroy();
 }
Пример #15
0
void
deploy_test_components (CORBA::ORB_ptr orb, CosNaming::NamingContext_ptr ns, const char* hostname)
{
	cout << "Getting Component Installation from Qedo/ComponentInstallation/" << hostname << endl;

	CosNaming::Name installer_name;
	installer_name.length (3);
	installer_name[0].id = CORBA::string_dup ("Qedo");
	installer_name[0].kind = CORBA::string_dup ("");
	installer_name[1].id = CORBA::string_dup ("ComponentInstallation");
	installer_name[1].kind = CORBA::string_dup ("");
	installer_name[2].id = CORBA::string_dup (hostname);
	installer_name[2].kind = CORBA::string_dup ("");

	Components::Deployment::ComponentInstallation_var component_installer;
	CORBA::Object_var component_installer_obj;

	try
	{
		component_installer_obj = ns->resolve (installer_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		cerr << "Component Installer not found in Name Service" << endl;
		orb->destroy();
		exit (1);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "CORBA system exception during resolve()" << endl;
		orb->destroy();
		exit (1);
	}

	try
	{
		component_installer = Components::Deployment::ComponentInstallation::_narrow (component_installer_obj);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "Cannot narrow Component Installer" << endl;
		orb->destroy();
		exit (1);
	}

#ifdef _WIN32
	std::string servant_loc = getCurrentDirectory() + "\\dinner_SERVANT.dll";
	std::string phil_loc = getCurrentDirectory() + "\\dinner_PhilosopherImpl.dll";
	std::string cutl_loc = getCurrentDirectory() + "\\dinner_CutleryImpl.dll";
	std::string obse_loc = getCurrentDirectory() + "\\dinner_ObserverImpl.dll";
#else
	std::string servant_loc = getCurrentDirectory() + "/libdinner_SERVANT.so";
	std::string phil_loc = getCurrentDirectory() + "/libdinner_PhilosopherImpl.so";
	std::string cutl_loc = getCurrentDirectory() + "/libdinner_CutleryImpl.so";
	std::string obse_loc = getCurrentDirectory() + "/libdinner_ObserverImpl.so";
#endif
	std::string loc_p = servant_loc + ";create_PhilosopherHomeS;" + phil_loc + ";create_PhilosopherHomeE";
	std::string loc_c = servant_loc + ";create_CutleryHomeS;" + cutl_loc + ";create_CutleryHomeE";
	std::string loc_o = servant_loc + ";create_ObserverHomeS;" + obse_loc + ";create_ObserverHomeE";

	try
	{
		component_installer->install ("PHILOSOPHER", loc_p.c_str());
		component_installer->install ("CUTLERY", loc_c.c_str());
		component_installer->install ("OBSERVER", loc_o.c_str());
	}
	catch (Components::Deployment::InvalidLocation&)
	{
		cerr << "Component Installer raised Components::Deployment::InvalidLocation" << endl;
	}
	catch (Components::Deployment::InstallationFailure&)
	{
		cerr << "Component Installer raised Components::Deployment::InstallationFailure" << endl;
	}
}
Пример #16
0
    bool
    bind_object (const char *name,
                 CORBA::Object_ptr obj,
                 CosNaming::NamingContext_ptr ctx)
    {
      CIAO_TRACE ("Name_Utilities::bind_object");

      if (CORBA::is_nil (ctx))
        {
          CIAO_ERROR (1, (LM_WARNING, CLINFO "Name_Utilities::bind_object - "
                          "Provided naming context is nil, component <%C> will not be registered.",
                          name));
          return false;
        }

      try
        {
          CosNaming::Name nm;

          Name_Utilities::build_name (name, nm);

          if (nm.length () == 0)
            {
              CIAO_ERROR (1, (LM_WARNING, CLINFO
                              "Name_Utilities::bind_object - "
                              "build_name resulted in an invalid name for string <%C>\n",
                              name));
              return false;
            }

          Name_Utilities::bind_context (nm, ctx);

          try
            {
              ctx->bind (nm, obj);
            }
          catch (const CosNaming::NamingContext::AlreadyBound &)
            {
              CIAO_ERROR (1, (LM_WARNING, CLINFO "Name_Utilities::bind_object - "
                              "Name <%C> already bound, rebinding....\n",
                              name));
              ctx->rebind (nm, obj);
            }
        }
      catch (const CORBA::Exception &ex)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "Name_Utilities::bind_object - "
                          "Caught CORBA exception while attempting to bind name <%C>: <%C>\n",
                          name, ex._info ().c_str ()));
          return false;
        }
      catch (...)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "Name_Utilities::bind_object - "
                          "Caught unknown C++ exception while attemptint to bind name <%C>\n",
                          name));
          return false;
        }

      return true;
    }
Пример #17
0
void
loadPersistence(PortableServer::POA_ptr namingContextsPOA, 
                PortableServer::POA_ptr bindingIteratorsPOA,
                const char* ior_file) 
{
  TIDorb::core::TIDORB* m_orb = 
    dynamic_cast<TIDorb::core::TIDORB*> (CORBA::ORB::_duplicate(my_global_orb));
  
  
  TIDNaming::NamingContextIOFactory & iofac =
    TIDNaming::NamingContextIOFactory::getFactory();
  
  try {

    //
    // Read data persistence into ContextInfo sequence
    //
    NamingInternals::ContextInfoSeq_ptr ctxs = 
      new NamingInternals::ContextInfoSeq(0);
    ctxs->length(0);

    NamingInternals::ContextInfo_ptr root_ctx = 
      iofac.getReader().loadAll(ctxs);
    

    if (!ctxs->length()) {
      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, 
                           "No naming context found to be recovered");
    } else {
      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, 
                           "Preparing for persistent data recovery");
    }

    
    //
    // Create object references for each context read
    // Then the objects will added to Active Object Map
    for (CORBA::ULong i = 0; i < ctxs->length(); i++) {

      const NamingInternals::ContextInfo & ctx_inf = (*ctxs)[i];
      if (m_orb->trace != NULL){
        TIDorb::util::StringBuffer msg;
        msg << "Recovering naming context '" << ctx_inf.oid << "'... ";
        m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data());
      }

      CosNaming::NamingContext_ptr nc = 
        createNamingContextReference(namingContextsPOA,
                                     ctx_inf.oid);     

      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done");

      if (strcmp(ctx_inf.oid, NamingInternals::RootNamingContextOID) == 0) {
        if (m_orb->trace != NULL){
          TIDorb::util::StringBuffer msg;
          msg << "Setting '" << ctx_inf.oid << "' as name server... ";
          m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data());
        }
        registerNameService(my_global_orb, nc, ior_file);

        if (m_orb->trace != NULL)
          m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done");

      } else {
        CORBA::ULong count;
        sscanf(ctx_inf.oid, "nc-%u.ctx", &count);
        TIDNaming::NamingContextImpl::setObjectIdCounter(count);
      }
      CORBA::release(nc);
    }
      
    //
    // Set binding information for each context read
    //  
    for (CORBA::ULong i = 0; i < ctxs->length(); i++) {
      const NamingInternals::ContextInfo & ctx_inf = (*ctxs)[i];
      
      CosNaming::NamingContext_ptr nc =
        getNamingContextReference(namingContextsPOA, ctx_inf.oid);
      
      
      for (CORBA::ULong j = 0; j < ctx_inf.refs.length(); j++) {

        const NamingInternals::Reference & ref = ctx_inf.refs[j];
        
        if (m_orb->trace != NULL){
          TIDorb::util::StringBuffer msg;
          msg << "Binding artifact '" << ref.name.id << ".";
          msg << ref.name.kind << "' for context '" << ctx_inf.oid;
          msg << "...";
          m_orb->print_trace(TIDorb::util::TR_DEBUG, msg.str().data());
        }

        CORBA::Object_ptr obj = my_global_orb->string_to_object(ref.ior);
        CosNaming::NamingContext_ptr obj_ctx;
        CosNaming::Name ref_name;
        ref_name.length(1);
        ref_name[0] = ref.name;

        switch (ref.type)  {
        case CosNaming::nobject:
          nc->bind(ref_name, obj);
          CORBA::release(obj);
          break;
        case CosNaming::ncontext:
          obj_ctx = CosNaming::NamingContext::_narrow(obj);
          nc->bind_context(ref_name, obj_ctx);
          CORBA::release(obj_ctx);
          CORBA::release(obj);
          break;
        default:
          if (m_orb->trace != NULL)
            m_orb->print_trace(TIDorb::util::TR_DEBUG, "Error: unknown binding type");
        }
        
        if (m_orb->trace != NULL)
          m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done");
      }
      CORBA::release(nc);
    }
      
    if (ctxs->length()) {
      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, 
                           "Persistent data loaded successfully");
    }
    
    
    //
    // Check to set root naming context
    // 
    if (!root_ctx) {
      
      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, 
                           "No root context found. Initializing a new one... ");

      CosNaming::NamingContext_ptr root_nc = 
        createNamingContextReference(namingContextsPOA, 
                                     NamingInternals::RootNamingContextOID);
      
      NamingInternals::ReferenceSeq refs;
      TIDNaming::NamingContextIOFactory::getFactory().getWriter().store(
                                                 NamingInternals::RootNamingContextOID, refs);
      
      registerNameService(my_global_orb, root_nc, ior_file);
      
      CORBA::release(root_nc);
      
      if (m_orb->trace != NULL)
        m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done");

    } 

    delete ctxs;

  } catch (NamingInternals::PersistenceException &) {
    if (m_orb->trace != NULL)
      m_orb->print_trace(TIDorb::util::TR_ERROR, "Error: cannot read persistence data");
    throw;
  }
}
Пример #18
0
/*引数にTreeObjectを追加*/
void ListRecursive(CosNaming::NamingContext_ptr context,vector<OtherPort> &rtclist,vector<string> &name, TreeObject *to){
    CosNaming::BindingList_var     bl;
    CosNaming::BindingIterator_var bi;
    CORBA::Boolean cont(true);
    int m_blLength=100;
    context->list(m_blLength, bl, bi);
 
    while (cont){
        CORBA::ULong len(bl->length());
        for (CORBA::ULong i = 0; i < len; ++i){
 
            if (bl[i].binding_type == CosNaming::ncontext){
                CosNaming::NamingContext_var next_context;
                next_context = CosNaming::NamingContext::_narrow(context->resolve(bl[i].binding_name));
                vector<string> namebuff=name;
                name.push_back(string(bl[i].binding_name[0].id));
                //name.push_back("/");
				TreeObject *to2 = new TreeObject(string(bl[i].binding_name[0].id));
				to->to.push_back(to2);
                ListRecursive(next_context,rtclist,name,to2); 
                name=namebuff;
            }
            else if (bl[i].binding_type == CosNaming::nobject){
                if(rtclist.size()>m_blLength)
                    break;
                vector<string> namebuff=name;
                name.push_back(string(bl[i].binding_name[0].id));
/*
データポートの情報を取得するためのコードを追加
*/
				if(string(bl[i].binding_name[0].kind) == "rtc")
				{
					
					RTC::CorbaConsumer<RTC::RTObject> rto;
					rto.setObject(context->resolve(bl[i].binding_name));
					try
					{
						RTC::PortServiceList_var tp = rto._ptr()->get_ports();
					
						TreeObject *to2 = new TreeObject(string(bl[i].binding_name[0].id));
						to->to.push_back(to2);

						for(int k=0;k < tp->length();k++)
						{
							vector<string> namebuff2=name;
							string tname = tp[(CORBA::ULong)k]->get_port_profile()->name;
							PortService_var p = tp[(CORBA::ULong)k];
							vector<string> pn = coil::split(tname, ".");
							namebuff2.push_back(pn[1]);

							TreeObject *to3 = new TreeObject(string(pn[1]));
							to2->to.push_back(to3);

							rtclist.push_back(OtherPort(p, namebuff2));
						}
					}
					catch(...)
					{

					}

					
					

					//name=namebuff2;
				}
/*ここまで*/
				name=namebuff;
				
                //rtclist.push_back(name_buff);
            }
            else {
            }
        }
        if (CORBA::is_nil(bi)) {
            cont = 0;
        }
        else {
            bi->next_n(m_blLength, bl);
        }
    }
    return;
}