コード例 #1
0
void
VOmniORBHelper::nsRegisterObject(CORBA::Object_ptr obj,
				 const char* program, const char* object,
				 int telescopenumber)
  throw(CORBA::SystemException, 
	CosNaming::NamingContext::NotFound,
	CosNaming::NamingContext::CannotProceed,
	CosNaming::NamingContext::InvalidName,
	CosNaming::NamingContext::AlreadyBound)
{
  ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex);
  CosNaming::NamingContext_var root = nsRootContext();
  CosNaming::Name_var name = 
    nsPathToObjectName(program, object, telescopenumber);

  for(unsigned int n=0; n<name->length()-1; n++)
    {
      CosNaming::Name_var child_name = name;
      child_name->length(n+1);
      
      try
	{
	  CORBA::Object_var object = root->resolve(child_name);
	}
      catch(CosNaming::NamingContext::NotFound)
	{
	  CosNaming::NamingContext_var 
	    child = root->bind_new_context(child_name);
	}
    }

  root->rebind(name,obj);
}
コード例 #2
0
  /*!
   * @if jp
   * @brief 与えられた文字列表現を NameComponent に分解する
   * @else
   * @brief Resolve given string representation to NameComponent
   * @endif
   */
  CosNaming::Name CorbaNaming::toName(const char* sname)
    throw (SystemException, InvalidName)
  {
    if (!sname)         throw InvalidName();
    if (*sname == '\0') throw InvalidName();
    
    std::string string_name(sname);
    std::vector<std::string> name_comps;
    
    // String name should include 1 or more names
    CORBA::ULong nc_length = 0;
    nc_length = split(string_name, std::string("/"), name_comps);
    if (!(nc_length > 0)) throw InvalidName();
    
    // Name components are allocated
    CosNaming::Name_var    name = new CosNaming::Name();
    name->length(nc_length);
    
    // Insert id and kind to name components
    for (CORBA::ULong i = 0; i < nc_length; ++i)
      {
	std::string::size_type pos;
	pos = name_comps[i].find_last_of(".");
	if (pos != name_comps[i].npos)
	  {
	    name[i].id   = 
	      CORBA::string_dup(name_comps[i].substr(0, pos).c_str());
	    name[i].kind = 
	      CORBA::string_dup(name_comps[i].substr(pos + 1).c_str());
	  }
	else
	  {
	    name[i].id   = CORBA::string_dup(name_comps[i].c_str());
#ifndef ORB_IS_RTORB
	    name[i].kind = "";
#else // ORB_IS_RTORB
	    name[i].kind = (char*)"";
#endif // ORB_IS_RTORB
	  }
      }
    return name;
  }