Esempio n. 1
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. 2
0
File: server.cpp Progetto: manut/TAO
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
#if TAO_HAS_INTERCEPTORS == 1
      bool destroy_called = false;

      Server_ORBInitializer *temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer (destroy_called),
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());
#endif /* TAO_HAS_INTERCEPTORS == 1 */

      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "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;

      test_i servant (orb.in ());

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

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

      CORBA::Object_var obj =
        CORBA::Object::_narrow (object.in ());

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

      ACE_DEBUG ((LM_DEBUG,
                  "test servant: <%C>\n",
                  ior.in ()));

      // Write IOR to a file.
      FILE *output_file= ACE_OS::fopen (ior_file, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file <%s> for writing "
                           "IOR: %C",
                           ior_file,
                           ior.in ()),
                          1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      // Run the ORB event loop.
      orb->run ();

      root_poa->destroy (1, 1);

      orb->destroy ();

#if TAO_HAS_INTERCEPTORS == 1
      ACE_TEST_ASSERT (destroy_called == true);
#endif

      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. 3
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;
}
Esempio n. 4
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;
}