Ejemplo n.º 1
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer =
        PortableInterceptor::ORBInitializer::_nil ();

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -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,
                                            "Client ORB");

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

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

      Test_var server =
        Test::_narrow (object.in ());

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

      ::client_test (server.in ());

      ::server_test (server.in ());

      server->shutdown ();

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

  ACE_DEBUG ((LM_INFO,
              "Request interceptor flow test passed.\n"));

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

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

      Test_var server = Test::_narrow (object.in ());

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

      // Make an invocation on the obtained Test object.
      server->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return -1;
    }

  return 0;
}
Ejemplo n.º 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;

    CORBA::Object_var obj = orb->resolve_initial_references("Test");
    ACE_ASSERT (!CORBA::is_nil(obj.in()));
    Test_var test = Test::_narrow( obj.in() );
    ACE_ASSERT (!CORBA::is_nil(test.in()));

    CORBA::Short n = test->get_server_num ();
    ACE_DEBUG ((LM_DEBUG,
                "Client received reply from server %d\n",
                n));
    if (expect_transient)
      return -1;
    return 0;

  }
  catch(const CORBA::TRANSIENT& ex) {
    if (expect_transient)
      return 0;

    ex._tao_print_exception ("client:");
  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception ("client:");
  }
  return -1;
}
Ejemplo n.º 4
0
Archivo: client.cpp Proyecto: CCJY/ATCD
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;

    CORBA::Object_var obj = orb->resolve_initial_references("Test");
    if (CORBA::is_nil(obj.in()))
      {
        ACE_DEBUG ((LM_DEBUG, "Client could not RIR Test\n"));
        return 1;
      }
    Test_var test = Test::_narrow( obj.in() );
    if (CORBA::is_nil(test.in()))
      {
        ACE_DEBUG ((LM_DEBUG, "Client could not narrow Test\n"));
        return 1;
      }

    test->_stubobj()->reset_profiles();

    test->foo ();

    CORBA::Any a;
    a <<= Messaging::SYNC_WITH_SERVER;

    CORBA::PolicyList policy_list (1);
    policy_list.length (1);
    policy_list[0] =
      orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, a);

    obj = test->_set_policy_overrides (policy_list, CORBA::ADD_OVERRIDE);
    test = Test::_narrow ( obj.in());

    test->_stubobj()->reset_profiles();

    test->foo ();

    CORBA::Short n = test->get_call_count();
    ACE_DEBUG ((LM_DEBUG,
                "Got call count of %d\n",
                n));

    return n != 1;

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

  return -1;
}
Ejemplo n.º 5
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;

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t|%T) Client %d sending request to %C\n"),
                  client_num, server_ior));
      try
        {
          CORBA::Object_var obj =
            orb->string_to_object (server_ior);
          ACE_ASSERT (!CORBA::is_nil (obj.in ()));
          Test_var test = Test::_narrow (obj.in());
          ACE_ASSERT (!CORBA::is_nil (test.in()));
          CORBA::Short n = test->get_server_num ();
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t|%T) Client %d received reply from server %d\n"),
                      client_num, n));
        }
      catch (CORBA::TRANSIENT &)
        {
          if (expect_transient)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t|%T) Client %d got expected transient exception\n"),
                          client_num));
            }
          else
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t|%T) Client %d caught unexpected transent\n"),
                          client_num));
              return -1;
            }
        }
      return 0;

    }
  catch(const CORBA::Exception& ex)
    {
      ex._tao_print_exception (ACE_TEXT ("client:"));
    }

  return -1;
}
Ejemplo n.º 6
0
Archivo: client.cpp Proyecto: CCJY/ATCD
void
do_restart_test (void)
{
  CORBA::Object_var obj = orb->string_to_object (ior);
  ACE_ASSERT (!CORBA::is_nil(obj.in ()));
  obj = set_timeout_policy (obj.in (), ACE_Time_Value (5,0));
  Test_var test = Test::_narrow( obj.in () );
  ACE_ASSERT (!CORBA::is_nil(test.in ()));
  int attempt = 2;
  while (attempt > 0)
    {
      try
        {
          test->arm ();
          attempt = 0;
        }
      catch (const CORBA::Exception& ex)
        {
          attempt--;
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("client caught %C during arm, retrying\n"),
                      ex._name ()));
        }
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("client sleeping %d seconds\n"),
              request_delay_secs));
  ACE_OS::sleep (request_delay_secs);

  try
    {
      test->trigger ();
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("client trigger completed\n")));
      return;
    }
  catch (const CORBA::Exception& ex)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("client caught %C during first trigger\n"),
                  ex._name ()));
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("client second trigger\n")));
  test->trigger ();
}
Ejemplo n.º 7
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int result = 0;
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

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

      Test_var server =
        Test::_narrow(tmp.in ());

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

      server->test_method();
      result =0;

      if (shutdown_server)
        {
          server->shutdown ();
        }

      orb->destroy ();
    }
  catch (const CORBA::Exception&)
    {
      result = 1;
    }

  return result;
}
Ejemplo n.º 8
0
void
do_test (void)
{
  CORBA::Object_var obj = orb->string_to_object (ior);
  Test_var test = Test::_narrow( obj.in () );
  ACE_ASSERT (!CORBA::is_nil(test.in ()));

  try
    {
      test->contact ();
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("client contact completed\n")));
      return;
    }
  catch (const CORBA::Exception& ex)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("client caught %C during contact\n"),
                  ex._name ()));
    }
}
Ejemplo n.º 9
0
char *
test_i::
create_and_activate_server()
{
  PortableServer::Servant_var<test_i> impl(
      new test_i (this->orb_.in ()));

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

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

  PortableServer::ObjectId_var id =
    root_poa->activate_object (impl.in ());

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

  Test_var ref = Test::_narrow (object.in ());

  return this->orb_->object_to_string(ref.in());
}
Ejemplo n.º 10
0
int
run_test (CORBA::ORB_ptr orb_ptr,
          int target)
{
  CORBA::ORB_var orb = CORBA::ORB::_duplicate (orb_ptr);
  CORBA::Object_var object;
  try
    {
      if (target == 1)
        {
          object =
            orb->string_to_object (ior1);
        }
      else
        {
          object =
            orb->string_to_object (ior2);
        }

      Test_var server =
        Test::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Object reference is nil\n"),
                          1);

      server->method (0);

      server->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Client-side exception:");
    }
