improve HasIodev
- automatically reuse communicators (iodevs) with the same uri - when uri and iodev is given, iodev gets the name of the auto-created communicator Change-Id: If30353c0b61104837e0f940968080c3c1e53c1c6 Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/23122 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@@ -196,20 +196,29 @@ class StringIO(Communicator):
|
|||||||
|
|
||||||
|
|
||||||
class HasIodev(Module):
|
class HasIodev(Module):
|
||||||
"""Mixin for modules using a communicator"""
|
"""Mixin for modules using a communicator
|
||||||
|
|
||||||
|
not only StringIO !
|
||||||
|
"""
|
||||||
properties = {
|
properties = {
|
||||||
'iodev': Attached(),
|
'iodev': Attached(),
|
||||||
'uri': Property('uri for auto creation of iodev', StringType(), default=''),
|
'uri': Property('uri for auto creation of iodev', StringType(), default=''),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iodevDict = {}
|
||||||
|
|
||||||
def __init__(self, name, logger, opts, srv):
|
def __init__(self, name, logger, opts, srv):
|
||||||
|
iodev = opts.pop('iodev', None)
|
||||||
super().__init__(name, logger, opts, srv)
|
super().__init__(name, logger, opts, srv)
|
||||||
if self.uri:
|
if self.uri:
|
||||||
opts = {'uri': self.uri, 'description': 'communication device for %s' % name,
|
opts = {'uri': self.uri, 'description': 'communication device for %s' % name,
|
||||||
'export': False}
|
'export': False}
|
||||||
ioname = name + '_iodev'
|
ioname = self.iodevDict.get(self.uri)
|
||||||
|
if not ioname:
|
||||||
|
ioname = iodev or name + '_iodev'
|
||||||
iodev = self.iodevClass(ioname, srv.log.getChild(ioname), opts, srv)
|
iodev = self.iodevClass(ioname, srv.log.getChild(ioname), opts, srv)
|
||||||
srv.modules[ioname] = iodev
|
srv.modules[ioname] = iodev
|
||||||
|
self.iodevDict[self.uri] = ioname
|
||||||
self.setProperty('iodev', ioname)
|
self.setProperty('iodev', ioname)
|
||||||
|
|
||||||
def initModule(self):
|
def initModule(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user