Skip to content

Commit

Permalink
Support multiple parameter callback
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
  • Loading branch information
suab321321 committed Nov 12, 2019
2 parents 3a941ab + e566f3e commit 6ce54c9
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions rclpy/rclpy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,24 +763,35 @@ def _set_parameters_atomically(

return result

def add_on_set_paramters_callback(
def add_on_set_parameters_callback(
self,
callback: Callable[[List[Parameter]], SetParametersResult]
) -> None:
"""Add the callback to list."""
prevCallBack = self._parameters_callback
prevCallBack.insert(0, callback)
self._parameters_callback = prevCallBack
"""
Add a callback in front to the list of callback.
Calling this function will add a callback in self._parameter_callback list.
:param callback: The function that is called whenever parameters are set for the node.
"""
self._parameters_callback.insert(0, callback)

def remove_on_set_parameters_callback(
self,
callback: Callable[[List[Parameter]], SetParametersResult]
) -> None:
"""Remove callback from list."""
if callback in self._parameters_callback:
"""
Remove a callback from list of callback.
Calling this function will remove the callback from self._parameter_callback list.
:param callback: The function that is called whenever parameters are set for the node.
:raises: ValueError if a callback is not present in the list of callback.
"""
try:
self._parameters_callback.remove(callback)
else:
print('Callback does not exist')
except ValueError as vr:
print(vr)

def _apply_descriptors(
self,
Expand Down Expand Up @@ -1040,11 +1051,11 @@ def set_parameters_callback(
"""
Register a set parameters callback.
Calling this function will override any previously registered callback.
Calling this function will add a callback in self._parameter_callback list.
:param callback: The function that is called whenever parameters are set for the node.
"""
self._parameters_callback = callback
self.add_on_set_parameters_callback(callback)

def _validate_topic_or_service_name(self, topic_or_service_name, *, is_service=False):
name = self.get_name()
Expand Down

0 comments on commit 6ce54c9

Please sign in to comment.