return 0;
}
Ejemplo n.º 11
0
void test_impl(
    CORBA::ORB_ptr orb,
    ACE_TCHAR const * ior,
    bool shutdown)
{
  CORBA::Object_var object = orb->string_to_object(ior);
  Test_var test = Test::_narrow(object.in());

  if(CORBA::is_nil(test.in()))
  {
    throw "Nil reference after narrow";
  }

  for(int i = 0; i != niterations; ++i)
  {
    test->sendc_the_operation(AMI_TestHandler::_nil());
  }

  ACE_Time_Value wait_for_responses_interval(1, 0);
  orb->run(wait_for_responses_interval);

  if (shutdown)
    test->shutdown ();
}
Ejemplo n.º 12
0
Archivo: server.cpp Proyecto: CCJY/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    const ACE_TCHAR *iorfile = ACE_TEXT ("");

    ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:?"));
    int c;

    while ((c = get_opts ()) != -1)
      switch (c)
        {
        case 'o':
          iorfile = get_opts.opt_arg ();
          break;
        case '?':
          ACE_DEBUG ((LM_DEBUG,
                      "usage: %s "
                      "-d <seconds to delay before initializing POA> "
                      "-n Number of the server\n",
                      argv[0]));
          return 1;
          break;
        }

    CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
    root_poa = PortableServer::POA::_narrow (obj.in ());
    //    TAO_Root_POA::imr_client_adapter_name ("Test_Imr_Adapter");

    ACE_CString base = ACE_CString ("TestObject");
    createPOAs (base);

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

    PortableServer::ObjectId_var object_id =
      PortableServer::string_to_ObjectId (base.c_str());

    poa_a->activate_object_with_id (object_id.in(), test_servant.in ());
    obj = poa_a->id_to_reference (object_id.in());

    Test_var tva = Test::_narrow (obj.in());

    if (ACE_OS::strlen (iorfile) > 0)
      {
        CORBA::String_var ior = orb->object_to_string (obj.in());
        FILE *output_file= ACE_OS::fopen (iorfile, "w");
        if (output_file == 0)
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Cannot open output file for writing IOR: %s\n",
                             iorfile),
                            1);
        ACE_OS::fprintf (output_file, "%s", ior.in ());
        ACE_OS::fclose (output_file);
      }

    poa_b->activate_object_with_id (object_id.in(), test_servant.in ());
    obj = poa_b->id_to_reference (object_id.in());

    Test_var tvb = Test::_narrow (obj.in());

    //    object_id = root_poa->activate_object (test_servant.in());

    //
    // This server is now ready to run.
    // This version does not create an IOR
    // file as demonstrated in the
    // Developer's Guide.  It assumes that
    // users create IORs for the client using
    // the tao_imr utility.
    //
    //
    // Stop discarding requests.
    //
    activatePOAs ();

    //
    // 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*> (poa_a.in ());
    ACE_ASSERT (tpoa != 0);

    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(base.c_str (), test_ior.in ());

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

    test_ior = orb->object_to_string (tva.in());
    base += "_a";
    ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in()));
    table->bind (base.c_str (), test_ior.in ());
    base[base.length()-1] = 'b';
    test_ior = orb->object_to_string (tvb.in());
    ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in()));
    table->bind (base.c_str (), test_ior.in ());

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

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

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

  return 0;
}
Ejemplo n.º 13
0
/// Thread entry point
int Client_Task::svc (void)
{
  try
    {
      // Get a ref to the IORManipulation object
      CORBA::Object_var IORM =
        corb_->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
        0);

      // Narrow
      this->iorm_ =
        TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in());

      CORBA::Object_var iogr = make_iogr ("Domain_1", 1, 1);

      CORBA::String_var iorgr_string =
        corb_->object_to_string (iogr.in ());

      CORBA::Object_var object =
        corb_->string_to_object (iorgr_string.in ());

      Test_var server =
        Test::_narrow (object.in ());

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

      CORBA::Object_var remote_server(
        corb_->string_to_object (ACE_TString(file_prefix + this->server_ior_file_).c_str()));

      Test_var remote_server_as_test =
        Test::_narrow (remote_server.in ());

      CORBA::Object_var collocated_server(
        corb_->string_to_object (ACE_TString(file_prefix + this->collocated_ior_file_).c_str()));

      Test_var collocated_server_as_test =
        Test::_narrow (collocated_server.in ());

      if (!collocated_server->_is_collocated())
        { // Collocation is disabled, just skip the test - it has no sense.
          ACE_DEBUG ((LM_ERROR, "Test has no sense, because collocation is disabled.\n") );
        }
      else
        {
          try
          {
            // Following call will fail if the problem is not fixed.

            // Because we are using TRANSIENT objects with the SYSTEM_ID policy
            // the object keys won't match so the POA won't be able to dispatch locally.
            // This wouldn't work with 'direct' collocation strategy but the default is 'through poa'.
            server->myMethod ();
          }
          catch (const CORBA::Exception& ex)
          {
            ex._tao_print_exception ("Exception caught in client task:");
          }
        }

      remote_server_as_test->shutdown();

      collocated_server_as_test->shutdown();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in client task:");
      return 1;
    }

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

      // All factories are kindly provided by
      // compiler so we just to put everything in a right order.

      // Create and register factory for BaseNode.
      BaseNode_init *bn_factory = 0;
      ACE_NEW_RETURN (bn_factory,
                      BaseNode_init,
                      1);

      orb->register_value_factory (bn_factory->tao_repository_id (),
                                   bn_factory);
      bn_factory->_remove_ref (); // release ownership

      // Create and register factory for TreeController.
      TreeController_init *tc_factory = 0;
      ACE_NEW_RETURN (tc_factory,
                      TreeController_init,
                      1);

      orb->register_value_factory (tc_factory->tao_repository_id (),
                                   tc_factory);
      tc_factory->_remove_ref (); // release ownership

      // Create and register factory for StringNode.
      StringNode_init *sn_factory = 0;
      ACE_NEW_RETURN (sn_factory,
                      StringNode_init,
                      1);

      orb->register_value_factory (sn_factory->tao_repository_id (),
                                   sn_factory);
      sn_factory->_remove_ref (); // release ownership

      //Well, done with factories.

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

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

      Test_impl *test_impl;
      ACE_NEW_RETURN (test_impl,
                      Test_impl (orb.in ()),
                      1);

      PortableServer::ServantBase_var owner_transfer(test_impl);

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

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

      Test_var test = Test::_narrow (object.in ());

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

      // If the ior_output_file exists, output the ior to it
      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"));

      root_poa->destroy (1, 1);

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

  return 0;
}
Ejemplo n.º 15
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 obj = orb->string_to_object (ior);

        // force a scope to see the destruction of the server object
        {
            Test_Smart_Factory *test_factory = 0;
            ACE_NEW_RETURN (test_factory,
                            Test_Smart_Factory,
                            -1);

            ACE_UNUSED_ARG (test_factory);

            Test_var server =
                Test::_narrow(obj.in());

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

            server->hello(3);

#if (TAO_HAS_MINIMUM_CORBA == 0)
            // Testing the _non_existent function
            ACE_DEBUG ((LM_DEBUG, "Testing _non_existent()\n"));
            CORBA::Boolean ne =
                server->_non_existent();
            if (ne)
                ACE_ERROR_RETURN ((LM_ERROR,
                                   "Not a Messenger object reference\n"),
                                  1);
            else
                ACE_DEBUG ((LM_DEBUG,"Successfully called _non_existent()\n"));
#endif /* TAO_HAS_MINIMUM_CORBA */

            server->shutdown();

            // The following sleep is a hack to make sure the above oneway
            // request gets sent before we exit. Otherwise, at least on
            // Windows XP, the server may not even get the request.
            ACE_Time_Value tv (0, 100000);
            ACE_OS::sleep(tv);
        }
        // here we should get the smart proxy destructor printout
        if (!dtor_called) {
            ACE_ERROR_RETURN((LM_ERROR,
                              "The Smart proxy is not deleted\n"),1);
        }

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

    return 0;
}
Ejemplo n.º 16
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
#if defined (ACE_WIN32)
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
  cout << "HandleExhaustion test not available on Windows" << endl;
