diff --git a/secop/modules.py b/secop/modules.py index 5d3dfad..3153d6f 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -407,3 +407,14 @@ class Communicator(Module): result=StringType() ), } + + + +class Attached(Property): + # we can not put this to properties.py, as it needs datatypes + def __init__(self, attrname=None): + self.attrname = attrname + super().__init__('attached module', StringType()) + + def __repr__(self): + return 'Attached(%r)' % self.description diff --git a/secop/properties.py b/secop/properties.py index 5fe4bd1..eac01d4 100644 --- a/secop/properties.py +++ b/secop/properties.py @@ -52,7 +52,7 @@ class Property: self.settable = settable or mandatory # settable means settable from the cfg file def __repr__(self): - return 'Property(%s, %s, default=%r, extname=%r, export=%r, mandatory=%r)' % ( + return 'Property(%r, %s, default=%r, extname=%r, export=%r, mandatory=%r)' % ( self.description, self.datatype, self.default, self.extname, self.export, self.mandatory) diff --git a/secop/server.py b/secop/server.py index 09ac38a..5eef4ed 100644 --- a/secop/server.py +++ b/secop/server.py @@ -33,6 +33,7 @@ from daemon import DaemonContext from secop.errors import ConfigError from secop.lib import formatException, get_class, getGeneralConfig +from secop.modules import Attached try: import daemon.pidlockfile as pidlockfile @@ -186,6 +187,12 @@ class Server: # also call earlyInit on the modules modobj.earlyInit() + # handle attached modules + for modname, modobj in self.modules.items(): + for propname, propobj in modobj.__class__.properties.items(): + if isinstance(propobj, Attached): + setattr(modobj, propobj.attrname or '_' + propname, + self.dispatcher.get_module(modobj.properties[propname])) # call init on each module after registering all for modname, modobj in self.modules.items(): modobj.initModule() diff --git a/secop_psi/ppms.py b/secop_psi/ppms.py index 28acb48..0420d6b 100755 --- a/secop_psi/ppms.py +++ b/secop_psi/ppms.py @@ -42,7 +42,7 @@ import threading import json from secop.modules import Module, Readable, Drivable, Parameter, Override,\ - Communicator, Property + Communicator, Property, Attached from secop.datatypes import EnumType, FloatRange, IntRange, StringType,\ BoolType, StatusType from secop.lib.enum import Enum @@ -124,9 +124,7 @@ class Main(Communicator): class PpmsMixin(Module): properties = { - 'iodev': - Property('attached communicator module', - datatype=StringType(), export=False, default=''), + 'iodev': Attached('_main'), } parameters = { 'settings': @@ -142,7 +140,6 @@ class PpmsMixin(Module): slow_pollfactor = 1 def initModule(self): - self._main = self.DISPATCHER.get_module(self.iodev) self._main.register(self) def startModule(self, started_callback):