Exemple #1
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    try
    {
        PortableInterceptor::ORBInitializer_ptr temp_initializer;

        ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -1);  // No exceptions yet!
        PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

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

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

        CORBA::Object_var object =
        orb->string_to_object (ior);

        Test_Interceptors::Visual_var server =
        Test_Interceptors::Visual::_narrow (object.in ());

        if (CORBA::is_nil (server.in ()))
        {
            ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

        ACE_hthread_t threadHandle;
        if ( ACE_Thread::spawn(run_test,
                               static_cast<void*>(server.in()),
                               THR_NEW_LWP | THR_JOINABLE ,
                               0,
                               & threadHandle) == -1 )
        {
           ACE_ERROR_RETURN ((LM_ERROR,"Cannot start thread"), 1);
        }

        ACE_Thread::join (threadHandle);

        server->shutdown ();

        orb->destroy ();
    }

    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("Caught exception in client:");
        return 1;
    }


    return 0;
}
int
TAO_LB_ClientComponent::register_orb_initializer (void)
{
  try
    {
      // Register the LB_ClientComponent ORB initializer.
      PortableInterceptor::ORBInitializer_ptr tmp;
      ACE_NEW_THROW_EX (tmp,
                        TAO_LB_ClientORBInitializer,
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      PortableInterceptor::ORBInitializer_var initializer = tmp;

      PortableInterceptor::register_orb_initializer (initializer.in ());
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unable to register LB_ClientComponent ORB ""initializer.");
      return -1;
    }

  return 0;
}
Exemple #3
0
int
TAO_LB_Component::register_orb_initializer (
  const CORBA::StringSeq & object_groups,
  const CORBA::StringSeq & repository_ids,
  const char * location)
{
  try
    {
      // Register the LB_Component ORB initializer.
      PortableInterceptor::ORBInitializer_ptr tmp;
      ACE_NEW_THROW_EX (tmp,
                        TAO_LB_ORBInitializer (object_groups,
                                               repository_ids,
                                               location),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      PortableInterceptor::ORBInitializer_var initializer = tmp;

      PortableInterceptor::register_orb_initializer (initializer.in ());
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unable to register LB_Component ORB ""initializer.");
      return -1;
    }

  return 0;
}
Exemple #4
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

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

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

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Interop::CDR_Out_Arg_var server =
        Interop::CDR_Out_Arg::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      CORBA::Long lv;
      CORBA::Long_out arg (lv);

      server->get_out (arg);

      ACE_DEBUG ((LM_DEBUG, "first call passed\n"));

      server->get_out (arg);

      ACE_DEBUG ((LM_DEBUG, "second call passed\n"));

      server->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception in client:");
      return 1;
    }

  return 0;
}
Exemple #5
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

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

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

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Test_Interceptors::Visual_var server =
        Test_Interceptors::Visual::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      run_test (server.in ());

      server->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception in client:");
      return 1;
    }

  return 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Create the ORB initializer.
      Server_ORBInitializer *temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer,
                      -1);

      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      // Now initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv,
                                            "Remote_Server_ORB");

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

      if (CORBA::is_nil (poa_object.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             " (%P|%t) Unable to initialize the POA.\n" ),
                             1);
        }

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

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

      poa_manager->activate ();

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

      // Create the interceptor.
      Echo_Server_Request_Interceptor * server_interceptor =
        temp_initializer->server_interceptor();

      if (server_interceptor == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
            "(%P|%t) Could not obtain reference to "
            "server request interceptor.\n"),
            -1);
        }

      // Pull in the ior from the remote server to use as the forward location.
      CORBA::Object_var forward_location = orb->string_to_object (ior_input_file);

      if (CORBA::is_nil (forward_location.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil\n",
                             ior_input_file),
                             1);
        }

      server_interceptor->forward_reference (forward_location.in ());

      Bug1495_i server_impl (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&server_impl);

      CORBA::Object_var test_obj =
        root_poa->id_to_reference (id.in ());

      Bug1495_Regression::Bug1495_var server =
        Bug1495_Regression::Bug1495::_narrow (test_obj.in ());

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

      // Output the server IOR to a file
      if (ior_output_file != 0)
        {
          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 the "
                                 "server IOR: %s", ior_output_file),
                                 1);
            }

          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      ACE_Time_Value tv (15, 0);

      orb->run (tv);

      if (server_interceptor->forward_location_done() == false)
        {
          ACE_ERROR ((LM_ERROR, "ERROR: Forward location has not occurred!\n"));
        }

      ACE_DEBUG ((LM_DEBUG, "Threaded Server event loop finished\n"));
      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught an exception in server:");
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG, "Threaded Server ready\n"));

  return 0;
}
Exemple #7
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int interceptor_type;
  get_interceptor_type (argc, argv, interceptor_type);

  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer (interceptor_type),
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      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");
      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

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

      poa_manager->activate ();

      Secure_Vault_i server_impl (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&server_impl);

      CORBA::Object_var test_obj =
        root_poa->id_to_reference (id.in ());

      Test_Interceptors::Secure_Vault_var server =
        Test_Interceptors::Secure_Vault::_narrow (test_obj.in ());

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

      ACE_DEBUG ((LM_DEBUG,
                  "Test_Interceptors::Secure_Vault: <%s>\n",
                  ior.in ()));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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);
        }

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));

      root_poa->destroy (1, 1);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Exemple #8
