Example #1
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 object =
      orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow (object.in ());
    PortableServer::POAManager_var poa_manager =
      rootPOA->the_POAManager ();

    CORBA::PolicyList policies (5);
    policies.length (5);

    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );

    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);

    PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA",
        poa_manager.in (),
        policies
        );
    PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC",
        poa_manager.in (),
        policies
        );

    for (CORBA::ULong i = 0;
      i < policies.length ();
      ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    Test_Time_i* time = new Test_Time_i();

    PortableServer::ObjectId_var oid =
      PortableServer::string_to_ObjectId ("Server_A");
    poa_a->activate_object_with_id (oid.in (), time);
    CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in());
    CORBA::String_var ior =
      orb->object_to_string (time_obj.in ());

    poa_manager->activate ();

    FILE *output_file = ACE_OS::fopen (pid_file, ACE_TEXT ("w"));
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Cannot open output file for writing IOR: %s\n"),
                         pid_file),
                        1);
    int pid = static_cast<int> (ACE_OS::getpid ());
    ACE_OS::fprintf (output_file, "%d\n", pid);
    ACE_OS::fclose (output_file);

    orb->run ();

    rootPOA->destroy (1, 1);
    orb->destroy ();
  }
  catch (const CORBA::Exception &ex)
  {
    ex._tao_print_exception (ACE_TEXT ("server:"));
    return 1;
  }

  return 0;
}
Example #2
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 object =
      orb->resolve_initial_references ("RootPOA");

    ORB_Task worker (orb.in ());
    worker.activate (THR_NEW_LWP | THR_JOINABLE,
                      1);

    PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow (object.in ());
    PortableServer::POAManager_var poa_manager =
      rootPOA->the_POAManager ();

    CORBA::PolicyList policies (5);
    policies.length (5);

    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );

    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);

    if (server_notify_delay > 0)
    {
      ACE_OS::sleep (server_notify_delay);
      ACE_DEBUG ((LM_DEBUG, "(%P|%t)ServerB Now register with IMR \n"));
    }

    PortableServer::POA_var poa_a = rootPOA->create_POA ("poaB",
        poa_manager.in (),
        policies
        );

    for (CORBA::ULong i = 0;
      i < policies.length ();
      ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    Test_Dummy_i* dummy = new Test_Dummy_i();

    PortableServer::ObjectId_var oid =
      PortableServer::string_to_ObjectId ("Server_B");
    poa_a->activate_object_with_id (oid.in (), dummy);
    CORBA::Object_var dummy_obj = poa_a->id_to_reference(oid.in());
    CORBA::String_var ior =
      orb->object_to_string (dummy_obj.in ());

    poa_manager->activate ();

    // Output the IOR to the <ior_output_file>
    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",
      ior_output_file),
      1);
    ACE_OS::fprintf (output_file, "%s", ior.in ());
    ACE_OS::fclose (output_file);

    worker.wait ();

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

  return 0;
}
Example #3
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    CORBA::ORB_var orb;

    try {
        // Initialize orb
        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 ());

        // Get POA manager
        PortableServer::POAManager_var poa_mgr = poa->the_POAManager ();

        // Create a policy list. We use persistent objects with
        // user-assigned IDs, and explicit activation.
        CORBA::PolicyList policy_list;
        policy_list.length (6);
        policy_list[0] = poa->create_lifespan_policy (
                             PortableServer::TRANSIENT   // REVISIT
                         );
        policy_list[1] = poa->create_id_assignment_policy (
                             PortableServer::USER_ID
                         );
        policy_list[2] = poa->create_implicit_activation_policy (
                             PortableServer::NO_IMPLICIT_ACTIVATION
                         );
        policy_list[3] = poa->create_request_processing_policy (
                             PortableServer::USE_SERVANT_MANAGER
                         );
        policy_list[4] = poa->create_servant_retention_policy (
                             PortableServer::NON_RETAIN
                         );
        policy_list[5] = poa->create_thread_policy (
                             PortableServer::SINGLE_THREAD_MODEL
                         );

        // Create a POA for all CCS elements.
        PortableServer::POA_var ccs_poa
            = poa->create_POA ("CCS_POA", poa_mgr.in (), policy_list);

        // Create a controller and set static m_ctrl member
        // for thermostats and thermometers.
        Controller_impl ctrl_servant (ccs_poa.in (), "/tmp/CCS_assets");
        Thermometer_impl::m_ctrl = &ctrl_servant;

        // Create a reference for the controller and
        // create the corresponding CORBA object.
        PortableServer::ObjectId_var oid
            = PortableServer::string_to_ObjectId (Controller_oid);
        CORBA::Object_var ctrl
            = ccs_poa->create_reference_with_id (
                  oid.in (), "IDL:acme.com/CCS/Controller:1.0"
              );

        // Get reference to initial naming context.
        CosNaming::NamingContext_var inc
            = resolve_init<CosNaming::NamingContext> (
                  orb.in (), "NameService"
              );

        // Attempt to create CCS context.
        CosNaming::Name n;
        n.length (1);
        n[0].id = CORBA::string_dup ("CCS");
        try {
            CosNaming::NamingContext_var nc
                = inc->bind_new_context (n);
        } catch (const CosNaming::NamingContext::AlreadyBound &) {
            // Fine, CCS context already exists.
        }

        // Force binding of controller reference to make
        // sure it is always up-to-date.
        n.length (2);
        n[1].id = CORBA::string_dup ("Controller");
        inc->rebind (n, ctrl.in ());

        // Instantiate the servant locator for devices.
        PortableServer::ServantManager_var locator =
            new DeviceLocator_impl (&ctrl_servant);

        // Set servant locator.
        ccs_poa->set_servant_manager (locator.in ());

        // Activate the POA manager.
        poa_mgr->activate ();

        // Accept requests
        orb->run ();
    }
    catch (const CORBA::Exception & e) {
        std::cerr << "Uncaught CORBA exception: "
                  << e
                  << std::endl;
        return 1;
    }
    catch (...) {
        assert (0);  // Uncaught exception, dump core
    }
    return 0;
}
Example #4
0
File: server.cpp Project: manut/TAO
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 poa_object =  orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var rootPOA =  PortableServer::POA::_narrow (poa_object.in ());
    PortableServer::POAManager_var poa_manager =  rootPOA->the_POAManager ();

    // Policies for the firstPOA to be created.
    CORBA::PolicyList policies (5);
    policies.length (5);
    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT );

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );


    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL  );

    PortableServer::POA_var demoPOA
      = rootPOA->create_POA ("HelloWorldServer",
                              poa_manager.in (),
                              policies
                              );

    for (CORBA::ULong i = 0;
        i < policies.length ();
        ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    // Create object for shutdown commanded by client.
    {
        // create the object
        Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in());

        // Get the Object ID.
        PortableServer::ObjectId_var oid =  PortableServer::string_to_ObjectId ("shutdown");
        demoPOA->activate_object_with_id (oid.in (),  hello);


        // Create an object reference.
        CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in());

        // Put the object reference as an IOR string
        ofstream out(ACE_TEXT_ALWAYS_CHAR (shutdown_ior_output_file));
        CORBA::String_var ior = orb->object_to_string (myhello.in ());
        out  << ior.in();
        // save the reference into a file
        out.close();
    }

    // Create object to handle client sayHello requests.
    {
        // create the object
        Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in());

        // Get the Object ID.
        PortableServer::ObjectId_var oid =  PortableServer::string_to_ObjectId ("hello");
        demoPOA->activate_object_with_id (oid.in (),  hello);


        // Create an object reference.
        CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in());

        // Put the object reference as an IOR string
        ofstream out(ACE_TEXT_ALWAYS_CHAR (ior_output_file));
        CORBA::String_var ior = orb->object_to_string (myhello.in ());
        out  << ior.in();
        // save the reference into a file
        out.close();
    }



    //////////////////////////////////////////////////////////////////////////////////////////////////
    poa_manager->activate ();

    std::cout << ior_output_file << " is ready " << std::endl;
    orb->run ();


    // Destroy the POA, waiting until the destruction terminates
    rootPOA->destroy (1, 1);
    orb->destroy ();
  }
  catch (const CORBA::Exception &e)
  {
    std::cerr << "Unexpected exception: " << e << std::endl;
    return 1;
  }

  return 0;
}
Example #5
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);

	//
	// Create Persistent POA
	//
	CORBA::PolicyList pl;
	pl.length (4);
 	pl[0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
  	pl[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
  	pl[2] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
  	pl[3] = rootPOA->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);

	//
	// Get a reference to the POA manager
	//
	PortableServer::POAManager_var manager = rootPOA -> the_POAManager();

	//
	// Create Persistent POA
	//
	PortableServer::POA_var stapoa = rootPOA->create_POA ("stapoa",manager,pl) ;

	//
	// Resolve the BootManager and register the server
	//
	CORBA::Object_var obj = orb -> resolve_initial_references("BootManager");
	OB::BootManager_var bootManager = OB::BootManager::_narrow(obj);
	
	//
	// Create implementation object
	//
	Hello_impl* helloImpl = new Hello_impl(stapoa);
	PortableServer::ServantBase_var servant = helloImpl;
	PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("Hello");
	stapoa->activate_object_with_id(oid, servant);
	Hello_var hello = helloImpl -> _this();

	//
	// add binding to  BootManager
	//
	bootManager -> add_binding(oid, hello);

	//
	// Save reference
	//
	CORBA::String_var s = orb -> object_to_string(hello);

	const char* refFile = "Hello.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;
}