#else
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
#endif
- SALOME_NamingService* NS;
+ SALOME_NamingService NS;
// Obtain a reference to the root POA.
long TIMESleep = 500000000;
int NumberOfTries = 40;
if(EnvL==1)
{
CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
- NS = SINGLETON_<SALOME_NamingService>::Instance() ;
- NS->init_orb( orb1 ) ;
+ NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
+ NS.init_orb( orb1 ) ;
for(int j=1; j<=NumberOfTries; j++)
{
if (j!=1)
// ready to accept requests.
PortableServer::ObjectId_var myStudy_iid = poa->activate_object(myStudy_i);
SALOMEDS::Study_var Study = myStudy_i->_this();
-
- if (!NS)
- {
- NS = SINGLETON_<SALOME_NamingService>::Instance();
- NS->init_orb( orb );
- }
- NS->Register(Study.in(), "/Study");
+ NS.Register(Study.in(), "/Study");
// Assign the value of the IOR in the study->root
CORBA::String_var IORStudy = orb->object_to_string(Study);
CORBA::ORB_var _orb;
};
+ class GenObjRegister: public SALOMEDSImpl_AbstractCallback
+ {
+ public:
+ GenObjRegister(CORBA::ORB_ptr orb)
+ {
+ _orb = CORBA::ORB::_duplicate(orb);
+ }
+ virtual void RegisterGenObj (const std::string& theIOR)
+ {
+ try
+ {
+ CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+ if ( obj->_non_existent() ) return;
+ SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->Register();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+ }
+ virtual void UnRegisterGenObj(const std::string& theIOR)
+ {
+ try
+ {
+ CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+ if ( obj->_non_existent() ) return;
+ SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->UnRegister();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+ }
+
+ private:
+ CORBA::ORB_var _orb;
+ };
+
} // namespace SALOMEDS
//============================================================================
{
_builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
_notifier = new SALOMEDS::Notifier(_orb);
+ _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
_closed = false;
_impl->setNotifier(_notifier);
+ _impl->setGenObjRegister( _genObjRegister );
// Notify GUI that study was created
SALOME_NamingService *aNamingService = KERNEL::getNamingService();
_impl->Clear();
_impl->setNotifier(0);
delete _notifier;
+ delete _genObjRegister;
SALOMEDS::Locker lock;
_impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
}
+SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
+{
+ SALOMEDS::Locker lock;
+
+ SALOMEDSImpl_AttributeIOR* Att = NULL;
+ if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
+ char* IOR = CORBA::string_dup(Att->Value().c_str());
+ CORBA::Object_var obj = orb->string_to_object(IOR);
+ SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
+ ASSERT(!CORBA::is_nil(aStudy));
+ return SALOMEDS::Study::_duplicate(aStudy);
+ } else {
+ MESSAGE("GetStudy: Problem to get study");
+ }
+ return SALOMEDS::Study::_nil();
+}
+
void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
{
SALOMEDS::Locker lock;
SALOMEDSImpl_Study* _impl;
SALOMEDS_StudyBuilder_i* _builder;
SALOMEDSImpl_AbstractCallback* _notifier;
+ SALOMEDSImpl_AbstractCallback* _genObjRegister;
SALOMEDS_DriverFactory_i* _factory;
bool _closed;
CheckLocked();
Backup();
+ //remove IOR entry in study
+ if(theValue != myString)
+ {
+ SALOMEDSImpl_Study* study=SALOMEDSImpl_Study::GetStudy(Label());
+ study->RegisterGenObj(theValue, Label());
+ study->UnRegisterGenObj(myString, Label());
+ study->DeleteIORLabelMapItem(myString);
+ }
myString = theValue;
+
+ //add IOR entry in study
+ SALOMEDSImpl_Study::IORUpdated(this);
//Reason = 5 means that IOR attribute updated
//Used in the gui module to detect that IOR attribure was assigned to the object
SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR()
{
+ SALOMEDSImpl_Study::UnRegisterGenObj(myString, Label());
}
//=======================================================================
virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;};
virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason ){return false;};
virtual bool modifyNB_Notification(const char* theVarName){return false;};
+ virtual void RegisterGenObj (const std::string& theIOR) {}
+ virtual void UnRegisterGenObj(const std::string& theIOR) {}
};
#endif
_builder = new SALOMEDSImpl_StudyBuilder(this);
_cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
_notifier=0;
+ _genObjRegister=0;
//Put on the root label a StudyHandle attribute to store the address of this object
//It will be used to retrieve the study object by DF_Label that belongs to the study
SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
_notifier=notifier;
}
+static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc )
+{
+ static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec;
+ if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() )
+ _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 );
+ return _genObjRegVec[ doc->GetDocumentID() ];
+}
+
+//================================================================================
+/*!
+ * \brief Stores theRegister
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister)
+{
+ getGenObjRegister( _doc ) = theRegister;
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::Register()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::RegisterGenObj (const std::string& theIOR, DF_Label label)
+{
+ if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+ goRegister->RegisterGenObj( theIOR );
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::UnRegister()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label)
+{
+ if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+ goRegister->UnRegisterGenObj( theIOR );
+}
+
//#######################################################################################################
//# STATIC PRIVATE FUNCTIONS
//#######################################################################################################
SALOMEDSImpl_StudyBuilder* _builder;
SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
SALOMEDSImpl_AbstractCallback* _notifier;
+ SALOMEDSImpl_AbstractCallback* _genObjRegister;
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason);
virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier);
+ static void RegisterGenObj (const std::string& theIOR, DF_Label label);
+ static void UnRegisterGenObj(const std::string& theIOR, DF_Label label);
+ void setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister);
+
friend class SALOMEDSImpl_GenericAttribute;
friend class SALOMEDSImpl_GenericVariable;
};
persist_ref,
isMultiFile,
isASCII);
- SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
+ SALOMEDSImpl_AttributeIOR* iorAttr = SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
+
+ // make myRefCounter of a loaded GenericObj == 1
+ SALOMEDSImpl_Study::UnRegisterGenObj( ior_string, iorAttr->Label());
}
Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);
}