Ejemplo n.º 1
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');
}
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
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;
  }
}
Ejemplo n.º 4
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;
    }