Skip to content
Snippets Groups Projects
Commit 140a3f53 authored by Jan David Mol's avatar Jan David Mol
Browse files

Use uniform calling convention for function wrappers (always with brackets)

parent 382aa4d7
No related branches found
No related tags found
1 merge request!16Generic code cleanup
...@@ -160,8 +160,8 @@ class PCC(hardware_device): ...@@ -160,8 +160,8 @@ class PCC(hardware_device):
# -------- # --------
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_off(self): def RCU_off(self):
""" """
...@@ -171,8 +171,8 @@ class PCC(hardware_device): ...@@ -171,8 +171,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_on(self): def RCU_on(self):
""" """
...@@ -182,8 +182,8 @@ class PCC(hardware_device): ...@@ -182,8 +182,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def ADC_on(self): def ADC_on(self):
""" """
...@@ -193,8 +193,8 @@ class PCC(hardware_device): ...@@ -193,8 +193,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_update(self): def RCU_update(self):
""" """
...@@ -204,8 +204,8 @@ class PCC(hardware_device): ...@@ -204,8 +204,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_off(self): def CLK_off(self):
""" """
...@@ -215,8 +215,8 @@ class PCC(hardware_device): ...@@ -215,8 +215,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_on(self): def CLK_on(self):
""" """
...@@ -226,8 +226,8 @@ class PCC(hardware_device): ...@@ -226,8 +226,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_PLL_setup(self): def CLK_PLL_setup(self):
""" """
......
...@@ -58,8 +58,8 @@ class attribute_wrapper(attribute): ...@@ -58,8 +58,8 @@ class attribute_wrapper(attribute):
if access == AttrWriteType.READ_WRITE: if access == AttrWriteType.READ_WRITE:
""" if the attribute is of READ_WRITE type, assign the RW and write function to it""" """ if the attribute is of READ_WRITE type, assign the RW and write function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_RW(device): def read_RW(device):
# print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value)) # print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value))
""" """
...@@ -71,8 +71,8 @@ class attribute_wrapper(attribute): ...@@ -71,8 +71,8 @@ class attribute_wrapper(attribute):
raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", self) from e raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", self) from e
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def write_RW(device, value): def write_RW(device, value):
""" """
_write_RW writes a value to this attribute _write_RW writes a value to this attribute
...@@ -87,8 +87,8 @@ class attribute_wrapper(attribute): ...@@ -87,8 +87,8 @@ class attribute_wrapper(attribute):
else: else:
""" if the attribute is of READ type, assign the read function to it""" """ if the attribute is of READ type, assign the read function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_R(device): def read_R(device):
""" """
_read_R reads the attribute value, stores it and returns it" _read_R reads the attribute value, stores it and returns it"
......
...@@ -76,7 +76,7 @@ class hardware_device(Device): ...@@ -76,7 +76,7 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.FAULT, DevState.OFF]) @only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt() @DebugIt()
@fault_on_error @fault_on_error()
@log_exceptions() @log_exceptions()
def Initialise(self): def Initialise(self):
""" """
...@@ -104,7 +104,7 @@ class hardware_device(Device): ...@@ -104,7 +104,7 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.STANDBY]) @only_in_states([DevState.STANDBY])
@DebugIt() @DebugIt()
@fault_on_error @fault_on_error()
@log_exceptions() @log_exceptions()
def On(self): def On(self):
""" """
......
...@@ -22,32 +22,38 @@ def only_in_states(allowed_states): ...@@ -22,32 +22,38 @@ def only_in_states(allowed_states):
return wrapper return wrapper
def only_when_on(func): def only_when_on():
""" """
Wrapper to call and return the wrapped function if the device is Wrapper to call and return the wrapped function if the device is
in the ON state. Otherwise None is returned and nothing in the ON state. Otherwise None is returned and nothing
will be called. will be called.
""" """
@wraps(func) def inner(func):
def when_on_wrapper(self, *args, **kwargs): @wraps(func)
if self.get_state() == DevState.ON: def when_on_wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs) if self.get_state() == DevState.ON:
return func(self, *args, **kwargs)
return None
return None return when_on_wrapper
return when_on_wrapper return inner
def fault_on_error(func): def fault_on_error():
""" """
Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs. Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs.
""" """
@wraps(func) def inner(func):
def error_wrapper(self, *args, **kwargs): @wraps(func)
try: def error_wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs) try:
except Exception as e: return func(self, *args, **kwargs)
self.error_stream("Function failed. Trace: %s", traceback.format_exc()) except Exception as e:
self.Fault() self.error_stream("Function failed. Trace: %s", traceback.format_exc())
return None self.Fault()
return None
return error_wrapper
return error_wrapper return inner
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment