ACSErr::Completion *ErrorComponent::completionFromCompletion(CORBA::Short depth) { ACS_TRACE("ErrorComponent::completionFromCompletion"); CompletionImpl *comp; if(depth==1){ ACSErrTypeCommon::GenericErrorCompletion *erg = new ACSErrTypeCommon::GenericErrorCompletion( __FILE__, __LINE__, "ErrorComponent::completionFromCompletion"); erg->setErrorDesc("Put an error trace in completionFromCompletion(depth 1, so not generated from another completion)"); comp = erg; } else{ comp = createCompletion(depth>0?depth-1:0); // if comp does not conatin error (=is error free) we return it // otherwise we create a new completion which takes the error trace from a completion comp. if (!comp->isErrorFree()) { // comp is deleted inside the constructor ACSErrTypeCommon::GenericErrorCompletion *erg = new ACSErrTypeCommon::GenericErrorCompletion(comp, __FILE__, __LINE__, "ErrorComponent::completionFromCompletion"); erg->setErrorDesc("Put an error trace in completionFromCompletion"); comp = erg; }//if } return comp->returnCompletion(); }//completionFromCompletion
/* ----------------------------------------------------------------*/ ACSErr::Completion *ErrorComponent::completionFromException(CORBA::Short depth) { ACS_TRACE("::ErrorComponent::completionFromException"); // here we get LOCAL (C++) completion CompletionImpl *er = createCompletion(depth); // returnCompletion() automatically deletes er // NOTE: you can use returnCompletion() // just if completion is allocated on the heap. // If completion is allocated on the stack // returnCompletion(false) has to be used. return er->returnCompletion(); }//completionFromException
void ClientErrorComponent::TestReceiveRemoteCompletion() { ACS_TRACE("ClientErrorComponent::TestReceiveRemoteCompletion"); if (CORBA::is_nil(foo_m.in()) == true) { throw ACSErrTypeCommon::CouldntAccessComponentExImpl( __FILE__, __LINE__, "ClientErrorComponent::TestReceiveRemoteCompletion"); } try { CompletionImpl comp; // OK Completion ACS_SHORT_LOG((LM_INFO, "Example 2a: Calls a method that returns an OK completion.")); comp = foo_m->completionFromException(0); comp.log(); // ERROR completion with an error trace inside. ACS_SHORT_LOG((LM_INFO, "Example 2b: Calls a method that returns an Error completion.")); comp = foo_m->completionFromException(3); comp.log(); } catch(CORBA::SystemException &ex) { ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx( __FILE__, __LINE__, "ClientErrorComponent::TestReceiveRemoteCompletion"); corbaProblemEx.setMinor(ex.minor()); corbaProblemEx.setCompletionStatus(ex.completed()); corbaProblemEx.setInfo(ex._info().c_str()); corbaProblemEx.log(); } catch(...) { ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__, "ClientErrorComponent::TestReceiveRemoteCompletion"); ex.setErrorDesc("completionFromException has thrown an UNEXPECTED exception"); ex.log(); } }
void ClientErrorComponent::testCompletionOnStack() { ACS_TRACE("ClientErrorComponent::testCompletionOnStack"); if (CORBA::is_nil(foo_m.in()) == true) { throw ACSErrTypeCommon::CouldntAccessComponentExImpl( __FILE__, __LINE__, "ClientErrorComponent::testCompletionOnStack"); } try { CompletionImpl comp; // OK Completion ACS_SHORT_LOG((LM_INFO, "Example 7a: completionOnStack with depth 0.")); comp = foo_m->completionOnStack(0); comp.log(); // ERROR completion with an error trace inside. ACS_SHORT_LOG((LM_INFO, "Example 7b: completionOnStack with depth 3.")); comp = foo_m->completionOnStack(3); comp.log(); } catch(CORBA::SystemException &ex) { ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx( __FILE__, __LINE__, "ClientErrorComponent::TestCompletionOnStack"); corbaProblemEx.setMinor(ex.minor()); corbaProblemEx.setCompletionStatus(ex.completed()); corbaProblemEx.setInfo(ex._info().c_str()); corbaProblemEx.log(); } catch(...) { ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__, "ClientErrorComponent::testCompletionOnStack"); ex.setErrorDesc("CompletionOnStack has thrown an UNEXPECTED exception"); ex.log(); } }
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 }
ACSErr::Completion *ErrorComponent::completionOnStack(CORBA::Short depth) { ACS_TRACE("::ErrorComponent::completionOnStack"); // here we get LOCAL (C++) completion CompletionImpl *comp = createCompletion(depth); // if comp does not contain error (=is error free) we return it // otherwise we create a new completion which takes the error trace from a completion comp. if (comp->isErrorFree()) { // memory for comp is released in the call return comp->returnCompletion(); } else { // 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::GenericErrorCompletion erg(comp, __FILE__, __LINE__, "ErrorComponent::completionOnStack"); erg.setErrorDesc("Put an error trace in completionOnStack"); return erg.returnCompletion(false); // With false flag we tell returnCompletion() // not to delete its object // since it is automatically deleted when we go out of scope }//if }//completionOnStack
void actionThreadWorker(void* param) { if (param==0) return; BACIThreadParameter* baciParameter_p = static_cast<BACIThreadParameter*>(param); BACIThread* myself_p = baciParameter_p->getBACIThread(); BACIComponent* component_p = (BACIComponent*)baciParameter_p->getParameter(); if (BACIThread::InitThread) { BACIThread::InitThread(myself_p->getName().c_str()); } ACS_TRACE("baci::actionThreadWorker"); BACIAction* action_p = 0; bool pushActionBack; int callbackID; BACICallback* callback_p = 0; CBDescOut descOut; ActionRequest request = reqNone; ACS_DEBUG_PARAM("baci::actionThreadWorker", "%s", component_p->getName()); while (myself_p->check()==true && component_p->isInDestructionState()==false) { if (myself_p->isSuspended()==false && component_p->isInDestructionState()==false && (component_p->getActionCount()>0)) { if ( (action_p = component_p->popAction()) != 0 ) { Completion completion; callbackID = action_p->getCallbackID(); callback_p = component_p->getCallback(callbackID); if (callback_p==0) { //ACS_LOG(LM_RUNTIME_CONTEXT, "baci::actionThreadWorker", // (LM_CRITICAL, "Callback not found: %s", component_p->getName())); delete action_p; continue; } if (action_p->isCompleted()==true) { completion = action_p->getCompletion(); request = reqInvokeDone; } else { CompletionImpl co; request = action_p->invoke(callback_p->getComponent(), callbackID, callback_p->getDescIn(), action_p->getValueRef(), co, descOut); if (co.isErrorFree()) { completion = co; } else { completion = CouldntPerformActionCompletion(co, __FILE__, __LINE__, "baci::actionThreadWorker"); }//if-else }//if-else pushActionBack = false; switch (request) { case reqNone: break; case reqInvokeWorking: component_p->dispatchCallback(callbackID, action_p->getValue(), descOut, completion); pushActionBack = true; break; case reqInvokeDone: pushActionBack = !component_p->finishCallback(callbackID, action_p->getValue(), descOut, completion); if (pushActionBack==false) { //component_p->removeCallback(callbackID); /// already removed delete action_p; } else if (callback_p->isOK()==true) { action_p->setCompletion(completion); } else { pushActionBack = false; // drop message //component_p->removeCallback(callbackID); delete action_p; } break; case reqDestroy: component_p->removeCallback(callbackID); delete action_p; default: // error msg ACS_LOG(LM_RUNTIME_CONTEXT, "baci::actionThreadWorker", (LM_ERROR, "Wrong request for action in Component %s! Return value must type of 'enum ActionRequest { reqNone, reqInvokeWorking, reqInvokeDone, reqDestroy }'", component_p->getName())); break; } if (pushActionBack==true) { component_p->pushAction(action_p); } } } if (myself_p->exitRequested()==false) { myself_p->sleep(); } } delete baciParameter_p; myself_p->setStopped(); if (BACIThread::DoneThread) { BACIThread::DoneThread(); } }
void monitorThreadWorker(void* param) { if (param==0) { return; } BACIThreadParameter* baciParameter_p = static_cast<BACIThreadParameter*>(param); BACIThread* myself_p = baciParameter_p->getBACIThread(); BACIComponent* component_p = (BACIComponent*)baciParameter_p->getParameter(); if (BACIThread::InitThread) { BACIThread::InitThread(myself_p->getName().c_str()); } ACS_TRACE("baci::monitorThreadWorker"); ACS::TimeInterval pollInterval, time, lastPollTime; BACIValue value; bool timeTriggered; BACIProperty* property_p=0; CBDescOut descOut; ACS_DEBUG_PARAM("baci::monitorThreadWorker", "%s", component_p->getName()); // already in getPropertAt ?!!! //ThreadSyncGuard guard(component_p->&property_mpVectorMutex); while (myself_p->check()==true && component_p->isInDestructionState()==false) { if (myself_p->isSuspended()==false) { // sync. monitors time = getTimeStamp(); //guard.acquire(); for (int n=0; component_p->isInDestructionState()==false && n < component_p->getPropertyCount() && myself_p->exitRequested()==false; n++) { property_p = component_p->getPropertyAt(n); if (property_p==0 || property_p->isInDestructionState()==true) { continue; } if ((property_p->getMonitorCount() > 0) && ((property_p->getPollInterval() > 0) || property_p->hasTriggerOnValueMonitor()==true || property_p->hasTriggerOnValuePercentMonitor()==true)) { pollInterval = property_p->getPollInterval(); //if we're dealing with a property containing trigger by value monitors AND //the minimum monitor time is NOT default AND //it's less than the main polling interval... if ((property_p->hasTriggerOnValueMonitor()==true || property_p->hasTriggerOnValuePercentMonitor()==true) && (property_p->getMonMinTriggerTime()!=0) && (property_p->getMonMinTriggerTime()<pollInterval)) { pollInterval = property_p->getMonMinTriggerTime(); } lastPollTime = property_p->getLastPollTime(); //time = getTimeStamp(); // time fix ACS::TimeInterval etime = time; if (pollInterval!=0) { etime -= calculateModulus(time-lastPollTime, pollInterval); timeTriggered = (etime-lastPollTime)>=pollInterval; } else { timeTriggered = false; } //timeTriggered = (time-lastPollTime)>=pollInterval; //if (timeTriggered==true)//property_p->hasTriggerOnValueMonitor() || timeTriggered) if (property_p->hasTriggerOnValueMonitor() || property_p->hasTriggerOnValuePercentMonitor() || timeTriggered == true) { CompletionImpl co; value.reset(); property_p->getValue(property_p, (BACIValue*)&value, co, descOut); property_p->setLastValue(value); // !!! //property_p->setLastCompletion(completion); // !!! if (timeTriggered==true) { property_p->setLastPollTime(etime); // !!! do not set in case of error } //property_p->setLastPollTime(time); // !!! do not set in case of error if( co.isErrorFree() ) { property_p->dispatchMonitors(co, descOut); } else { CanNotGetValueCompletion errComp(co, __FILE__, __LINE__, "baci::monitorThreadWorker"); property_p->dispatchMonitors(errComp, descOut); }//if-else } } } //guard.release(); } if (myself_p->exitRequested()==false) { myself_p->sleep(); } } delete baciParameter_p; myself_p->setStopped(); if (BACIThread::DoneThread) { BACIThread::DoneThread(); } }
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; }