Skip to content

Commit

Permalink
Use constants for parameter separator and request depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearsandwich committed Aug 10, 2018
1 parent 39698fb commit 4cd964a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions rclpy/rclpy/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from rcl_interfaces.msg import ParameterDescriptor, ParameterType, ParameterValue

PARAMETER_SEPARATOR_STRING = '.'


class Parameter:

Expand Down
14 changes: 7 additions & 7 deletions rclpy/rclpy/parameter_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from rcl_interfaces.srv import DescribeParameters, GetParameters, GetParameterTypes
from rcl_interfaces.srv import ListParameters, SetParameters, SetParametersAtomically
from rclpy.parameter import Parameter
from rclpy.parameter import Parameter, PARAMETER_SEPARATOR_STRING


class ParameterService:
Expand Down Expand Up @@ -81,24 +81,24 @@ def _list_parameters_callback(self, request, response):
if 1 == request.depth:
return response

if not 0 == request.depth:
# A depth of zero indicates infinite depth
if not request.DEPTH_RECURSIVE == request.depth:
names_with_prefixes = filter(
lambda name: name.count('.') + 1 <= request.depth, names_with_prefixes
)
for name in names_with_prefixes:
if request.prefixes:
for prefix in request.prefixes:
prefix_with_trailing_dot = '%s.' % (prefix)
if name.startswith(prefix_with_trailing_dot):
if name.startswith(prefix + PARAMETER_SEPARATOR_STRING):
response.result.names.append(name)
full_prefix = '.'.join(name.split('.')[0:-1])
full_prefix = PARAMETER_SEPARATOR_STRING.join(
name.split(PARAMETER_SEPARATOR_STRING)[0:-1])
if full_prefix not in response.result.prefixes:
response.result.prefixes.append(full_prefix)
if prefix not in response.result.prefixes:
response.result.prefixes.append(prefix)
else:
prefix = '.'.join(name.split('.')[0:-1])
prefix = PARAMETER_SEPARATOR_STRING.join(
name.split(PARAMETER_SEPARATOR_STRING)[0:-1])
if prefix not in response.result.prefixes:
response.result.prefixes.append(prefix)
response.result.names.append(name)
Expand Down

0 comments on commit 4cd964a

Please sign in to comment.