From: caremoli Date: Fri, 22 May 2009 08:53:41 +0000 (+0000) Subject: CCAR: add automatic management of GenericObj in study. X-Git-Tag: V5_1_2rc1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=46fc79e7d0eaf01688ab5f2c445f05731280b86c;p=modules%2Fkernel.git CCAR: add automatic management of GenericObj in study. If a GenericObj id publish in study, its reference count must be incremented (call to Register()). When it is unpublished, its reference count must be decremented (call to Destroy()). This was not done when calling SetValue on a AttributeIOR so if someone manages GenericObj in the right way, the references in study could be lost. --- diff --git a/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx index 1ca91189e..79aee1e5b 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx @@ -36,8 +36,41 @@ char* SALOMEDS_AttributeIOR_i::Value() return c_s._retn(); } +//To disable automatic management of GenericObj, comment the following line +#define WITHGENERICOBJ + void SALOMEDS_AttributeIOR_i::SetValue(const char* value) { +#ifdef WITHGENERICOBJ + CORBA::Object_var obj; + SALOME::GenericObj_var gobj; + try + { + obj = _orb->string_to_object(value); + gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + gobj->Register(); + } + catch(const CORBA::Exception& e) + { + } + //unregister value + try + { + std::string value=dynamic_cast(_impl)->Value(); + if(value != "") + { + obj = _orb->string_to_object(value.c_str()); + gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + gobj->Destroy(); + } + } + catch(const CORBA::Exception& e) + { + } +#endif + SALOMEDS::Locker lock; CheckLocked(); CORBA::String_var Str = CORBA::string_dup(value);