#else
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

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

      Test_var test = Test::_narrow(tmp.in ());

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

      // Try a few times until we run out of "trys" or we no longer get
      // an exception.  Some times it takes a little while to begin
      // accepting again on AIX.
      for(size_t i = 0; i < 10; i++)
        try
          {
            cout << "Client: calling simple, i = " << i << endl;
            // This first invocation will actually cause the connection to
            // the server.  Since the server has run out of file handles,
            // it can not accept the new connection.  On AIX, this will
            // receive a CORBA::COMM_FAILURE exception because it doesn't
            // complete in a timely manner.  It does not mean that the test
            // has failed, as long as the server performs the correct
            // function.
            test->simple ();
            break;
          }
        catch (const CORBA::COMM_FAILURE&)
          {
            cout << "Client: simple raised COMMFAIL, i = " << i << endl;
            ACE_OS::sleep (1);
          }

      cout << "Client: calling simple again" << endl;
      test->simple ();
      cout << "Client: calling shutdown" <<  endl;
      test->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }
#endif /* ACE_WIN32 */
  return 0;
}
Ejemplo n.º 17
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
    {
      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);

      // To use the smart proxy it is necessary to allocate the
      // user-defined smart factory on the heap as the smart proxy
      // generated classes take care of destroying the object. This
      // way it a win situation for the application developer who
      // doesnt have to make sure to destoy it and also for the smart
      // proxy designer who now can manage the lifetime of the object
      // much surely.
      Smart_Test_Factory *test_factory = 0;
      ACE_NEW_RETURN (test_factory,
                      Smart_Test_Factory,
                      -1);

      ACE_UNUSED_ARG (test_factory);

      Test_var server =
        Test::_narrow (object.in ());

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

      try
        {
          CORBA::String_var sm_ior = orb->object_to_string (server.in ());
          if (Smart_Test_Proxy::fake_ior () != sm_ior.in ())
            {
              status = 1;
              ACE_ERROR ((LM_ERROR,
                          "ERROR: The Smart Proxy IOR is:\n%C\n"
                          "but should have been: %C\n",
                          sm_ior.in (),
                          Smart_Test_Proxy::fake_ior ().c_str ()));
            }
        }
      catch (const CORBA::MARSHAL& ex)
        {
          status = 1;
          ex._tao_print_exception ("Unexpected MARSHAL exception:");
        }

      server->method (0);

      server->shutdown ();

      // The following sleep is a hack to make sure the above oneway
      // request gets sent before we exit. Otherwise, at least on
      // Windows XP, the server may not even get the request.
      ACE_Time_Value tv (0, 100000);
      ACE_OS::sleep(tv);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Client-side exception:");
      status = 1;
    }

  return status;
}
Ejemplo n.º 18
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
#if defined (ACE_WIN32)
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
  cout << "HandleExhaustion test not available on Windows" << endl;
