Skip to content
Snippets Groups Projects
Commit 3e84e4eb authored by Johannes Kung's avatar Johannes Kung
Browse files

Refactor signal

parent ddb95637
No related branches found
No related tags found
1 merge request!27Docstring refactor of core
...@@ -5,54 +5,77 @@ from typing import Any ...@@ -5,54 +5,77 @@ from typing import Any
class Signal: class Signal:
""" """
Handles datatransportation between modules in the processor. Signal class to send data between modules in a processor.
Each signal has one source module and can have multiple
destination modules. Parameters
----------
processor : Processor
Processor that the signal belongs to. Needed to queue processor modules
for update.
name : str
Name of the signal.
value : Any
Initial value of the signal.
""" """
def __init__(self, processor: Processor, name: str = "Signal", value = None):
self.processor = processor def __init__(self, processor: Processor, name: str = "Signal", value=None):
self.name = name self._processor = processor
self.source = None self._name = name
self.destinations = set() self._source = None
self.value = value self._destinations = set()
self._value = value
def add_destination(self, module: Module) -> None: def add_destination(self, module: Module) -> None:
""" """Add a module as a destination that the signal will send new
Add a destination module that the signal will send new
values to. values to.
""" """
self.destinations.add(module) self._destinations.add(module)
def set_source(self, module: Module) -> None:
"""
Set source module that will send values through the signal.
"""
self.source = module
def update_value(self, value) -> None: def update_value(self, value) -> None:
""" """
Sets value in signal and queues destination moduels for update. Set the value of the signal and queue destination modules for update.
Parameters
----------
value : Any
Value to set the signal to.
""" """
if value != self.value: if value != self._value:
self.value = value self._value = value
# Inform the processor on what modules have been given # Inform the processor on what modules have been given
# signal so they can update # signal so they can update
for destination in self.destinations: for destination in self._destinations:
self.processor.add_modules_to_update(destination) self._processor.add_modules_to_update(destination)
def get_value(self) -> Any: def get_value(self) -> Any:
""" """Get the current value of the signal.
Get the signals current value.
"""
return self.value
def set_value(self, value) -> None: Returns
-------
Any
Value of the signal.
""" """
Set the value of the signal without queuing the destination return self._value
modules of the signal for update. This method should not
be called by a module. def set_value(self, value: Any) -> None:
"""Set the value of the signal without queuing the destination
modules of the signal for update.
This method should not be called by a module.
Parameters
----------
value : any
Value to set the signal to.
""" """
self.value = value self._value = value
def get_name(self) -> str: def get_name(self) -> str:
return self.name """Return the name of the signal.
Returns
-------
str
Name of the signal.
"""
return self._name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment