void logBatchUsingMacrosGeneralLogger() { std::cout << "Log batch for logger [" << "GeneralLogger" << "]. USING ACS MACROS." << std::endl; // Test macros { AUTO_TRACE("TEST_MACROS"); ACS_LOG(LM_RUNTIME_CONTEXT, __PRETTY_FUNCTION__, (LM_INFO, "LM_RUNTIME_CONTEXT inside TEST_MACROS")); ACS_LOG(LM_SOURCE_INFO, __PRETTY_FUNCTION__, (LM_INFO, "LM_SOURCE_INFO inside TEST_MACROS")); } ACS_LOG(LM_RUNTIME_CONTEXT, __PRETTY_FUNCTION__, (LM_INFO, "LM_RUNTIME_CONTEXT outside TEST_MACROS")); ACS_LOG( LM_SOURCE_INFO, __PRETTY_FUNCTION__, (LM_INFO, "LM_SOURCE_INFO outside TEST_MACROS")); ACS_TRACE(__PRETTY_FUNCTION__); ACS_SHORT_LOG((LM_INFO, "Test ACS_SHORT_LOG with LM_INFO")); //ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_SHUTDOWN, "Test of LM_SHUTDOWN log")); // NOT logging a thing ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_TRACE, "Test of LM_TRACE log")); //ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_DELOUSE, "Test of LM_DELOUSE log")); // Not logginf a thing ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_DEBUG, "Test of LM_DEBUG log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_INFO, "Test of LM_INFO log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_NOTICE, "Test of LM_NOTICE log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_WARNING, "Test of LM_WARNING log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_ERROR, "Test of LM_ERROR log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_CRITICAL, "Test of LM_CRITICAL log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_ALERT, "Test of LM_ALERT log")); ACS_LOG( LM_FULL_INFO, __PRETTY_FUNCTION__, (LM_EMERGENCY, "Test of LM_EMERGENCY log")); // Debug messages ACS_DEBUG(__PRETTY_FUNCTION__, "Test of ACS_DEBUG macro"); ACS_DEBUG_PARAM(__PRETTY_FUNCTION__, "Test of ACS_DEBUG_PARAM macro with param: %s", "param1"); } // 17 + 2 messages (entering + exiting)
void ErrorComponent::sleepingCmd(CORBA::Short nb_seconds) { ACS_DEBUG_PARAM("ErrorComponent::sleepingCmd","Sleeping for %d second(s)",nb_seconds); sleep(nb_seconds); ACS_DEBUG("ErrorComponent::sleepingCmd","Exiting..."); return; }
// Implementation skeleton destructor enumpropTestDeviceImpl::~enumpropTestDeviceImpl (void) { ACS_TRACE("enumpropTestDeviceImpl::~enumpropTestDeviceImpl"); if (getComponent()) ACS_DEBUG_PARAM("::BaciTestClassImpl::~BaciTestClassImpl", "Destroying %s...", getComponent()->getName()); // stop threads if (getComponent()) getComponent()->stopAllThreads(); // properties if (m_currentState) { m_currentState->destroy(); m_currentState=0; } if (m_currentStateRW) { m_currentStateRW->destroy(); m_currentStateRW=0; } ACS_DEBUG("::eumpropTestDeviceImpl::~enumpropTestDeviceImpl", "Properties destroyed"); ACS_DEBUG("::enumpropTestDeviceImpl::~enumpropTestDeviceImpl", "Component destroyed"); }//~
void ErrorComponent::exceptionFromCompletion(CORBA::Short depth) { ACS_TRACE("ErrorComponent::exceptionFromCompletion"); if(depth==1){ ACSErrTypeCommon::GenericErrorExImpl ex2( __FILE__, __LINE__, "ErrorComponent::exceptionFromCompletion"); ex2.setErrorDesc("Exception with trace of depth 1 (not generated from a completion)"); throw ex2.getGenericErrorEx(); } CompletionImpl *comp = createCompletion(depth>0?depth-1:0); ACS_DEBUG("ErrorComponent::exceptionFromCompletion","first step"); // if comp does not conatin error (=is error free) we just return // otherwise we create a new exception which takes the error trace from a completion comp. if (!comp->isErrorFree()) { ACS_DEBUG("ErrorComponent::exceptionFromCompletion","second step"); // The constructor takes care for the memory manamgent // for the passed completion or exception. // If a completion or an exception is passed as pointer the constructor assumes that // completion was created on the heap and thus it deletes it afterwards, // so it MUST NOT be deleted by the user ! // If a completion or an exception is passed as an object (or reference to it) // the constructor assumes that the it was created on the stack // and thus it does not delete it. // // NOTE: do not pass a pointer of a completion or an exception // which was created on the stack !! In this case just send the completion object. ACSErrTypeCommon::GenericErrorExImpl ex2(comp, __FILE__, __LINE__, "ErrorComponent::exceptionFromCompletion"); ex2.setErrorDesc("Exception generated by adding an error trace from a completion"); throw ex2.getGenericErrorEx(); }//if }
void ErrorComponent::generateSIGSEGV (CORBA::Short way) { switch(way) { case 0: { // Send the SIGSEGV signal ACS_DEBUG("ErrorComponent::generateSIGSEGV","Send SIGSEGV signal"); pid_t myPid = getpid(); kill(myPid,SIGSEGV); } break; case 1: default: { // Access to null pointer ACS_DEBUG("ErrorComponent::generateSIGSEGV","Tries to access to null pointer"); int * badPointer = 0; *badPointer = 42; } } // switch(way) }
void ErrorComponent::generateSIGFPE (CORBA::Short way) { switch(way) { case 0: { // Send the SIGFPE signal ACS_DEBUG("ErrorComponent::generateSIGFPE","Send SIGFPE signal"); pid_t myPid = getpid(); kill(myPid,SIGFPE); } break; case 1: default: { // Division by 0 ACS_DEBUG("ErrorComponent::generateSIGFPE","Tries to divide by zero"); int zero = 0; printf("5/0 = %d\n",5/zero); } } // switch(way) }
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); }
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; }
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; }
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