Esempio n. 1
1
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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 ();

      // Policies for the childPOA to be created.
      CORBA::PolicyList policies (1);
      policies.length (1);

      CORBA::Any pol;
      pol <<= BiDirPolicy::BOTH;
      policies[0] =
        orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
                            pol);

      // Create POA as child of RootPOA with the above policies.  This POA
      // will receive request in the same connection in which it sent
      // the request
      PortableServer::POA_var child_poa =
        root_poa->create_POA ("childPOA",
                              poa_manager.in (),
                              policies);

      // Creation of childPOA is over. Destroy the Policy objects.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          policies[i]->destroy ();
        }

      poa_manager->activate ();

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

      Simple_Server_i server_impl (orb.in (),
                                   no_iterations);

      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("simple_server");

      child_poa->activate_object_with_id (id.in (),
                                          &server_impl);

      CORBA::Object_var obj =
        child_poa->id_to_reference (id.in ());

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\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);
        }

      int retval = 0;
      while (retval == 0)
        {
          // Just process one upcall. We know that we would get the
          // clients IOR in that call.
          CORBA::Boolean pending =
            orb->work_pending();

          if (pending)
            {
              orb->perform_work();
            }

          // Now that hopefully we have the clients IOR, just start
          // making remote calls to the client.
          retval = server_impl.call_client ();
        }
      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;
}
Esempio n. 2
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      // ORB.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      // Parse arguments.
      if (parse_args (argc, argv) != 0)
        return -1;

      // RootPOA.
      CORBA::Object_var object =
        orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (object.in ());
      if (check_for_nil (root_poa.in (), "RootPOA") == -1)
        return -1;

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

      // Servant.
      Test_i server_impl (orb.in ());

      // Create Object.
      int result;
      result = create_object (root_poa.in (),
                              orb.in (),
                              &server_impl,
                              ior_output_file);
      if (result == -1)
        return -1;

      // Run ORB Event loop.
      poa_manager->activate ();

      orb->run ();

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

  return 0;
}
Esempio n. 3
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;
}
Esempio n. 4
0
int
Task::svc (void)
{
  try
    {
      CORBA::Object_var object =
        this->orb_->resolve_initial_references("RootPOA");

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

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "ERROR: Panic <RootPOA> is nil\n"),
                          -1);

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

      object = this->orb_->resolve_initial_references ("RTORB");

      RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ());


      object =
        this->orb_->resolve_initial_references ("RTCurrent");

      RTCORBA::Current_var current =
        RTCORBA::Current::_narrow (object.in ());

      // Create POA with CLIENT_PROPAGATED PriorityModelPolicy,
      // and register Test object with it.
      CORBA::PolicyList poa_policy_list;
      poa_policy_list.length (1);
      poa_policy_list[0] =
        rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED,
                                              0);

      PortableServer::POA_var child_poa =
        root_poa->create_POA ("Child_POA",
                              poa_manager.in (),
                              poa_policy_list);

      Test_i server_impl (this->orb_.in ());

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

      CORBA::Object_var server =
        child_poa->id_to_reference (id.in ());

      // Print Object IOR.
      CORBA::String_var ior =
        this->orb_->object_to_string (server.in ());

      ACE_DEBUG ((LM_DEBUG, "Activated as <%s>\n\n", ior.in ()));

      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);
        }

      // Get the initial priority of the current thread.
      CORBA::Short initial_thread_priority =
        get_implicit_thread_CORBA_priority (this->orb_.in ());

      current->the_priority (initial_thread_priority);

      // Run ORB Event loop.
      poa_manager->activate ();

      this->orb_->run ();

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

      // Get the final priority of the current thread.
      CORBA::Short final_thread_priority =
        current->the_priority ();

      if (final_thread_priority != initial_thread_priority)
        ACE_DEBUG ((LM_DEBUG,
                    "ERROR: Priority of the servant thread "
                    "has been permanently changed!\n"
                    "Initial priority: %d  Final priority: %d\n",
                    initial_thread_priority, final_thread_priority));
      else
        ACE_DEBUG ((LM_DEBUG,
                    "Final priority of the servant thread"
                    " == its initial priority\n"));

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

  return 0;
}
Esempio n. 5
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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 ());

      // Get the POAManager of the RootPOA.
      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      poa_manager->activate ();

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

      Simple_Server_i server_impl (orb.in ());

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

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

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\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);
        }

      // RUn the event loop if needed
      if (orb_run)
        {
          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;
}
Esempio n. 6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      Manager manager;

      // Initilaize the ORB, POA etc.
      manager.init (argc, argv);

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

      manager.activate_servant ();

      CORBA::ORB_var orb = manager.orb ();
      CORBA::Object_var server_ref = manager.server ();

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

      FILE *output_file = 0;

      if (proxy_ior != 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Writing the servant locator object ref out to file %s\n",
                      proxy_ior));
          output_file = ACE_OS::fopen (proxy_ior, "w");
          if (output_file == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Cannot open output file for writing IOR: %s",
                               proxy_ior),
                               1);
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      // this is only to shutdown the manager afterwards
      Simple_Server_i server_impl (orb.in ());

      Simple_Server_var server = server_impl._this ();

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      // If the proxy_ior exists, output the ior to it
      if (control_ior != 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Writing the root poa servant server IOR out to file %s\n",
                      control_ior));
          output_file = ACE_OS::fopen (control_ior, "w");
          if (output_file == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Cannot open output file for writing IOR: %s",
                               control_ior),
                               1);
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      manager.run ();
    }
  catch (const CORBA::Exception & ex)
    {
      ex._tao_print_exception ("Exception caught in manager:");
      return -1;
    }

  return 0;
}
Esempio n. 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;
}
Esempio n. 8
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    try
    {
        CORBA::ORB_var orb =
            CORBA::ORB_init (argc, argv);

        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) Unable to initialize the POA.\n"),
                              1);

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

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

        Simple_Server_i server_impl (orb.in ());

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

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

        Simple_Server_var server =
            Simple_Server::_narrow (object.in ());

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

        CORBA::Object_var table_object =
            orb->resolve_initial_references("IORTable");

        IORTable::Table_var table =
            IORTable::Table::_narrow (table_object.in ());
        if (CORBA::is_nil (table.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Unable to initialize the IORTable.\n"),
                              1);
        table->bind ("Simple_Server", ior.in ());

        //ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.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",
                               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"));

        // If expect_servant_calls is 0, it means it's the request forward looping case so the
        // servant continue receiving calls from a single request. We can not determine how many
        // servant calls but it should be more than the number of requests.
        if ((expect_servant_calls == 0 && (server_impl.ncalls () > num_requests))
                || (expect_servant_calls > 0 && (server_impl.ncalls () == expect_servant_calls)))
        {
            return 0;
        }
        else
            ACE_ERROR_RETURN ((LM_ERROR,
                               "server: Test failed - expected %d servant calls but got %d calls \n",
                               expect_servant_calls, server_impl.ncalls ()),
                              1);
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("Exception caught:");
        return 1;
    }

    return 0;
}
Esempio n. 9
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  Fl_Window window(300, 300);
  TAO::FlResource_Loader fl_loader;

  Simple_Window sw (10, 10,
                    window.w () - 20, window.h () - 20);
  window.resizable (&sw);

  window.end ();

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

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

      char* targv[] = { ACE_TEXT_ALWAYS_CHAR (argv[0]) };
      window.show (1, targv);

      sw.show ();

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

      Simple_Server_i server_impl (orb.in (), &sw);

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

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

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\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);
        }

      poa_manager->activate ();

      if (Fl::run () == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Fl::run"), -1);
      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }
  return 0;
}
Esempio n. 10
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  Fixed_Priority_Scheduler* scheduler=0;
  RTScheduling::Current_var current;
  long flags;
  int sched_policy = ACE_SCHED_RR;
  int sched_scope = ACE_SCOPE_THREAD;

  if (sched_policy == ACE_SCHED_RR)
    flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_RR;
  else
    flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_FIFO;

  task_stats.init (100000);

  try
    {
      RTScheduling::Scheduler_var sched_owner;

      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;

      if (enable_dynamic_scheduling)
        {
          CORBA::Object_var manager_obj =
            orb->resolve_initial_references ("RTSchedulerManager");

          TAO_RTScheduler_Manager_var manager =
            TAO_RTScheduler_Manager::_narrow (manager_obj.in ());

          Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type;
          if (enable_yield)
            {
              disp_impl_type = Kokyu::DSRT_CV_BASED;
            }
          else
            {
              disp_impl_type = Kokyu::DSRT_OS_BASED;
            }

          ACE_NEW_RETURN (scheduler,
                          Fixed_Priority_Scheduler (orb.in (),
                                         disp_impl_type,
                                         sched_policy,
                                         sched_scope), -1);
          sched_owner = scheduler;

          manager->rtscheduler (scheduler);

          CORBA::Object_var object =
            orb->resolve_initial_references ("RTScheduler_Current");

          current  =
            RTScheduling::Current::_narrow (object.in ());
        }

      Simple_Server_i server_impl (orb.in (),
                                   current.in (),
                                   task_stats,
                                   enable_yield);

      Simple_Server_var server =
        server_impl._this ();

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\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);
        }

      poa_manager->activate ();

      Worker worker (orb.in ());
      if (worker.activate (flags,
                           nthreads,
                           0,
                           ACE_Sched_Params::priority_max(sched_policy,
                                                          sched_scope)) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "Cannot activate threads in RT class.",
                      "Trying to activate in non-RT class\n"));

          flags = THR_NEW_LWP | THR_JOINABLE | THR_BOUND;
          if (worker.activate (flags, nthreads) != 0)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "Cannot activate server threads\n"),
                                1);
            }
        }

      worker.wait ();

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

      ACE_DEBUG ((LM_DEBUG, "shutting down scheduler\n"));
      scheduler->shutdown ();

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

  ACE_DEBUG ((LM_DEBUG, "Exiting main...\n"));
  task_stats.dump_samples (ACE_TEXT("timeline.txt"),
                           ACE_TEXT("Time\t\tGUID"));
  return 0;
}
Esempio n. 11
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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;

      Simple_Server_i server_impl (orb.in ());

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

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

      Simple_Server_var server = Simple_Server::_narrow (object.in ());

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\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);
        }

      poa_manager->activate ();

      Worker worker (orb.in ());
      if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
                           nthreads) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate client threads\n"),
                          1);

      worker.thr_mgr ()->wait ();

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

      const char *fname = "server_terminated";
      FILE *output_file= ACE_OS::fopen (fname, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing: ",
                           fname),
                          1);
      ACE_OS::fprintf (output_file, "%s", "OK\n");
      ACE_OS::fclose (output_file);
    }
  catch (CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Esempio n. 12
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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;

      Simple_Server_i server_impl (orb.in ());

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

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

      Simple_Server_var server = Simple_Server::_narrow (object.in ());

      CORBA::String_var local_ior = orb->object_to_string (server.in ());
      ACE_DEBUG ((LM_DEBUG,
                  "Client interface started on <%C>\n",
                  local_ior.in ()));
      CORBA::Object_var remote_object = orb->string_to_object (ior);

      Simple_Server_var remote_server =
        Simple_Server::_narrow (remote_object.in ());

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

      if (do_shutdown)
        {
          remote_server->shutdown ();
        }
      else
        {
          poa_manager->activate ();
          Worker worker (orb.in ());
          if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
                               1) != 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Cannot activate client thread\n"),
                              1);
          ACE_DEBUG ((LM_DEBUG, "ORB Thread started\n"));
          CORBA::String_var str = remote_server->test_method (server.in ());
          ACE_DEBUG ((LM_DEBUG, "Received \"%C\"\n", str.in ()));
          orb->shutdown (true);
          worker.thr_mgr ()->wait ();
          ACE_DEBUG ((LM_DEBUG, "ORB Thread completed\n"));
        }
      orb->destroy ();
    }
  catch (CORBA::Exception& ex)
    {
      ACE_DEBUG ((LM_ERROR, ACE_TEXT ("(%P|%t) Exception caught: \n%s\n"),
                  ACE_TEXT_CHAR_TO_TCHAR (ex._info ().c_str ())));
      return 1;
    }

  return 0;
}
Esempio n. 13
0
File: server.cpp Progetto: manut/TAO
int
Task::svc (void)
{
  try
    {
      // RTORB.
      CORBA::Object_var object =
        this->orb_->resolve_initial_references ("RTORB");
      RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ());
      if (check_for_nil (rt_orb.in (), "RTORB") == -1)
        return -1;

      // RootPOA.
      object =
        this->orb_->resolve_initial_references("RootPOA");
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (object.in ());
      if (check_for_nil (root_poa.in (), "RootPOA") == -1)
        return -1;

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

      // Create child POA with SERVER_DECLARED PriorityModelPolicy,
      // and MULTIPLE_ID id uniqueness policy (so we can use one
      // servant to create several objects).
      CORBA::PolicyList poa_policy_list;
      poa_policy_list.length (2);
      poa_policy_list[0] =
        rt_orb->create_priority_model_policy (RTCORBA::SERVER_DECLARED,
                                              poa_priority);

      poa_policy_list[1] =
        root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);

      PortableServer::POA_var child_poa =
        root_poa->create_POA ("Child_POA",
                              poa_manager.in (),
                              poa_policy_list);

      RTPortableServer::POA_var rt_poa =
        RTPortableServer::POA::_narrow (child_poa.in ());
      if (check_for_nil (rt_poa.in (), "RTPOA") == -1)
        return -1;

      // Servant.
      Test_i server_impl (this->orb_.in ());

      // Create object 1 (it will inherit POA's priority).
      int result;
      ACE_DEBUG ((LM_DEBUG, "\nActivated object one as "));
      result = create_object (rt_poa.in (), this->orb_.in (), &server_impl,
                              -1, ior_output_file1);
      if (result == -1)
        return -1;

      // Create object 2 (override POA's priority).
      ACE_DEBUG ((LM_DEBUG, "\nActivated object two as "));
      result = create_object (rt_poa.in (), this->orb_.in (), &server_impl,
                              object_priority, ior_output_file2);
      if (result == -1)
        return -1;

      // Activate POA manager.
      poa_manager->activate ();

      // Start ORB event loop.
      this->orb_->run ();

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

  return 0;
}
Esempio n. 14
0
int
main (int argc, char *argv[])
{
	try
	{
		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;
		}

		// 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 ServerAgent callback
		ServerAgent_i server_agent_impl (mapper);
		Lorica::ServerAgent_var  server_agent =
			server_agent_impl._this ();

		// getting the original oject
		Simple_Server_i server_impl (orb.in (), &server_agent_impl,  timeout);
		Simple_Server_var server =
			server_impl._this ();


		// getting the mapped object
		obj = mapper->as_server(server.in(),"SimpleServer",
					server_agent.in ());
		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
		Simple_Server_var h2 = Simple_Server::_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);

		server_agent_impl.add_managed_ref (&server_impl, obj.in());

		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;
}
Esempio n. 15
0
int
server_main (int argc,
             ACE_TCHAR *argv[],
             Test::Server_Request_Interceptor *cri)
{

#if TAO_HAS_TRANSPORT_CURRENT == 1

  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Test::Server_ORBInitializer (cri),
                      -1);  // No exceptions yet!

      PortableInterceptor::ORBInitializer_var orb_initializer (temp_initializer);

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


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

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

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

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Server (%P|%t) Unable to obtain")
                           ACE_TEXT (" RootPOA reference.\n")),
                          -1);

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

      poa_manager->activate ();

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

      Current_Test_Impl server_impl (orb.in (),
                                     root_poa.in (),
                                     use_collocated_call);

      obj = server_impl._this ();

      Test::Transport::CurrentTest_var server =
        Test::Transport::CurrentTest::_narrow (obj.in ());

      if (CORBA::is_nil (server.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Server (%P|%t) Unable to obtain ")
                           ACE_TEXT ("reference to CurrentTest object.\n")),
                          -1);

      CORBA::String_var ior =
        orb->object_to_string (server.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,
                               "Server (%P|%t) Cannot write %s "
                               "IOR: %C - %m",
                               ior_output_file,
                               ior.in ()),
                              -1);
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      // Spawn a number of clients doing the same thing for a
      // predetermined number of times
      Worker worker (orb.in ());