0
int
TAO::SSLIOP::Protocol_Factory::register_orb_initializer (
  CSIIOP::AssociationOptions csiv2_target_supports,
  CSIIOP::AssociationOptions csiv2_target_requires)
{
  try
    {
      // @todo: This hard-coding should be fixed once SECIOP is
      // supported.
      // Register the Security ORB initializer.
      PortableInterceptor::ORBInitializer_ptr tmp;
      ACE_NEW_THROW_EX (tmp,
                        TAO::Security::ORBInitializer,
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      PortableInterceptor::ORBInitializer_var initializer = tmp;

  PortableInterceptor::ORBInitializer_ptr temp_dll_initializer =
        PortableInterceptor::ORBInitializer::_nil ();

  ACE_NEW_THROW_EX (temp_dll_initializer,
        PortableInterceptor::DLL_Resident_ORB_Initializer(
  initializer.in (),
  ACE_TEXT ("TAO_Security")),
  CORBA::NO_MEMORY (
  CORBA::SystemException::_tao_minor_code (
  TAO::VMCID,
  ENOMEM),
  CORBA::COMPLETED_NO));

  PortableInterceptor::ORBInitializer_var dll_initializer
  = temp_dll_initializer;

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


      // Register the SSLIOP ORB initializer.
      ACE_NEW_THROW_EX (tmp,
                        TAO::SSLIOP::ORBInitializer (this->qop_,
                                                     csiv2_target_supports,
                                                     csiv2_target_requires),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      initializer = tmp;

  temp_dll_initializer = PortableInterceptor::ORBInitializer::_nil ();

  ACE_NEW_THROW_EX (temp_dll_initializer,
        PortableInterceptor::DLL_Resident_ORB_Initializer(
  initializer.in (),
  ACE_TEXT ("TAO_SSLIOP")),
  CORBA::NO_MEMORY (
  CORBA::SystemException::_tao_minor_code (
  TAO::VMCID,
  ENOMEM),
  CORBA::COMPLETED_NO));

  dll_initializer = temp_dll_initializer;

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

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unable to register SSLIOP ORB initializer.");
      return -1;
    }

  return 0;
}
Exemple #9
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    try
    {
        PortableInterceptor::ORBInitializer_ptr temp_initializer = 0;

        ACE_NEW_RETURN (temp_initializer,
                        Server_ORBInitializer (),
                        -1);  // No exceptions yet!
        PortableInterceptor::ORBInitializer_var initializer =
            temp_initializer;

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

        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 root_poa =
            PortableServer::POA::_narrow (poa_object.in ());

        if (CORBA::is_nil (root_poa.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Panic: nil RootPOA\n"),
                              1);

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

        Hello *hello_impl = 0;
        ACE_NEW_RETURN (hello_impl,
                        Hello (orb.in ()),
                        1);
        PortableServer::ServantBase_var owner_transfer(hello_impl);

        PortableServer::ObjectId_var id =
            root_poa->activate_object (hello_impl);

        CORBA::Object_var object = root_poa->id_to_reference (id.in ());

        Test::Hello_var hello = Test::Hello::_narrow (object.in ());

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

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

        poa_manager->activate ();

        orb->run ();

        ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

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

    return 0;
}
Exemple #10
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (parse_args (argc, argv) == -1)
    return -1;

  server_orb.set ("server_orb");
  client_orb.set ("client_orb");

  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Collocated_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      CORBA::ORB_var sorb =
        CORBA::ORB_init (argc, argv, server_orb.c_str ());

      ACE_Manual_Event me;

      Server_Task server_task (output,
                               sorb.in (),
                               me,
                               ACE_Thread_Manager::instance ());

      if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
                                1,
                                1) == -1)
        {
          ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
        }

      // Wait for the server thread to do some processing
      me.wait ();

      CORBA::ORB_var corb =
        CORBA::ORB_init (argc, argv, client_orb.c_str ());

      Client_Task client_task (input,
                               corb.in (),
                               ACE_Thread_Manager::instance ());

      if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
                                1,
                                1) == -1)
        {
          ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
        }

      ACE_Thread_Manager::instance ()->wait ();
    }
  catch (const CORBA::Exception&)
    {
      // Ignore exceptions..
    }

  return 0;
}
Exemple #11
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int result = 0;
  try
    {
      // Register the interceptors to check for the RTCORBA
      // service contexts in the reply messages.
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      // Initialize and obtain reference to the Test object.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

      // Make sure we can support multiple priorities that are required
      // for this test.
      if (!check_supported_priorities (orb.in ()))
        return 2;

      // Thread Manager for managing task.
      ACE_Thread_Manager thread_manager;

      // Create task.
      Task task (thread_manager,
                 orb.in ());

      // Task activation flags.
      long flags =
        THR_NEW_LWP |
        THR_JOINABLE |
        orb->orb_core ()->orb_params ()->thread_creation_flags ();

      // Activate task.
      result =
        task.activate (flags);
      if (result == -1)
        {
          if (errno == EPERM)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "Cannot create thread with scheduling policy %s\n"
                                 "because the user does not have the appropriate privileges, terminating program....\n"
                                 "Check svc.conf options and/or run as root\n",
                                 sched_policy_name (orb->orb_core ()->orb_params ()->ace_sched_policy ())),
                                2);
            }
          else
            // Unexpected error.
            ACE_ERROR_RETURN ((LM_ERROR,
                                 "ERROR: Cannot create thread. errno = %d\n",
                                 ACE_ERRNO_GET),
                                -1);
        }

      // Wait for task to exit.
      result =
        thread_manager.wait ();
    }
  catch (const CORBA::Exception & ae)
    {
      ae._tao_print_exception (
                           "Caught exception:");
      return -1;
    }

  return result;
}
Exemple #12
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int priority =
    (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
     + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
  // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.

  if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
                                              priority,
                                              ACE_SCOPE_PROCESS)) != 0)
    {
      if (ACE_OS::last_error () == EPERM)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "client (%P|%t): user is not superuser, "
                      "test runs in time-shared class\n"));
        }
      else
        ACE_ERROR ((LM_ERROR,
                    "client (%P|%t): sched_params failed\n"));
    }

  int interceptor_type;
  get_interceptor_type (argc, argv, interceptor_type);

  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer (interceptor_type),
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

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

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

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Test_Interceptors::Secure_Vault_var server =
        Test_Interceptors::Secure_Vault::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      ACE_DEBUG ((LM_DEBUG, "\nFunctionality test begins now...\n"));

      // This test is useful for  benchmarking the differences when
      // the same method is intercepted by different interceptors
      // wanting to achieve different functionality.
      run_test (server.in ());

      server->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
     return 1;
    }

  return 0;
}
Exemple #13
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      {
        PortableInterceptor::ORBInitializer_var initializer (
            new Client_ORBInitializer);
        PortableInterceptor::register_orb_initializer (initializer.in());
      }

      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 root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Panic: nil RootPOA\n"),
                          1);

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

      CORBA::Object_var tmp =
        orb->string_to_object (ior);

      Test::Echo_var echo =
        Test::Echo::_narrow (tmp.in ());

      poa_manager->activate ();

      if (CORBA::is_nil (echo.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Echo reference <%s>\n",
                             ior),
                            1);
        }

      test_synchronous (echo.in ());

      test_ami (orb.in (),
                echo.in ());

      echo->shutdown ();

      orb->destroy ();

      unsigned long request_count =
        Echo_Client_Request_Interceptor::request_count;
      unsigned long response_count =
        Echo_Client_Request_Interceptor::reply_count
        + Echo_Client_Request_Interceptor::other_count
        + Echo_Client_Request_Interceptor::exception_count;

      if (request_count != response_count)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: Mismatched count of requests and responses "
                      " (request = %d, response = %d)\n",
                      request_count, response_count));
        }

      if (request_count == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: No requests handled "));
        }

      if (response_count == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: No response handled "));
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return exit_status;
}
Exemple #14
0
int
main (int argc, char *argv[])
{
  try
    {
      // Create the ORB initializer.
      Server_ORBInitializer *temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer,
                      -1);

      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      // Now initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "");
      CORBA::Object_var poa_object =
				orb->resolve_initial_references("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
			     " (%P|%t) Unable to initialize the POA.\n"),
			    1);
        }

      PortableServer::POA_var root_poa =
	      PortableServer::POA::_narrow (poa_object.in ());

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

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

			// Create the interceptor.
			ForwardTest_Request_Interceptor * server_interceptor =
				temp_initializer->server_interceptor();

      // getting the original oject
      Forward_Test_i *final_impl = new Forward_Test_i(orb.in ());
      PortableServer::ServantBase_var servant = final_impl;
      Forward::Test_var target = final_impl->_this ();

			server_interceptor->forward_reference (target.in());

			Forward_Test_i *server_impl = new Forward_Test_i (orb.in());
      servant = server_impl;
      Forward::Test_var server = server_impl->_this ();

      // getting the mapper object
      CORBA::Object_var obj =
	      orb->string_to_object (lorica_ior);
      Lorica::ReferenceMapper_var mapper =
	      Lorica::ReferenceMapper::_narrow(obj.in());
      if (CORBA::is_nil(mapper.in()))
	      ACE_ERROR_RETURN ((LM_ERROR,
				 "Cannot get reference to Lorica "
				 "reference mapper\n"),1);

      // getting the mapped object
      obj = mapper->as_server(server.in(),"ForwardTest",
			      Lorica::ServerAgent::_nil());
      if (CORBA::is_nil (obj.in()))
	      ACE_ERROR_RETURN ((LM_ERROR,
				 "Lorica reference mapper returned a nil "
				 "mapped reference.\n"),1);

      // narrowing the mapped object
      Forward::Test_var h2 = Forward::Test::_narrow(obj.in());
      if (CORBA::is_nil(h2.in()))
	      ACE_ERROR_RETURN ((LM_ERROR,
				 "Lorica reference mapper returned an "
				 "incorrectly typed reference\n"),1);


      CORBA::String_var orig_ior =
	      orb->object_to_string (server.in ());
      CORBA::String_var mapped_ior =
	      orb->object_to_string (h2.in());

      if (ACE_OS::strcmp (orig_ior.in(), mapped_ior.in()) == 0)
	      ACE_ERROR_RETURN ((LM_ERROR,
				 "Lorica reference mapper returned "
				 "the original reference unmapped.\n"),1);

      ACE_DEBUG ((LM_DEBUG,"writing original IOR to file %s\n",orig_file));
      ACE_DEBUG ((LM_DEBUG,"writing mapped IOR to file %s\n",mapped_file));
      ACE_DEBUG ((LM_DEBUG,"Size of orig IOR = %d, size of mapped = %d\n",
		  ACE_OS::strlen(orig_ior.in()),
		  ACE_OS::strlen(mapped_ior.in())));

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

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

      poa_manager->activate ();

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
    }
  catch (const CORBA::Exception& ex)
	  {
		  ex._tao_print_exception ("Server: exception caught - ");
		  return 1;
	  }

  return 0;
}
Exemple #15
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      int server_num = 0;
      int die_on_ping = 1;
      int ping_count = 0;

      for (int i = 1; i < argc; i++)
        {
          ACE_TCHAR *c = argv[i];
          if (ACE_OS::strcasecmp (ACE_TEXT ("-n"), c) == 0)
            {
              server_num = ACE_OS::atoi (argv[++i]);
            }
          else if (ACE_OS::strcasecmp (ACE_TEXT ("-?"),c) == 0)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("usage: %C ")
                          ACE_TEXT ("-n Number of the server\n"),
                          argv[0]));
              return 1;
            }
        }

      Server_ORBInitializer * temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer (&ping_count),
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

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

      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.in());

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

      ACE_CString poa_name_base = ACE_CString("TestObject_") + toStr (server_num);
      PortableServer::POA_var test_poa;
      test_poa = createPOA(root_poa.in (), true, poa_name_base.c_str ());
      temp_initializer->set_poa (test_poa.in());

      mgr->activate();

      PortableServer::Servant_var<Test_i> test_servant =
        new Test_i(server_num);

      PortableServer::ObjectId_var object_id =
        PortableServer::string_to_ObjectId("test_object");

    //
    // Activate the servant with the test POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    test_poa->activate_object_with_id(object_id.in(), test_servant.in());

    //
    // Create binding between "TestService" and
    // the test object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var test_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name_base.c_str (), test_ior.in());

    ACE_DEBUG ((LM_DEBUG, "Started Server %s \n",
                poa_name_base.c_str()));

    {
      ACE_CString status_file = poa_name_base + ACE_CString(".status");
      ofstream out(status_file.c_str ());
      out << "started" << endl;
    }

    while (ping_count < die_on_ping)
      {
        orb->perform_work ();
      }

    root_poa->destroy(1,1);
    orb->destroy();

  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception ("Server main()");
    return 1;
  }

  return 0;
}