#else
  try
    {
#if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
    // We must make sure that our file descriptor limit does not exceed
    // the size allowed (in the fd set) by the reactor.  If it does, this
    // test will fail (in a different way than expected) which is a
    // completely different bug than this test is designed to address
    // (see Bug #3326).
    //
    // We must also make sure that this happens before creating the first
    // ORB.  Otherwise, the reactor will be created with a maximum size of
    // the current rlimit for file desriptors (which will later on be
    // increased).
    rlimit rlim;
    if (ACE_OS::getrlimit(RLIMIT_NOFILE, &rlim) == 0)
      {
        cout << "server evaluating rlimit, cur = "
             << rlim.rlim_cur << " max = " << rlim.rlim_max
             << " reactor max = "
             << ACE_DEFAULT_SELECT_REACTOR_SIZE << endl;
        if (rlim.rlim_cur < static_cast<rlim_t> (ACE_DEFAULT_SELECT_REACTOR_SIZE) &&
            rlim.rlim_max > static_cast<rlim_t> (ACE_DEFAULT_SELECT_REACTOR_SIZE))
          {
            rlim.rlim_cur = ACE_DEFAULT_SELECT_REACTOR_SIZE;
            rlim.rlim_max = ACE_DEFAULT_SELECT_REACTOR_SIZE;
            ACE_OS::setrlimit(RLIMIT_NOFILE, &rlim);
            cout << "server set rlimit_nofile" << endl;
          }
      }
#else
    cout << "server does not support setting rlimit, reactor max = "
         << ACE_DEFAULT_SELECT_REACTOR_SIZE << endl;
#endif /* !ACE_LACKS_RLIMIT && RLIMIT_NOFILE */

    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) Panic: nil RootPOA\n"),
                          1);

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

      Test_i* test_i;
      ACE_NEW_RETURN (test_i,
                      Test_i (orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(test_i);

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

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

      Test_var test = Test::_narrow (object.in ());

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

      // 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 %s for writing IOR: %C\n",
                           ior_output_file,
                           ior.in ()),
                           1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

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

      Descriptors descriptors;
      descriptors.leak (
#ifdef _WRS_KERNEL
                        "server.out");
#else
                        argv[0]);