#if defined (ACE_HAS_THREADS)
      if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
                           nthreads) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Server (%P|%t) Cannot activate %d threads\n"),
                           nthreads),
                          -1);
      //FUZZ: disable check_for_lack_ACE_OS
      if(worker.thr_mgr ()->wait () != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Server (%P|%t) wait() Cannot wait for all %d threads\n"),
                           nthreads),
                          -1);
      //FUZZ: enable check_for_lack_ACE_OS
#else
      if (nthreads > 1)
        ACE_ERROR ((LM_WARNING,
                    ACE_TEXT ("Server (%P|%t) Cannot use threads other than ")
                    ACE_TEXT ("the only one available.\n")));
      worker.svc ();
#endif

      if (TAO_debug_level >= 1)
        ACE_DEBUG ((LM_INFO, ACE_TEXT ("Server (%P|%t) Event loop finished.\n")));

      if (!cri->self_test ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Server (%P|%t) ERROR: Interceptor self_test failed\n")));

      root_poa->destroy (1, 1);

      server->shutdown ();

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Server (%P|%t) Invoking orb->destroy ()\n")));

      orb->destroy ();

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (ACE_TEXT ("Server (%P|%t) ERROR: "));

      return -1;
    }

  ACE_DEBUG ((LM_INFO, ACE_TEXT ("Server (%P|%t) Completed successfuly.\n")));
  return 0;
#else /*  TAO_HAS_TRANSPORT_CURRENT == 1 */
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("Server (%P|%t) Need TAO_HAS_TRANSPORT_CURRENT enabled to run.\n")));
  return 0;
#endif /*  TAO_HAS_TRANSPORT_CURRENT == 1 */
}