示例#1
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;
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    try {
        // Initialize the ORB.
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

        // Create a MessengerServer object.
        MessengerServer * server = new MessengerServer (orb.in());
        ACE_Auto_Ptr<MessengerServer> safe_ptr (server);

        // Parse arguments to determine how we should shutdown.
        if (server->parse_args (argc, argv) != 0)
            return 1;

        //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();

        // Create a servant.
        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() );
        std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR (ior_output_file.c_str ()));
        iorFile << str.in() << std::endl;
        iorFile.close();
        std::cout << "IOR written to file " <<
                  ACE_TEXT_ALWAYS_CHAR (ior_output_file.c_str ()) << std::endl;

        switch (s_method)
        {
        // shutdown on client invocation
        case MessengerServer::s_client_call:
            std::cout << "Will shutdown on client invocation." << std::endl;
            server->run ();
            break;

        // shutdown after some iterations through loop
        case MessengerServer::s_polling_loop:
            server->poll (loop_iterations);
            break;

        // schedule a timer to shutdown
        case MessengerServer::s_timer:
            server->schedule_shutdown_timer (timeout);
            server->run ();
            break;

        // shutdown on console input
        case MessengerServer::s_console_input:
            server->shutdown_on_console_input ();
            server->run ();
            break;

        // use CORBA::ORB::run() with time value
        case MessengerServer::s_run_time_value:
            server->run (timeout);
            break;
        }
    }
    catch(const CORBA::Exception& ex) {
        std::cerr << "CORBA exception: " << ex << std::endl;
        return 1;
    }

    return 0;
}
示例#3
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 POA_obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( POA_obj.in() );

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

    // Create an object
    Messenger_i messenger_servant (orb);
    Messenger_var messenger_factory = messenger_servant._this ();

    // In order to allow collocated invocations we need to allow unsecured
    // collocated invocations to the object else our security manager will
    // block the collocated invocation unless you explicitly allow it
    CORBA::Object_var sec_man =
      orb->resolve_initial_references ("SecurityLevel2:SecurityManager");
    SecurityLevel2::SecurityManager_var sec2manager =
      SecurityLevel2::SecurityManager::_narrow (sec_man.in ());
    SecurityLevel2::AccessDecision_var ad_tmp =
      sec2manager->access_decision ();
    TAO::SL2::AccessDecision_var ad =
      TAO::SL2::AccessDecision::_narrow (ad_tmp.in ());
    // Allow unsecured collocated invocations
    ad->default_collocated_decision (true);

    CORBA::String_var ior =
      orb->object_to_string (messenger_factory.in ());

    // If the ior_output_file exists, output the ior to it
    if (ior_output_file != 0)
    {
      FILE *output_file= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file), "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s",
                           ACE_TEXT_ALWAYS_CHAR(ior_output_file)),
                          1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);
    }

    // Accept requests
    orb->run();

    poa->destroy (1, 1);

    orb->destroy();
  }
  catch (const CORBA::Exception&)
  {
    ACE_ERROR((LM_ERROR, "Caught a CORBA exception: "));
    return 1;
  }

  return 0;
}