Ejemplo n.º 1
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    //Get reference to the RootPOA.
    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

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

    if (parse_args (argc, argv) != 0)
      return 1;

    // Create a servant.
    PortableServer::Servant_var<Messenger_i> messenger_servant = new Messenger_i;

    // Register the servant with the RootPOA, obtain its object
    // reference, stringify it, and write it to a file.
    PortableServer::ObjectId_var oid =
      poa->activate_object( messenger_servant.in() );
    CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
    CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
    std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR (ior_output_file));
    iorFile << str.in() << std::endl;
    iorFile.close();
    std::cout << "IOR written to file " <<
      ACE_TEXT_ALWAYS_CHAR (ior_output_file) << std::endl;

    // 3. Create and activate threads for the thread pool.
    ORB_Task task (orb.in());
    int retval = task.activate (THR_NEW_LWP | THR_JOINABLE, nthreads);
    if (retval != 0) {
      std::cerr << "Failed to activate " << nthreads << " threads." << std::endl;
      return 1;
    }

    // 4. Wait for threads to finish.
    task.wait();

    // Clean up.
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Ejemplo n.º 2
0
int
ACE_TMAIN (int argc,
      ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var obj
        = orb->resolve_initial_references ("RootPOA");

      // Get the POA_var object from Object_var
      PortableServer::POA_var root_poa
        = PortableServer::POA::_narrow (obj.in ());

      PortableServer::POAManager_var mgr
        = root_poa->the_POAManager ();

      mgr->activate ();

      // Initialize the AV Stream components.
      TAO_AV_CORE::instance ()->init (orb.in (),
                                      root_poa.in ());

      // Initialize the Sender.
      int result = 0;
      result = SENDER::instance ()->init (argc,
                                          argv);

      if (result < 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Sender::init failed\n"),
                          -1);

      SENDER::instance ()->pace_data ();

      ACE_Time_Value tv (10);
      orb->run (tv);
      // Hack for now....
      ACE_OS::sleep (1);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Sender Failed\n");
      return -1;
    }

  SENDER::close ();  // Explicitly finalize the Unmanaged_Singleton.

  return 0;
}
Ejemplo n.º 3
0
int
ACE_TMAIN (int argc,
      ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var obj
        = orb->resolve_initial_references ("RootPOA");

      // Get the POA_var object from Object_var.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      PortableServer::POAManager_var mgr
        = root_poa->the_POAManager ();

      mgr->activate ();

      // Initialize the AVStreams components.
      TAO_AV_CORE::instance ()->init (orb.in (),
                                      root_poa.in ());

      // Initialize the Distributer
      int result =
        DISTRIBUTER::instance ()->init (argc,
                                        argv);

      if (result != 0)
        return result;

      while (!DISTRIBUTER::instance ()->done ())
        {
          orb->perform_work ();
        }

      // Hack for now....
      ACE_OS::sleep (1);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("main");
      return -1;
    }

  DISTRIBUTER::close ();  // Explicitly finalize the Unmanaged_Singleton.

  return 0;
}
Ejemplo n.º 4
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.º 5
0
PortableServer::POA_var MACIContainerServices::createOffShootPOA()
{

	// Check if the POA was already created
	if (!CORBA::is_nil(m_offShootPOA.ptr())) {
		return m_offShootPOA;
	}

  // get the container POA
  PortableServer::POA_var containerPOA = m_poa;

  try{
	  m_offShootPOA = containerPOA->find_POA("OffShootPOA", false);
	  return m_offShootPOA;
  }catch(CORBA::Exception &ex){
	  //if does not exist we just continue and create a new one
  }

  // get the POA Manager
  PortableServer::POAManager_var poaManager = m_poa->the_POAManager();

  //
  // Prepare policies OffShoot POA will be using.
  //
  PortableServer::IdAssignmentPolicy_var offshoot_system_id_policy =
    containerPOA->create_id_assignment_policy(PortableServer::SYSTEM_ID);


  PortableServer::LifespanPolicy_var offshoot_transient_policy =
    containerPOA->create_lifespan_policy(PortableServer::TRANSIENT);


  PortableServer::RequestProcessingPolicy_var offshoot_use_active_object_map_only_policy =
    containerPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);


  PortableServer::ServantRetentionPolicy_var offshoot_servant_retention_policy  =
    containerPOA->create_servant_retention_policy (PortableServer::RETAIN);

  CORBA::PolicyList policiesOffShoot;
  policiesOffShoot.length(4);

  policiesOffShoot[0] = PortableServer::LifespanPolicy::_duplicate(offshoot_transient_policy.in());
  policiesOffShoot[1] = PortableServer::IdAssignmentPolicy::_duplicate(offshoot_system_id_policy.in());
  policiesOffShoot[2] = PortableServer::ServantRetentionPolicy::_duplicate(offshoot_servant_retention_policy.in());
  policiesOffShoot[3] = PortableServer::RequestProcessingPolicy::_duplicate(offshoot_use_active_object_map_only_policy.in());


  m_offShootPOA = containerPOA->create_POA("OffShootPOA",poaManager.in(),policiesOffShoot);
  return m_offShootPOA;
}
Ejemplo n.º 6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    PortableInterceptor::ORBInitializer_var orb_initializer =
      new ServerInitializer;

    PortableInterceptor::register_orb_initializer (orb_initializer.in ());

    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    //Get reference to Root POA
    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

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

    // Create an object
    PortableServer::Servant_var<Messenger_i> messenger_servant = new Messenger_i;

    // Register the servant with the RootPOA, obtain its object
    // reference, stringify it, and write it to a file.
    PortableServer::ObjectId_var oid =
      poa->activate_object( messenger_servant.in() );
    CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
    CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
    std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(ior_output_file) );
    iorFile << str.in() << std::endl;
    iorFile.close();
    std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();
  }

  catch(const CORBA::Exception& ex)
    {
      std::cerr << "Exception in MessengerServer: " << ex << std::endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 7
0
int main (int argc, char *argv[])
{
    try 
    {
      // Initialize orb
      printf("orb init\n");
      CORBA::ORB_var orb = CORBA::ORB_init (argc, (char**)argv);
        
      // Get reference to Root POA.
      printf("resolve_initial_references\n");

      CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
      PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ());

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

      // Create an object
      HelloWorld_impl HelloWorld_servant;

      // Write its stringified reference to stdout
      perf::jitter::HelloWorld_var myInterface = HelloWorld_servant._this ();
      CORBA::String_var str = orb->object_to_string (myInterface.in ());

      FILE* outFile = fopen("ior.txt", "w");
      if (outFile == NULL)
      {
          printf("Error: Cannot open IOR file for writing\n");
      }
      else
      {
          if (fprintf(outFile, "%s\n", str.in ()) <= 0)
          {
              printf("Error: Could not write IOR string to file\n");
          }

          fclose(outFile);
          
          printf("Listening for CORBA requests...\n");
          orb->run();
      }
    }
    catch (const CORBA::Exception &) 
    {
      printf("Uncaught CORBA exception");
    }
	
	return 0;
}
Ejemplo n.º 8
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;
    }
}
Ejemplo n.º 9
0
void CorbaService::run()
{
   vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Server is running!\n"
                                              << vprDEBUG_FLUSH;

//   PortableServer::POAManager_var pman = mChildPOA->the_POAManager();
   PortableServer::POAManager_var pman = mRootPOA->the_POAManager();

   pman->activate();
   mORB->run();
//   mORB->destroy();

   vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Server has shut down\n"
                                              << vprDEBUG_FLUSH;
}
Ejemplo n.º 10
0
void PersistentServantBase::create_user_persistent_POA(const char* POAname)
{
  Object_var poaObj = orb_->resolve_initial_references("RootPOA"); 
  PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj.in());

  PortableServer::POAManager_var poaManager = rootPOA->the_POAManager();
  poaManager->activate();
  PolicyList policyList;
  policyList.length(2);
  policyList[0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
  policyList[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
  defaultPOA_ = rootPOA->create_POA( POAname,
                                     poaManager,
                                     policyList );
}
Ejemplo n.º 11
0
void cnoid::initializeCorbaUtil(CORBA::ORB_ptr orb_, bool activatePOAManager)
{
    if(!orb){
        orb = orb_;
    }

    namingContextHelper.setLocation("localhost", 2809);

    if(activatePOAManager){
        CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj);
        PortableServer::POAManager_var manager = poa->the_POAManager();
        manager->activate();
    }
}
Ejemplo n.º 12
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    //Get reference to Root POA
    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

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

    // Create an object
    Messenger_i messenger_servant (orb.in ());

    // Register the servant with the RootPOA, obtain its object
    // reference, stringify it, and write it to a file.
    PortableServer::ObjectId_var oid =
      poa->activate_object( &messenger_servant );
    CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
    CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
    FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file for writing IOR: %s\n",
                          ior_output_file),
                          1);
    ACE_OS::fprintf (output_file, "%s", str.in ());
    ACE_OS::fclose (output_file);

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

  return 0;
}
Ejemplo n.º 13
0
TAO_BEGIN_VERSIONED_NAMESPACE_DECL

