Beispiel #1
0
int main(int argc, char *argv[])
{

    if (argc<4) {
        ACE_OS::printf ("usage: testClient <server_name> <depth> <isError> [iteration]\n");
        return -1;
    }//if



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

    CORBA::ORB_var orb;
    ACS_TEST_INIT_CORBA;

    // init ACS error system
    ACSError::init (orb.ptr());


    /**************************************/
    acserrTest_var test;
    int depth;
    sscanf (argv[2], "%d", &depth);
    bool isErr = *argv[3]-'0';
    int iteration=1, i=1;
    const int size = 20;  // max value 1.84 x 10^19
    char printBuf[size+1];

    if (argc>4)
        sscanf (argv[4], "%d", &iteration);

    ACS_DEBUG("main", "****** Test Block *****");

    try
    {
        ACS_DEBUG("acserrTestClient", "Getting object reference ... ");
        char fileName[64];
        sprintf(fileName, "file://%s.ior", argv[1]);
        CORBA::Object_var testObj = orb->string_to_object (fileName);

        ACS_DEBUG("acserrTestClient", "Narrowing it .... ");
        test = acserrTest::_narrow (testObj.in());

        unsigned long long numToPrint;
        while( iteration >= i )
        {
            ACS_SHORT_LOG((LM_INFO, "Performing test1 (remote call)... (%d/%d)", i, iteration));
            ACSErr::ErrorTrace *corbaErrorTrace=0;
            ErrorTraceHelper *errorTrace=0;
            // here is also test for converting Completion_var to CompletionImpl
            CompletionImpl comp;
            ACSErr::Completion_var tc = test->test (depth, isErr);

            comp = tc;


            if (comp.isErrorFree())
            {
                ACS_SHORT_LOG((LM_INFO, "Completion does not contain an error trace"));
                comp.log();
                return 0;
            }

            ACS_SHORT_LOG((LM_INFO, "We got Completion that is equal to ACSErrTest0Completion: %d", ACSErrTest0Completion::isEqual(tc)));
            ACS_SHORT_LOG((LM_INFO, "We got Completion that is NOT equal to ACSErrTest1Completion: %d", ACSErrTest1Completion::isEqual(tc)));

            errorTrace = comp.getErrorTraceHelper();
            ACS_SHORT_LOG((LM_INFO, "Stack depth: %d", errorTrace->getDepth()));
            comp.log();
            ACE_OS::printf( "%s", errorTrace->toString().c_str() );

            corbaErrorTrace = &(errorTrace->getErrorTrace());

            do
            {
                ACS_SHORT_LOG((LM_INFO, "FileName:   \"%s\"",errorTrace->getFileName()));
                ACS_SHORT_LOG((LM_INFO, "LineNumber: \"%d\"",errorTrace->getLineNumber()));
                ACS_SHORT_LOG((LM_INFO, "Routine:    \"%s\"",errorTrace->getRoutine()));
                ACS_SHORT_LOG((LM_INFO, "HostName:   \"%s\"",errorTrace->getHostName()));
                ACS_SHORT_LOG((LM_INFO, "Process:    \"%s\"",errorTrace->getProcessName()));
                ACS_SHORT_LOG((LM_INFO, "Thread:     \"%s\"",errorTrace->getThread()));

                for (int ii = 0; ii < size; ii++) printBuf[ii] = ' ';

                printBuf[size] = '\0';
                numToPrint = errorTrace->getTimeStamp();

                for (int ii = size - 1; ii >= 0; ii--) {
                    printBuf[ii] = numToPrint % 10 + '0';
                    numToPrint /= 10;
                    if (numToPrint == 0)
                        break;
                }
                ACS_SHORT_LOG((LM_INFO, "TimeStamp:  \"%s\"",printBuf));
                ACS_SHORT_LOG((LM_INFO, "ErrorType:  \"%d\"",errorTrace->getErrorType()));
                ACS_SHORT_LOG((LM_INFO, "ErrorCode:  \"%d\"",errorTrace->getErrorCode()));
                ACS_SHORT_LOG((LM_INFO, "Severity:   \"%d\"", errorTrace->getSeverity()));
                ACS_SHORT_LOG((LM_INFO, "Description: \"%s\"",errorTrace->getDescription()));
            } while (errorTrace->getNext()!=NULL);

            i++;
        } // while iterator >= i

    }
    catch( CORBA::Exception &ex )
    {
        ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
        return -1;
    }
    ACS_SHORT_LOG((LM_INFO, "Test1 performed."));

//test2
    i=1;

    while (i<=iteration)
    {
        try
        {
            ACS_SHORT_LOG((LM_INFO,
                           "Performing test2 (remote call - exceptions) ... (%d/%d)", i, iteration));
            test->testExceptions (depth, isErr);
        }
        catch (ACSErr::ACSException &acse)
        {
            ACS_SHORT_LOG((LM_INFO, "Catch ACSException !"));
            ACSError exception (acse); // put CORBA exception (ACSException) into ACSError wrapper
            exception.log();
        }
        catch (ACSErrTypeTest::ACSErrTest0Ex &_ex)
        {
            ACS_SHORT_LOG((LM_INFO, "Catch ACSErrTest0Ex !"));
            ACSErrTest0ExImpl exorg(_ex);
            ACE_CString buf = exorg.getMember3();
            ACS_SHORT_LOG((LM_INFO, "Members of the caught exception are: %d, %f, %s, %d",
                           exorg.getMember1(),
                           exorg.getMember2(),
                           buf.c_str(), exorg.getMember4()));

            ACS_SHORT_LOG((LM_INFO, "Caught an exception that is equal to ACSErrTest0ExImpl: %d", ACSErrTest0ExImpl::isEqual(exorg)));
            ACS_SHORT_LOG((LM_INFO, "Caught an exception that is NOT equal to ACSErrTest1ExImpl: %d", ACSErrTest1ExImpl::isEqual(exorg)));

            ACSErrTest0ExImpl *ex = new ACSErrTest0ExImpl(_ex, __FILE__, __LINE__, "testClient::main");
            ex->log();
//	ACSErrTest0Completion c(_ex.errorTrace,  __FILE__, __LINE__, "testClient::main-convertion");
//	c.log();
            delete ex;
        }
        catch(CORBA::Exception &__ex)
        {
            ACE_PRINT_EXCEPTION (__ex, "EXCEPTION CAUGHT");
            return -1;
        }

        i++;
    }//while

    ACS_SHORT_LOG((LM_INFO, "Test2 performed."));

// test3 (no error)
    i=1;
    while (i<=iteration)
    {
        try
        {
            ACS_SHORT_LOG((LM_INFO,
                           "Performing test3 (no error) ... (%d/%d)", i, iteration));
            CompletionImpl comp = test->testNoError ();
            comp.log();
            // test CompletionImpl copy constructor where there is no error
            CompletionImpl c1(comp);
            c1.log();

        }
        catch( CORBA::Exception &ex )
        {
            ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
            return -1;
        }

        i++;
    }//while

    ACS_SHORT_LOG((LM_INFO, "Test3 performed."));

// test4 (default error and operator=)
    try
    {
        ACS_SHORT_LOG((LM_INFO,
                       "Performing test4 (default error and operator=)" ));
        CompletionImpl defaultComp = test->testDefaultError ();
        defaultComp.log();
        CompletionImpl OKComp = test->testNoError ();
        OKComp.log();
        defaultComp = OKComp;
        defaultComp.log();
    }
    catch( CORBA::Exception &ex )
    {
        ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
        return -1;
    }

    ACS_SHORT_LOG((LM_INFO, "Test4 performed."));

// test5 ( error completion, assignment and copy constructor)
    try
    {
        ACS_SHORT_LOG((LM_INFO, "Performing test5" ));
        CompletionImpl comp = test->test(depth, isErr);
        comp.log();

        ACS_SHORT_LOG((LM_INFO, "Performing test5  - copy constructor" ));
// test CompletionImpl copy constructor where there is no error
        CompletionImpl c1(comp);
        c1.log();

        ACS_SHORT_LOG((LM_INFO, "Performing test5  - assignment constructor" ));
        CompletionImpl OKComp = test->testNoError ();

        comp = OKComp;
        comp.log();

        comp = c1;
        comp.log();
    }
    catch( CORBA::Exception &ex )
    {
        ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
        return -1;
    }

    ACS_SHORT_LOG((LM_INFO, "Test5 performed."));


// test 6 (completion out)
    try
    {
        ACS_SHORT_LOG((LM_INFO, "Performing test6 (completion out)" ));

        ACSErr::CompletionImpl comp;
        ACSErr::Completion_var c; // CORBA completion

        test->testCompletionOut(depth, isErr, c.out());

        comp = c;
        comp.log();
    }
    catch( CORBA::Exception &ex )
    {
        ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
        return -1;
    }

    ACS_SHORT_LOG((LM_INFO, "Test6 performed (completion out)."));



    test->shutdown();
    ACE_OS::sleep(5);
    LoggingProxy::done();

    return 0;
}
int acserrOldTestServer (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] = "acserrOldTestServer";
#else
  int acserrOldTestServer (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      
      ACSError::processName (szCmdLn);
#else 
      char *buf;
      ACE_OS::argv_to_string (argv, buf);
      ACSError::processName (buf);
      delete[] buf;
#endif      
      ACS_DEBUG ("errorServer", "Creating test object ...");
      acserrOldTest_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 = acserrOldTest::_narrow (destObj.in());
      }//if

      acserrOldTestImpl  esTest (dest.in(), argv[1]);
      acserrOldTest_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\n", 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 acserrOldTestServer (argc, argv); 
}
int main(int argc, char *argv[])
{

  if (argc<4){
    ACE_OS::printf ("usage: testClient <server_name> <depth> <isError> [iteration]\n");
    return -1;
  }//if

  

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

  CORBA::ORB_var orb;
  ACS_TEST_INIT_CORBA;

  // init ACS error system
  ACSError::init (orb.ptr());


  /**************************************/
  acserrOldTest_var test;
  int depth;
  sscanf (argv[2], "%d", &depth);
  bool isErr = *argv[3]-'0';
  int iteration=1, i=1;
  const int size = 20;  // max value 1.84 x 10^19
  char printBuf[size+1];

  if (argc>4)
	sscanf (argv[4], "%d", &iteration); 
  
  ACS_DEBUG("main", "****** Test Block *****");
 
  try
    {
      ACS_DEBUG("acserrOldTestClient", "Getting object reference ... ");
      char fileName[64];
      sprintf(fileName, "file://%s.ior", argv[1]);
      CORBA::Object_var testObj = orb->string_to_object (fileName);

      ACS_DEBUG("acserrOldTestClient", "Narrowing it .... ");
      test = acserrOldTest::_narrow (testObj.in());

      unsigned long long numToPrint; 
      while( iteration >= i ){
	ACS_SHORT_LOG((LM_INFO, "Performing test1 (remote call)... (%d/%d)", i, iteration));
	ACSErr::ErrorTrace *c = test->test (depth, isErr);
	
	ACSError error(c, true);
	ACS_SHORT_LOG((LM_INFO, "Stack depth: %d", error.getDepth()));
	error.log();

	//ACSError *error = new ACSError (c, true) -> new ACS_ERROR (c, true);
	while (c!=NULL){
	  ACS_SHORT_LOG((LM_INFO, "FileName:   \"%s\"",error.getFileName()));
	  ACS_SHORT_LOG((LM_INFO, "LineNumber: \"%d\"",error.getLineNumber()));  
	  ACS_SHORT_LOG((LM_INFO, "Routine:    \"%s\"",error.getRoutine()));
          ACS_SHORT_LOG((LM_INFO, "HostName:   \"%s\"",error.getHostName()));
	  ACS_SHORT_LOG((LM_INFO, "Process:    \"%s\"",error.getProcess()));
          ACS_SHORT_LOG((LM_INFO, "Thread:     \"%s\"",error.getThread()));
          for (int ii = 0; ii < size; ii++) printBuf[ii] = ' ';
          printBuf[size] = '\0';
          numToPrint = error.getTimeStamp(); 
          for (int ii = size - 1; ii >= 0; ii--) {
                 printBuf[ii] = numToPrint % 10 + '0';
                 numToPrint /= 10;
                 if (numToPrint == 0)
                  break;
             }
	  ACS_SHORT_LOG((LM_INFO, "TimeStamp:  \"%s\"",printBuf));
	  ACS_SHORT_LOG((LM_INFO, "ErrorType:  \"%d\"",error.getErrorType()));
	  ACS_SHORT_LOG((LM_INFO, "ErrorCode:  \"%d\"",error.getErrorCode()));
	  ACS_SHORT_LOG((LM_INFO, "Severity:   \"%d\"", error.getSeverity()));
          ACS_SHORT_LOG((LM_INFO, "Description: \"%s\"",error.getDescription()));
	  c = error.getNext();
	  }	
	i++;
      }//while
      
   
    }
  catch( CORBA::Exception &ex)
    {    
      ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
      return -1;
    }
  ACS_SHORT_LOG((LM_INFO, "Test1 performed."));

//test2
  i=1;
  while (i<=iteration){
    try
      {
	ACS_SHORT_LOG((LM_INFO, 
              "Performing test2 (remote call - exceptions) ... (%d/%d)", i, iteration));
	test->testExceptions (depth, isErr);
      }
    catch (ACSErr::ACSException &ex)
      {
	ACS_SHORT_LOG((LM_INFO, "Catch ACSException !"));
	ACSError exception (ex); // put CORBA exception (ACSException) into ACSError wrapper
	exception.log();
      }
    catch( CORBA::Exception &_ex)
      {    
	ACE_PRINT_EXCEPTION (_ex, "EXCEPTION CAUGHT");
	return -1;
      }
    
    i++;
  }//while

  ACS_SHORT_LOG((LM_INFO, "Test2 performed."));

// test3 (no error)
  i=1;
  while (i<=iteration){
    try
      {
	ACS_SHORT_LOG((LM_INFO, 
              "Performing test3 (no error) ... (%d/%d)", i, iteration));
	test->testNoError ();
      }
    catch( CORBA::Exception &_ex)
      {    
	ACE_PRINT_EXCEPTION (_ex, "EXCEPTION CAUGHT");
	return -1;
      }
    
    i++;
  }//while

  ACS_SHORT_LOG((LM_INFO, "Test3 performed."));

  test->shutdown();
  ACE_OS::sleep(5);
  LoggingProxy::done();

  return 0;
}
Beispiel #4
0
int
main (int argc, char *argv[])
{

    if (argc < 3)
    	printUsageAndExit(argc, argv);

	char * command = argv[2];

	#define SET 1
	#define GET 2
	#define LIST 3
	#define REFRESH 4
	int cmd;
	if (ACE_OS::strcmp(command, "set") == 0)
		cmd = SET;
	else if (ACE_OS::strcmp(command, "get") == 0)
		cmd = GET;
	else if (ACE_OS::strcmp(command, "list") == 0)
		cmd = LIST;
	else if (ACE_OS::strcmp(command, "refresh") == 0)
		cmd = REFRESH;
	else
	{
		ACE_OS::printf("Invalid command, must be one of {set,get,list,refresh}.\n");
	    printUsageAndExit(argc, argv);
	}

	if (cmd == SET && argc < 4)
	{
		// if only 4 then default is set
		ACE_OS::printf("Not enough parameters.\n");
	    printUsageAndExit(argc, argv);
	}

	if (cmd == GET && argc < 4)
	{
		ACE_OS::printf("Not enough parameters.\n");
		printUsageAndExit(argc, argv);
	}


    LoggingProxy * logger = new LoggingProxy(0, 0, 31);
    if (logger)
    {
    	LoggingProxy::init(logger);
    	LoggingProxy::ProcessName(argv[0]);
    	LoggingProxy::ThreadName("main");
    }
    else
    	ACS_SHORT_LOG((LM_INFO, "Failed to initialize logging."));


    try
    {
	// Initialize the ORB.
	CORBA::ORB_var orb = CORBA::ORB_init (argc,
					      argv,
					      "TAO"
					      );


	maci::Manager_var mgr = MACIHelper::resolveManager(orb.ptr(), argc, argv, 0, 0);
    if (CORBA::is_nil(mgr.ptr()))
	{
	    ACS_SHORT_LOG((LM_ERROR, "Failed to resolve Manager reference."));
	    return -1;
	}

	maci::HandleSeq handles;
	handles.length(0);

	// a little hack to manager (this clas should implement administrator interface, etc..)
	maci::Handle h = 0x05000000;
	maci::ContainerInfoSeq_var containers = mgr->get_container_info(h, handles, argv[1]);


	if (!containers.ptr() || containers->length()==0)
	{
	    ACS_SHORT_LOG((LM_INFO, "No containers matching name %s found.", argv[1]));
	    return -1;
	}

	for (CORBA::ULong i = 0; i < containers->length(); i++)
	{
	    try
	    {
	    	ACS_SHORT_LOG((LM_INFO, "Container: %s", containers[i].name.in()));

	    	if (cmd == LIST)
	    	{
	    		ACS_SHORT_LOG((LM_INFO, "\tLogger names:"));
	    		maci::stringSeq_var loggerNames = containers[i].reference->get_logger_names();
	    		for (CORBA::ULong j = 0; j < loggerNames->length(); j++)
	   				ACS_SHORT_LOG((LM_INFO, "\t\t%s", loggerNames[j].in()));
	    	}
	    	else if (cmd == REFRESH)
	    	{
	    		ACS_SHORT_LOG((LM_INFO, "\tRefreshing logging config."));
				containers[i].reference->refresh_logging_config();
	    	}
	    	else if (cmd == GET)
	    	{
	    		char * loggerName = argv[3];

			    LoggingConfigurable::LogLevels logLevels;
			    if (ACE_OS::strcmp(loggerName, "default") == 0)
			     	logLevels = containers[i].reference->get_default_logLevels();
			    else
			    	logLevels = containers[i].reference->get_logLevels(loggerName);

			    ACS_SHORT_LOG((LM_INFO, "\tLog levels for logger '%s':", loggerName));
			    ACS_SHORT_LOG((LM_INFO, "\t\tuseDefault      : %s", logLevels.useDefault ? "true" : "false"));
			    ACS_SHORT_LOG((LM_INFO, "\t\tminLogLevel     : %d", logLevels.minLogLevel));
			    ACS_SHORT_LOG((LM_INFO, "\t\tminLogLevelLocal: %d", logLevels.minLogLevelLocal));
	    	}
	    	else if (cmd == SET)
	    	{
	    		char * loggerName = argv[3];

			    LoggingConfigurable::LogLevels logLevels;

			    logLevels.useDefault = argc < 6;
			    if (!logLevels.useDefault)
			    {
	    			logLevels.minLogLevel = atoi(argv[4]);
	    			logLevels.minLogLevelLocal = atoi(argv[5]);
			    	if (!isLogLevelValid(logLevels.minLogLevel) || !isLogLevelValid(logLevels.minLogLevelLocal))
			    	{
			    		printUsageAndExit(argc, argv);
			    	}
			    }
			    else
			    {
	    			logLevels.minLogLevel = 0;
	    			logLevels.minLogLevelLocal = 0;
			    }

			    ACS_SHORT_LOG((LM_INFO, "\tSetting levels for logger '%s':", loggerName));
			    ACS_SHORT_LOG((LM_INFO, "\t\tuseDefault      : %s", logLevels.useDefault ? "true" : "false"));
			    //if (!logLevels.useDefault)
			    {
			    	ACS_SHORT_LOG((LM_INFO, "\t\tminLogLevel     : %d", logLevels.minLogLevel));
			    	ACS_SHORT_LOG((LM_INFO, "\t\tminLogLevelLocal: %d", logLevels.minLogLevelLocal));
			    }

			    if (ACE_OS::strcmp(loggerName, "default") == 0)
	    			containers[i].reference->set_default_logLevels(logLevels);
				else
	    			containers[i].reference->set_logLevels(loggerName, logLevels);
	    	}

			ACS_SHORT_LOG((LM_INFO, "\t... done."));
	    }
	    catch( CORBA::Exception &ex )
	    {
	        ACS_SHORT_LOG((LM_INFO, "... failed!"));
			ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, ACE_TEXT ("Exception caught while calling remote method."));
	    }

	}

	ACS_SHORT_LOG((LM_INFO, "Done all."));

    }
  catch( CORBA::Exception &ex )
  {
      ACS_SHORT_LOG((LM_INFO, "Failed."));
      ACE_PRINT_EXCEPTION (ex,
                           ACE_TEXT ("Caught unexpected exception:"));

      return -1;
  }

  return 0;
}