MESSAGE("activate object");
_thisObj = this ;
_id = _poa->activate_object(_thisObj);
+
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
}
CALCULATOR::~CALCULATOR()
CORBA::Double CALCULATOR::norm2(SALOME_MED::FIELDDOUBLE_ptr field1)
{
beginService( "CALCULATOR::norm2");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::Norm2(SALOME_MED::FIELDDOUBLE_ptr field1)");
- // Create a local field from corba field, apply method normMax on it.
- // When exiting the function, f1 is deleted, and with it the remote corba field.
- TFieldDouble_c f1(field1);
- CORBA::Double norme = f1.norm2();
- END_OF("CALCULATOR::Norm2(SALOME_MED::FIELDDOUBLE_ptr field1)");
+
+ if(CORBA::is_nil(field1)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return 0.0;
+ }
+
+ CORBA::Double norme = 0.0;
+ // Create a local field from corba field, apply method normMax on it.
+ // When exiting the function, f1 is deleted, and with it the remote corba field.
+ TFieldDouble_c f1(field1);
+
+ try {
+ norme = f1.norm2();
+ }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
+
+ END_OF("CALCULATOR::Norm2(SALOME_MED::FIELDDOUBLE_ptr field1)");
endService( "CALCULATOR::norm2");
return norme;
}
CORBA::Double CALCULATOR::normL2(SALOME_MED::FIELDDOUBLE_ptr field1)
{
beginService( "CALCULATOR::normL2");
- BEGIN_OF("CALCULATOR::NormL2(SALOME_MED::FIELDDOUBLE_ptr field1)");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
+ BEGIN_OF("CALCULATOR::NormL2(SALOME_MED::FIELDDOUBLE_ptr field1)");
+
+ if(CORBA::is_nil(field1)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return 0.0;
+ }
+
+ //Check that the Field is not on the Nodes (a limitation of normL2)
+ SALOME_MED::SUPPORT_var aSupport = field1->getSupport();
+ if(CORBA::is_nil(aSupport) || aSupport->getEntity() == SALOME_MED::MED_NODE) {
+ _errorCode = CALCULATOR_ORB::NOT_COMPATIBLE;
+ return 0.0;
+ }
// Create a local field (on the stack) from corba field, apply method normMax on it.
// When exiting the function, FIELDClient f1 is deleted, and with it the remote corba field.
TFieldDouble_c f1(field1);
- CORBA::Double norme = f1.normL2();
- // Send a notification message to supervision
+
+ CORBA::Double norme = 0.0;
+ try {
+ norme = f1.normL2();
+ }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
+
+ // Send a notification message to supervision
ostringstream message("CALCULATOR::normL2 : ");
message << norme;
sendMessage("warning",message.str().c_str());
CORBA::Double CALCULATOR::normMax(SALOME_MED::FIELDDOUBLE_ptr field1)
{
beginService( "CALCULATOR::normMax");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::NormMax(SALOME_MED::FIELDDOUBLE_ptr field1)");
- // An other way to do it : create an local field on the heap, inside an auto_ptr.
- // When exiting the function, auto_ptr is deleted, and with it the local field and
- // the remote field if ownership was transferred.
- auto_ptr<TFieldDouble> f1 (new TFieldDouble_c(field1) );
- CORBA::Double norme = f1->normMax();
- END_OF("CALCULATOR::NormMax(SALOME_MED::FIELDDOUBLE_ptr field1)");
+
+ if(CORBA::is_nil(field1)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return 0.0;
+ }
+
+ CORBA::Double norme = 0.0;
+ // An other way to do it : create an local field on the heap, inside an auto_ptr.
+ // When exiting the function, auto_ptr is deleted, and with it the local field and
+ // the remote field if ownership was transferred.
+ auto_ptr<TFieldDouble> f1 (new TFieldDouble_c(field1) );
+
+ try {
+ norme = f1->normMax();
+ }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
+
+ END_OF("CALCULATOR::NormMax(SALOME_MED::FIELDDOUBLE_ptr field1)");
endService( "CALCULATOR::normMax");
return norme;
}
CORBA::Double CALCULATOR::normL1(SALOME_MED::FIELDDOUBLE_ptr field1)
{
beginService( "CALCULATOR::normL1");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::NormL1(SALOME_MED::FIELDDOUBLE_ptr field1)");
- auto_ptr<TFieldDouble> f1 (new TFieldDouble_c(field1) );
- CORBA::Double norme = f1->normL1();
+
+ if(CORBA::is_nil(field1)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return 0.0;
+ }
+
+ //Check that the Field is not on the Nodes (a limitation of normL1)
+ SALOME_MED::SUPPORT_var aSupport = field1->getSupport();
+
+ if(CORBA::is_nil(aSupport) || aSupport->getEntity() == SALOME_MED::MED_NODE) {
+ _errorCode = CALCULATOR_ORB::NOT_COMPATIBLE;
+ return 0.0;
+ }
+
+ CORBA::Double norme = 0.0;
+ auto_ptr<TFieldDouble> f1 (new TFieldDouble_c(field1) );
+
+ try {
+ norme = f1->normL1();
+ }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
+
END_OF("CALCULATOR::Norm2(SALOME_MED::FIELDDOUBLE_ptr field1)");
endService( "CALCULATOR::normL1");
return norme;
SALOME_MED::FIELDDOUBLE_ptr CALCULATOR::applyLin(SALOME_MED::FIELDDOUBLE_ptr field1,CORBA::Double a,CORBA::Double b)
{
beginService( "CALCULATOR::applyLin");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("applyLin(SALOME_MED::FIELDDOUBLE_ptr field1,CORBA::Double a,CORBA::Double b)");
- // create a local field on the heap, because it has to remain after exiting the function
- TFieldDouble * f1 = new TFieldDouble_c(field1);
- f1->applyLin(a,b);
- // create servant from f1, give it the property of c++ field (parameter true).
- // This imply that when the client will release it's field, it will delete NewField,
- // and f1.
- TFieldDouble_i * NewField = new TFieldDouble_i(f1,true) ;
- // activate object
- SALOME_MED::FIELDDOUBLE_ptr myFieldIOR = NewField->_this() ;
+ if(CORBA::is_nil(field1)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return NULL;
+ }
+
+ SALOME_MED::FIELDDOUBLE_ptr myFieldIOR = NULL;
+ // create a local field on the heap, because it has to remain after exiting the function
+ TFieldDouble * f1 = new TFieldDouble_c(field1);
+ TFieldDouble_i * NewField = NULL;
+
+ try {
+ f1->applyLin(a,b);
+ // create servant from f1, give it the property of c++ field (parameter true).
+ // This imply that when the client will release it's field, it will delete NewField,
+ // and f1.
+ NewField = new TFieldDouble_i(f1,true) ;
+ // activate object
+ myFieldIOR = NewField->_this() ;
+ }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
END_OF("applyLin(SALOME_MED::FIELDDOUBLE_ptr field1,CORBA::Double a,CORBA::Double b)");
endService( "CALCULATOR::applyLin");
}
SALOME_MED::FIELDDOUBLE_ptr CALCULATOR::add(SALOME_MED::FIELDDOUBLE_ptr field1, SALOME_MED::FIELDDOUBLE_ptr field2)
- throw ( SALOME::SALOME_Exception )
{
beginService( "CALCULATOR::add");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::add(SALOME_MED::FIELDDOUBLE_ptr field1, SALOME_MED::FIELDDOUBLE_ptr field2)");
+
+ if(CORBA::is_nil(field1) || CORBA::is_nil(field2)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return NULL;
+ }
+
// Create local fields from corba field
TFieldDouble_c f1(field1);
TFieldDouble_c f2(field2);
// Create new c++ field on the heap by copying f1, add f2 to it.
TFieldDouble* fres = new TFieldDouble(f1);
- // catch exception for non compatible fields
+
+ // catch exception for non compatible fields
try
{
*fres+=f2;
}
catch(MEDEXCEPTION)
{
- throw(SALOME_Exception(LOCALIZED("Fields are not compatible")));
+ _errorCode = CALCULATOR_ORB::NOT_COMPATIBLE;
+ return NULL;
}
+
// create CORBA field from c++ toField. give property to servant (true)
TFieldDouble_i * myFieldDoubleI = new TFieldDouble_i(fres,true);
SALOME_MED::FIELDDOUBLE_ptr myFieldIOR = myFieldDoubleI->_this() ;
SALOME_MED::FIELDDOUBLE_out clone3, SALOME_MED::FIELDDOUBLE_out clone4)
{
beginService( "CALCULATOR::cloneField");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::cloneField");
+ if(CORBA::is_nil(field)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return;
+ }
+
// load local field, using MED ressource file pointe.med
TFieldDouble_c f(field);
void CALCULATOR::printField(SALOME_MED::FIELDDOUBLE_ptr field)
{
beginService( "CALCULATOR::printField");
-
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
+
+ if(CORBA::is_nil(field)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return;
+ }
+
// Create a local field from corba field.
// Use auto_ptr to perform automatic deletion after usage.
// The deletion of the FIELDClient will delete the remote Corba object.
CORBA::Double CALCULATOR::convergenceCriteria(SALOME_MED::FIELDDOUBLE_ptr field)
{
beginService( "CALCULATOR::convergenceCriteria");
+ _errorCode = CALCULATOR_ORB::NO_ERROR;
BEGIN_OF("CALCULATOR::convergenceCriteria(SALOME_MED::FIELDDOUBLE_ptr field)");
+ if(CORBA::is_nil(field)) {
+ _errorCode = CALCULATOR_ORB::INVALID_FIELD;
+ return 0.0;
+ }
+
double criteria=1;
- static auto_ptr<TFieldDouble> fold(0);
- auto_ptr<TFieldDouble> fnew (new TFieldDouble_c(field) );
- if (fold.get() == NULL) // if old field is not set, set it and return 1
- fold=fnew;
- else
- {
- // if size of fields are not equal, return 1
- const int size=fold->getNumberOfValues()*fold->getNumberOfComponents();
- if ( size == fnew->getNumberOfValues()*fnew->getNumberOfComponents() )
- {
- MED_EN::medModeSwitch mode=fold->getInterlacingType(); // storage mode
- const double* oldVal= fold->getValue(); // retrieve values
- const double* newVal= fnew->getValue();
- criteria=0.0;
- double ecart_rel=0.0;
- for (unsigned i=0; i!=size; ++i) // compute criteria
- {
- if ( oldVal[i] != 0.0)
+ static auto_ptr<TFieldDouble> fold(0);
+ auto_ptr<TFieldDouble> fnew (new TFieldDouble_c(field) );
+
+ try {
+ if (fold.get() == NULL) // if old field is not set, set it and return 1
+ fold=fnew;
+ else
{
- ecart_rel = std::abs( (oldVal[i]-newVal[i])/oldVal[i] );
- if ( ecart_rel>criteria )
- criteria=ecart_rel;
+ // if size of fields are not equal, return 1
+ const int size=fold->getNumberOfValues()*fold->getNumberOfComponents();
+ if ( size == fnew->getNumberOfValues()*fnew->getNumberOfComponents() )
+ {
+ //MED_EN::medModeSwitch mode=fold->getInterlacingType(); // storage mode
+ const double* oldVal= fold->getValue(); // retrieve values
+ const double* newVal= fnew->getValue();
+ criteria=0.0;
+ double ecart_rel=0.0;
+ for (unsigned i=0; i!=size; ++i) // compute criteria
+ {
+ if ( oldVal[i] != 0.0)
+ {
+ ecart_rel = std::abs( (oldVal[i]-newVal[i])/oldVal[i] );
+ if ( ecart_rel>criteria )
+ criteria=ecart_rel;
+ }
+ }
+ }
}
- }
-
}
- }
+ catch(...) {
+ _errorCode = CALCULATOR_ORB::EXCEPTION_RAISED;
+ }
endService( "CALCULATOR::convergenceCriteria");
END_OF("CALCULATOR::convergenceCriteria(SALOME_MED::FIELDDOUBLE_ptr field1)");
return criteria;
}
+CORBA::Boolean CALCULATOR::isDone()
+{
+ return (_errorCode == CALCULATOR_ORB::NO_ERROR);
+}
+
+CALCULATOR_ORB::ErrorCode CALCULATOR::getErrorCode()
+{
+ return _errorCode;
+}
extern "C"