PortableServer::POA_var create_persistent_poa(PortableServer::POA_var root_poa,
                                              PortableServer::POAManager_var mgr,
                                              const char* name,
                                              CORBA::PolicyList& policy_list)
{
  PortableServer::POA_var result;
    PortableServer::LifespanPolicy_var lifespan =
    root_poa->create_lifespan_policy(PortableServer::PERSISTENT);

  // create a USER_ID IdAssignmentPolicy object
  PortableServer::IdAssignmentPolicy_var assign =
    root_poa->create_id_assignment_policy(PortableServer::USER_ID);

  // create PolicyList.
  size_t orig_len =  policy_list.length();
  policy_list.length(orig_len+2);
  policy_list[orig_len+0]=
    PortableServer::LifespanPolicy::_duplicate(lifespan.in());
  policy_list[orig_len+1]=
    PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  // create the child POA
  result = root_poa->create_POA(name, mgr.in(), policy_list);


  return result;
}
Ejemplo n.º 14
0
void
Hello::method (CORBA::Short count)
{
  if (++this->count_ > 10)
    {
      ACE_DEBUG ((LM_DEBUG, "(%P|%t) supplied count = %d\n", count));
      PortableServer::POA_var poa = this->_default_POA();
      PortableServer::POAManager_var mgr = poa->the_POAManager();
      mgr->hold_requests(false);
      // Pass duplicated ptr to a thread and let the thread to free the reference.
      CORBA::ORB_ptr orb = CORBA::ORB::_duplicate (this->orb_.in ());
      ACE_Thread_Manager::instance()->spawn_n (1,
                                               ACE_THR_FUNC (killer),
                                               static_cast<void*> (orb));
    }
}
Ejemplo n.º 15
0
Archivo: corba.cpp Proyecto: golems/ach
static void s_init_send() {
    // First initialize the ORB, that will remove some arguments...
    int argc=1;
    const char *argv[] = {"foo"};
    orb = CORBA::ORB_init (argc, (char**)argv, "my_orb" );

    poa_object = orb->resolve_initial_references ("RootPOA");
    poa = PortableServer::POA::_narrow (poa_object.in ());

    poa_manager = poa->the_POAManager ();

    poa_manager->activate ();

    // Activate it to obtain the object reference
    factory = factory_i._this ();

    // Put the object reference as an IOR string
    CORBA::String_var ior = orb->object_to_string (factory.in ());

    {
        const char *ior_str = ior;
        char buf[strlen(ior_str)+2];
        strcpy(buf, ior_str);
        strcat(buf, "\n");
        ssize_t r = write( ior_pipe[1], buf, strlen(buf) );

        if( strlen(buf) != r ) {
            perror( "could not send data on pipe" );
            abort();
        }
    }
}
Ejemplo n.º 16
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int result = 0;

  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      ACE_DEBUG ((LM_DEBUG,"Client using ior source %s\n", ior));
      CORBA::Object_var server = orb->string_to_object (ior);

      CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
      PortableServer::POA_var root =
        PortableServer::POA::_narrow (obj.in());

      PortableServer::POAManager_var pm = root->the_POAManager();
      pm->activate();
      bool got_reply = false;
      Messaging::ReplyHandler_var callback = new DII_ReplyHandler(got_reply);

      do_primary_test (server,callback);

      for (int i = 0; i < 100 && !got_reply; i++)
        {
          ACE_Time_Value t(0,10000);
          orb->perform_work(t);
        }

      if (do_shutdown)
        result = do_shutdown_test (server);

      ACE_DEBUG ((LM_DEBUG,"Shutting down and destrying ORB.\n"));
      orb->destroy();
      ACE_DEBUG ((LM_DEBUG,"ORB destroyed\n"));
    }
  catch (const ::CORBA::Exception &ex)
    {
      ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
      ++result;
    }
  return result;
}
Ejemplo n.º 17
0
void omnijni::ORB::Init (JNIEnv* env)
{
    // Initialize the ORB with no arguments.
    int argc = 0;
    char** argv = 0;
    orb = CORBA::ORB_init(argc, argv);

    // Automatically activate the root POA manager.
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
    PortableServer::POAManager_var manager = root_poa->the_POAManager();
    manager->activate();

    // Initialize JNI references
    cls_ = omnijni::loadClass(env, "omnijni.ORB");
    object_to_string_ = env->GetStaticMethodID(cls_, "object_to_string", "(Lorg/omg/CORBA/Object;)Ljava/lang/String;");
}
Ejemplo n.º 18
0
int
run(CORBA::ORB_ptr orb, int argc, char* argv[])
{
    //
    // Resolve Root POA
    //
    CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA");
    PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj);
    
    //
    // Get a reference to the POA manager
    //
    PortableServer::POAManager_var manager = rootPOA -> the_POAManager();
    
    //
    // Create implementation object
    //
    Testing_impl* testingImpl = new Testing_impl(rootPOA);
    PortableServer::ServantBase_var servant = testingImpl;
    Testing_var testing = testingImpl->_this();
    
    //
    // Save reference
    //
    CORBA::String_var s = orb->object_to_string(testing);
    
    const char* refFile = "testing.ref";
    ofstream out(refFile);
    if(out.fail())
    {
	cerr << argv[0] << ": can't open `" << refFile << "': "
	     << strerror(errno) << endl;
	return EXIT_FAILURE;
    }

    out << s << endl;
    out.close();
    
    //
    // Run implementation
    //
    manager->activate();
    orb->run();

    return EXIT_SUCCESS;
}
Ejemplo n.º 19
0
void
DAnCE_NodeManager_Module::create_poas (void)
{
  DANCE_TRACE("DAnCE_NodeManager_Module::create_poas");
  // Get reference to Root POA.
  DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE,
                   (LM_TRACE, DLINFO
                    ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ")
                    ACE_TEXT ("Resolving root POA\n")));
  CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA");

  this->root_poa_ = PortableServer::POA::_narrow (obj.in ());

  DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE,
                   (LM_TRACE, DLINFO
                    ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ")
                    ACE_TEXT ("Obtaining the POAManager\n")));
  PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager ();

  TAO::Utils::PolicyList_Destroyer policies (2);
  policies.length (2);

  try
    {
      DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                       (LM_TRACE, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ")
                        ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ")
                        ACE_TEXT ("Creating the \"Managers\" POA.\n")));

      policies[0] = this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);
      policies[1] = this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);
      this->nm_poa_ = this->root_poa_->create_POA ("Managers",
                                       mgr.in(),
                                       policies);
    }
  catch (const PortableServer::POA::AdapterAlreadyExists &)
    {
      DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                       (LM_INFO, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ")
                        ACE_TEXT ("Using existing \"Managers\" POA\n")));
      this->nm_poa_ = this->root_poa_->find_POA ("Managers", 0);
    }
}
Ejemplo n.º 20
0
void OmniORBThread::run()
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(_argc, _argv);

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);

    Echo_i* myecho = new Echo_i();

    PortableServer::ObjectId_var myechoid = poa->activate_object(myecho);

    // Obtain a reference to the object, and register it in
    // the naming service.
    obj = myecho->_this();

    CORBA::String_var x;
    x = orb->object_to_string(obj);
    cout << x << endl;

    if( !bindObjectToName(orb, obj) )
      return;

    myecho->_remove_ref();

    PortableServer::POAManager_var pman = poa->the_POAManager();
    pman->activate();

    orb->run();
  }
  catch(CORBA::SystemException& ex) {
    cerr << "Caught CORBA::" << ex._name() << endl;
  }
  catch(CORBA::Exception& ex) {
    cerr << "Caught CORBA::Exception: " << ex._name() << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }

  //emit finished();
}
Ejemplo n.º 21
0
int
main( int argc, char *argv[] )
{
  try
    {
      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

      //Get reference to Root POA
      CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
      PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

      PortableServer::POAManager_var mgr = poa->the_POAManager();

      // Activate POA Manager
      mgr->activate();

      // Create an object
      GoodDay_i servant;

      // Register the servant with the RootPOA, obtain its object
      // reference, stringify it, and write it to a file.
      obj = poa->servant_to_reference( &servant );

      CORBA::String_var str = orb->object_to_string( obj.in() );
      ofstream iorFile( "IOR" );
      iorFile << str.in() << endl;
      iorFile.close();

      cout << "IOR written to file IOR" << endl;

      // Accept requests
      orb->run();
      orb->destroy();
    }

  catch( const CORBA::Exception &ex )
    {
      cerr << "Uncaught CORBA exception: " << ex <<endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 22
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      TestShutdown killer (orb.in ());

      if (parse_args (argc, argv) != 0)
        return 1;

      CORBA::Object_var pPoaObj =
        orb->resolve_initial_references ("RootPOA");
      PortableServer::POA_var poa =
        PortableServer::POA::_narrow (pPoaObj.in ());
      PortableServer::POAManager_var pMgr = poa->the_POAManager ();
      pMgr->activate ();

      SimpleNamingService_i* servant = new SimpleNamingService_i;
      PortableServer::ObjectId_var oid = poa->activate_object (servant);
      CORBA::Object_var obj = poa->id_to_reference (oid.in ());
      CORBA::String_var str = orb->object_to_string (obj.in ());

      FILE *output_file= ACE_OS::fopen (iorFileName, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s\n",
                           iorFileName),
                           1);
      ACE_OS::fprintf (output_file, "%s", str.in ());
      ACE_OS::fclose (output_file);

      orb->run ();
    }
  catch (CORBA::Exception& ex)
    {
      ACE_DEBUG ((LM_ERROR, "Corba Exception: %s\n", ex._info ().c_str ()));
      return 1;
    }

  return 0;
}
Ejemplo n.º 23
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Get reference to Root POA.
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

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

    // Create an object
    PortableServer::Servant_var<Messenger_i> messenger_servant =
      new Messenger_i;

    // Write its stringified reference to a file
    PortableServer::ObjectId_var oid = poa->activate_object(messenger_servant.in());
    obj = poa->id_to_reference(oid.in());
    Messenger_var messenger = Messenger::_narrow(obj.in());
    CORBA::String_var str = orb->object_to_string(messenger.in());
    std::ofstream fout(ACE_TEXT_ALWAYS_CHAR(ior_output_file));
    fout << str.in() << std::endl;
    fout.close();
    std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA::Exception " << ex << std::endl;
    return 1;
  }

  return 0;
}
Ejemplo n.º 24
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Get a reference to 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 a Logger_i servant.
    PortableServer::Servant_var<Logger_i> logger_servant = new Logger_i;

    // Register the servant with the RootPOA, obtain its object reference,
    // stringify it, and write it to a file.
    PortableServer::ObjectId_var oid = poa->activate_object(logger_servant.in());
    CORBA::Object_var logger_obj = poa->id_to_reference(oid.in());
    CORBA::String_var str = orb->object_to_string(logger_obj.in());
    std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR(ior_output_file));
    iorFile << str.in() << std::endl;
    iorFile.close();
    std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;

    // Accept requests from clients.
    orb->run();

    // Release resources.
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA exception:" << ex << std::endl;
    return 1;
  }
  return 0;
}
Ejemplo n.º 25
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      CORBA::Object_var rootObj = orb->resolve_initial_references("NameService");
      CosNaming::NamingContext_var rootNC =
      CosNaming::NamingContext::_narrow(rootObj.in());

      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
      PortableServer::POAManager_var mgr = poa->the_POAManager();
      mgr->activate();

      PortableServer::Servant_var<Messenger_i> messenger_servant =
        new Messenger_i(orb.in ());
      PortableServer::ObjectId_var oid = poa->activate_object (messenger_servant.in());
      CORBA::Object_var messenger_obj = poa->id_to_reference (oid.in ());
      CORBA::String_var str = orb->object_to_string (messenger_obj.in());

      std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
      iorFile << str.in () << std::endl;
      iorFile.close ();
      std::cout << "IOR written to file " << ior_output_file << std::endl;

      orb->run ();
      orb->destroy ();
    }

  catch(const CORBA::Exception& ex)
  {
      std::cerr << "Caught exception: " << ex << std::endl;
      return 1;
  }

  return 0;
}
Ejemplo n.º 26
0
Archivo: server.cpp Proyecto: CCJY/ATCD
void
createPOAs(ACE_CString &base)
{
  PortableServer::LifespanPolicy_var life =
    root_poa->create_lifespan_policy(PortableServer::PERSISTENT);

  PortableServer::IdAssignmentPolicy_var assign =
    root_poa->create_id_assignment_policy(PortableServer::USER_ID);

  CORBA::PolicyList pols;
  pols.length(2);
  pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in());
  pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in());

  PortableServer::POAManager_var mgr = PortableServer::POAManager::_nil();
  ACE_CString poa_name = base + ACE_CString ("_a");
  poa_a = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
  poa_name = base + ACE_CString ("_b");
  poa_b = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
}
Ejemplo n.º 27
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      MessageFactory::register_new_factory(* orb.in());

      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

      PortableServer::POAManager_var poaman = poa->the_POAManager();

      PortableServer::Servant_var<Messenger_i> svt = new Messenger_i;

      PortableServer::ObjectId_var id = poa->activate_object(svt.in());
      obj = poa->id_to_reference(id.in());
      CORBA::String_var ior = orb->object_to_string(obj.in());
      write_ior(ior.in());

      std::cout << "Starting server." << std::endl;

      poaman->activate();

      orb->run();

      poa->destroy(true, true);
      orb->destroy();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Ejemplo n.º 28
