From 46fc79e7d0eaf01688ab5f2c445f05731280b86c Mon Sep 17 00:00:00 2001 From: caremoli Date: Fri, 22 May 2009 08:53:41 +0000 Subject: [PATCH] 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. --- src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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); -- 2.39.2