#endif

      ACE_Time_Value tv (10);
      orb->run (tv);

      cout << "Server: closing some fds" << endl;

      descriptors.allow_accepts ();
      orb->run ();
      orb->destroy ();

      if (!descriptors.ok ())
        {
          cout << "Server: the accept error never occurred" << endl;
          ACE_ERROR_RETURN ((LM_ERROR, "The accept error never occurred\n"), 1);
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }
#endif /* ACE_WIN32 */
  return 0;
}
Ejemplo n.º 19
0
int
Task::svc (void)
{
  try
    {
      // Priority Mapping Manager.
      CORBA::Object_var object =
        this->orb_->resolve_initial_references ("PriorityMappingManager");
      RTCORBA::PriorityMappingManager_var mapping_manager =
        RTCORBA::PriorityMappingManager::_narrow (object.in ());
      if (check_for_nil (mapping_manager.in (), "Mapping Manager") == -1)
        return -1;

      RTCORBA::PriorityMapping *pm =
        mapping_manager->mapping ();

      // RTCurrent.
      object =
        this->orb_->resolve_initial_references ("RTCurrent");
      RTCORBA::Current_var current =
        RTCORBA::Current::_narrow (object.in ());
      if (check_for_nil (current.in (), "RTCurrent") == -1)
        return -1;

      // Obtain Test object reference.
      object =
        this->orb_->string_to_object (ior);
      Test_var server = Test::_narrow (object.in ());
      if (check_for_nil (server.in (), "Test object") == -1)
        return -1;

      // Check that test object is configured with CLIENT_PROPAGATED
      // PriorityModelPolicy.
      CORBA::Policy_var policy =
        server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE);

      RTCORBA::PriorityModelPolicy_var priority_policy =
        RTCORBA::PriorityModelPolicy::_narrow (policy.in ());

      if (check_for_nil (priority_policy.in (), "PriorityModelPolicy") == -1)
        return -1;

      RTCORBA::PriorityModel priority_model =
        priority_policy->priority_model ();
      if (priority_model != RTCORBA::CLIENT_PROPAGATED)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "ERROR: priority_model != "
                           "RTCORBA::CLIENT_PROPAGATED!\n"),
                          -1);

      // Spawn two worker threads.
      ACE_Barrier thread_barrier (2);
      int flags  =
        THR_NEW_LWP |
        THR_JOINABLE |
        this->orb_->orb_core ()->orb_params ()->thread_creation_flags ();

      // Worker 1.
      Worker_Thread worker1 (this->orb_.in (),
                             server.in (),
                             protocol1,
                             &thread_barrier);

      CORBA::Short native_priority1 = 0;
      if (pm->to_native (priority1, native_priority1) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot convert corba priority %d to native priority\n",
                           priority1),
                          -1);

      if (worker1.activate (flags,
                            1, 0,
                            native_priority1) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate first client worker threads\n"),
                          -1);

      // Worker 2.
      Worker_Thread worker2 (this->orb_.in (),
                             server.in (),
                             protocol2,
                             &thread_barrier);

      CORBA::Short native_priority2 = 0;
      if (pm->to_native (priority2, native_priority2) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot convert corba priority %d to native priority\n",
                           priority2),
                          -1);

      if (worker2.activate (flags,
                            1, 0,
                            native_priority2) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate second client worker threads\n"),
                          -1);

      // Wait for worker threads to finish.
      ACE_Thread_Manager::instance ()->wait ();

      // Testing over.  Shut down the server.
      ACE_DEBUG ((LM_DEBUG, "Client threads finished\n"));
      current->the_priority (priority1);
      server->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception in MT_Client_Protocol_Priority test client:");
      return -1;
    }

  return 0;
}
Ejemplo n.º 20
0
Archivo: client.cpp Proyecto: manut/TAO
int
Task::svc (void)
{

  int result = 0;
  try
    {
      CORBA::Object_var object =
        this->orb_->string_to_object (ior);

      Test_var server =
        Test::_narrow (object.in ());

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

      // Check that the object is configured with CLIENT_PROPAGATED
      // PriorityModelPolicy.
      CORBA::Policy_var policy =
        server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE);

      RTCORBA::PriorityModelPolicy_var priority_policy =
        RTCORBA::PriorityModelPolicy::_narrow (policy.in ());

      if (CORBA::is_nil (priority_policy.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "ERROR: Priority Model Policy not exposed!\n"),
                          -1);

      RTCORBA::PriorityModel priority_model =
        priority_policy->priority_model ();

      if (priority_model != RTCORBA::CLIENT_PROPAGATED)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "ERROR: priority_model != "
                           "RTCORBA::CLIENT_PROPAGATED!\n"),
                          -1);

      // Make several invocations, changing the priority of this thread
      // for each.
      object =
        this->orb_->resolve_initial_references ("RTCurrent");

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

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

      RTCORBA::PriorityMappingManager_var mapping_manager =
        RTCORBA::PriorityMappingManager::_narrow (object.in ());

      RTCORBA::PriorityMapping *pm =
        mapping_manager->mapping ();

      int sched_policy =
        this->orb_->orb_core ()->orb_params ()->ace_sched_policy ();

      int max_priority =
        ACE_Sched_Params::priority_max (sched_policy);
      int min_priority =
        ACE_Sched_Params::priority_min (sched_policy);

      CORBA::Short native_priority =
        (max_priority - min_priority) / 2;

      CORBA::Short desired_priority = 0;

      for (int i = 0; i < 3; ++i)
        {
          if (pm->to_CORBA (native_priority, desired_priority) == 0)
            {
              ACE_ERROR ((LM_ERROR,
                           "ERROR: Cannot convert native priority %d to corba priority\n",
                           native_priority));
              result = -1;
              break;
            }

          current->the_priority (desired_priority);

          CORBA::Short priority =
            current->the_priority ();

          if (desired_priority != priority)
            {
              ACE_ERROR ((LM_ERROR,
                               "ERROR: No exception setting the priority but mismatch between requested and returned value from Current. "
                               "Set to %d but Current::the_priority returns %d\n", desired_priority, priority));
              result = -1;
            }


          server->test_method (priority);

          native_priority++;
        }

      // Shut down Server ORB.
      server->shutdown ();
    }
  catch (const CORBA::DATA_CONVERSION& ex)
    {
      ex._tao_print_exception (
                          "Most likely, this is due to the in-ability "
                          "to set the thread priority.");
      return -1;
    }
  catch (const CORBA::Exception & ae)
    {
      ae._tao_print_exception (
                           "Caught exception:");
      return -1;
    }

  return result;
}
Ejemplo n.º 21
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;

    CORBA::Object_var obj = orb->resolve_initial_references("Test");
    Test_var test;

    try
      {
        test = Test::_narrow( obj.in() );
        if (killit)
          {
            test->terminate ();
          }
        else
          {
            CORBA::Short n = test->get_server_num ();
            ACE_DEBUG ((LM_DEBUG,
                        "Client received reply from server %d on first attempt\n",
                        n));
          }
      }
    catch (const CORBA::Exception &ex)
      {
        ex._tao_print_exception ("Client caught: ");
#if 0
        try
          {
            if (CORBA::is_nil (test.in()))
              {
                test = Test::_narrow( obj.in() );
              }
            CORBA::Short n = test->get_server_num ();
            ACE_DEBUG ((LM_DEBUG,
                        "Client received reply from server %d on second attempt\n",
                        n));
          }
        catch (const CORBA::Exception &ex)
          {
            ex._tao_print_exception ("Client second attempt: ");
          }
#endif
      }

    orb->destroy ();

    return 0;
  }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("client:");
    }

  return -1;
}
Ejemplo n.º 22
0
int
ACE_TMAIN(int, ACE_TCHAR *[])
{
  int niterations = 10;
  int norbs = 10;

  try
    {
      for (int i = 0; i != niterations; ++i)
        {
          for (int j = 0; j != norbs; ++j)
            {
              char buf[16];
              ACE_OS::sprintf (buf, "ORB_%4.4d", j);

              int argc = 0;
              ACE_TCHAR **argv = 0;
              CORBA::ORB_var orb =
                CORBA::ORB_init (argc, argv, buf);

              CORBA::Object_var object =
                orb->string_to_object ("DLL:Test_Object");

              Test_var test =
                Test::_narrow (object.in ());

              if (CORBA::is_nil (test.in ()))
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "Nil object reference.\n"),
                                    1);
                }

              CORBA::Long count =
                test->instance_count ();

              if (count != norbs*i + j + 1)
                {
                  ACE_DEBUG ((LM_DEBUG,
                              "Incorrect number of objects "
                              "(%d != %d)\n",
                              count, norbs * i + j + 1));
                }
              test->destroy ();
            }
        }

      for (int j = 0; j != norbs; ++j)
        {
          char buf[16];
          ACE_OS::sprintf (buf, "ORB_%4.4d", j);

          int argc = 0;
          ACE_TCHAR **argv = 0;
          CORBA::ORB_var orb =
            CORBA::ORB_init (argc, argv, buf);

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

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

          poa->destroy (1, 1);

          orb->destroy ();
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("main()");
      return 1;
    }
  return 0;
}
Ejemplo n.º 23
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

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

    CORBA::Object_var obj;

    //Specify the relative round trip policy
    if (rt_timeout_msecs > 0)
      {
        // Timeout specified in hundreds of nanoseconds which is
        // 10000 milliseconds.
        TimeBase::TimeT relative_rt_timeout = rt_timeout_msecs * 10000;

        CORBA::Any relative_rt_timeout_as_any;
        relative_rt_timeout_as_any <<= relative_rt_timeout;
        CORBA::PolicyList policy_list(1);
        policy_list.length(1);
        policy_list[0] =
          orb->create_policy(Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
          relative_rt_timeout_as_any);

        // Apply the policy at the ORB level.
        obj = orb->resolve_initial_references("ORBPolicyManager");
        CORBA::PolicyManager_var policy_manager =
          CORBA::PolicyManager::_narrow(obj.in());
        policy_manager->set_policy_overrides (policy_list, CORBA::ADD_OVERRIDE);

        // Destroy the Policy objects.
        for (CORBA::ULong i = 0; i < policy_list.length(); ++i) {
          policy_list[i]->destroy ();
        }
        policy_list.length(0);
      }

    ///// Get object reference /////
    obj = orb->resolve_initial_references("Test");
    ACE_ASSERT (!CORBA::is_nil(obj.in()));
    Test_var test = Test::_narrow( obj.in() );
    ACE_ASSERT (!CORBA::is_nil(test.in()));

    if (max_tries > 1)
      {
        ACE_DEBUG ((LM_DEBUG,
                    "(%P|%t) Maximum number of tries = %d\n",
                    max_tries));
      }

    CORBA::Short n = 0;
    for (int i = 0; i < max_tries; ++i)
      {
        try
          {
            n = test->get_num_requests (request_delay_secs);
          }
        catch (const CORBA::TIMEOUT &ex)
          {
            ex._tao_print_exception ("timeout exception:");
            if (i == max_tries - 1)
              throw;
          }
      }

    if (n == 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) ERROR: Expected number of requests from "
                           "server to be > 0\n"),
                          -1);
      }
    else
      {
        ACE_DEBUG ((LM_DEBUG,
                    "(%P|%t) Client got back <%d>\n",
                    n));
      }

    // In a per client situation the client has to shutdown the server
    if (shutdown_server)
    {
      test->shutdown();
    }

    orb->destroy ();

    return 0;

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

  return -1;
}
Ejemplo n.º 24
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) Panic: nil RootPOA\n"),
                          1);

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

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

      Test_i *test_impl = new Test_i(orb.in());

      PortableServer::ServantBase_var owner_transfer(test_impl);

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

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

      Test_var test = Test::_narrow (object.in ());

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

      // Output the IOR to the <ior_output_file>
      FILE* file = ACE_OS::fopen(ior_output_file, "w");

      if (file == 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) could not open server.ior\n"),
                          1);
      }

      ACE_OS::fprintf(file, "%s", ior.in ());
      ACE_OS::fclose(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;
}