Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1273 from reszelaz/call-DeleteDevice
Browse files Browse the repository at this point in the history
Call controller's DeleteDevice when Tango calls delete_device
  • Loading branch information
reszelaz authored Feb 28, 2020
2 parents 256944d + e226724 commit 76a8cf3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sardana/pool/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ def delete_element(self, name):
self.remove_element(elem)

self.fire_event(EventType("ElementDeleted"), elem)
if hasattr(elem, "get_controller"):
elem.set_deleted(True)

def create_instrument(self, full_name, klass_name, id=None):
is_root = full_name.count('/') == 1
Expand Down
9 changes: 9 additions & 0 deletions src/sardana/pool/poolelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, **kwargs):
self._ctrl = weakref.ref(ctrl)
self._axis = kwargs.pop('axis')
self._ctrl_id = ctrl.get_id()
self._deleted = False
try:
instrument = kwargs.pop('instrument')
self.set_instrument(instrument)
Expand Down Expand Up @@ -74,6 +75,12 @@ def get_controller_id(self):
def get_axis(self):
return self._axis

def is_deleted(self):
return self._deleted

def set_deleted(self, deleted):
self._deleted = deleted

def set_action_cache(self, action_cache):
self._action_cache = action_cache
action_cache.add_element(self)
Expand Down Expand Up @@ -143,3 +150,5 @@ def set_extra_par(self, name, value):
controller_id = property(get_controller_id, doc="element controller id")
instrument = property(get_instrument, set_instrument,
doc="element instrument")
deleted = property(is_deleted, set_deleted,
doc="element is deleted from pool (experimental API)")
15 changes: 15 additions & 0 deletions src/sardana/tango/pool/PoolDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,21 @@ def init_device(self):
except ValueError:
pass

def delete_device(self):
element = self.element
if not element.deleted:
pool_ctrl = self.ctrl
ctrl = pool_ctrl.ctrl
if ctrl is not None:
axis = element.axis
try:
ctrl.DeleteDevice(axis)
except Exception:
name = element.name
self.error("Unable to delete %s(%s)", name, axis,
exc_info=1)
PoolDevice.delete_device(self)

def read_Instrument(self, attr):
"""Read the value of the ``Instrument`` tango attribute.
Returns the instrument full name or empty string if this element doesn't
Expand Down

0 comments on commit 76a8cf3

Please sign in to comment.