示例#1
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;
    }
  /*!
   * @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;
  }