0
int main (int argc, char* argv[])
{
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
    PortableServer::POAManager_var manager = root_poa->the_POAManager();
    manager->activate();

    Writer* writer = new Writer();
    PortableServer::ObjectId_var oid = root_poa->activate_object(writer);
    rawdata::writer_var ref = writer->_this();
    CORBA::String_var ior = orb->object_to_string(ref);
    std::cout << ior << std::endl;

    orb->run();

    orb->shutdown(true);

    orb->destroy();
}
Ejemplo n.º 29
0
int
Locator_Repository::init (PortableServer::POA_ptr root_poa,
                          PortableServer::POA_ptr imr_poa,
                          const char* this_ior)
{
  this->imr_ior_ = this_ior;
  int err = init_repo(imr_poa);
  if (err != 0)
    {
      return err;
    }

  // Activate the two poa managers
  PortableServer::POAManager_var poaman =
    root_poa->the_POAManager ();
  poaman->activate ();
  poaman = imr_poa->the_POAManager ();
  poaman->activate ();

  return err;
}
Ejemplo n.º 30
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try{
    orb = CORBA::ORB_init (argc, argv);


    RtecEventChannelAdmin::EventChannel_var channel
      = get_event_channel (argc, argv);


    if (CORBA::is_nil (channel.in ()))
       return -1;

    PortableServer::POA_var poa =
      resolve_init<PortableServer::POA> (orb.in (), "RootPOA");

    PortableServer::POAManager_var mgr = poa->the_POAManager ();

    mgr->activate ();

    PushSupplier_impl push_supplier(orb.in ());
    if (push_supplier.init(channel.in ()) == -1)
      return -1;

    RtecEventComm::PushSupplier_var
      supplier = push_supplier._this();


    orb->run();

  }
  catch (const CORBA::Exception& ex){
      ex._tao_print_exception ("A CORBA Exception occurred.");
  }


  return 0;
}