예제 #1
0
파일: server.cpp 프로젝트: colding/lorica
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, "Server::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 lorica reference mapper
		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, "Server::Cannot get reference to Lorica reference mapper\n"), 1);
		}

		// getting the original object
		TestServer_impl *server_impl;
		ACE_NEW_RETURN(server_impl, TestServer_impl(orb.in()), 1);
		PortableServer::ServantBase_var receiver_owner_transfer(server_impl);
		UnionTest::TestServer_var server = server_impl->_this();

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

		// narrowing the mapped object
		UnionTest::TestServer_var mappedServer = UnionTest::TestServer::_narrow(obj.in());
		if (CORBA::is_nil(mappedServer.in())) {
			ACE_ERROR_RETURN((LM_ERROR, "Server::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(mappedServer.in());
		ACE_DEBUG((LM_DEBUG,"Server::Size of orig IOR = %d, size of mapped = %d\n", ACE_OS::strlen(orig_ior.in()), ACE_OS::strlen(mapped_ior.in())));

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

		ACE_DEBUG((LM_DEBUG,"Server::Writing original IOR to file %s\n", orig_file));
		output_file = ACE_OS::fopen (orig_file, "w");
		if (output_file == 0) {
			ACE_ERROR_RETURN((LM_ERROR, "Server::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);

		ACE_DEBUG((LM_DEBUG,"Server::Writing mapped IOR to file %s\n", mapped_file));		
		output_file = ACE_OS::fopen(mapped_file, "w");
		if (output_file == 0) {
			ACE_ERROR_RETURN((LM_ERROR, "Server::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);

		poa_manager->activate ();
		orb->run ();

		ACE_DEBUG ((LM_DEBUG, "Server::ORB event loop finished\n"));
		return 0;
	} catch (const CORBA::Exception& ex) {
		ex._tao_print_exception ("Server::Caught Exception => ");
		return 1;
	}
}
예제 #2
0
파일: server.cpp 프로젝트: OspreyHub/ATCD
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;

      Sender *sender_impl = 0;
      ACE_NEW_RETURN (sender_impl,
                      Sender (orb.in ()),
                      1);
      PortableServer::ServantBase_var receiver_owner_transfer(sender_impl);

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

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

      Test::Sender_var sender =
        Test::Sender::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (sender.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 ();

      Server_Task server_task (orb.in (),
                               sender_impl,
                               ACE_Thread_Manager::instance ());

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

      ACE_DEBUG ((LM_DEBUG, "Now terminating test\n"));

      root_poa->destroy (1,
                         1);

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

  return 0;
}
예제 #3
0
파일: server.cpp 프로젝트: asdlei00/ACE
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  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;

      Payload_Receiver *payload_receiver_impl;
      ACE_NEW_RETURN (payload_receiver_impl,
                      Payload_Receiver (orb.in ()),
                      1);
      PortableServer::ServantBase_var receiver_owner_transfer(payload_receiver_impl);

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

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

      Test::Payload_Receiver_var payload_receiver =
        Test::Payload_Receiver::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (payload_receiver.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 ();

      if (payload_receiver_impl->get_count () != 20)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: %d is not the correct "
                      "number of calls\n",
                      payload_receiver_impl->get_count ()));
          ++status;
        }

      root_poa->destroy (1, 1);

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

  return status;
}