introduced attached modules

for the module names, use Attach instead of Property,
which get attached modules automatically before calling initModule

Change-Id: Iff1b37828d4345c03a18ed29b9970bea149a812d
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/21885
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2019-11-22 17:00:46 +01:00
parent b2f730e53e
commit e953b53963
4 changed files with 21 additions and 6 deletions

View File

@ -407,3 +407,14 @@ class Communicator(Module):
result=StringType() 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

View File

@ -52,7 +52,7 @@ class Property:
self.settable = settable or mandatory # settable means settable from the cfg file self.settable = settable or mandatory # settable means settable from the cfg file
def __repr__(self): 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) self.description, self.datatype, self.default, self.extname, self.export, self.mandatory)

View File

@ -33,6 +33,7 @@ from daemon import DaemonContext
from secop.errors import ConfigError from secop.errors import ConfigError
from secop.lib import formatException, get_class, getGeneralConfig from secop.lib import formatException, get_class, getGeneralConfig
from secop.modules import Attached
try: try:
import daemon.pidlockfile as pidlockfile import daemon.pidlockfile as pidlockfile
@ -186,6 +187,12 @@ class Server:
# also call earlyInit on the modules # also call earlyInit on the modules
modobj.earlyInit() 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 # call init on each module after registering all
for modname, modobj in self.modules.items(): for modname, modobj in self.modules.items():
modobj.initModule() modobj.initModule()

View File

@ -42,7 +42,7 @@ import threading
import json import json
from secop.modules import Module, Readable, Drivable, Parameter, Override,\ from secop.modules import Module, Readable, Drivable, Parameter, Override,\
Communicator, Property Communicator, Property, Attached
from secop.datatypes import EnumType, FloatRange, IntRange, StringType,\ from secop.datatypes import EnumType, FloatRange, IntRange, StringType,\
BoolType, StatusType BoolType, StatusType
from secop.lib.enum import Enum from secop.lib.enum import Enum
@ -124,9 +124,7 @@ class Main(Communicator):
class PpmsMixin(Module): class PpmsMixin(Module):
properties = { properties = {
'iodev': 'iodev': Attached('_main'),
Property('attached communicator module',
datatype=StringType(), export=False, default=''),
} }
parameters = { parameters = {
'settings': 'settings':
@ -142,7 +140,6 @@ class PpmsMixin(Module):
slow_pollfactor = 1 slow_pollfactor = 1
def initModule(self): def initModule(self):
self._main = self.DISPATCHER.get_module(self.iodev)
self._main.register(self) self._main.register(self)
def startModule(self, started_callback): def startModule(self, started_callback):