Salome HOME
CCAR: add a python module for automatic management of genericobj
authorcaremoli <caremoli>
Mon, 18 May 2009 17:11:32 +0000 (17:11 +0000)
committercaremoli <caremoli>
Mon, 18 May 2009 17:11:32 +0000 (17:11 +0000)
      reference counting.
      The module is not active by default.
      It must be imported to activate the automatic reference counting

src/KERNEL_PY/Makefile.am
src/KERNEL_PY/salome_genericobj.py [new file with mode: 0644]

index 869e2f9137af27ad3b6f6063c178b64dd5ca98d4..6b2457c055e30505212ac6039fd6f1f00b8496ba 100755 (executable)
@@ -47,7 +47,8 @@ if CORBA_GEN
                omnipatch.py \
                iparameters.py \
                salome_version.py \
-               salome_notebook.py
+               salome_notebook.py \
+    salome_genericobj.py
 endif
 
 sharedpkgpython_PYTHON = kernel_shared_modules.py
diff --git a/src/KERNEL_PY/salome_genericobj.py b/src/KERNEL_PY/salome_genericobj.py
new file mode 100644 (file)
index 0000000..053f4ae
--- /dev/null
@@ -0,0 +1,24 @@
+"""
+ When imported this module adds to CORBA objref from GenericObj type
+ automatic management of reference count
+ The reference count is incremented when the local proxy is created (assignment of __omni_obj attribute)
+ and is decremented when the local proxy is deleted (call of __del__) 
+
+ The GenericObj class for proxy is modified by adding two methods : __del__ and __setattr__
+ The module must be imported before any other import of SALOME CORBA module
+"""
+import omniORB
+import SALOME
+
+def mydel(self):
+    self.Destroy()
+    omniORB.CORBA.Object.__del__(self)
+
+def mysetattr(self,attr,value):
+    self.__dict__[attr]=value
+    if attr == "__omni_obj":
+      self.Register()
+
+SALOME._objref_GenericObj.__del__=mydel
+SALOME._objref_GenericObj.__setattr__=mysetattr
+