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):
# --------
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def RCU_off(self):
"""
......@@ -171,8 +171,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def RCU_on(self):
"""
......@@ -182,8 +182,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def ADC_on(self):
"""
......@@ -193,8 +193,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def RCU_update(self):
"""
......@@ -204,8 +204,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def CLK_off(self):
"""
......@@ -215,8 +215,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def CLK_on(self):
"""
......@@ -226,8 +226,8 @@ class PCC(hardware_device):
@command()
@DebugIt()
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def CLK_PLL_setup(self):
"""
......
......@@ -58,8 +58,8 @@ class attribute_wrapper(attribute):
if access == AttrWriteType.READ_WRITE:
""" if the attribute is of READ_WRITE type, assign the RW and write function to it"""
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def read_RW(device):
# 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):
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
@fault_on_error
@only_when_on()
@fault_on_error()
def write_RW(device, value):
"""
_write_RW writes a value to this attribute
......@@ -87,8 +87,8 @@ class attribute_wrapper(attribute):
else:
""" if the attribute is of READ type, assign the read function to it"""
@only_when_on
@fault_on_error
@only_when_on()
@fault_on_error()
def read_R(device):
"""
_read_R reads the attribute value, stores it and returns it"
......
......@@ -76,7 +76,7 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt()
@fault_on_error
@fault_on_error()
@log_exceptions()
def Initialise(self):
"""
......@@ -104,7 +104,7 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.STANDBY])
@DebugIt()
@fault_on_error
@fault_on_error()
@log_exceptions()
def On(self):
"""
......
......@@ -22,32 +22,38 @@ def only_in_states(allowed_states):
return wrapper
def only_when_on(func):
def only_when_on():
"""
Wrapper to call and return the wrapped function if the device is
in the ON state. Otherwise None is returned and nothing
will be called.
"""
@wraps(func)
def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON:
return func(self, *args, **kwargs)
def inner(func):
@wraps(func)
def when_on_wrapper(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.
"""
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
self.error_stream("Function failed. Trace: %s", traceback.format_exc())
self.Fault()
return None
def inner(func):
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
self.error_stream("Function failed. Trace: %s", traceback.format_exc())
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