int acscomponentTestServer (char *szCmdLn)
{
  int  argc;
  char *argv[100];

  argc = argUnpack(szCmdLn, argv);
  argv[0] = "acscomponentTestServer";
#else
int main(int argc, char* argv[]) 
{
#endif // defined( MAKE_VXWORKS )

 
  // creating ORB
  ACS_TEST_INIT_CORBA;


  try
    {
    ACE_OS::signal(SIGINT,  TerminationSignalHandler);  // Ctrl+C
    ACE_OS::signal(SIGTERM, TerminationSignalHandler);  // termination request

      //Get a reference to the RootPOA
      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      
      PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
      
   
      PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      

      // The component will throw an exception if receives a NULL ContainerServices
      // in the constructor.
      // We pass a value only to avoid that i throws the exception. On the other 
      // hand the test doe not use the ContainerServices (remember: ContainerServices
      // does not yet exist at this point!!!!)
      ACE_CString compName("TEST");
      ACSComponentTestClassImpl mytestImpl(compName.c_str(), new TestContainerServices(compName,NULL));
      ACSCOMPONENT_TEST::ACSComponentTestClass_var mytest = mytestImpl._this ();;
      


      poa_manager->activate ();
      
      ACS_DEBUG ("acscomponentTestServer","POA Manager -> activate");

      ACS_DEBUG ("acscomponentTestServer", "Writing ior to the file: ACSCOMPONENTTEST1");
      char* ior =  orb->object_to_string (mytest.in());
      
      
      char fileName[64];
      sprintf(fileName, "%s.ior", "ACSCOMPONENTTEST1");
      FILE *output_file = ACE_OS::fopen (fileName, "w");
      if (output_file == 0) {
	ACS_SHORT_LOG((LM_ERROR, "Cannot open output files for writing IOR: ior.ior"));
	return -1;
      }

      int result = ACE_OS::fprintf (output_file, "%s", ior);
      if (result < 0) {
	ACE_ERROR_RETURN ((LM_ERROR, "ACE_OS::fprintf failed while writing %s to ior.ior", ior), -1);
      }

      ACE_OS::fclose (output_file);
      
      ACS_DEBUG ("acscomponentTestServer", "Waiting for requests ...");
      orb->run ();
      
    }

  catch( CORBA::Exception &_ex )
    {
      _ex._tao_print_exception("EXCEPTION CAUGHT");
      return -1;
    }

  //    orb->shutdown(true); //wait until all requests have completed

  return 0;


}
示例#2
0
int acserrTestServer (char *szCmdLn){
    ACE_OS_Object_Manager ace_os_object_manager;
    ACE_Object_Manager ace_object_manager;
  int  argc;
  char *argv[100];

  argc = argUnpack(szCmdLn, argv);
  argv[0] = "errorServer";
#else
  int acserrTestServer (int argc, char *argv[]){
#endif // defined( MAKE_VXWORKS )

  

  if (argc<2){
    ACE_OS::printf ("usage: errorServer <server_name> [destination_server_name] \n");
    return -1;
  }

  ACE_OS::signal(SIGINT,  TerminationSignalHandler);  // Ctrl+C
  ACE_OS::signal(SIGTERM, TerminationSignalHandler);  // termination request

  // create logging proxy
  LoggingProxy m_logger (0, 0, 31, 0);
  LoggingProxy::init (&m_logger); 

  // creating ORB
  ACS_TEST_INIT_CORBA;

  // init ACS error system (and inside also logging)
//  ACSError::init (orb.ptr());

  try
  {
      //Get a reference to the RootPOA
      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      
      PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
      
   
      PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      

#ifdef MAKE_VXWORKS      
      ErrorTraceHelper::setProcessName (szCmdLn);
#else 
      char *buf;
      ACE_OS::argv_to_string (argv, buf);
      ACSError::setProcessName (buf); // = ErrorTraceHelper::setProcessName (buf);
      delete[] buf;
#endif      
      ACS_DEBUG ("errorServer", "Creating test object ...");
      acserrTest_var dest;
      
      if (argc>2){
	ACS_DEBUG ("errorServer", "Getting object reference ... ");
	char refName[64];
	sprintf(refName, "file://%s.ior", argv[2]);
	CORBA::Object_var destObj = orb->string_to_object (refName);
	

	ACS_DEBUG ("errorServer", "Narrowing it .... ");
	dest = acserrTest::_narrow (destObj.in());
      }//if

      acserrTestImpl  esTest (dest.in(), argv[1]);
      acserrTest_var testObj = esTest._this ();
      
           
      poa_manager->activate ();
      
      ACS_DEBUG ("errorServer","POA Manager -> activate");
      
      ACS_DEBUG_PARAM ("errorServer", "Writing ior to the file: %s .... ", argv[1]);
      char* ior =  orb->object_to_string (testObj.in());
      
      
      char fileName[64];
      sprintf(fileName, "%s.ior", argv[1]);
      FILE *output_file = ACE_OS::fopen (fileName, "w");
      if (output_file == 0) {
	ACS_SHORT_LOG((LM_ERROR,
			   "Cannot open output files for writing IOR: ior.ior"));
	return -1;
      }

      int result = ACE_OS::fprintf (output_file, "%s", ior);
      if (result < 0) {
	ACS_SHORT_LOG ((LM_ERROR,
			   "ACE_OS::fprintf failed while writing %s to ior.ior", ior));
	return  -1;
      }

      ACE_OS::fclose (output_file);
      
      ACS_DEBUG ("errorServer", "Waiting for requests ...");
      orb->run ();
      
  }
  catch( CORBA::Exception &ex )
  {
  ex._tao_print_exception("EXCEPTION CAUGHT");
    return -1;
  }

//  orb->shutdown(true); //wait until all requests have completed

  LoggingProxy::done();
  std::cout << std::flush;
  sleep(3);
  return 0;
}//startErrorServer


#ifndef MAKE_VXWORKS
int main(int argc, char *argv[])
{
  return acserrTestServer (argc, argv); 
}
示例#3
0
int acslogErrorServer (char *szCmdLn){
  int  argc;
  char *argv[100];

  argc = argUnpack(szCmdLn, argv);
  argv[0] = " acslogErrorServer";
#else
  int acslogErrorServer (int argc, char *argv[]){
#endif // defined( MAKE_VXWORKS )

  CORBA::ORB_var orb;
  

  if (argc<2){
    ACE_OS::printf ("usage: acslogErrorServer <server_name> [destination_server_name] \n");
    return -1;
  }
  
  try
    {
      // Initialize the ORB
      ACS_DEBUG(" acslogErrorServer", "Initialising ORB ... ");
      orb = CORBA::ORB_init (argc, argv, 0);
      ACS_DEBUG ("acslogErrorServer", "ORB initialsed !");
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION (ex, "Failed to initalise ORB");
      return -1;
    }

  // create logging proxy
  ACS_DEBUG (" acslogErrorServer", "Creating logging proxy ... ");
  LoggingProxy *m_logger = new LoggingProxy(0, 0, 31, 0);
  LoggingProxy::init (m_logger);  
  ACS_DEBUG (" acslogErrorServer", "Logging proxy successfully created !");

  try
    {

      //Naming Service 
      ACS_DEBUG (" acslogErrorServer", "Resolving  Naming service ... ");
      ACE_CString nameService;
      nameService +="corbaloc::";
      nameService += ACSPorts::getIP();
      nameService += ":"; 
      nameService += ACSPorts::getNamingServicePort().c_str();
      nameService += "/"; 
      nameService += acscommon::NAMING_SERVICE_NAME;

      CORBA::Object_var naming_obj = orb->string_to_object(nameService.c_str());
      if (!CORBA::is_nil (naming_obj.in ()))
	{
	  CosNaming::NamingContext_var naming_context =
	    CosNaming::NamingContext::_narrow (naming_obj.in ());
	  ACS_DEBUG ("acslogErrorServer", "Naming Service resolved !");

	  CosNaming::Name name;
	  name.length(1);
	  name[0].id = CORBA::string_dup("Log");
	  CORBA::Object_var log_obj = naming_context->resolve(name);

	  if (!CORBA::is_nil (log_obj.in()))
	    {
	      Logging::AcsLogService_var logger = Logging::AcsLogService::_narrow(log_obj.in());
	      ACS_DEBUG ("acslogErrorServer", "Logging Service resolved !");

	      m_logger->setCentralizedLogger(logger.in());
	    }
	  else
	    {
	      ACS_DEBUG ("acslogErrorServer", "Failed to initialise the Logging Service!");
	    }

	}
      else
	{
	  ACS_DEBUG ("acslogErrorServer", "Failed to initialise the NameService!");
	}//if-else
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION(ex, "Failed to get and set the centralized logger");
    }

  try
    {
      //Get a reference to the RootPOA
      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      
      PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
      
   
      PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      
      /* 
      CORBA::PolicyList policy_list;
      policy_list.length(5);
      policy_list[0] = root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);
     policy_list[1] =  root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);
      policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); 
      policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); 
      policy_list[4] =  root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
      printf("policies are created !\n");

      PortableServer::POA_var poa = root_poa->create_POA("cdbSrv", poa_manager.in(), policy_list);
      printf("Poa created !\n");

      for (CORBA::ULong i = 0; i < policy_list.length (); ++i) {
	CORBA::Policy_ptr policy = policy_list[i];
	policy->destroy ();
      }
      printf("Policies are destructed !\n");
      */


#ifdef MAKE_VXWORKS      
      ACSError::processName (szCmdLn);
#else 
      char *buf;
      ACE_OS::argv_to_string (argv, buf);
      ACSError::processName (buf);
      delete[] buf;
#endif      
      ACS_DEBUG ("acslogErrorServer", "Creating test object ...");
      ESTest_var dest;
      
      if (argc>2){
	ACS_DEBUG ("acslogErrorServer", "Getting object reference ... ");
	char refName[64];
	sprintf(refName, "file://%s.ior", argv[2]);
	CORBA::Object_var destObj = orb->string_to_object (refName);
	

	ACS_DEBUG ("acslogErrorServer", "Narrowing it .... ");
	dest = ESTest::_narrow (destObj.in());
      }//if

      ESTestImpl  esTest (dest.in(), argv[1]);
      ESTest_var testObj = esTest._this ();
      
           
      poa_manager->activate ();
      
      ACS_DEBUG ("acslogErrorServer","POA Manager -> activate");
      
      ACS_DEBUG_PARAM ("acslogErrorServer", "Writing ior to the file: %s .... ", argv[1]);
      char* ior =  orb->object_to_string (testObj.in());
      
      
      char fileName[64];
      sprintf(fileName, "%s.ior", argv[1]);
      FILE *output_file = ACE_OS::fopen (fileName, "w");
      if (output_file == 0) {
	ACS_SHORT_LOG ((LM_ERROR,
			   "Cannot open output files for writing IOR: ior.ior"));
	return  -1;
      }

      int result = ACE_OS::fprintf (output_file, "%s", ior);
      if (result < 0) {
	ACS_SHORT_LOG ((LM_ERROR,
			   "ACE_OS::fprintf failed while writing %s to ior.ior\n", ior));
	return  -1;
      }

      ACE_OS::fclose (output_file);
      
      ACS_DEBUG ("acslogErrorServer", "Waiting for requests ...");
      orb->run ();
      
      ACS_DEBUG ("acslogErrorServer", "ORB -> run");
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
      return -1;
    }
  
  return 0;
}//startErrorServer