Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions rosidl_generator_py/resource/_idl_support.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ TEMPLATE(
package_name=package_name, interface_path=interface_path,
message=service.response_message, include_directives=include_directives)
}@

@{
TEMPLATE(
'_msg_support.c.em',
package_name=package_name, interface_path=interface_path,
message=service.event_message, include_directives=include_directives)
}@
@[end for]@
@
@#######################################################################
Expand Down Expand Up @@ -97,6 +104,14 @@ TEMPLATE(
include_directives=include_directives)
}@

@{
TEMPLATE(
'_msg_support.c.em',
package_name=package_name, interface_path=interface_path,
message=action.send_goal_service.event_message,
include_directives=include_directives)
}@

@{
TEMPLATE(
'_msg_support.c.em',
Expand All @@ -113,6 +128,14 @@ TEMPLATE(
include_directives=include_directives)
}@

@{
TEMPLATE(
'_msg_support.c.em',
package_name=package_name, interface_path=interface_path,
message=action.get_result_service.event_message,
include_directives=include_directives)
}@

@{
TEMPLATE(
'_msg_support.c.em',
Expand Down
8 changes: 8 additions & 0 deletions rosidl_generator_py/resource/_msg.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ from rosidl_parser.definition import AbstractWString
from rosidl_parser.definition import ACTION_FEEDBACK_SUFFIX
from rosidl_parser.definition import ACTION_GOAL_SUFFIX
from rosidl_parser.definition import ACTION_RESULT_SUFFIX
from rosidl_parser.definition import SERVICE_EVENT_MESSAGE_SUFFIX
from rosidl_parser.definition import SERVICE_REQUEST_MESSAGE_SUFFIX
from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX
from rosidl_parser.definition import Array
from rosidl_parser.definition import BasicType
from rosidl_parser.definition import BOOLEAN_TYPE
Expand Down Expand Up @@ -129,6 +132,11 @@ for member in message.structure.members:
if isinstance(type_, AbstractNestedType):
type_ = type_.value_type
if isinstance(type_, NamespacedType):
if (
type_.name.endswith(SERVICE_RESPONSE_MESSAGE_SUFFIX) or
type_.name.endswith(SERVICE_REQUEST_MESSAGE_SUFFIX)
):
continue
if (
type_.name.endswith(ACTION_GOAL_SUFFIX) or
type_.name.endswith(ACTION_RESULT_SUFFIX) or
Expand Down
7 changes: 6 additions & 1 deletion rosidl_generator_py/resource/_msg_support.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ from rosidl_parser.definition import Array
from rosidl_parser.definition import BasicType
from rosidl_parser.definition import EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME
from rosidl_parser.definition import NamespacedType
from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX
from rosidl_parser.definition import SERVICE_REQUEST_MESSAGE_SUFFIX


def primitive_msg_type_to_c(type_):
Expand Down Expand Up @@ -119,7 +121,10 @@ if isinstance(member.type, AbstractNestedType) and isinstance(member.type.value_
nested_header = '/'.join(type_[:-1] + ('detail', convert_camel_case_to_lower_case_underscore(type_[-1]),))
nested_header += '__functions.h'
}@
@[ if nested_header in include_directives]@
@[ if type_[-1].endswith(SERVICE_REQUEST_MESSAGE_SUFFIX) or type_[-1].endswith(SERVICE_RESPONSE_MESSAGE_SUFFIX)]
@# Service request/response messages are included in the srv__struct
@[continue]
Comment on lines +125 to +126
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use the same style as L128-129 to avoid confusions

@[ elif nested_header in include_directives]@
// already included above
// @
@[ else]@
Expand Down
7 changes: 7 additions & 0 deletions rosidl_generator_py/resource/_srv.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ TEMPLATE(
'_msg.py.em',
package_name=package_name, interface_path=interface_path,
message=service.response_message, import_statements=import_statements)
TEMPLATE(
'_msg.py.em',
package_name=package_name, interface_path=interface_path,
message=service.event_message, import_statements=import_statements)
}@


Expand Down Expand Up @@ -42,11 +46,14 @@ class Metaclass_@(service.namespaced_type.name)(type):
@(module_name).Metaclass_@(service.request_message.structure.namespaced_type.name).__import_type_support__()
if @(module_name).Metaclass_@(service.response_message.structure.namespaced_type.name)._TYPE_SUPPORT is None:
@(module_name).Metaclass_@(service.response_message.structure.namespaced_type.name).__import_type_support__()
if @(module_name).Metaclass_@(service.event_message.structure.namespaced_type.name)._TYPE_SUPPORT is None:
@(module_name).Metaclass_@(service.event_message.structure.namespaced_type.name).__import_type_support__()


class @(service.namespaced_type.name)(metaclass=Metaclass_@(service.namespaced_type.name)):
from @('.'.join(service.namespaced_type.namespaces)).@(module_name) import @(service.request_message.structure.namespaced_type.name) as Request
from @('.'.join(service.namespaced_type.namespaces)).@(module_name) import @(service.response_message.structure.namespaced_type.name) as Response
from @('.'.join(service.namespaced_type.namespaces)).@(module_name) import @(service.event_message.structure.namespaced_type.name) as Event

def __init__(self):
raise NotImplementedError('Service classes can not be instantiated')
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ TEMPLATE(
include_directives=include_directives,
register_functions=register_functions)
}@

@{
TEMPLATE(
'_msg_pkg_typesupport_entry_point.c.em',
package_name=package_name, idl_type=idl_type,
message=service.event_message, typesupport_impl=typesupport_impl,
include_directives=include_directives,
register_functions=register_functions)
}@
@
@{
from rosidl_pycommon import convert_camel_case_to_lower_case_underscore
Expand Down
29 changes: 29 additions & 0 deletions rosidl_generator_py/rosidl_generator_py/generate_py_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,35 @@ def print_warning_if_reserved_keyword(member_name, interface_type, interface_nam
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem} # noqa: F401\n')
if subfolder == 'srv':
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_Event # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_Request # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_Response # noqa: F401\n')
elif subfolder == 'action':
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_GetResult_Event # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_GetResult_Request # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_GetResult_Response # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_SendGoal_Event # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_SendGoal_Request # noqa: F401\n')
f.write(
f'from {package_name}.{subfolder}.{module_name} import '
f'{idl_stem}_SendGoal_Response # noqa: F401\n')

# expand templates per available typesupport implementation
template_dir = args['template_dir']
Expand Down