From fd95a631a998c126acff3ca96c88b4dff7636438 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Wed, 15 Jun 2022 13:15:33 +0200 Subject: [PATCH 1/4] add .editorconfig --- .editorconfig | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..a90be369 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,268 @@ +# See http://EditorConfig.org for more information about .editorconfig files. + +# Install VSCode extension for support in all file types. +# The C# extension does the .NET specific stuff. +# https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig +# https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp + + +# Non C# specific config taken from https://github.com/RehanSaeed/EditorConfig/ + +# This file is the top-most EditorConfig file +root = true + +# All Files +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +# Visual Studio Solution Files +[*.sln] +indent_style = tab + +# Visual Studio XML Project Files +[*.{csproj,vbproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# XML Configuration Files +[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}] +indent_size = 2 + +# JSON Files +[*.{json,json5,webmanifest}] +indent_size = 2 + +# YAML Files +[*.{yml,yaml}] +indent_size = 2 + +# Markdown Files +[*.{md,mdx}] +indent_size = 2 +trim_trailing_whitespace = false + +# Web Files +[*.{htm,html,js,jsm,ts,tsx,cjs,cts,ctsx,mjs,mts,mtsx,css,sass,scss,less,pcss,svg,vue}] +indent_size = 2 + +# Batch Files +[*.{cmd,bat}] +end_of_line = crlf + +# Bash Files +[*.sh] +end_of_line = lf + +# Makefiles +[Makefile] +indent_style = tab + +# Generic stuff not taken from the above repo + +# CMake +[{CMakeLists.txt,*.cmake,*.rst}] +indent_size = 2 +indent_style = space + + +# The next section is based on https://github.com/terrajobst/apireview.net/blob/main/.editorconfig +# with some modifications to not be so strict or more in sync with the +# Coding Style Conventions from the book "Framework Design Guidlines". +# The Coding Style Conventions the book are derived from this file https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md + +# see https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ + +# Dotnet code style settings: +[*.{cs,vb}] +# Sort using and Import directives with System.* appearing first +dotnet_sort_system_directives_first = true +# Avoid "this." and "Me." if not necessary +dotnet_style_qualification_for_field = false:error +dotnet_style_qualification_for_property = false:error +dotnet_style_qualification_for_method = false:error +dotnet_style_qualification_for_event = false:error + +# Use language keywords instead of framework type names for type references +dotnet_style_predefined_type_for_locals_parameters_members = true:error +dotnet_style_predefined_type_for_member_access = true:error + +# Suggest more modern language features when available +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion + +# Non-private static fields are PascalCase +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style + +dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected internal, private protected +dotnet_naming_symbols.non_private_static_fields.required_modifiers = static + +dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case + +# Constants are PascalCase +dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants +dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style + +dotnet_naming_symbols.constants.applicable_kinds = field, local +dotnet_naming_symbols.constants.required_modifiers = const + +dotnet_naming_style.constant_style.capitalization = pascal_case + +# Instance fields are camelCase and start with _ +dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion +dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields +dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style + +dotnet_naming_symbols.instance_fields.applicable_kinds = field + +dotnet_naming_style.instance_field_style.capitalization = camel_case +dotnet_naming_style.instance_field_style.required_prefix = _ + +# Locals and parameters are camelCase +dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion +dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters +dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style + +dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local + +dotnet_naming_style.camel_case_style.capitalization = camel_case + +# Local functions are PascalCase +dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions +dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style + +dotnet_naming_symbols.local_functions.applicable_kinds = local_function + +dotnet_naming_style.local_function_style.capitalization = pascal_case + +# By default, name items with PascalCase +dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members +dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style + +dotnet_naming_symbols.all_members.applicable_kinds = * + +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# CSharp code style settings: +[*.cs] +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left + +# Prefer "var" everywhere +# Deactivated to not prefere "var", as the recomendation from "Framework Design Guidelines" is to be explicit +# unless the type is apparent from the initializer. +# Main reason is so this is clearer to the reader of the code which types are involved. +# I wouldn't go the other extreme to require explicit types everywhere (except where apparent) as well. +# Maybe we can agree without tooling to not use var when not apparent but don't call it "wrong" either if we do. +# +# dotnet_diagnostic.IDE0007.severity = error +# csharp_style_var_for_built_in_types = false:error +# csharp_style_var_when_type_is_apparent = true:error +# csharp_style_var_elsewhere = true:error + +# Prefer method-like constructs to have a block body +csharp_style_expression_bodied_methods = false:none +csharp_style_expression_bodied_constructors = false:none +csharp_style_expression_bodied_operators = false:none + +# Prefer property-like constructs to have an expression-body +csharp_style_expression_bodied_properties = true:error +csharp_style_expression_bodied_indexers = true:error +csharp_style_expression_bodied_accessors = true:error + +# Suggest more modern language features when available +csharp_style_pattern_matching_over_is_with_cast_check = true:error +csharp_style_pattern_matching_over_as_with_null_check = true:error +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_throw_expression = true:error +csharp_style_conditional_delegate_call = true:suggestion + +# Newline settings +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Spacing +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_around_binary_operators = before_and_after +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false + +# Labels (should someone need them...) +csharp_indent_labels = one_less_than_current + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = always:warning +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning + +# Blocks are allowed +# AVOID omitting braces, except for argument validation at the start of the method. +# Not enforced though via tooling. +csharp_prefer_braces = false:silent +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +# DO NOT use the bracless variant of the "using" statement +csharp_prefer_simple_using_statement = false:warning + +# IDE0035: Remove unreachable code +dotnet_diagnostic.IDE0035.severity = warning + +# IDE0036: Order modifiers +dotnet_diagnostic.IDE0036.severity = warning + +# IDE0040: Add accessibility modifiers +dotnet_diagnostic.IDE0040.severity = warning + +# IDE0043: Format string contains invalid placeholder +dotnet_diagnostic.IDE0043.severity = warning + +# IDE0044: Make field readonly +dotnet_diagnostic.IDE0044.severity = warning + +# CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings? +# IDE0051: Remove unused private member +dotnet_diagnostic.IDE0051.severity = warning + +# IDE0052: Remove unread private member +dotnet_diagnostic.IDE0052.severity = warning + +# IDE0055: Fix formating +# see https://docs.microsoft.com/de-de/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#rule-id-ide0055-fix-formatting +dotnet_diagnostic.IDE0055.severity = warning + +# IDE0059: Unnecessary assignment to a value +dotnet_diagnostic.IDE0059.severity = warning + +# IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0060.severity = warning + +# IDE0005: Using directive is unnecessary +dotnet_diagnostic.IDE0005.severity = warning From 665535536ee2c467998188b2d337240fa45cfc19 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Wed, 15 Jun 2022 15:28:05 +0200 Subject: [PATCH 2/4] format code using `dotnet format` This was done with an temporary *.csproj file in the root of the repository: ```xml netstandard2.0 ``` Then run command `dotnet format` (from .NET6) in the root of the repository. Did some manual whitespace changes as well, mainly indented wrapped parameters. --- rcldotnet/Client.cs | 6 +- rcldotnet/MessageStaticMemberCache.cs | 6 +- rcldotnet/Node.cs | 379 +-- rcldotnet/Publisher.cs | 119 +- rcldotnet/RCLExceptionHelper.cs | 2 +- rcldotnet/RCLdotnet.cs | 1041 +++---- rcldotnet/SafeClientHandle.cs | 6 +- rcldotnet/SafeNodeHandle.cs | 2 +- rcldotnet/SafePublisherHandle.cs | 6 +- rcldotnet/SafeServiceHandle.cs | 6 +- rcldotnet/SafeSubscriptionHandle.cs | 6 +- rcldotnet/SafeWaitSetHandle.cs | 2 +- rcldotnet/Service.cs | 18 +- .../ServiceDefinitionStaticMemberCache.cs | 4 +- rcldotnet/Subscription.cs | 68 +- rcldotnet/test/test_messages.cs | 2640 ++++++++--------- rcldotnet/test/test_services.cs | 4 +- rcldotnet_common/DllLoadUtils.cs | 562 ++-- rcldotnet_common/IRosMessage.cs | 2 +- rcldotnet_examples/RCLDotnetClient.cs | 10 +- rcldotnet_examples/RCLDotnetListener.cs | 25 +- rcldotnet_examples/RCLDotnetService.cs | 4 - rcldotnet_examples/RCLDotnetTalker.cs | 42 +- 23 files changed, 2525 insertions(+), 2435 deletions(-) diff --git a/rcldotnet/Client.cs b/rcldotnet/Client.cs index fd7d2a35..695c8ec4 100644 --- a/rcldotnet/Client.cs +++ b/rcldotnet/Client.cs @@ -25,13 +25,13 @@ internal static class ClientDelegates { internal static readonly DllLoadUtils dllLoadUtils; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLSendRequestType( SafeClientHandle clientHandle, SafeHandle requestHandle, out long seqneceNumber); internal static NativeRCLSendRequestType native_rcl_send_request = null; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLServiceServerIsAvailableType( SafeNodeHandle nodeHandle, SafeClientHandle clientHandle, out bool isAvailable); @@ -84,7 +84,7 @@ public sealed class Client : Client // ros2_java uses a WeakReference here. Not sure if its needed or not. private readonly Node _node; private readonly ConcurrentDictionary _pendingRequests = new ConcurrentDictionary(); - + internal Client(SafeClientHandle handle, Node node) { Handle = handle; diff --git a/rcldotnet/MessageStaticMemberCache.cs b/rcldotnet/MessageStaticMemberCache.cs index 0bade221..2567cb5f 100644 --- a/rcldotnet/MessageStaticMemberCache.cs +++ b/rcldotnet/MessageStaticMemberCache.cs @@ -22,8 +22,8 @@ namespace ROS2 internal static class MessageStaticMemberCache where T : IRosMessage { - private static IntPtr s_typeSupport; - private static Func s_createMessageHandle; + private static readonly IntPtr s_typeSupport; + private static readonly Func s_createMessageHandle; static MessageStaticMemberCache() { @@ -71,7 +71,7 @@ public static IntPtr GetTypeSupport() { throw new InvalidOperationException($"Type '{typeof(T).FullName}' did not define a correct __GetTypeSupport mehtod."); } - + return s_typeSupport; } diff --git a/rcldotnet/Node.cs b/rcldotnet/Node.cs index 9d020b4a..342dbb6b 100644 --- a/rcldotnet/Node.cs +++ b/rcldotnet/Node.cs @@ -18,228 +18,235 @@ using System.Runtime.InteropServices; using ROS2.Utils; -namespace ROS2 { - internal static class NodeDelegates { - private static readonly DllLoadUtils dllLoadUtils; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreatePublisherHandleType ( - ref SafePublisherHandle publisherHandle, SafeNodeHandle nodeHandle, [MarshalAs (UnmanagedType.LPStr)] string nodeName, IntPtr typesupportHandle); - - internal static NativeRCLCreatePublisherHandleType native_rcl_create_publisher_handle = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroyPublisherHandleType ( - IntPtr publisherHandle, SafeNodeHandle nodeHandle); - - internal static NativeRCLDestroyPublisherHandleType native_rcl_destroy_publisher_handle = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreateSubscriptionHandleType ( - ref SafeSubscriptionHandle subscriptionHandle, SafeNodeHandle nodeHandle, [MarshalAs (UnmanagedType.LPStr)] string nodeName, IntPtr typesupportHandle); - - internal static NativeRCLCreateSubscriptionHandleType native_rcl_create_subscription_handle = null; +namespace ROS2 +{ + internal static class NodeDelegates + { + private static readonly DllLoadUtils dllLoadUtils; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroySubscriptionHandleType ( - IntPtr subscriptionHandle, SafeNodeHandle nodeHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreatePublisherHandleType( + ref SafePublisherHandle publisherHandle, SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string nodeName, IntPtr typesupportHandle); - internal static NativeRCLDestroySubscriptionHandleType native_rcl_destroy_subscription_handle = null; + internal static NativeRCLCreatePublisherHandleType native_rcl_create_publisher_handle = null; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreateServiceHandleType ( - ref SafeServiceHandle serviceHandle, SafeNodeHandle nodeHandle, [MarshalAs (UnmanagedType.LPStr)] string serviceName, IntPtr typesupportHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroyPublisherHandleType( + IntPtr publisherHandle, SafeNodeHandle nodeHandle); - internal static NativeRCLCreateServiceHandleType native_rcl_create_service_handle = null; + internal static NativeRCLDestroyPublisherHandleType native_rcl_destroy_publisher_handle = null; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroyServiceHandleType ( - IntPtr serviceHandle, SafeNodeHandle nodeHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreateSubscriptionHandleType( + ref SafeSubscriptionHandle subscriptionHandle, SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string nodeName, IntPtr typesupportHandle); - internal static NativeRCLDestroyServiceHandleType native_rcl_destroy_service_handle = null; + internal static NativeRCLCreateSubscriptionHandleType native_rcl_create_subscription_handle = null; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreateClientHandleType ( - ref SafeClientHandle clientHandle, SafeNodeHandle nodeHandle, [MarshalAs (UnmanagedType.LPStr)] string serviceName, IntPtr typesupportHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroySubscriptionHandleType( + IntPtr subscriptionHandle, SafeNodeHandle nodeHandle); - internal static NativeRCLCreateClientHandleType native_rcl_create_client_handle = null; + internal static NativeRCLDestroySubscriptionHandleType native_rcl_destroy_subscription_handle = null; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroyClientHandleType ( - IntPtr clientHandle, SafeNodeHandle nodeHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreateServiceHandleType( + ref SafeServiceHandle serviceHandle, SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string serviceName, IntPtr typesupportHandle); - internal static NativeRCLDestroyClientHandleType native_rcl_destroy_client_handle = null; + internal static NativeRCLCreateServiceHandleType native_rcl_create_service_handle = null; - static NodeDelegates () { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils (); - IntPtr nativelibrary = dllLoadUtils.LoadLibrary ("rcldotnet_node"); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroyServiceHandleType( + IntPtr serviceHandle, SafeNodeHandle nodeHandle); - IntPtr native_rcl_create_publisher_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_create_publisher_handle"); + internal static NativeRCLDestroyServiceHandleType native_rcl_destroy_service_handle = null; - NodeDelegates.native_rcl_create_publisher_handle = - (NativeRCLCreatePublisherHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_publisher_handle_ptr, typeof (NativeRCLCreatePublisherHandleType)); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreateClientHandleType( + ref SafeClientHandle clientHandle, SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string serviceName, IntPtr typesupportHandle); - IntPtr native_rcl_destroy_publisher_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_destroy_publisher_handle"); + internal static NativeRCLCreateClientHandleType native_rcl_create_client_handle = null; - NodeDelegates.native_rcl_destroy_publisher_handle = - (NativeRCLDestroyPublisherHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_publisher_handle_ptr, typeof (NativeRCLDestroyPublisherHandleType)); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroyClientHandleType( + IntPtr clientHandle, SafeNodeHandle nodeHandle); - IntPtr native_rcl_create_subscription_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_create_subscription_handle"); + internal static NativeRCLDestroyClientHandleType native_rcl_destroy_client_handle = null; - NodeDelegates.native_rcl_create_subscription_handle = - (NativeRCLCreateSubscriptionHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_subscription_handle_ptr, typeof (NativeRCLCreateSubscriptionHandleType)); + static NodeDelegates() + { + dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativelibrary = dllLoadUtils.LoadLibrary("rcldotnet_node"); - IntPtr native_rcl_destroy_subscription_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_destroy_subscription_handle"); + IntPtr native_rcl_create_publisher_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_create_publisher_handle"); - NodeDelegates.native_rcl_destroy_subscription_handle = - (NativeRCLDestroySubscriptionHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_subscription_handle_ptr, typeof (NativeRCLDestroySubscriptionHandleType)); - - IntPtr native_rcl_create_service_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_create_service_handle"); + NodeDelegates.native_rcl_create_publisher_handle = + (NativeRCLCreatePublisherHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_publisher_handle_ptr, typeof(NativeRCLCreatePublisherHandleType)); - NodeDelegates.native_rcl_create_service_handle = - (NativeRCLCreateServiceHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_service_handle_ptr, typeof (NativeRCLCreateServiceHandleType)); + IntPtr native_rcl_destroy_publisher_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_destroy_publisher_handle"); - IntPtr native_rcl_destroy_service_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_destroy_service_handle"); + NodeDelegates.native_rcl_destroy_publisher_handle = + (NativeRCLDestroyPublisherHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_publisher_handle_ptr, typeof(NativeRCLDestroyPublisherHandleType)); - NodeDelegates.native_rcl_destroy_service_handle = - (NativeRCLDestroyServiceHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_service_handle_ptr, typeof (NativeRCLDestroyServiceHandleType)); + IntPtr native_rcl_create_subscription_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_create_subscription_handle"); - IntPtr native_rcl_create_client_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_create_client_handle"); + NodeDelegates.native_rcl_create_subscription_handle = + (NativeRCLCreateSubscriptionHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_subscription_handle_ptr, typeof(NativeRCLCreateSubscriptionHandleType)); - NodeDelegates.native_rcl_create_client_handle = - (NativeRCLCreateClientHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_client_handle_ptr, typeof (NativeRCLCreateClientHandleType)); + IntPtr native_rcl_destroy_subscription_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_destroy_subscription_handle"); - IntPtr native_rcl_destroy_client_handle_ptr = dllLoadUtils.GetProcAddress ( - nativelibrary, "native_rcl_destroy_client_handle"); + NodeDelegates.native_rcl_destroy_subscription_handle = + (NativeRCLDestroySubscriptionHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_subscription_handle_ptr, typeof(NativeRCLDestroySubscriptionHandleType)); - NodeDelegates.native_rcl_destroy_client_handle = - (NativeRCLDestroyClientHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_client_handle_ptr, typeof (NativeRCLDestroyClientHandleType)); - } - } + IntPtr native_rcl_create_service_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_create_service_handle"); - public sealed class Node { + NodeDelegates.native_rcl_create_service_handle = + (NativeRCLCreateServiceHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_service_handle_ptr, typeof(NativeRCLCreateServiceHandleType)); - private IList subscriptions_; + IntPtr native_rcl_destroy_service_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_destroy_service_handle"); - private IList services_; + NodeDelegates.native_rcl_destroy_service_handle = + (NativeRCLDestroyServiceHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_service_handle_ptr, typeof(NativeRCLDestroyServiceHandleType)); - private IList clients_; + IntPtr native_rcl_create_client_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_create_client_handle"); - internal Node (SafeNodeHandle handle) { - Handle = handle; - subscriptions_ = new List(); - services_ = new List(); - clients_ = new List(); - } + NodeDelegates.native_rcl_create_client_handle = + (NativeRCLCreateClientHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_client_handle_ptr, typeof(NativeRCLCreateClientHandleType)); - public IList Subscriptions => subscriptions_; - - // TODO: (sh) wrap in readonly collection - // TODO: (sh) Add posibility to remove Subscriptions/Services/Clients from Node (if this is a thing in ROS) - // Now there is no Api to remove these Objects, and there is a strong reference from these fileds to them so they dont't get collected. - public IList Services => services_; - - public IList Clients => clients_; - - // Node does intentionaly (for now) not implement IDisposable as this - // needs some extra consideration how the type works after its - // internal handle is disposed. - // By relying on the GC/Finalizer of SafeHandle the handle only gets - // Disposed if the node is not live anymore. - internal SafeNodeHandle Handle { get; } - - public Publisher CreatePublisher (string topic) where T : IRosMessage { - IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); - - var publisherHandle = new SafePublisherHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_publisher_handle (ref publisherHandle, Handle, topic, typesupport); - publisherHandle.SetParent(Handle); - if (ret != RCLRet.Ok) - { - publisherHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_publisher_handle)}() failed."); - } - - // TODO: (sh) Add topic as propety to Publisher. - Publisher publisher = new Publisher (publisherHandle); - return publisher; - } + IntPtr native_rcl_destroy_client_handle_ptr = dllLoadUtils.GetProcAddress( + nativelibrary, "native_rcl_destroy_client_handle"); - public Subscription CreateSubscription (string topic, Action callback) where T : IRosMessage, new () { - IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); - - var subscriptionHandle = new SafeSubscriptionHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_subscription_handle (ref subscriptionHandle, Handle, topic, typesupport); - subscriptionHandle.SetParent(Handle); - if (ret != RCLRet.Ok) - { - subscriptionHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_subscription_handle)}() failed."); - } - - // TODO: (sh) Add topic as propety to Subscription. - Subscription subscription = new Subscription (subscriptionHandle, callback); - this.subscriptions_.Add(subscription); - return subscription; + NodeDelegates.native_rcl_destroy_client_handle = + (NativeRCLDestroyClientHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_client_handle_ptr, typeof(NativeRCLDestroyClientHandleType)); + } } - public Service CreateService(string serviceName, Action callback) - where TService : IRosServiceDefinition - where TRequest : IRosMessage, new() - where TResponse : IRosMessage, new() + public sealed class Node { - IntPtr typesupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); - - var serviceHandle = new SafeServiceHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_service_handle(ref serviceHandle, Handle, serviceName, typesupport); - serviceHandle.SetParent(Handle); - if (ret != RCLRet.Ok) - { - serviceHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_service_handle)}() failed."); - } - - // TODO: (sh) Add serviceName to Service. - var service = new Service(serviceHandle, callback); - this.services_.Add(service); - return service; - } - public Client CreateClient(string serviceName) - where TService : IRosServiceDefinition - where TRequest : IRosMessage, new() - where TResponse : IRosMessage, new() - { - IntPtr typesupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); - - var clientHandle = new SafeClientHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_client_handle(ref clientHandle, Handle, serviceName, typesupport); - clientHandle.SetParent(Handle); - if (ret != RCLRet.Ok) - { - clientHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_client_handle)}() failed."); - } - - // TODO: (sh) Add serviceName to Client. - var client = new Client(clientHandle, this); - this.clients_.Add(client); - return client; + private readonly IList subscriptions_; + + private readonly IList services_; + + private readonly IList clients_; + + internal Node(SafeNodeHandle handle) + { + Handle = handle; + subscriptions_ = new List(); + services_ = new List(); + clients_ = new List(); + } + + public IList Subscriptions => subscriptions_; + + // TODO: (sh) wrap in readonly collection + // TODO: (sh) Add posibility to remove Subscriptions/Services/Clients from Node (if this is a thing in ROS) + // Now there is no Api to remove these Objects, and there is a strong reference from these fileds to them so they dont't get collected. + public IList Services => services_; + + public IList Clients => clients_; + + // Node does intentionaly (for now) not implement IDisposable as this + // needs some extra consideration how the type works after its + // internal handle is disposed. + // By relying on the GC/Finalizer of SafeHandle the handle only gets + // Disposed if the node is not live anymore. + internal SafeNodeHandle Handle { get; } + + public Publisher CreatePublisher(string topic) where T : IRosMessage + { + IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); + + var publisherHandle = new SafePublisherHandle(); + RCLRet ret = NodeDelegates.native_rcl_create_publisher_handle(ref publisherHandle, Handle, topic, typesupport); + publisherHandle.SetParent(Handle); + if (ret != RCLRet.Ok) + { + publisherHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_publisher_handle)}() failed."); + } + + // TODO: (sh) Add topic as propety to Publisher. + Publisher publisher = new Publisher(publisherHandle); + return publisher; + } + + public Subscription CreateSubscription(string topic, Action callback) where T : IRosMessage, new() + { + IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); + + var subscriptionHandle = new SafeSubscriptionHandle(); + RCLRet ret = NodeDelegates.native_rcl_create_subscription_handle(ref subscriptionHandle, Handle, topic, typesupport); + subscriptionHandle.SetParent(Handle); + if (ret != RCLRet.Ok) + { + subscriptionHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_subscription_handle)}() failed."); + } + + // TODO: (sh) Add topic as propety to Subscription. + Subscription subscription = new Subscription(subscriptionHandle, callback); + subscriptions_.Add(subscription); + return subscription; + } + + public Service CreateService(string serviceName, Action callback) + where TService : IRosServiceDefinition + where TRequest : IRosMessage, new() + where TResponse : IRosMessage, new() + { + IntPtr typesupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); + + var serviceHandle = new SafeServiceHandle(); + RCLRet ret = NodeDelegates.native_rcl_create_service_handle(ref serviceHandle, Handle, serviceName, typesupport); + serviceHandle.SetParent(Handle); + if (ret != RCLRet.Ok) + { + serviceHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_service_handle)}() failed."); + } + + // TODO: (sh) Add serviceName to Service. + var service = new Service(serviceHandle, callback); + services_.Add(service); + return service; + } + + public Client CreateClient(string serviceName) + where TService : IRosServiceDefinition + where TRequest : IRosMessage, new() + where TResponse : IRosMessage, new() + { + IntPtr typesupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); + + var clientHandle = new SafeClientHandle(); + RCLRet ret = NodeDelegates.native_rcl_create_client_handle(ref clientHandle, Handle, serviceName, typesupport); + clientHandle.SetParent(Handle); + if (ret != RCLRet.Ok) + { + clientHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(NodeDelegates.native_rcl_create_client_handle)}() failed."); + } + + // TODO: (sh) Add serviceName to Client. + var client = new Client(clientHandle, this); + clients_.Add(client); + return client; + } } - } } diff --git a/rcldotnet/Publisher.cs b/rcldotnet/Publisher.cs index 6d828e5c..6edaa285 100644 --- a/rcldotnet/Publisher.cs +++ b/rcldotnet/Publisher.cs @@ -19,77 +19,82 @@ namespace ROS2 { - internal static class PublisherDelegates { - internal static readonly DllLoadUtils dllLoadUtils; + internal static class PublisherDelegates + { + internal static readonly DllLoadUtils dllLoadUtils; - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLPublishType ( - SafePublisherHandle publisherHandle, SafeHandle messageHandle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLPublishType( + SafePublisherHandle publisherHandle, SafeHandle messageHandle); - internal static NativeRCLPublishType native_rcl_publish = null; + internal static NativeRCLPublishType native_rcl_publish = null; - static PublisherDelegates () { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils (); - IntPtr nativelibrary = dllLoadUtils.LoadLibrary ("rcldotnet_publisher"); + static PublisherDelegates() + { + dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativelibrary = dllLoadUtils.LoadLibrary("rcldotnet_publisher"); - IntPtr native_rcl_publish_ptr = dllLoadUtils.GetProcAddress (nativelibrary, "native_rcl_publish"); - PublisherDelegates.native_rcl_publish = (NativeRCLPublishType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_publish_ptr, typeof (NativeRCLPublishType)); + IntPtr native_rcl_publish_ptr = dllLoadUtils.GetProcAddress(nativelibrary, "native_rcl_publish"); + PublisherDelegates.native_rcl_publish = (NativeRCLPublishType)Marshal.GetDelegateForFunctionPointer( + native_rcl_publish_ptr, typeof(NativeRCLPublishType)); + } } - } - /// - /// Base class of a Publisher without generic type arguments for use in collections or so. - /// - public abstract class Publisher - { - // Only allow internal subclasses. - internal Publisher() + /// + /// Base class of a Publisher without generic type arguments for use in collections or so. + /// + public abstract class Publisher { - } - - // Publisher does intentionaly (for now) not implement IDisposable as this - // needs some extra consideration how the type works after its - // internal handle is disposed. - // By relying on the GC/Finalizer of SafeHandle the handle only gets - // Disposed if the publisher is not live anymore. - internal abstract SafePublisherHandle Handle { get; } - } - - public sealed class Publisher : Publisher - where T : IRosMessage { + // Only allow internal subclasses. + internal Publisher() + { + } - internal Publisher (SafePublisherHandle handle) { - Handle = handle; + // Publisher does intentionaly (for now) not implement IDisposable as this + // needs some extra consideration how the type works after its + // internal handle is disposed. + // By relying on the GC/Finalizer of SafeHandle the handle only gets + // Disposed if the publisher is not live anymore. + internal abstract SafePublisherHandle Handle { get; } } - internal override SafePublisherHandle Handle { get; } + public sealed class Publisher : Publisher + where T : IRosMessage + { - public void Publish (T message) { - using (var messageHandle = MessageStaticMemberCache.CreateMessageHandle()) - { - bool mustRelease = false; - try + internal Publisher(SafePublisherHandle handle) { - // Using SafeHandles for __WriteToHandle() is very tedious as this needs to be - // handled in generated code across multiple assemblies. - // Array and collection indexing would need to create SafeHandles everywere. - // It's not worth it, especialy considering the extra allocations for SafeHandles in - // arrays or collections that don't realy represent their own native recource. - messageHandle.DangerousAddRef(ref mustRelease); - message.__WriteToHandle(messageHandle.DangerousGetHandle()); + Handle = handle; } - finally + + internal override SafePublisherHandle Handle { get; } + + public void Publish(T message) { - if (mustRelease) - { - messageHandle.DangerousRelease(); - } - } + using (var messageHandle = MessageStaticMemberCache.CreateMessageHandle()) + { + bool mustRelease = false; + try + { + // Using SafeHandles for __WriteToHandle() is very tedious as this needs to be + // handled in generated code across multiple assemblies. + // Array and collection indexing would need to create SafeHandles everywere. + // It's not worth it, especialy considering the extra allocations for SafeHandles in + // arrays or collections that don't realy represent their own native recource. + messageHandle.DangerousAddRef(ref mustRelease); + message.__WriteToHandle(messageHandle.DangerousGetHandle()); + } + finally + { + if (mustRelease) + { + messageHandle.DangerousRelease(); + } + } - RCLRet ret = PublisherDelegates.native_rcl_publish(Handle, messageHandle); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(PublisherDelegates.native_rcl_publish)}() failed."); - } + RCLRet ret = PublisherDelegates.native_rcl_publish(Handle, messageHandle); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(PublisherDelegates.native_rcl_publish)}() failed."); + } + } } - } } diff --git a/rcldotnet/RCLExceptionHelper.cs b/rcldotnet/RCLExceptionHelper.cs index fd0684d7..1f8d8b29 100644 --- a/rcldotnet/RCLExceptionHelper.cs +++ b/rcldotnet/RCLExceptionHelper.cs @@ -34,7 +34,7 @@ public static Exception CreateFromReturnValue(RCLRet value, string messagePrefix // #define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1024 var errorStringBuffer = new byte[1024]; RCLdotnetDelegates.native_rcl_get_error_string(errorStringBuffer, errorStringBuffer.Length); - + string errorString = System.Text.Encoding.UTF8.GetString(errorStringBuffer).TrimEnd('\0'); RCLdotnetDelegates.native_rcl_reset_error(); diff --git a/rcldotnet/RCLdotnet.cs b/rcldotnet/RCLdotnet.cs index 260aec97..585b1ab1 100644 --- a/rcldotnet/RCLdotnet.cs +++ b/rcldotnet/RCLdotnet.cs @@ -17,606 +17,633 @@ using System.Runtime.InteropServices; using ROS2.Utils; -namespace ROS2 { - internal static class RCLdotnetDelegates { - internal static readonly DllLoadUtils dllLoadUtils; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLInitType (); - - internal static NativeRCLInitType native_rcl_init = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void NativeRCLGetErrorStringType( - byte[] buffer, int bufferSize); - - internal static NativeRCLGetErrorStringType native_rcl_get_error_string = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void NativeRCLResetErrorType (); - - internal static NativeRCLResetErrorType native_rcl_reset_error = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate bool NativeRCLOkType (); - - internal static NativeRCLOkType native_rcl_ok = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - internal delegate RCLRet NativeRCLCreateNodeHandleType ( - ref SafeNodeHandle nodeHandle, [MarshalAs (UnmanagedType.LPStr)] string nodeName, [MarshalAs (UnmanagedType.LPStr)] string nodeNamespace); - - internal static NativeRCLCreateNodeHandleType native_rcl_create_node_handle = null; - - [UnmanagedFunctionPointer (CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - internal delegate RCLRet NativeRCLDestroyNodeHandleType ( - IntPtr nodeHandle); +namespace ROS2 +{ + internal static class RCLdotnetDelegates + { + internal static readonly DllLoadUtils dllLoadUtils; - internal static NativeRCLDestroyNodeHandleType native_rcl_destroy_node_handle = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLInitType(); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate IntPtr NativeRCLGetRMWIdentifierType (); + internal static NativeRCLInitType native_rcl_init = null; - internal static NativeRCLGetRMWIdentifierType native_rcl_get_rmw_identifier = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void NativeRCLGetErrorStringType( + byte[] buffer, int bufferSize); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreateWaitSetHandleType ( - ref SafeWaitSetHandle waitSetHandle, int numberOfSubscriptions, - int numberOfGuardConditions, int numberOfTimers, - int numberOfClients, int numberOfServices, int numberOfEvents); + internal static NativeRCLGetErrorStringType native_rcl_get_error_string = null; - internal static NativeRCLCreateWaitSetHandleType native_rcl_create_wait_set_handle = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void NativeRCLResetErrorType(); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroyWaitSetType (IntPtr waitSetHandle); + internal static NativeRCLResetErrorType native_rcl_reset_error = null; - internal static NativeRCLDestroyWaitSetType native_rcl_destroy_wait_set_handle = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool NativeRCLOkType(); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLWaitSetClearType (SafeWaitSetHandle waitSetHandle); + internal static NativeRCLOkType native_rcl_ok = null; - internal static NativeRCLWaitSetClearType native_rcl_wait_set_clear = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + internal delegate RCLRet NativeRCLCreateNodeHandleType( + ref SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string nodeName, [MarshalAs(UnmanagedType.LPStr)] string nodeNamespace); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLWaitSetAddSubscriptionType (SafeWaitSetHandle waitSetHandle, SafeSubscriptionHandle subscriptionHandle); + internal static NativeRCLCreateNodeHandleType native_rcl_create_node_handle = null; - internal static NativeRCLWaitSetAddSubscriptionType native_rcl_wait_set_add_subscription = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + internal delegate RCLRet NativeRCLDestroyNodeHandleType( + IntPtr nodeHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLWaitSetAddServiceType (SafeWaitSetHandle waitSetHandle, SafeServiceHandle serviceHandle); + internal static NativeRCLDestroyNodeHandleType native_rcl_destroy_node_handle = null; - internal static NativeRCLWaitSetAddServiceType native_rcl_wait_set_add_service = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate IntPtr NativeRCLGetRMWIdentifierType(); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLWaitSetAddClientType (SafeWaitSetHandle waitSetHandle, SafeClientHandle clientHandle); + internal static NativeRCLGetRMWIdentifierType native_rcl_get_rmw_identifier = null; - internal static NativeRCLWaitSetAddClientType native_rcl_wait_set_add_client = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreateWaitSetHandleType( + ref SafeWaitSetHandle waitSetHandle, int numberOfSubscriptions, + int numberOfGuardConditions, int numberOfTimers, + int numberOfClients, int numberOfServices, int numberOfEvents); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLWaitType (SafeWaitSetHandle waitSetHandle, long timeout); + internal static NativeRCLCreateWaitSetHandleType native_rcl_create_wait_set_handle = null; - internal static NativeRCLWaitType native_rcl_wait = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroyWaitSetType(IntPtr waitSetHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLTakeType (SafeSubscriptionHandle subscriptionHandle, SafeHandle messageHandle); + internal static NativeRCLDestroyWaitSetType native_rcl_destroy_wait_set_handle = null; - internal static NativeRCLTakeType native_rcl_take = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLWaitSetClearType(SafeWaitSetHandle waitSetHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLCreateRequestIdHandleType ( - ref SafeRequestIdHandle requestIdHandle); + internal static NativeRCLWaitSetClearType native_rcl_wait_set_clear = null; - internal static NativeRCLCreateRequestIdHandleType native_rcl_create_request_id_handle = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLWaitSetAddSubscriptionType(SafeWaitSetHandle waitSetHandle, SafeSubscriptionHandle subscriptionHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLDestroyRequestIdHandleType (IntPtr requestIdHandle); + internal static NativeRCLWaitSetAddSubscriptionType native_rcl_wait_set_add_subscription = null; - internal static NativeRCLDestroyRequestIdHandleType native_rcl_destroy_request_id_handle = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLWaitSetAddServiceType(SafeWaitSetHandle waitSetHandle, SafeServiceHandle serviceHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate long NativeRCLRequestIdGetSequenceNumberType (SafeRequestIdHandle requestIdHandle); + internal static NativeRCLWaitSetAddServiceType native_rcl_wait_set_add_service = null; - internal static NativeRCLRequestIdGetSequenceNumberType native_rcl_request_id_get_sequence_number = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLWaitSetAddClientType(SafeWaitSetHandle waitSetHandle, SafeClientHandle clientHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLTakeRequestType (SafeServiceHandle serviceHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle requestHandle); + internal static NativeRCLWaitSetAddClientType native_rcl_wait_set_add_client = null; - internal static NativeRCLTakeRequestType native_rcl_take_request = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLWaitType(SafeWaitSetHandle waitSetHandle, long timeout); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLSendResponseType (SafeServiceHandle serviceHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle responseHandle); + internal static NativeRCLWaitType native_rcl_wait = null; - internal static NativeRCLSendResponseType native_rcl_send_response = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLTakeType(SafeSubscriptionHandle subscriptionHandle, SafeHandle messageHandle); - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate RCLRet NativeRCLTakeResponseType (SafeClientHandle clientHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle responseHandle); + internal static NativeRCLTakeType native_rcl_take = null; - internal static NativeRCLTakeResponseType native_rcl_take_response = null; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLCreateRequestIdHandleType( + ref SafeRequestIdHandle requestIdHandle); - static RCLdotnetDelegates () { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils (); - string library_name = "rcldotnet"; - IntPtr pDll = dllLoadUtils.LoadLibrary (library_name); + internal static NativeRCLCreateRequestIdHandleType native_rcl_create_request_id_handle = null; - IntPtr native_rcl_init_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_init"); - RCLdotnetDelegates.native_rcl_init = - (NativeRCLInitType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_init_ptr, typeof (NativeRCLInitType)); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLDestroyRequestIdHandleType(IntPtr requestIdHandle); - IntPtr native_rcl_get_error_string_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_get_error_string"); - RCLdotnetDelegates.native_rcl_get_error_string = - (NativeRCLGetErrorStringType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_get_error_string_ptr, typeof (NativeRCLGetErrorStringType)); - - IntPtr native_rcl_reset_error_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_reset_error"); - RCLdotnetDelegates.native_rcl_reset_error = - (NativeRCLResetErrorType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_reset_error_ptr, typeof (NativeRCLResetErrorType)); - - IntPtr native_rcl_get_rmw_identifier_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_get_rmw_identifier"); - RCLdotnetDelegates.native_rcl_get_rmw_identifier = - (NativeRCLGetRMWIdentifierType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_get_rmw_identifier_ptr, typeof (NativeRCLGetRMWIdentifierType)); - - IntPtr native_rcl_ok_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_ok"); - RCLdotnetDelegates.native_rcl_ok = - (NativeRCLOkType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_ok_ptr, typeof (NativeRCLOkType)); - - IntPtr native_rcl_create_node_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_create_node_handle"); - RCLdotnetDelegates.native_rcl_create_node_handle = - (NativeRCLCreateNodeHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_node_handle_ptr, typeof (NativeRCLCreateNodeHandleType)); - - IntPtr native_rcl_destroy_node_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_destroy_node_handle"); - RCLdotnetDelegates.native_rcl_destroy_node_handle = - (NativeRCLDestroyNodeHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_node_handle_ptr, typeof (NativeRCLDestroyNodeHandleType)); - - IntPtr native_rcl_create_wait_set_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_create_wait_set_handle"); - RCLdotnetDelegates.native_rcl_create_wait_set_handle = - (NativeRCLCreateWaitSetHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_wait_set_handle_ptr, typeof (NativeRCLCreateWaitSetHandleType)); - - IntPtr native_rcl_destroy_wait_set_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_destroy_wait_set_handle"); - RCLdotnetDelegates.native_rcl_destroy_wait_set_handle = - (NativeRCLDestroyWaitSetType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_wait_set_handle_ptr, typeof (NativeRCLDestroyWaitSetType)); - - IntPtr native_rcl_wait_set_clear_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_wait_set_clear"); - RCLdotnetDelegates.native_rcl_wait_set_clear = - (NativeRCLWaitSetClearType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_wait_set_clear_ptr, typeof (NativeRCLWaitSetClearType)); - - IntPtr native_rcl_wait_set_add_subscription_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_wait_set_add_subscription"); - RCLdotnetDelegates.native_rcl_wait_set_add_subscription = - (NativeRCLWaitSetAddSubscriptionType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_wait_set_add_subscription_ptr, typeof (NativeRCLWaitSetAddSubscriptionType)); - - IntPtr native_rcl_wait_set_add_service_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_wait_set_add_service"); - RCLdotnetDelegates.native_rcl_wait_set_add_service = - (NativeRCLWaitSetAddServiceType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_wait_set_add_service_ptr, typeof (NativeRCLWaitSetAddServiceType)); - - IntPtr native_rcl_wait_set_add_client_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_wait_set_add_client"); - RCLdotnetDelegates.native_rcl_wait_set_add_client = - (NativeRCLWaitSetAddClientType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_wait_set_add_client_ptr, typeof (NativeRCLWaitSetAddClientType)); - - IntPtr native_rcl_wait_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_wait"); - RCLdotnetDelegates.native_rcl_wait = - (NativeRCLWaitType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_wait_ptr, typeof (NativeRCLWaitType)); - - IntPtr native_rcl_take_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_take"); - RCLdotnetDelegates.native_rcl_take = - (NativeRCLTakeType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_take_ptr, typeof (NativeRCLTakeType)); - - IntPtr native_rcl_create_request_id_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_create_request_id_handle"); - RCLdotnetDelegates.native_rcl_create_request_id_handle = - (NativeRCLCreateRequestIdHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_create_request_id_handle_ptr, typeof (NativeRCLCreateRequestIdHandleType)); - - IntPtr native_rcl_destroy_request_id_handle_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_destroy_request_id_handle"); - RCLdotnetDelegates.native_rcl_destroy_request_id_handle = - (NativeRCLDestroyRequestIdHandleType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_destroy_request_id_handle_ptr, typeof (NativeRCLDestroyRequestIdHandleType)); - - IntPtr native_rcl_request_id_get_sequence_number_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_request_id_get_sequence_number"); - RCLdotnetDelegates.native_rcl_request_id_get_sequence_number = - (NativeRCLRequestIdGetSequenceNumberType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_request_id_get_sequence_number_ptr, typeof (NativeRCLRequestIdGetSequenceNumberType)); - - IntPtr native_rcl_take_request_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_take_request"); - RCLdotnetDelegates.native_rcl_take_request = - (NativeRCLTakeRequestType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_take_request_ptr, typeof (NativeRCLTakeRequestType)); - - IntPtr native_rcl_send_response_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_send_response"); - RCLdotnetDelegates.native_rcl_send_response = - (NativeRCLSendResponseType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_send_response_ptr, typeof (NativeRCLSendResponseType)); - - IntPtr native_rcl_take_response_ptr = - dllLoadUtils.GetProcAddress (pDll, "native_rcl_take_response"); - RCLdotnetDelegates.native_rcl_take_response = - (NativeRCLTakeResponseType) Marshal.GetDelegateForFunctionPointer ( - native_rcl_take_response_ptr, typeof (NativeRCLTakeResponseType)); - } - } + internal static NativeRCLDestroyRequestIdHandleType native_rcl_destroy_request_id_handle = null; - public static class RCLdotnet { - private static bool initialized = false; - private static readonly object syncLock = new object (); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate long NativeRCLRequestIdGetSequenceNumberType(SafeRequestIdHandle requestIdHandle); - public static bool Ok () { - return RCLdotnetDelegates.native_rcl_ok (); - } + internal static NativeRCLRequestIdGetSequenceNumberType native_rcl_request_id_get_sequence_number = null; - public static Node CreateNode (string nodeName) { - return CreateNode (nodeName, ""); - } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLTakeRequestType(SafeServiceHandle serviceHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle requestHandle); - public static Node CreateNode (string nodeName, string nodeNamespace) { - var nodeHandle = new SafeNodeHandle(); - RCLRet ret = RCLdotnetDelegates.native_rcl_create_node_handle (ref nodeHandle, nodeName, nodeNamespace); - if (ret != RCLRet.Ok) - { - nodeHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_node_handle)}() failed."); - } - - Node node = new Node (nodeHandle); - return node; - } + internal static NativeRCLTakeRequestType native_rcl_take_request = null; - public static void Spin (Node node) { - while (Ok ()) { - SpinOnce (node, 500); - } - } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLSendResponseType(SafeServiceHandle serviceHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle responseHandle); - private static SafeWaitSetHandle CreateWaitSet( - int numberOfSubscriptions, - int numberOfGuardConditions, - int numberOfTimers, - int numberOfClients, - int numberOfServices, - int numberOfEvents) { - var waitSetHandle = new SafeWaitSetHandle(); - RCLRet ret = RCLdotnetDelegates.native_rcl_create_wait_set_handle( - ref waitSetHandle, numberOfSubscriptions, numberOfGuardConditions, - numberOfTimers, numberOfClients, numberOfServices, numberOfEvents); - if (ret != RCLRet.Ok) - { - waitSetHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_wait_set_handle)}() failed."); - } - - return waitSetHandle; - } - - private static void WaitSetClear(SafeWaitSetHandle waitSetHandle) { - RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_clear(waitSetHandle); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_clear)}() failed."); - } - - private static void WaitSetAddSubscription(SafeWaitSetHandle waitSetHandle, SafeSubscriptionHandle subscriptionHandle) { - RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_subscription(waitSetHandle, subscriptionHandle); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_subscription)}() failed."); - } + internal static NativeRCLSendResponseType native_rcl_send_response = null; - private static void WaitSetAddService(SafeWaitSetHandle waitSetHandle, SafeServiceHandle serviceHandle) { - RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_service(waitSetHandle, serviceHandle); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_service)}() failed."); - } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate RCLRet NativeRCLTakeResponseType(SafeClientHandle clientHandle, SafeRequestIdHandle requestHeaderHandle, SafeHandle responseHandle); - private static void WaitSetAddClient(SafeWaitSetHandle waitSetHandle, SafeClientHandle clientHandle) { - RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_client(waitSetHandle, clientHandle); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_client)}() failed."); - } + internal static NativeRCLTakeResponseType native_rcl_take_response = null; - /// - /// Block until the wait set is ready or until the timeout has been exceeded. - /// - /// The wait set. - /// Timeout in ms. - /// True if wait set is ready, False on timeout. - private static bool Wait(SafeWaitSetHandle waitSetHandle, long timeout) { - long ns_timeout = timeout * 1000000; - RCLRet ret = RCLdotnetDelegates.native_rcl_wait(waitSetHandle, ns_timeout); - if (ret == RCLRet.Ok || ret == RCLRet.Timeout) - { - return ret == RCLRet.Ok; - } - else - { - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait)}() failed."); - } + static RCLdotnetDelegates() + { + dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + string library_name = "rcldotnet"; + IntPtr pDll = dllLoadUtils.LoadLibrary(library_name); + + IntPtr native_rcl_init_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_init"); + RCLdotnetDelegates.native_rcl_init = + (NativeRCLInitType)Marshal.GetDelegateForFunctionPointer( + native_rcl_init_ptr, typeof(NativeRCLInitType)); + + IntPtr native_rcl_get_error_string_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_get_error_string"); + RCLdotnetDelegates.native_rcl_get_error_string = + (NativeRCLGetErrorStringType)Marshal.GetDelegateForFunctionPointer( + native_rcl_get_error_string_ptr, typeof(NativeRCLGetErrorStringType)); + + IntPtr native_rcl_reset_error_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_reset_error"); + RCLdotnetDelegates.native_rcl_reset_error = + (NativeRCLResetErrorType)Marshal.GetDelegateForFunctionPointer( + native_rcl_reset_error_ptr, typeof(NativeRCLResetErrorType)); + + IntPtr native_rcl_get_rmw_identifier_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_get_rmw_identifier"); + RCLdotnetDelegates.native_rcl_get_rmw_identifier = + (NativeRCLGetRMWIdentifierType)Marshal.GetDelegateForFunctionPointer( + native_rcl_get_rmw_identifier_ptr, typeof(NativeRCLGetRMWIdentifierType)); + + IntPtr native_rcl_ok_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_ok"); + RCLdotnetDelegates.native_rcl_ok = + (NativeRCLOkType)Marshal.GetDelegateForFunctionPointer( + native_rcl_ok_ptr, typeof(NativeRCLOkType)); + + IntPtr native_rcl_create_node_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_node_handle"); + RCLdotnetDelegates.native_rcl_create_node_handle = + (NativeRCLCreateNodeHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_node_handle_ptr, typeof(NativeRCLCreateNodeHandleType)); + + IntPtr native_rcl_destroy_node_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_node_handle"); + RCLdotnetDelegates.native_rcl_destroy_node_handle = + (NativeRCLDestroyNodeHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_node_handle_ptr, typeof(NativeRCLDestroyNodeHandleType)); + + IntPtr native_rcl_create_wait_set_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_wait_set_handle"); + RCLdotnetDelegates.native_rcl_create_wait_set_handle = + (NativeRCLCreateWaitSetHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_wait_set_handle_ptr, typeof(NativeRCLCreateWaitSetHandleType)); + + IntPtr native_rcl_destroy_wait_set_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_wait_set_handle"); + RCLdotnetDelegates.native_rcl_destroy_wait_set_handle = + (NativeRCLDestroyWaitSetType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_wait_set_handle_ptr, typeof(NativeRCLDestroyWaitSetType)); + + IntPtr native_rcl_wait_set_clear_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_clear"); + RCLdotnetDelegates.native_rcl_wait_set_clear = + (NativeRCLWaitSetClearType)Marshal.GetDelegateForFunctionPointer( + native_rcl_wait_set_clear_ptr, typeof(NativeRCLWaitSetClearType)); + + IntPtr native_rcl_wait_set_add_subscription_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_subscription"); + RCLdotnetDelegates.native_rcl_wait_set_add_subscription = + (NativeRCLWaitSetAddSubscriptionType)Marshal.GetDelegateForFunctionPointer( + native_rcl_wait_set_add_subscription_ptr, typeof(NativeRCLWaitSetAddSubscriptionType)); + + IntPtr native_rcl_wait_set_add_service_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_service"); + RCLdotnetDelegates.native_rcl_wait_set_add_service = + (NativeRCLWaitSetAddServiceType)Marshal.GetDelegateForFunctionPointer( + native_rcl_wait_set_add_service_ptr, typeof(NativeRCLWaitSetAddServiceType)); + + IntPtr native_rcl_wait_set_add_client_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_client"); + RCLdotnetDelegates.native_rcl_wait_set_add_client = + (NativeRCLWaitSetAddClientType)Marshal.GetDelegateForFunctionPointer( + native_rcl_wait_set_add_client_ptr, typeof(NativeRCLWaitSetAddClientType)); + + IntPtr native_rcl_wait_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait"); + RCLdotnetDelegates.native_rcl_wait = + (NativeRCLWaitType)Marshal.GetDelegateForFunctionPointer( + native_rcl_wait_ptr, typeof(NativeRCLWaitType)); + + IntPtr native_rcl_take_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_take"); + RCLdotnetDelegates.native_rcl_take = + (NativeRCLTakeType)Marshal.GetDelegateForFunctionPointer( + native_rcl_take_ptr, typeof(NativeRCLTakeType)); + + IntPtr native_rcl_create_request_id_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_request_id_handle"); + RCLdotnetDelegates.native_rcl_create_request_id_handle = + (NativeRCLCreateRequestIdHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_create_request_id_handle_ptr, typeof(NativeRCLCreateRequestIdHandleType)); + + IntPtr native_rcl_destroy_request_id_handle_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_request_id_handle"); + RCLdotnetDelegates.native_rcl_destroy_request_id_handle = + (NativeRCLDestroyRequestIdHandleType)Marshal.GetDelegateForFunctionPointer( + native_rcl_destroy_request_id_handle_ptr, typeof(NativeRCLDestroyRequestIdHandleType)); + + IntPtr native_rcl_request_id_get_sequence_number_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_request_id_get_sequence_number"); + RCLdotnetDelegates.native_rcl_request_id_get_sequence_number = + (NativeRCLRequestIdGetSequenceNumberType)Marshal.GetDelegateForFunctionPointer( + native_rcl_request_id_get_sequence_number_ptr, typeof(NativeRCLRequestIdGetSequenceNumberType)); + + IntPtr native_rcl_take_request_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_take_request"); + RCLdotnetDelegates.native_rcl_take_request = + (NativeRCLTakeRequestType)Marshal.GetDelegateForFunctionPointer( + native_rcl_take_request_ptr, typeof(NativeRCLTakeRequestType)); + + IntPtr native_rcl_send_response_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_send_response"); + RCLdotnetDelegates.native_rcl_send_response = + (NativeRCLSendResponseType)Marshal.GetDelegateForFunctionPointer( + native_rcl_send_response_ptr, typeof(NativeRCLSendResponseType)); + + IntPtr native_rcl_take_response_ptr = + dllLoadUtils.GetProcAddress(pDll, "native_rcl_take_response"); + RCLdotnetDelegates.native_rcl_take_response = + (NativeRCLTakeResponseType)Marshal.GetDelegateForFunctionPointer( + native_rcl_take_response_ptr, typeof(NativeRCLTakeResponseType)); + } } - private static SafeRequestIdHandle CreateRequestId() + public static class RCLdotnet { - var requestIdHandle = new SafeRequestIdHandle(); - RCLRet ret = RCLdotnetDelegates.native_rcl_create_request_id_handle(ref requestIdHandle); - if (ret != RCLRet.Ok) - { - requestIdHandle.Dispose(); - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_request_id_handle)}() failed."); - } - - return requestIdHandle; - } + private static bool initialized = false; + private static readonly object syncLock = new object(); - private static bool Take (Subscription subscription, IRosMessage message) { - using (var messageHandle = subscription.CreateMessageHandle()) - { - RCLRet ret = RCLdotnetDelegates.native_rcl_take(subscription.Handle, messageHandle); - switch (ret) + public static bool Ok() { - case RCLRet.Ok: - bool mustRelease = false; - try - { - // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be - // handled in generated code across multiple assemblies. - // Array and collection indexing would need to create SafeHandles everywere. - // It's not worth it, especialy considering the extra allocations for SafeHandles in - // arrays or collections that don't realy represent their own native recource. - messageHandle.DangerousAddRef(ref mustRelease); - message.__ReadFromHandle(messageHandle.DangerousGetHandle()); - } - finally - { - if (mustRelease) - { - messageHandle.DangerousRelease(); - } - } - - return true; - - case RCLRet.SubscriptionTakeFailed: - return false; + return RCLdotnetDelegates.native_rcl_ok(); + } - default: - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take)}() failed."); + public static Node CreateNode(string nodeName) + { + return CreateNode(nodeName, ""); } - } - } - private static bool TakeRequest(Service service, SafeRequestIdHandle requestHeaderHandle, IRosMessage request) { - using (var requestHandle = service.CreateRequestHandle()) - { - RCLRet ret = RCLdotnetDelegates.native_rcl_take_request(service.Handle, requestHeaderHandle, requestHandle); - switch (ret) + public static Node CreateNode(string nodeName, string nodeNamespace) { - case RCLRet.Ok: - bool mustRelease = false; - try + var nodeHandle = new SafeNodeHandle(); + RCLRet ret = RCLdotnetDelegates.native_rcl_create_node_handle(ref nodeHandle, nodeName, nodeNamespace); + if (ret != RCLRet.Ok) { - // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be - // handled in generated code across multiple assemblies. - // Array and collection indexing would need to create SafeHandles everywere. - // It's not worth it, especialy considering the extra allocations for SafeHandles in - // arrays or collections that don't realy represent their own native recource. - requestHandle.DangerousAddRef(ref mustRelease); - request.__ReadFromHandle(requestHandle.DangerousGetHandle()); + nodeHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_node_handle)}() failed."); } - finally - { - if (mustRelease) - { - requestHandle.DangerousRelease(); - } - } - - return true; - case RCLRet.ServiceTakeFailed: - return false; - - default: - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take_request)}() failed."); + Node node = new Node(nodeHandle); + return node; } - } - } - private static bool TakeResponse(Client client, SafeRequestIdHandle requestHeaderHandle, IRosMessage response) { - using (var responseHandle = client.CreateResponseHandle()) - { - RCLRet ret = RCLdotnetDelegates.native_rcl_take_response(client.Handle, requestHeaderHandle, responseHandle); - switch (ret) + public static void Spin(Node node) { - case RCLRet.Ok: - bool mustRelease = false; - try + while (Ok()) { - // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be - // handled in generated code across multiple assemblies. - // Array and collection indexing would need to create SafeHandles everywere. - // It's not worth it, especialy considering the extra allocations for SafeHandles in - // arrays or collections that don't realy represent their own native recource. - responseHandle.DangerousAddRef(ref mustRelease); - response.__ReadFromHandle(responseHandle.DangerousGetHandle()); + SpinOnce(node, 500); } - finally + } + + private static SafeWaitSetHandle CreateWaitSet( + int numberOfSubscriptions, + int numberOfGuardConditions, + int numberOfTimers, + int numberOfClients, + int numberOfServices, + int numberOfEvents) + { + var waitSetHandle = new SafeWaitSetHandle(); + RCLRet ret = RCLdotnetDelegates.native_rcl_create_wait_set_handle( + ref waitSetHandle, numberOfSubscriptions, numberOfGuardConditions, + numberOfTimers, numberOfClients, numberOfServices, numberOfEvents); + if (ret != RCLRet.Ok) { - if (mustRelease) - { - responseHandle.DangerousRelease(); - } + waitSetHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_wait_set_handle)}() failed."); } - return true; + return waitSetHandle; + } - case RCLRet.ClientTakeFailed: - return false; - - default: - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take_response)}() failed."); + private static void WaitSetClear(SafeWaitSetHandle waitSetHandle) + { + RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_clear(waitSetHandle); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_clear)}() failed."); } - } - } - private static void SendResponse(Service service, SafeRequestIdHandle requestHeaderHandle, IRosMessage response) - { - using (var responseHandle = service.CreateResponseHandle()) - { - bool mustRelease = false; - try + private static void WaitSetAddSubscription(SafeWaitSetHandle waitSetHandle, SafeSubscriptionHandle subscriptionHandle) { - // Using SafeHandles for __WriteToHandle() is very tedious as this needs to be - // handled in generated code across multiple assemblies. - // Array and collection indexing would need to create SafeHandles everywere. - // It's not worth it, especialy considering the extra allocations for SafeHandles in - // arrays or collections that don't realy represent their own native recource. - responseHandle.DangerousAddRef(ref mustRelease); - response.__WriteToHandle(responseHandle.DangerousGetHandle()); + RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_subscription(waitSetHandle, subscriptionHandle); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_subscription)}() failed."); } - finally + + private static void WaitSetAddService(SafeWaitSetHandle waitSetHandle, SafeServiceHandle serviceHandle) { - if (mustRelease) - { - responseHandle.DangerousRelease(); - } + RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_service(waitSetHandle, serviceHandle); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_service)}() failed."); } - - RCLRet ret = RCLdotnetDelegates.native_rcl_send_response(service.Handle, requestHeaderHandle, responseHandle); - if (ret != RCLRet.Ok) + + private static void WaitSetAddClient(SafeWaitSetHandle waitSetHandle, SafeClientHandle clientHandle) { - throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_send_response)}() failed."); + RCLRet ret = RCLdotnetDelegates.native_rcl_wait_set_add_client(waitSetHandle, clientHandle); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait_set_add_client)}() failed."); } - } - } - public static void SpinOnce (Node node, long timeout) { - int numberOfSubscriptions = node.Subscriptions.Count; - int numberOfGuardConditions = 0; - int numberOfTimers = 0; - int numberOfClients = node.Clients.Count; - int numberOfServices = node.Services.Count; - int numberOfEvents = 0; - - bool waitSetEmpty = numberOfSubscriptions == 0 - && numberOfGuardConditions == 0 - && numberOfTimers == 0 - && numberOfClients == 0 - && numberOfServices == 0 - && numberOfEvents == 0; - - if (waitSetEmpty) - { - // TODO: (sh) Should we sleep here for the timeout to avoid loops without sleep? - // Avoid WaitSetEmpty return value from rcl_wait. - return; - } - - // TODO: (sh) Reuse wait set (see executer in rclc, rclcpp and rclpy) - using (SafeWaitSetHandle waitSetHandle = CreateWaitSet(numberOfSubscriptions, - numberOfGuardConditions, - numberOfTimers, - numberOfClients, - numberOfServices, - numberOfEvents)) - { - WaitSetClear(waitSetHandle); - - foreach (Subscription subscription in node.Subscriptions) { - WaitSetAddSubscription(waitSetHandle, subscription.Handle); + /// + /// Block until the wait set is ready or until the timeout has been exceeded. + /// + /// The wait set. + /// Timeout in ms. + /// True if wait set is ready, False on timeout. + private static bool Wait(SafeWaitSetHandle waitSetHandle, long timeout) + { + long ns_timeout = timeout * 1000000; + RCLRet ret = RCLdotnetDelegates.native_rcl_wait(waitSetHandle, ns_timeout); + if (ret == RCLRet.Ok || ret == RCLRet.Timeout) + { + return ret == RCLRet.Ok; + } + else + { + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_wait)}() failed."); + } } - foreach (var service in node.Services) + private static SafeRequestIdHandle CreateRequestId() { - WaitSetAddService(waitSetHandle, service.Handle); + var requestIdHandle = new SafeRequestIdHandle(); + RCLRet ret = RCLdotnetDelegates.native_rcl_create_request_id_handle(ref requestIdHandle); + if (ret != RCLRet.Ok) + { + requestIdHandle.Dispose(); + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_create_request_id_handle)}() failed."); + } + + return requestIdHandle; } - foreach (var client in node.Clients) + private static bool Take(Subscription subscription, IRosMessage message) { - WaitSetAddClient(waitSetHandle, client.Handle); + using (var messageHandle = subscription.CreateMessageHandle()) + { + RCLRet ret = RCLdotnetDelegates.native_rcl_take(subscription.Handle, messageHandle); + switch (ret) + { + case RCLRet.Ok: + bool mustRelease = false; + try + { + // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be + // handled in generated code across multiple assemblies. + // Array and collection indexing would need to create SafeHandles everywere. + // It's not worth it, especialy considering the extra allocations for SafeHandles in + // arrays or collections that don't realy represent their own native recource. + messageHandle.DangerousAddRef(ref mustRelease); + message.__ReadFromHandle(messageHandle.DangerousGetHandle()); + } + finally + { + if (mustRelease) + { + messageHandle.DangerousRelease(); + } + } + + return true; + + case RCLRet.SubscriptionTakeFailed: + return false; + + default: + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take)}() failed."); + } + } } - bool ready = Wait(waitSetHandle, timeout); - if (!ready) + private static bool TakeRequest(Service service, SafeRequestIdHandle requestHeaderHandle, IRosMessage request) { - return; // timeout + using (var requestHandle = service.CreateRequestHandle()) + { + RCLRet ret = RCLdotnetDelegates.native_rcl_take_request(service.Handle, requestHeaderHandle, requestHandle); + switch (ret) + { + case RCLRet.Ok: + bool mustRelease = false; + try + { + // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be + // handled in generated code across multiple assemblies. + // Array and collection indexing would need to create SafeHandles everywere. + // It's not worth it, especialy considering the extra allocations for SafeHandles in + // arrays or collections that don't realy represent their own native recource. + requestHandle.DangerousAddRef(ref mustRelease); + request.__ReadFromHandle(requestHandle.DangerousGetHandle()); + } + finally + { + if (mustRelease) + { + requestHandle.DangerousRelease(); + } + } + + return true; + + case RCLRet.ServiceTakeFailed: + return false; + + default: + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take_request)}() failed."); + } + } } - } - foreach (Subscription subscription in node.Subscriptions) { - IRosMessage message = subscription.CreateMessage(); - bool result = Take(subscription, message); - if (result) { - subscription.TriggerCallback (message); + private static bool TakeResponse(Client client, SafeRequestIdHandle requestHeaderHandle, IRosMessage response) + { + using (var responseHandle = client.CreateResponseHandle()) + { + RCLRet ret = RCLdotnetDelegates.native_rcl_take_response(client.Handle, requestHeaderHandle, responseHandle); + switch (ret) + { + case RCLRet.Ok: + bool mustRelease = false; + try + { + // Using SafeHandles for __ReadFromHandle() is very tedious as this needs to be + // handled in generated code across multiple assemblies. + // Array and collection indexing would need to create SafeHandles everywere. + // It's not worth it, especialy considering the extra allocations for SafeHandles in + // arrays or collections that don't realy represent their own native recource. + responseHandle.DangerousAddRef(ref mustRelease); + response.__ReadFromHandle(responseHandle.DangerousGetHandle()); + } + finally + { + if (mustRelease) + { + responseHandle.DangerousRelease(); + } + } + + return true; + + case RCLRet.ClientTakeFailed: + return false; + + default: + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_take_response)}() failed."); + } + } } - } - - // requestIdHandle gets reused for each element in the loop. - using (SafeRequestIdHandle requestIdHandle = CreateRequestId()) - { - foreach (var service in node.Services) + + private static void SendResponse(Service service, SafeRequestIdHandle requestHeaderHandle, IRosMessage response) { - var request = service.CreateRequest(); - var response = service.CreateResponse(); + using (var responseHandle = service.CreateResponseHandle()) + { + bool mustRelease = false; + try + { + // Using SafeHandles for __WriteToHandle() is very tedious as this needs to be + // handled in generated code across multiple assemblies. + // Array and collection indexing would need to create SafeHandles everywere. + // It's not worth it, especialy considering the extra allocations for SafeHandles in + // arrays or collections that don't realy represent their own native recource. + responseHandle.DangerousAddRef(ref mustRelease); + response.__WriteToHandle(responseHandle.DangerousGetHandle()); + } + finally + { + if (mustRelease) + { + responseHandle.DangerousRelease(); + } + } + + RCLRet ret = RCLdotnetDelegates.native_rcl_send_response(service.Handle, requestHeaderHandle, responseHandle); + if (ret != RCLRet.Ok) + { + throw RCLExceptionHelper.CreateFromReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_send_response)}() failed."); + } + } + } - var result = TakeRequest(service, requestIdHandle, request); - if (result) - { - service.TriggerCallback(request, response); + public static void SpinOnce(Node node, long timeout) + { + int numberOfSubscriptions = node.Subscriptions.Count; + int numberOfGuardConditions = 0; + int numberOfTimers = 0; + int numberOfClients = node.Clients.Count; + int numberOfServices = node.Services.Count; + int numberOfEvents = 0; + + bool waitSetEmpty = numberOfSubscriptions == 0 + && numberOfGuardConditions == 0 + && numberOfTimers == 0 + && numberOfClients == 0 + && numberOfServices == 0 + && numberOfEvents == 0; + + if (waitSetEmpty) + { + // TODO: (sh) Should we sleep here for the timeout to avoid loops without sleep? + // Avoid WaitSetEmpty return value from rcl_wait. + return; + } - SendResponse(service, requestIdHandle, response); - } + // TODO: (sh) Reuse wait set (see executer in rclc, rclcpp and rclpy) + using (SafeWaitSetHandle waitSetHandle = CreateWaitSet( + numberOfSubscriptions, + numberOfGuardConditions, + numberOfTimers, + numberOfClients, + numberOfServices, + numberOfEvents)) + { + WaitSetClear(waitSetHandle); + + foreach (Subscription subscription in node.Subscriptions) + { + WaitSetAddSubscription(waitSetHandle, subscription.Handle); + } + + foreach (var service in node.Services) + { + WaitSetAddService(waitSetHandle, service.Handle); + } + + foreach (var client in node.Clients) + { + WaitSetAddClient(waitSetHandle, client.Handle); + } + + bool ready = Wait(waitSetHandle, timeout); + if (!ready) + { + return; // timeout + } + } + + foreach (Subscription subscription in node.Subscriptions) + { + IRosMessage message = subscription.CreateMessage(); + bool result = Take(subscription, message); + if (result) + { + subscription.TriggerCallback(message); + } + } + + // requestIdHandle gets reused for each element in the loop. + using (SafeRequestIdHandle requestIdHandle = CreateRequestId()) + { + foreach (var service in node.Services) + { + var request = service.CreateRequest(); + var response = service.CreateResponse(); + + var result = TakeRequest(service, requestIdHandle, request); + if (result) + { + service.TriggerCallback(request, response); + + SendResponse(service, requestIdHandle, response); + } + } + + foreach (var client in node.Clients) + { + var response = client.CreateResponse(); + + var result = TakeResponse(client, requestIdHandle, response); + if (result) + { + var sequenceNumber = RCLdotnetDelegates.native_rcl_request_id_get_sequence_number(requestIdHandle); + client.HandleResponse(sequenceNumber, response); + } + } + } } - foreach (var client in node.Clients) + public static void Init() { - var response = client.CreateResponse(); - - var result = TakeResponse(client, requestIdHandle, response); - if (result) - { - var sequenceNumber = RCLdotnetDelegates.native_rcl_request_id_get_sequence_number(requestIdHandle); - client.HandleResponse(sequenceNumber, response); - } + lock (syncLock) + { + if (!initialized) + { + RCLRet ret = RCLdotnetDelegates.native_rcl_init(); + RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_init)}() failed."); + initialized = true; + } + } } - } - } - public static void Init () { - lock (syncLock) { - if (!initialized) { - RCLRet ret = RCLdotnetDelegates.native_rcl_init(); - RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_init)}() failed."); - initialized = true; + public static string GetRMWIdentifier() + { + IntPtr ptr = RCLdotnetDelegates.native_rcl_get_rmw_identifier(); + string rmw_identifier = Marshal.PtrToStringAnsi(ptr); + return rmw_identifier; } - } - } - - public static string GetRMWIdentifier () { - IntPtr ptr = RCLdotnetDelegates.native_rcl_get_rmw_identifier (); - string rmw_identifier = Marshal.PtrToStringAnsi (ptr); - return rmw_identifier; } - } } diff --git a/rcldotnet/SafeClientHandle.cs b/rcldotnet/SafeClientHandle.cs index c5400eff..98fb121f 100644 --- a/rcldotnet/SafeClientHandle.cs +++ b/rcldotnet/SafeClientHandle.cs @@ -29,7 +29,7 @@ namespace ROS2 /// which point to a rcl_publisher_t, rcl_subscription_t or rcl_service_t. /// internal sealed class SafeClientHandle : SafeHandleZeroOrMinusOneIsInvalid - { + { // Trick with parent handles taken from https://github.com/dotnet/corefx/pull/6366 // Commit from early 2016, but still in current .NET as of september 2021: // https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs @@ -53,7 +53,7 @@ protected override bool ReleaseHandle() { var parent = _parent; _parent = null; - + bool successfullyFreed = false; if (parent != null) { @@ -62,7 +62,7 @@ protected override bool ReleaseHandle() RCLRet ret = NodeDelegates.native_rcl_destroy_client_handle(handle, parent); successfullyFreed = ret == RCLRet.Ok; - + parent.DangerousRelease(); } diff --git a/rcldotnet/SafeNodeHandle.cs b/rcldotnet/SafeNodeHandle.cs index 2c6ea769..b9c1f857 100644 --- a/rcldotnet/SafeNodeHandle.cs +++ b/rcldotnet/SafeNodeHandle.cs @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + using System.Diagnostics; using Microsoft.Win32.SafeHandles; diff --git a/rcldotnet/SafePublisherHandle.cs b/rcldotnet/SafePublisherHandle.cs index a51d3003..649cf4d2 100644 --- a/rcldotnet/SafePublisherHandle.cs +++ b/rcldotnet/SafePublisherHandle.cs @@ -29,7 +29,7 @@ namespace ROS2 /// which point to a rcl_subscription_t, rcl_service_t or rcl_client_t. /// internal sealed class SafePublisherHandle : SafeHandleZeroOrMinusOneIsInvalid - { + { // Trick with parent handles taken from https://github.com/dotnet/corefx/pull/6366 // Commit from early 2016, but still in current .NET as of september 2021: // https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs @@ -53,7 +53,7 @@ protected override bool ReleaseHandle() { var parent = _parent; _parent = null; - + bool successfullyFreed = false; if (parent != null) { @@ -62,7 +62,7 @@ protected override bool ReleaseHandle() RCLRet ret = NodeDelegates.native_rcl_destroy_publisher_handle(handle, parent); successfullyFreed = ret == RCLRet.Ok; - + parent.DangerousRelease(); } diff --git a/rcldotnet/SafeServiceHandle.cs b/rcldotnet/SafeServiceHandle.cs index 3307137b..23b5ff33 100644 --- a/rcldotnet/SafeServiceHandle.cs +++ b/rcldotnet/SafeServiceHandle.cs @@ -29,7 +29,7 @@ namespace ROS2 /// which point to a rcl_publisher_t, rcl_subscription_t or rcl_client_t. /// internal sealed class SafeServiceHandle : SafeHandleZeroOrMinusOneIsInvalid - { + { // Trick with parent handles taken from https://github.com/dotnet/corefx/pull/6366 // Commit from early 2016, but still in current .NET as of september 2021: // https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs @@ -53,7 +53,7 @@ protected override bool ReleaseHandle() { var parent = _parent; _parent = null; - + bool successfullyFreed = false; if (parent != null) { @@ -62,7 +62,7 @@ protected override bool ReleaseHandle() RCLRet ret = NodeDelegates.native_rcl_destroy_service_handle(handle, parent); successfullyFreed = ret == RCLRet.Ok; - + parent.DangerousRelease(); } diff --git a/rcldotnet/SafeSubscriptionHandle.cs b/rcldotnet/SafeSubscriptionHandle.cs index 77d0738f..a7075035 100644 --- a/rcldotnet/SafeSubscriptionHandle.cs +++ b/rcldotnet/SafeSubscriptionHandle.cs @@ -29,7 +29,7 @@ namespace ROS2 /// which point to a rcl_publisher_t, rcl_service_t or rcl_client_t. /// internal sealed class SafeSubscriptionHandle : SafeHandleZeroOrMinusOneIsInvalid - { + { // Trick with parent handles taken from https://github.com/dotnet/corefx/pull/6366 // Commit from early 2016, but still in current .NET as of september 2021: // https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs @@ -53,7 +53,7 @@ protected override bool ReleaseHandle() { var parent = _parent; _parent = null; - + bool successfullyFreed = false; if (parent != null) { @@ -62,7 +62,7 @@ protected override bool ReleaseHandle() RCLRet ret = NodeDelegates.native_rcl_destroy_subscription_handle(handle, parent); successfullyFreed = ret == RCLRet.Ok; - + parent.DangerousRelease(); } diff --git a/rcldotnet/SafeWaitSetHandle.cs b/rcldotnet/SafeWaitSetHandle.cs index 3a6c0945..2d5faf7c 100644 --- a/rcldotnet/SafeWaitSetHandle.cs +++ b/rcldotnet/SafeWaitSetHandle.cs @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + using System.Diagnostics; using Microsoft.Win32.SafeHandles; diff --git a/rcldotnet/Service.cs b/rcldotnet/Service.cs index dbfebf9d..d5a2f86c 100644 --- a/rcldotnet/Service.cs +++ b/rcldotnet/Service.cs @@ -33,17 +33,17 @@ internal Service() // internal handle is disposed. // By relying on the GC/Finalizer of SafeHandle the handle only gets // Disposed if the service is not live anymore. - abstract internal SafeServiceHandle Handle { get; } + internal abstract SafeServiceHandle Handle { get; } - abstract internal IRosMessage CreateRequest(); - - abstract internal SafeHandle CreateRequestHandle(); + internal abstract IRosMessage CreateRequest(); - abstract internal IRosMessage CreateResponse(); + internal abstract SafeHandle CreateRequestHandle(); - abstract internal SafeHandle CreateResponseHandle(); + internal abstract IRosMessage CreateResponse(); - abstract internal void TriggerCallback(IRosMessage request, IRosMessage response); + internal abstract SafeHandle CreateResponseHandle(); + + internal abstract void TriggerCallback(IRosMessage request, IRosMessage response); } public sealed class Service : Service @@ -51,7 +51,7 @@ public sealed class Service : Service where TRequest : IRosMessage, new() where TResponse : IRosMessage, new() { - private Action _callback; + private readonly Action _callback; internal Service(SafeServiceHandle handle, Action callback) { @@ -59,7 +59,7 @@ internal Service(SafeServiceHandle handle, Action callback) _callback = callback; } - internal override SafeServiceHandle Handle { get; } + internal override SafeServiceHandle Handle { get; } internal override IRosMessage CreateRequest() => (IRosMessage)new TRequest(); diff --git a/rcldotnet/ServiceDefinitionStaticMemberCache.cs b/rcldotnet/ServiceDefinitionStaticMemberCache.cs index 20cb0abc..c222f9c9 100644 --- a/rcldotnet/ServiceDefinitionStaticMemberCache.cs +++ b/rcldotnet/ServiceDefinitionStaticMemberCache.cs @@ -23,7 +23,7 @@ internal static class ServiceDefinitionStaticMemberCache - /// Base class of a Subscription without generic type arguments for use in collections or so. - /// - public abstract class Subscription - { - // Only allow internal subclasses. - internal Subscription() + /// + /// Base class of a Subscription without generic type arguments for use in collections or so. + /// + public abstract class Subscription { - } + // Only allow internal subclasses. + internal Subscription() + { + } - // Subscription does intentionaly (for now) not implement IDisposable as this - // needs some extra consideration how the type works after its - // internal handle is disposed. - // By relying on the GC/Finalizer of SafeHandle the handle only gets - // Disposed if the subscription is not live anymore. - internal abstract SafeSubscriptionHandle Handle { get; } + // Subscription does intentionaly (for now) not implement IDisposable as this + // needs some extra consideration how the type works after its + // internal handle is disposed. + // By relying on the GC/Finalizer of SafeHandle the handle only gets + // Disposed if the subscription is not live anymore. + internal abstract SafeSubscriptionHandle Handle { get; } - internal abstract IRosMessage CreateMessage(); + internal abstract IRosMessage CreateMessage(); - internal abstract SafeHandle CreateMessageHandle(); + internal abstract SafeHandle CreateMessageHandle(); - internal abstract void TriggerCallback(IRosMessage message); - } + internal abstract void TriggerCallback(IRosMessage message); + } - public class Subscription : Subscription - where T : IRosMessage, new() { - private Action callback_; + public class Subscription : Subscription + where T : IRosMessage, new() + { + private readonly Action callback_; - internal Subscription(SafeSubscriptionHandle handle, Action callback) { - Handle = handle; - callback_ = callback; - } + internal Subscription(SafeSubscriptionHandle handle, Action callback) + { + Handle = handle; + callback_ = callback; + } - internal override SafeSubscriptionHandle Handle { get; } + internal override SafeSubscriptionHandle Handle { get; } - internal override IRosMessage CreateMessage() => (IRosMessage)new T(); + internal override IRosMessage CreateMessage() => (IRosMessage)new T(); - internal override SafeHandle CreateMessageHandle() => MessageStaticMemberCache.CreateMessageHandle(); + internal override SafeHandle CreateMessageHandle() => MessageStaticMemberCache.CreateMessageHandle(); - internal override void TriggerCallback(IRosMessage message) { - callback_((T) message); + internal override void TriggerCallback(IRosMessage message) + { + callback_((T)message); + } } - } } diff --git a/rcldotnet/test/test_messages.cs b/rcldotnet/test/test_messages.cs index f96e54f2..a344152f 100644 --- a/rcldotnet/test/test_messages.cs +++ b/rcldotnet/test/test_messages.cs @@ -6,1411 +6,1411 @@ namespace RCLdotnetTests { - public class TestMessages - { - [Fact] - public void TestPublishString() + public class TestMessages { - RCLdotnet.Init (); - Node node_string_1 = RCLdotnet.CreateNode ("test_string_1"); - Node node_string_2 = RCLdotnet.CreateNode ("test_string_2"); - Publisher chatter_pub = node_string_1.CreatePublisher ("topic_string"); - - std_msgs.msg.String msg = new std_msgs.msg.String (); - std_msgs.msg.String msg2 = new std_msgs.msg.String (); - msg.Data = "Hello"; - - bool received=false; - Subscription chatter_sub = node_string_2.CreateSubscription ( - "topic_string", rcv_msg => + [Fact] + public void TestPublishString() { - received=true; - msg2 = rcv_msg; + RCLdotnet.Init(); + Node node_string_1 = RCLdotnet.CreateNode("test_string_1"); + Node node_string_2 = RCLdotnet.CreateNode("test_string_2"); + Publisher chatter_pub = node_string_1.CreatePublisher("topic_string"); + + std_msgs.msg.String msg = new std_msgs.msg.String(); + std_msgs.msg.String msg2 = new std_msgs.msg.String(); + msg.Data = "Hello"; + + bool received = false; + Subscription chatter_sub = node_string_2.CreateSubscription( + "topic_string", rcv_msg => + { + received = true; + msg2 = rcv_msg; + } + ); + + while (!received) + { + chatter_pub.Publish(msg); + + RCLdotnet.SpinOnce(node_string_1, 500); + RCLdotnet.SpinOnce(node_string_2, 500); + } + Assert.Equal("Hello", msg2.Data); } - ); - while(!received) - { - chatter_pub.Publish (msg); - - RCLdotnet.SpinOnce(node_string_1, 500); - RCLdotnet.SpinOnce(node_string_2, 500); - } - Assert.Equal("Hello", msg2.Data); - } - - [Fact] - public void TestPublishBuiltins() - { - RCLdotnet.Init (); - Node node_builtins_1 = RCLdotnet.CreateNode ("test_builtins_1"); - Node node_builtins_2 = RCLdotnet.CreateNode ("test_builtins_2"); - Publisher chatter_pub = node_builtins_1.CreatePublisher ("topic_builtins"); - - test_msgs.msg.Builtins msg = new test_msgs.msg.Builtins (); - test_msgs.msg.Builtins msg2 = new test_msgs.msg.Builtins (); - msg.DurationValue.Sec = 1; - msg.DurationValue.Nanosec = 2u; - msg.TimeValue.Sec = 3; - msg.TimeValue.Nanosec = 4u; - - bool received=false; - Subscription chatter_sub = node_builtins_2.CreateSubscription ( - "topic_builtins", rcv_msg => + [Fact] + public void TestPublishBuiltins() { - received=true; - msg2 = rcv_msg; + RCLdotnet.Init(); + Node node_builtins_1 = RCLdotnet.CreateNode("test_builtins_1"); + Node node_builtins_2 = RCLdotnet.CreateNode("test_builtins_2"); + Publisher chatter_pub = node_builtins_1.CreatePublisher("topic_builtins"); + + test_msgs.msg.Builtins msg = new test_msgs.msg.Builtins(); + test_msgs.msg.Builtins msg2 = new test_msgs.msg.Builtins(); + msg.DurationValue.Sec = 1; + msg.DurationValue.Nanosec = 2u; + msg.TimeValue.Sec = 3; + msg.TimeValue.Nanosec = 4u; + + bool received = false; + Subscription chatter_sub = node_builtins_2.CreateSubscription( + "topic_builtins", rcv_msg => + { + received = true; + msg2 = rcv_msg; + } + ); + + while (!received) + { + chatter_pub.Publish(msg); + + RCLdotnet.SpinOnce(node_builtins_1, 500); + RCLdotnet.SpinOnce(node_builtins_2, 500); + } + + Assert.Equal(1, msg2.DurationValue.Sec); + Assert.Equal(2u, msg2.DurationValue.Nanosec); + Assert.Equal(3, msg2.TimeValue.Sec); + Assert.Equal(4u, msg2.TimeValue.Nanosec); } - ); - - while(!received) - { - chatter_pub.Publish (msg); - - RCLdotnet.SpinOnce(node_builtins_1, 500); - RCLdotnet.SpinOnce(node_builtins_2, 500); - } - Assert.Equal(1, msg2.DurationValue.Sec); - Assert.Equal(2u, msg2.DurationValue.Nanosec); - Assert.Equal(3, msg2.TimeValue.Sec); - Assert.Equal(4u, msg2.TimeValue.Nanosec); - } - - [Fact] - public void TestPublishArrays() - { - RCLdotnet.Init (); - Node node_array_1 = RCLdotnet.CreateNode ("test_arrays_1"); - Node node_array_2 = RCLdotnet.CreateNode ("test_arrays_2"); - Publisher chatter_pub = node_array_1.CreatePublisher ("topic_array"); - - test_msgs.msg.Arrays msg = new test_msgs.msg.Arrays (); - test_msgs.msg.Arrays msg2 = new test_msgs.msg.Arrays (); - - // boolValues - msg.BoolValues[0] = true; - msg.BoolValues[1] = false; - msg.BoolValues[2] = true; - - // byteValues - msg.ByteValues[0] = 0; - msg.ByteValues[1] = 1; - msg.ByteValues[2] = 2; - - // charValues - msg.CharValues[0] = 3; - msg.CharValues[1] = 4; - msg.CharValues[2] = 5; - - // float32Values - msg.Float32Values[0] = 6.1f; - msg.Float32Values[1] = 7.1f; - msg.Float32Values[2] = 8.1f; - - // float64Values - msg.Float64Values[0] = 9.1; - msg.Float64Values[1] = 10.1; - msg.Float64Values[2] = 11.1; - - // int8Values - msg.Int8Values[0] = 12; - msg.Int8Values[1] = 13; - msg.Int8Values[2] = 14; - - // uint8Values - msg.Uint8Values[0] = 15; - msg.Uint8Values[1] = 16; - msg.Uint8Values[2] = 17; - - // int16Values - msg.Int16Values[0] = 18; - msg.Int16Values[1] = 19; - msg.Int16Values[2] = 20; - - // uint16Values - msg.Uint16Values[0] = 21; - msg.Uint16Values[1] = 22; - msg.Uint16Values[2] = 23; - - // int32Values - msg.Int32Values[0] = 24; - msg.Int32Values[1] = 25; - msg.Int32Values[2] = 26; - - // uint32Values - msg.Uint32Values[0] = 27; - msg.Uint32Values[1] = 28; - msg.Uint32Values[2] = 29; - - // int64Values - msg.Int64Values[0] = 30; - msg.Int64Values[1] = 31; - msg.Int64Values[2] = 32; - - // uint64Values - msg.Uint64Values[0] = 33; - msg.Uint64Values[1] = 34; - msg.Uint64Values[2] = 35; - - // stringValues - msg.StringValues[0] = "one"; - msg.StringValues[1] = "two"; - msg.StringValues[2] = "three"; - - // basicTypesValues - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues[0] = basic_type_1; - msg.BasicTypesValues[1] = basic_type_2; - msg.BasicTypesValues[2] = basic_type_3; - - bool received=false; - Subscription chatter_sub = node_array_2.CreateSubscription ( - "topic_array", rcv_msg => + [Fact] + public void TestPublishArrays() { - received = true; - msg2 = rcv_msg; + RCLdotnet.Init(); + Node node_array_1 = RCLdotnet.CreateNode("test_arrays_1"); + Node node_array_2 = RCLdotnet.CreateNode("test_arrays_2"); + Publisher chatter_pub = node_array_1.CreatePublisher("topic_array"); + + test_msgs.msg.Arrays msg = new test_msgs.msg.Arrays(); + test_msgs.msg.Arrays msg2 = new test_msgs.msg.Arrays(); + + // boolValues + msg.BoolValues[0] = true; + msg.BoolValues[1] = false; + msg.BoolValues[2] = true; + + // byteValues + msg.ByteValues[0] = 0; + msg.ByteValues[1] = 1; + msg.ByteValues[2] = 2; + + // charValues + msg.CharValues[0] = 3; + msg.CharValues[1] = 4; + msg.CharValues[2] = 5; + + // float32Values + msg.Float32Values[0] = 6.1f; + msg.Float32Values[1] = 7.1f; + msg.Float32Values[2] = 8.1f; + + // float64Values + msg.Float64Values[0] = 9.1; + msg.Float64Values[1] = 10.1; + msg.Float64Values[2] = 11.1; + + // int8Values + msg.Int8Values[0] = 12; + msg.Int8Values[1] = 13; + msg.Int8Values[2] = 14; + + // uint8Values + msg.Uint8Values[0] = 15; + msg.Uint8Values[1] = 16; + msg.Uint8Values[2] = 17; + + // int16Values + msg.Int16Values[0] = 18; + msg.Int16Values[1] = 19; + msg.Int16Values[2] = 20; + + // uint16Values + msg.Uint16Values[0] = 21; + msg.Uint16Values[1] = 22; + msg.Uint16Values[2] = 23; + + // int32Values + msg.Int32Values[0] = 24; + msg.Int32Values[1] = 25; + msg.Int32Values[2] = 26; + + // uint32Values + msg.Uint32Values[0] = 27; + msg.Uint32Values[1] = 28; + msg.Uint32Values[2] = 29; + + // int64Values + msg.Int64Values[0] = 30; + msg.Int64Values[1] = 31; + msg.Int64Values[2] = 32; + + // uint64Values + msg.Uint64Values[0] = 33; + msg.Uint64Values[1] = 34; + msg.Uint64Values[2] = 35; + + // stringValues + msg.StringValues[0] = "one"; + msg.StringValues[1] = "two"; + msg.StringValues[2] = "three"; + + // basicTypesValues + test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); + basic_type_1.BoolValue = true; + basic_type_1.ByteValue = 36; + basic_type_1.CharValue = 37; + basic_type_1.Float32Value = 38.1f; + basic_type_1.Float64Value = 39.1; + basic_type_1.Int8Value = 40; + basic_type_1.Uint8Value = 41; + basic_type_1.Int16Value = 42; + basic_type_1.Uint16Value = 43; + basic_type_1.Int32Value = 44; + basic_type_1.Uint32Value = 45; + basic_type_1.Int64Value = 46; + basic_type_1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); + basic_type_2.BoolValue = false; + basic_type_2.ByteValue = 48; + basic_type_2.CharValue = 49; + basic_type_2.Float32Value = 50.1f; + basic_type_2.Float64Value = 51.1; + basic_type_2.Int8Value = 52; + basic_type_2.Uint8Value = 53; + basic_type_2.Int16Value = 54; + basic_type_2.Uint16Value = 55; + basic_type_2.Int32Value = 56; + basic_type_2.Uint32Value = 57; + basic_type_2.Int64Value = 58; + basic_type_2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); + basic_type_3.BoolValue = true; + basic_type_3.ByteValue = 60; + basic_type_3.CharValue = 61; + basic_type_3.Float32Value = 62.1f; + basic_type_3.Float64Value = 63.1; + basic_type_3.Int8Value = 64; + basic_type_3.Uint8Value = 65; + basic_type_3.Int16Value = 66; + basic_type_3.Uint16Value = 67; + basic_type_3.Int32Value = 68; + basic_type_3.Uint32Value = 69; + basic_type_3.Int64Value = 70; + basic_type_3.Uint64Value = 71; + + msg.BasicTypesValues[0] = basic_type_1; + msg.BasicTypesValues[1] = basic_type_2; + msg.BasicTypesValues[2] = basic_type_3; + + bool received = false; + Subscription chatter_sub = node_array_2.CreateSubscription( + "topic_array", rcv_msg => + { + received = true; + msg2 = rcv_msg; + } + ); + + while (!received) + { + chatter_pub.Publish(msg); + + RCLdotnet.SpinOnce(node_array_1, 500); + RCLdotnet.SpinOnce(node_array_2, 500); + } + + // boolValues + Assert.Equal(3, test_msgs.msg.Arrays.BoolValuesLength); + Assert.Equal(3, msg2.BoolValues.Length); + Assert.True(msg2.BoolValues[0]); + Assert.False(msg2.BoolValues[1]); + Assert.True(msg2.BoolValues[2]); + + // byteValues + Assert.Equal(3, test_msgs.msg.Arrays.ByteValuesLength); + Assert.Equal(3, msg2.ByteValues.Length); + Assert.Equal(0, msg2.ByteValues[0]); + Assert.Equal(1, msg2.ByteValues[1]); + Assert.Equal(2, msg2.ByteValues[2]); + + // charValues + Assert.Equal(3, test_msgs.msg.Arrays.CharValuesLength); + Assert.Equal(3, msg2.CharValues.Length); + Assert.Equal(3, msg2.CharValues[0]); + Assert.Equal(4, msg2.CharValues[1]); + Assert.Equal(5, msg2.CharValues[2]); + + // float32Values + Assert.Equal(3, test_msgs.msg.Arrays.Float32ValuesLength); + Assert.Equal(3, msg2.Float32Values.Length); + Assert.Equal(6.1f, msg2.Float32Values[0]); + Assert.Equal(7.1f, msg2.Float32Values[1]); + Assert.Equal(8.1f, msg2.Float32Values[2]); + + // float64Values + Assert.Equal(3, test_msgs.msg.Arrays.Float64ValuesLength); + Assert.Equal(3, msg2.Float64Values.Length); + Assert.Equal(9.1, msg2.Float64Values[0]); + Assert.Equal(10.1, msg2.Float64Values[1]); + Assert.Equal(11.1, msg2.Float64Values[2]); + + // int8Values + Assert.Equal(3, test_msgs.msg.Arrays.Int8ValuesLength); + Assert.Equal(3, msg2.Int8Values.Length); + Assert.Equal(12, msg2.Int8Values[0]); + Assert.Equal(13, msg2.Int8Values[1]); + Assert.Equal(14, msg2.Int8Values[2]); + + // uint8Values + Assert.Equal(3, test_msgs.msg.Arrays.Uint8ValuesLength); + Assert.Equal(3, msg2.Uint8Values.Length); + Assert.Equal(15, msg2.Uint8Values[0]); + Assert.Equal(16, msg2.Uint8Values[1]); + Assert.Equal(17, msg2.Uint8Values[2]); + + // int16Values + Assert.Equal(3, test_msgs.msg.Arrays.Int16ValuesLength); + Assert.Equal(3, msg2.Int16Values.Length); + Assert.Equal(18, msg2.Int16Values[0]); + Assert.Equal(19, msg2.Int16Values[1]); + Assert.Equal(20, msg2.Int16Values[2]); + + // uint16Values + Assert.Equal(3, test_msgs.msg.Arrays.Uint16ValuesLength); + Assert.Equal(3, msg2.Uint16Values.Length); + Assert.Equal(21, msg2.Uint16Values[0]); + Assert.Equal(22, msg2.Uint16Values[1]); + Assert.Equal(23, msg2.Uint16Values[2]); + + // int32Values + Assert.Equal(3, test_msgs.msg.Arrays.Int32ValuesLength); + Assert.Equal(3, msg2.Int32Values.Length); + Assert.Equal(24, msg2.Int32Values[0]); + Assert.Equal(25, msg2.Int32Values[1]); + Assert.Equal(26, msg2.Int32Values[2]); + + // uint32Values + Assert.Equal(3, test_msgs.msg.Arrays.Uint32ValuesLength); + Assert.Equal(3, msg2.Uint32Values.Length); + Assert.Equal((uint)27, msg2.Uint32Values[0]); + Assert.Equal((uint)28, msg2.Uint32Values[1]); + Assert.Equal((uint)29, msg2.Uint32Values[2]); + + // int64Values + Assert.Equal(3, test_msgs.msg.Arrays.Int64ValuesLength); + Assert.Equal(3, msg2.Int64Values.Length); + Assert.Equal(30, msg2.Int64Values[0]); + Assert.Equal(31, msg2.Int64Values[1]); + Assert.Equal(32, msg2.Int64Values[2]); + + // uint64Values + Assert.Equal(3, test_msgs.msg.Arrays.Uint64ValuesLength); + Assert.Equal(3, msg2.Uint64Values.Length); + Assert.Equal((ulong)33, msg2.Uint64Values[0]); + Assert.Equal((ulong)34, msg2.Uint64Values[1]); + Assert.Equal((ulong)35, msg2.Uint64Values[2]); + + // stringValues + Assert.Equal(3, test_msgs.msg.Arrays.StringValuesLength); + Assert.Equal(3, msg2.StringValues.Length); + Assert.Equal("one", msg2.StringValues[0]); + Assert.Equal("two", msg2.StringValues[1]); + Assert.Equal("three", msg2.StringValues[2]); + + // basicTypesValues + Assert.Equal(3, test_msgs.msg.Arrays.BasicTypesValuesLength); + Assert.Equal(3, msg2.BasicTypesValues.Length); + + Assert.True(msg2.BasicTypesValues[0].BoolValue); + Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); + Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); + Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); + Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); + Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); + Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); + Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); + Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); + Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); + Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); + Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); + Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); + + Assert.False(msg2.BasicTypesValues[1].BoolValue); + Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); + Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); + Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); + Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); + Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); + Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); + Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); + Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); + Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); + Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); + Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); + Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); + + Assert.True(msg2.BasicTypesValues[2].BoolValue); + Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); + Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); + Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); + Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); + Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); + Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); + Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); + Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); + Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); + Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); + Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); + Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); } - ); - - while (!received) - { - chatter_pub.Publish(msg); - - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); - } - - // boolValues - Assert.Equal(3, test_msgs.msg.Arrays.BoolValuesLength); - Assert.Equal(3, msg2.BoolValues.Length); - Assert.True(msg2.BoolValues[0]); - Assert.False(msg2.BoolValues[1]); - Assert.True(msg2.BoolValues[2]); - - // byteValues - Assert.Equal(3, test_msgs.msg.Arrays.ByteValuesLength); - Assert.Equal(3, msg2.ByteValues.Length); - Assert.Equal(0, msg2.ByteValues[0]); - Assert.Equal(1, msg2.ByteValues[1]); - Assert.Equal(2, msg2.ByteValues[2]); - - // charValues - Assert.Equal(3, test_msgs.msg.Arrays.CharValuesLength); - Assert.Equal(3, msg2.CharValues.Length); - Assert.Equal(3, msg2.CharValues[0]); - Assert.Equal(4, msg2.CharValues[1]); - Assert.Equal(5, msg2.CharValues[2]); - - // float32Values - Assert.Equal(3, test_msgs.msg.Arrays.Float32ValuesLength); - Assert.Equal(3, msg2.Float32Values.Length); - Assert.Equal(6.1f, msg2.Float32Values[0]); - Assert.Equal(7.1f, msg2.Float32Values[1]); - Assert.Equal(8.1f, msg2.Float32Values[2]); - - // float64Values - Assert.Equal(3, test_msgs.msg.Arrays.Float64ValuesLength); - Assert.Equal(3, msg2.Float64Values.Length); - Assert.Equal(9.1, msg2.Float64Values[0]); - Assert.Equal(10.1, msg2.Float64Values[1]); - Assert.Equal(11.1, msg2.Float64Values[2]); - - // int8Values - Assert.Equal(3, test_msgs.msg.Arrays.Int8ValuesLength); - Assert.Equal(3, msg2.Int8Values.Length); - Assert.Equal(12, msg2.Int8Values[0]); - Assert.Equal(13, msg2.Int8Values[1]); - Assert.Equal(14, msg2.Int8Values[2]); - - // uint8Values - Assert.Equal(3, test_msgs.msg.Arrays.Uint8ValuesLength); - Assert.Equal(3, msg2.Uint8Values.Length); - Assert.Equal(15, msg2.Uint8Values[0]); - Assert.Equal(16, msg2.Uint8Values[1]); - Assert.Equal(17, msg2.Uint8Values[2]); - - // int16Values - Assert.Equal(3, test_msgs.msg.Arrays.Int16ValuesLength); - Assert.Equal(3, msg2.Int16Values.Length); - Assert.Equal(18, msg2.Int16Values[0]); - Assert.Equal(19, msg2.Int16Values[1]); - Assert.Equal(20, msg2.Int16Values[2]); - - // uint16Values - Assert.Equal(3, test_msgs.msg.Arrays.Uint16ValuesLength); - Assert.Equal(3, msg2.Uint16Values.Length); - Assert.Equal(21, msg2.Uint16Values[0]); - Assert.Equal(22, msg2.Uint16Values[1]); - Assert.Equal(23, msg2.Uint16Values[2]); - - // int32Values - Assert.Equal(3, test_msgs.msg.Arrays.Int32ValuesLength); - Assert.Equal(3, msg2.Int32Values.Length); - Assert.Equal(24, msg2.Int32Values[0]); - Assert.Equal(25, msg2.Int32Values[1]); - Assert.Equal(26, msg2.Int32Values[2]); - - // uint32Values - Assert.Equal(3, test_msgs.msg.Arrays.Uint32ValuesLength); - Assert.Equal(3, msg2.Uint32Values.Length); - Assert.Equal((uint)27, msg2.Uint32Values[0]); - Assert.Equal((uint)28, msg2.Uint32Values[1]); - Assert.Equal((uint)29, msg2.Uint32Values[2]); - - // int64Values - Assert.Equal(3, test_msgs.msg.Arrays.Int64ValuesLength); - Assert.Equal(3, msg2.Int64Values.Length); - Assert.Equal(30, msg2.Int64Values[0]); - Assert.Equal(31, msg2.Int64Values[1]); - Assert.Equal(32, msg2.Int64Values[2]); - - // uint64Values - Assert.Equal(3, test_msgs.msg.Arrays.Uint64ValuesLength); - Assert.Equal(3, msg2.Uint64Values.Length); - Assert.Equal((ulong)33, msg2.Uint64Values[0]); - Assert.Equal((ulong)34, msg2.Uint64Values[1]); - Assert.Equal((ulong)35, msg2.Uint64Values[2]); - - // stringValues - Assert.Equal(3, test_msgs.msg.Arrays.StringValuesLength); - Assert.Equal(3, msg2.StringValues.Length); - Assert.Equal("one", msg2.StringValues[0]); - Assert.Equal("two", msg2.StringValues[1]); - Assert.Equal("three", msg2.StringValues[2]); - - // basicTypesValues - Assert.Equal(3, test_msgs.msg.Arrays.BasicTypesValuesLength); - Assert.Equal(3, msg2.BasicTypesValues.Length); - - Assert.True(msg2.BasicTypesValues[0].BoolValue); - Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); - Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); - Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); - Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); - Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); - Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); - Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); - Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); - Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); - Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); - Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); - Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); - - Assert.False(msg2.BasicTypesValues[1].BoolValue); - Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); - Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); - Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); - Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); - Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); - Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); - Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); - Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); - Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); - Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); - Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); - Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); - - Assert.True(msg2.BasicTypesValues[2].BoolValue); - Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); - Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); - Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); - Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); - Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); - Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); - Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); - Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); - Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); - Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); - Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); - Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); - } - [Fact] - public void TestPublishArraysSizeCheckToLittle() - { - RCLdotnet.Init(); - var nodeArraysSizeCheck = RCLdotnet.CreateNode("test_arrays_size_check_to_little"); - var chatterPub = nodeArraysSizeCheck.CreatePublisher("topic_array_size_check_to_little"); - - var msg = new test_msgs.msg.Arrays(); - msg.BoolValues = new bool[] - { - false, - true, - }; - - var exception = Assert.Throws(() => chatterPub.Publish(msg)); - Assert.Equal("Invalid size of array 'BoolValues'.", exception.Message); - } + [Fact] + public void TestPublishArraysSizeCheckToLittle() + { + RCLdotnet.Init(); + var nodeArraysSizeCheck = RCLdotnet.CreateNode("test_arrays_size_check_to_little"); + var chatterPub = nodeArraysSizeCheck.CreatePublisher("topic_array_size_check_to_little"); + + var msg = new test_msgs.msg.Arrays(); + msg.BoolValues = new bool[] + { + false, + true, + }; + + var exception = Assert.Throws(() => chatterPub.Publish(msg)); + Assert.Equal("Invalid size of array 'BoolValues'.", exception.Message); + } - [Fact] - public void TestPublishArraysSizeCheckToMuch() - { - RCLdotnet.Init(); - var nodeArraysSizeCheck = RCLdotnet.CreateNode("test_arrays_size_check_to_much"); - var chatterPub = nodeArraysSizeCheck.CreatePublisher("topic_array_size_check_to_much"); - - var msg = new test_msgs.msg.Arrays(); - msg.StringValues = new string[] - { - "0", - "1", - "2", - "3", - }; - - var exception = Assert.Throws(() => chatterPub.Publish(msg)); - Assert.Equal("Invalid size of array 'StringValues'.", exception.Message); - } + [Fact] + public void TestPublishArraysSizeCheckToMuch() + { + RCLdotnet.Init(); + var nodeArraysSizeCheck = RCLdotnet.CreateNode("test_arrays_size_check_to_much"); + var chatterPub = nodeArraysSizeCheck.CreatePublisher("topic_array_size_check_to_much"); + + var msg = new test_msgs.msg.Arrays(); + msg.StringValues = new string[] + { + "0", + "1", + "2", + "3", + }; + + var exception = Assert.Throws(() => chatterPub.Publish(msg)); + Assert.Equal("Invalid size of array 'StringValues'.", exception.Message); + } - [Fact] - public void TestPublishUnboundedSequences() - { - RCLdotnet.Init(); - Node node_array_1 = RCLdotnet.CreateNode("test_unbounded_sequences_1"); - Node node_array_2 = RCLdotnet.CreateNode("test_unbounded_sequences_2"); - Publisher chatter_pub = node_array_1.CreatePublisher("topic_unbounded_sequences"); - - test_msgs.msg.UnboundedSequences msg = new test_msgs.msg.UnboundedSequences(); - test_msgs.msg.UnboundedSequences msg2 = new test_msgs.msg.UnboundedSequences(); - - // boolValues - msg.BoolValues.Add(true); - msg.BoolValues.Add(false); - msg.BoolValues.Add(true); - - // byteValues - msg.ByteValues.Add(0); - msg.ByteValues.Add(1); - msg.ByteValues.Add(2); - - // charValues - msg.CharValues.Add(3); - msg.CharValues.Add(4); - msg.CharValues.Add(5); - - // float32Values - msg.Float32Values.Add(6.1f); - msg.Float32Values.Add(7.1f); - msg.Float32Values.Add(8.1f); - - // float64Values - msg.Float64Values.Add(9.1); - msg.Float64Values.Add(10.1); - msg.Float64Values.Add(11.1); - - // int8Values - msg.Int8Values.Add(12); - msg.Int8Values.Add(13); - msg.Int8Values.Add(14); - - // uint8Values - msg.Uint8Values.Add(15); - msg.Uint8Values.Add(16); - msg.Uint8Values.Add(17); - - // int16Values - msg.Int16Values.Add(18); - msg.Int16Values.Add(19); - msg.Int16Values.Add(20); - - // uint16Values - msg.Uint16Values.Add(21); - msg.Uint16Values.Add(22); - msg.Uint16Values.Add(23); - - // int32Values - msg.Int32Values.Add(24); - msg.Int32Values.Add(25); - msg.Int32Values.Add(26); - - // uint32Values - msg.Uint32Values.Add(27); - msg.Uint32Values.Add(28); - msg.Uint32Values.Add(29); - - // int64Values - msg.Int64Values.Add(30); - msg.Int64Values.Add(31); - msg.Int64Values.Add(32); - - // uint64Values - msg.Uint64Values.Add(33); - msg.Uint64Values.Add(34); - msg.Uint64Values.Add(35); - - // stringValues - msg.StringValues.Add("one"); - msg.StringValues.Add("two"); - msg.StringValues.Add("three"); - - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues.Add(basic_type_1); - msg.BasicTypesValues.Add(basic_type_2); - msg.BasicTypesValues.Add(basic_type_3); - - bool received=false; - Subscription chatter_sub = node_array_2.CreateSubscription( - "topic_unbounded_sequences", rcv_msg => + [Fact] + public void TestPublishUnboundedSequences() { - received=true; - msg2 = rcv_msg; + RCLdotnet.Init(); + Node node_array_1 = RCLdotnet.CreateNode("test_unbounded_sequences_1"); + Node node_array_2 = RCLdotnet.CreateNode("test_unbounded_sequences_2"); + Publisher chatter_pub = node_array_1.CreatePublisher("topic_unbounded_sequences"); + + test_msgs.msg.UnboundedSequences msg = new test_msgs.msg.UnboundedSequences(); + test_msgs.msg.UnboundedSequences msg2 = new test_msgs.msg.UnboundedSequences(); + + // boolValues + msg.BoolValues.Add(true); + msg.BoolValues.Add(false); + msg.BoolValues.Add(true); + + // byteValues + msg.ByteValues.Add(0); + msg.ByteValues.Add(1); + msg.ByteValues.Add(2); + + // charValues + msg.CharValues.Add(3); + msg.CharValues.Add(4); + msg.CharValues.Add(5); + + // float32Values + msg.Float32Values.Add(6.1f); + msg.Float32Values.Add(7.1f); + msg.Float32Values.Add(8.1f); + + // float64Values + msg.Float64Values.Add(9.1); + msg.Float64Values.Add(10.1); + msg.Float64Values.Add(11.1); + + // int8Values + msg.Int8Values.Add(12); + msg.Int8Values.Add(13); + msg.Int8Values.Add(14); + + // uint8Values + msg.Uint8Values.Add(15); + msg.Uint8Values.Add(16); + msg.Uint8Values.Add(17); + + // int16Values + msg.Int16Values.Add(18); + msg.Int16Values.Add(19); + msg.Int16Values.Add(20); + + // uint16Values + msg.Uint16Values.Add(21); + msg.Uint16Values.Add(22); + msg.Uint16Values.Add(23); + + // int32Values + msg.Int32Values.Add(24); + msg.Int32Values.Add(25); + msg.Int32Values.Add(26); + + // uint32Values + msg.Uint32Values.Add(27); + msg.Uint32Values.Add(28); + msg.Uint32Values.Add(29); + + // int64Values + msg.Int64Values.Add(30); + msg.Int64Values.Add(31); + msg.Int64Values.Add(32); + + // uint64Values + msg.Uint64Values.Add(33); + msg.Uint64Values.Add(34); + msg.Uint64Values.Add(35); + + // stringValues + msg.StringValues.Add("one"); + msg.StringValues.Add("two"); + msg.StringValues.Add("three"); + + test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); + basic_type_1.BoolValue = true; + basic_type_1.ByteValue = 36; + basic_type_1.CharValue = 37; + basic_type_1.Float32Value = 38.1f; + basic_type_1.Float64Value = 39.1; + basic_type_1.Int8Value = 40; + basic_type_1.Uint8Value = 41; + basic_type_1.Int16Value = 42; + basic_type_1.Uint16Value = 43; + basic_type_1.Int32Value = 44; + basic_type_1.Uint32Value = 45; + basic_type_1.Int64Value = 46; + basic_type_1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); + basic_type_2.BoolValue = false; + basic_type_2.ByteValue = 48; + basic_type_2.CharValue = 49; + basic_type_2.Float32Value = 50.1f; + basic_type_2.Float64Value = 51.1; + basic_type_2.Int8Value = 52; + basic_type_2.Uint8Value = 53; + basic_type_2.Int16Value = 54; + basic_type_2.Uint16Value = 55; + basic_type_2.Int32Value = 56; + basic_type_2.Uint32Value = 57; + basic_type_2.Int64Value = 58; + basic_type_2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); + basic_type_3.BoolValue = true; + basic_type_3.ByteValue = 60; + basic_type_3.CharValue = 61; + basic_type_3.Float32Value = 62.1f; + basic_type_3.Float64Value = 63.1; + basic_type_3.Int8Value = 64; + basic_type_3.Uint8Value = 65; + basic_type_3.Int16Value = 66; + basic_type_3.Uint16Value = 67; + basic_type_3.Int32Value = 68; + basic_type_3.Uint32Value = 69; + basic_type_3.Int64Value = 70; + basic_type_3.Uint64Value = 71; + + msg.BasicTypesValues.Add(basic_type_1); + msg.BasicTypesValues.Add(basic_type_2); + msg.BasicTypesValues.Add(basic_type_3); + + bool received = false; + Subscription chatter_sub = node_array_2.CreateSubscription( + "topic_unbounded_sequences", rcv_msg => + { + received = true; + msg2 = rcv_msg; + } + ); + + while (!received) + { + chatter_pub.Publish(msg); + + RCLdotnet.SpinOnce(node_array_1, 500); + RCLdotnet.SpinOnce(node_array_2, 500); + } + + // boolValues + Assert.Equal(3, msg2.BoolValues.Count); + Assert.True(msg2.BoolValues[0]); + Assert.False(msg2.BoolValues[1]); + Assert.True(msg2.BoolValues[2]); + + // byteValues + Assert.Equal(3, msg2.ByteValues.Count); + Assert.Equal(0, msg2.ByteValues[0]); + Assert.Equal(1, msg2.ByteValues[1]); + Assert.Equal(2, msg2.ByteValues[2]); + + // charValues + Assert.Equal(3, msg2.CharValues.Count); + Assert.Equal(3, msg2.CharValues[0]); + Assert.Equal(4, msg2.CharValues[1]); + Assert.Equal(5, msg2.CharValues[2]); + + // float32Values + Assert.Equal(3, msg2.Float32Values.Count); + Assert.Equal(6.1f, msg2.Float32Values[0]); + Assert.Equal(7.1f, msg2.Float32Values[1]); + Assert.Equal(8.1f, msg2.Float32Values[2]); + + // float64Values + Assert.Equal(3, msg2.Float64Values.Count); + Assert.Equal(9.1, msg2.Float64Values[0]); + Assert.Equal(10.1, msg2.Float64Values[1]); + Assert.Equal(11.1, msg2.Float64Values[2]); + + // int8Values + Assert.Equal(3, msg2.Int8Values.Count); + Assert.Equal(12, msg2.Int8Values[0]); + Assert.Equal(13, msg2.Int8Values[1]); + Assert.Equal(14, msg2.Int8Values[2]); + + // uint8Values + Assert.Equal(3, msg2.Uint8Values.Count); + Assert.Equal(15, msg2.Uint8Values[0]); + Assert.Equal(16, msg2.Uint8Values[1]); + Assert.Equal(17, msg2.Uint8Values[2]); + + // int16Values + Assert.Equal(3, msg2.Int16Values.Count); + Assert.Equal(18, msg2.Int16Values[0]); + Assert.Equal(19, msg2.Int16Values[1]); + Assert.Equal(20, msg2.Int16Values[2]); + + // uint16Values + Assert.Equal(3, msg2.Uint16Values.Count); + Assert.Equal(21, msg2.Uint16Values[0]); + Assert.Equal(22, msg2.Uint16Values[1]); + Assert.Equal(23, msg2.Uint16Values[2]); + + // int32Values + Assert.Equal(3, msg2.Int32Values.Count); + Assert.Equal(24, msg2.Int32Values[0]); + Assert.Equal(25, msg2.Int32Values[1]); + Assert.Equal(26, msg2.Int32Values[2]); + + // uint32Values + Assert.Equal(3, msg2.Uint32Values.Count); + Assert.Equal((uint)27, msg2.Uint32Values[0]); + Assert.Equal((uint)28, msg2.Uint32Values[1]); + Assert.Equal((uint)29, msg2.Uint32Values[2]); + + // int64Values + Assert.Equal(3, msg2.Int64Values.Count); + Assert.Equal(30, msg2.Int64Values[0]); + Assert.Equal(31, msg2.Int64Values[1]); + Assert.Equal(32, msg2.Int64Values[2]); + + // uint64Values + Assert.Equal(3, msg2.Uint64Values.Count); + Assert.Equal((ulong)33, msg2.Uint64Values[0]); + Assert.Equal((ulong)34, msg2.Uint64Values[1]); + Assert.Equal((ulong)35, msg2.Uint64Values[2]); + + // stringValues + Assert.Equal(3, msg2.StringValues.Count); + Assert.Equal("one", msg2.StringValues[0]); + Assert.Equal("two", msg2.StringValues[1]); + Assert.Equal("three", msg2.StringValues[2]); + + Assert.Equal(3, msg2.BasicTypesValues.Count); + Assert.True(msg2.BasicTypesValues[0].BoolValue); + Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); + Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); + Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); + Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); + Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); + Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); + Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); + Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); + Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); + Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); + Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); + Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); + + Assert.False(msg2.BasicTypesValues[1].BoolValue); + Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); + Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); + Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); + Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); + Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); + Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); + Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); + Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); + Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); + Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); + Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); + Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); + + Assert.True(msg2.BasicTypesValues[2].BoolValue); + Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); + Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); + Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); + Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); + Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); + Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); + Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); + Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); + Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); + Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); + Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); + Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); } - ); - - while(!received) - { - chatter_pub.Publish(msg); - - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); - } - - // boolValues - Assert.Equal(3, msg2.BoolValues.Count); - Assert.True(msg2.BoolValues[0]); - Assert.False(msg2.BoolValues[1]); - Assert.True(msg2.BoolValues[2]); - - // byteValues - Assert.Equal(3, msg2.ByteValues.Count); - Assert.Equal(0, msg2.ByteValues[0]); - Assert.Equal(1, msg2.ByteValues[1]); - Assert.Equal(2, msg2.ByteValues[2]); - - // charValues - Assert.Equal(3, msg2.CharValues.Count); - Assert.Equal(3, msg2.CharValues[0]); - Assert.Equal(4, msg2.CharValues[1]); - Assert.Equal(5, msg2.CharValues[2]); - - // float32Values - Assert.Equal(3, msg2.Float32Values.Count); - Assert.Equal(6.1f, msg2.Float32Values[0]); - Assert.Equal(7.1f, msg2.Float32Values[1]); - Assert.Equal(8.1f, msg2.Float32Values[2]); - - // float64Values - Assert.Equal(3, msg2.Float64Values.Count); - Assert.Equal(9.1, msg2.Float64Values[0]); - Assert.Equal(10.1, msg2.Float64Values[1]); - Assert.Equal(11.1, msg2.Float64Values[2]); - - // int8Values - Assert.Equal(3, msg2.Int8Values.Count); - Assert.Equal(12, msg2.Int8Values[0]); - Assert.Equal(13, msg2.Int8Values[1]); - Assert.Equal(14, msg2.Int8Values[2]); - - // uint8Values - Assert.Equal(3, msg2.Uint8Values.Count); - Assert.Equal(15, msg2.Uint8Values[0]); - Assert.Equal(16, msg2.Uint8Values[1]); - Assert.Equal(17, msg2.Uint8Values[2]); - - // int16Values - Assert.Equal(3, msg2.Int16Values.Count); - Assert.Equal(18, msg2.Int16Values[0]); - Assert.Equal(19, msg2.Int16Values[1]); - Assert.Equal(20, msg2.Int16Values[2]); - - // uint16Values - Assert.Equal(3, msg2.Uint16Values.Count); - Assert.Equal(21, msg2.Uint16Values[0]); - Assert.Equal(22, msg2.Uint16Values[1]); - Assert.Equal(23, msg2.Uint16Values[2]); - - // int32Values - Assert.Equal(3, msg2.Int32Values.Count); - Assert.Equal(24, msg2.Int32Values[0]); - Assert.Equal(25, msg2.Int32Values[1]); - Assert.Equal(26, msg2.Int32Values[2]); - - // uint32Values - Assert.Equal(3, msg2.Uint32Values.Count); - Assert.Equal((uint)27, msg2.Uint32Values[0]); - Assert.Equal((uint)28, msg2.Uint32Values[1]); - Assert.Equal((uint)29, msg2.Uint32Values[2]); - - // int64Values - Assert.Equal(3, msg2.Int64Values.Count); - Assert.Equal(30, msg2.Int64Values[0]); - Assert.Equal(31, msg2.Int64Values[1]); - Assert.Equal(32, msg2.Int64Values[2]); - - // uint64Values - Assert.Equal(3, msg2.Uint64Values.Count); - Assert.Equal((ulong)33, msg2.Uint64Values[0]); - Assert.Equal((ulong)34, msg2.Uint64Values[1]); - Assert.Equal((ulong)35, msg2.Uint64Values[2]); - - // stringValues - Assert.Equal(3, msg2.StringValues.Count); - Assert.Equal("one", msg2.StringValues[0]); - Assert.Equal("two", msg2.StringValues[1]); - Assert.Equal("three", msg2.StringValues[2]); - - Assert.Equal(3, msg2.BasicTypesValues.Count); - Assert.True(msg2.BasicTypesValues[0].BoolValue); - Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); - Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); - Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); - Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); - Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); - Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); - Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); - Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); - Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); - Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); - Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); - Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); - - Assert.False(msg2.BasicTypesValues[1].BoolValue); - Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); - Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); - Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); - Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); - Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); - Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); - Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); - Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); - Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); - Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); - Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); - Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); - - Assert.True(msg2.BasicTypesValues[2].BoolValue); - Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); - Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); - Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); - Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); - Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); - Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); - Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); - Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); - Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); - Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); - Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); - Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); - } - [Fact] - public void TestPublishBoundedSequences() - { - RCLdotnet.Init(); - Node node_array_1 = RCLdotnet.CreateNode("test_bounded_sequences_1"); - Node node_array_2 = RCLdotnet.CreateNode("test_bounded_sequences_2"); - Publisher chatter_pub = node_array_1.CreatePublisher("topic_bounded_sequences"); - - test_msgs.msg.BoundedSequences msg = new test_msgs.msg.BoundedSequences(); - test_msgs.msg.BoundedSequences msg2 = new test_msgs.msg.BoundedSequences(); - - // boolValues - msg.BoolValues.Add(true); - msg.BoolValues.Add(false); - msg.BoolValues.Add(true); - - // byteValues - msg.ByteValues.Add(0); - msg.ByteValues.Add(1); - msg.ByteValues.Add(2); - - // charValues - msg.CharValues.Add(3); - msg.CharValues.Add(4); - msg.CharValues.Add(5); - - // float32Values - msg.Float32Values.Add(6.1f); - msg.Float32Values.Add(7.1f); - msg.Float32Values.Add(8.1f); - - // float64Values - msg.Float64Values.Add(9.1); - msg.Float64Values.Add(10.1); - msg.Float64Values.Add(11.1); - - // int8Values - msg.Int8Values.Add(12); - msg.Int8Values.Add(13); - msg.Int8Values.Add(14); - - // uint8Values - msg.Uint8Values.Add(15); - msg.Uint8Values.Add(16); - msg.Uint8Values.Add(17); - - // int16Values - msg.Int16Values.Add(18); - msg.Int16Values.Add(19); - msg.Int16Values.Add(20); - - // uint16Values - msg.Uint16Values.Add(21); - msg.Uint16Values.Add(22); - msg.Uint16Values.Add(23); - - // int32Values - msg.Int32Values.Add(24); - msg.Int32Values.Add(25); - msg.Int32Values.Add(26); - - // uint32Values - msg.Uint32Values.Add(27); - msg.Uint32Values.Add(28); - msg.Uint32Values.Add(29); - - // int64Values - msg.Int64Values.Add(30); - msg.Int64Values.Add(31); - msg.Int64Values.Add(32); - - // uint64Values - msg.Uint64Values.Add(33); - msg.Uint64Values.Add(34); - msg.Uint64Values.Add(35); - - // stringValues - msg.StringValues.Add("one"); - msg.StringValues.Add("two"); - msg.StringValues.Add("three"); - - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues.Add(basic_type_1); - msg.BasicTypesValues.Add(basic_type_2); - msg.BasicTypesValues.Add(basic_type_3); - - bool received=false; - Subscription chatter_sub = node_array_2.CreateSubscription( - "topic_bounded_sequences", rcv_msg => + [Fact] + public void TestPublishBoundedSequences() { - received=true; - msg2 = rcv_msg; + RCLdotnet.Init(); + Node node_array_1 = RCLdotnet.CreateNode("test_bounded_sequences_1"); + Node node_array_2 = RCLdotnet.CreateNode("test_bounded_sequences_2"); + Publisher chatter_pub = node_array_1.CreatePublisher("topic_bounded_sequences"); + + test_msgs.msg.BoundedSequences msg = new test_msgs.msg.BoundedSequences(); + test_msgs.msg.BoundedSequences msg2 = new test_msgs.msg.BoundedSequences(); + + // boolValues + msg.BoolValues.Add(true); + msg.BoolValues.Add(false); + msg.BoolValues.Add(true); + + // byteValues + msg.ByteValues.Add(0); + msg.ByteValues.Add(1); + msg.ByteValues.Add(2); + + // charValues + msg.CharValues.Add(3); + msg.CharValues.Add(4); + msg.CharValues.Add(5); + + // float32Values + msg.Float32Values.Add(6.1f); + msg.Float32Values.Add(7.1f); + msg.Float32Values.Add(8.1f); + + // float64Values + msg.Float64Values.Add(9.1); + msg.Float64Values.Add(10.1); + msg.Float64Values.Add(11.1); + + // int8Values + msg.Int8Values.Add(12); + msg.Int8Values.Add(13); + msg.Int8Values.Add(14); + + // uint8Values + msg.Uint8Values.Add(15); + msg.Uint8Values.Add(16); + msg.Uint8Values.Add(17); + + // int16Values + msg.Int16Values.Add(18); + msg.Int16Values.Add(19); + msg.Int16Values.Add(20); + + // uint16Values + msg.Uint16Values.Add(21); + msg.Uint16Values.Add(22); + msg.Uint16Values.Add(23); + + // int32Values + msg.Int32Values.Add(24); + msg.Int32Values.Add(25); + msg.Int32Values.Add(26); + + // uint32Values + msg.Uint32Values.Add(27); + msg.Uint32Values.Add(28); + msg.Uint32Values.Add(29); + + // int64Values + msg.Int64Values.Add(30); + msg.Int64Values.Add(31); + msg.Int64Values.Add(32); + + // uint64Values + msg.Uint64Values.Add(33); + msg.Uint64Values.Add(34); + msg.Uint64Values.Add(35); + + // stringValues + msg.StringValues.Add("one"); + msg.StringValues.Add("two"); + msg.StringValues.Add("three"); + + test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); + basic_type_1.BoolValue = true; + basic_type_1.ByteValue = 36; + basic_type_1.CharValue = 37; + basic_type_1.Float32Value = 38.1f; + basic_type_1.Float64Value = 39.1; + basic_type_1.Int8Value = 40; + basic_type_1.Uint8Value = 41; + basic_type_1.Int16Value = 42; + basic_type_1.Uint16Value = 43; + basic_type_1.Int32Value = 44; + basic_type_1.Uint32Value = 45; + basic_type_1.Int64Value = 46; + basic_type_1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); + basic_type_2.BoolValue = false; + basic_type_2.ByteValue = 48; + basic_type_2.CharValue = 49; + basic_type_2.Float32Value = 50.1f; + basic_type_2.Float64Value = 51.1; + basic_type_2.Int8Value = 52; + basic_type_2.Uint8Value = 53; + basic_type_2.Int16Value = 54; + basic_type_2.Uint16Value = 55; + basic_type_2.Int32Value = 56; + basic_type_2.Uint32Value = 57; + basic_type_2.Int64Value = 58; + basic_type_2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); + basic_type_3.BoolValue = true; + basic_type_3.ByteValue = 60; + basic_type_3.CharValue = 61; + basic_type_3.Float32Value = 62.1f; + basic_type_3.Float64Value = 63.1; + basic_type_3.Int8Value = 64; + basic_type_3.Uint8Value = 65; + basic_type_3.Int16Value = 66; + basic_type_3.Uint16Value = 67; + basic_type_3.Int32Value = 68; + basic_type_3.Uint32Value = 69; + basic_type_3.Int64Value = 70; + basic_type_3.Uint64Value = 71; + + msg.BasicTypesValues.Add(basic_type_1); + msg.BasicTypesValues.Add(basic_type_2); + msg.BasicTypesValues.Add(basic_type_3); + + bool received = false; + Subscription chatter_sub = node_array_2.CreateSubscription( + "topic_bounded_sequences", rcv_msg => + { + received = true; + msg2 = rcv_msg; + } + ); + + while (!received) + { + chatter_pub.Publish(msg); + + RCLdotnet.SpinOnce(node_array_1, 500); + RCLdotnet.SpinOnce(node_array_2, 500); + } + + // boolValues + Assert.Equal(3, test_msgs.msg.BoundedSequences.BoolValuesMaxCount); + Assert.Equal(3, msg2.BoolValues.Count); + Assert.True(msg2.BoolValues[0]); + Assert.False(msg2.BoolValues[1]); + Assert.True(msg2.BoolValues[2]); + + // byteValues + Assert.Equal(3, test_msgs.msg.BoundedSequences.ByteValuesMaxCount); + Assert.Equal(3, msg2.ByteValues.Count); + Assert.Equal(0, msg2.ByteValues[0]); + Assert.Equal(1, msg2.ByteValues[1]); + Assert.Equal(2, msg2.ByteValues[2]); + + // charValues + Assert.Equal(3, test_msgs.msg.BoundedSequences.CharValuesMaxCount); + Assert.Equal(3, msg2.CharValues.Count); + Assert.Equal(3, msg2.CharValues[0]); + Assert.Equal(4, msg2.CharValues[1]); + Assert.Equal(5, msg2.CharValues[2]); + + // float32Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Float32ValuesMaxCount); + Assert.Equal(3, msg2.Float32Values.Count); + Assert.Equal(6.1f, msg2.Float32Values[0]); + Assert.Equal(7.1f, msg2.Float32Values[1]); + Assert.Equal(8.1f, msg2.Float32Values[2]); + + // float64Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Float64ValuesMaxCount); + Assert.Equal(3, msg2.Float64Values.Count); + Assert.Equal(9.1, msg2.Float64Values[0]); + Assert.Equal(10.1, msg2.Float64Values[1]); + Assert.Equal(11.1, msg2.Float64Values[2]); + + // int8Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Int8ValuesMaxCount); + Assert.Equal(3, msg2.Int8Values.Count); + Assert.Equal(12, msg2.Int8Values[0]); + Assert.Equal(13, msg2.Int8Values[1]); + Assert.Equal(14, msg2.Int8Values[2]); + + // uint8Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint8ValuesMaxCount); + Assert.Equal(3, msg2.Uint8Values.Count); + Assert.Equal(15, msg2.Uint8Values[0]); + Assert.Equal(16, msg2.Uint8Values[1]); + Assert.Equal(17, msg2.Uint8Values[2]); + + // int16Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Int16ValuesMaxCount); + Assert.Equal(3, msg2.Int16Values.Count); + Assert.Equal(18, msg2.Int16Values[0]); + Assert.Equal(19, msg2.Int16Values[1]); + Assert.Equal(20, msg2.Int16Values[2]); + + // uint16Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint16ValuesMaxCount); + Assert.Equal(3, msg2.Uint16Values.Count); + Assert.Equal(21, msg2.Uint16Values[0]); + Assert.Equal(22, msg2.Uint16Values[1]); + Assert.Equal(23, msg2.Uint16Values[2]); + + // int32Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Int32ValuesMaxCount); + Assert.Equal(3, msg2.Int32Values.Count); + Assert.Equal(24, msg2.Int32Values[0]); + Assert.Equal(25, msg2.Int32Values[1]); + Assert.Equal(26, msg2.Int32Values[2]); + + // uint32Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint32ValuesMaxCount); + Assert.Equal(3, msg2.Uint32Values.Count); + Assert.Equal((uint)27, msg2.Uint32Values[0]); + Assert.Equal((uint)28, msg2.Uint32Values[1]); + Assert.Equal((uint)29, msg2.Uint32Values[2]); + + // int64Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Int64ValuesMaxCount); + Assert.Equal(3, msg2.Int64Values.Count); + Assert.Equal(30, msg2.Int64Values[0]); + Assert.Equal(31, msg2.Int64Values[1]); + Assert.Equal(32, msg2.Int64Values[2]); + + // uint64Values + Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint64ValuesMaxCount); + Assert.Equal(3, msg2.Uint64Values.Count); + Assert.Equal((ulong)33, msg2.Uint64Values[0]); + Assert.Equal((ulong)34, msg2.Uint64Values[1]); + Assert.Equal((ulong)35, msg2.Uint64Values[2]); + + // stringValues + Assert.Equal(3, test_msgs.msg.BoundedSequences.StringValuesMaxCount); + Assert.Equal(3, msg2.StringValues.Count); + Assert.Equal("one", msg2.StringValues[0]); + Assert.Equal("two", msg2.StringValues[1]); + Assert.Equal("three", msg2.StringValues[2]); + + Assert.Equal(3, test_msgs.msg.BoundedSequences.BasicTypesValuesMaxCount); + Assert.Equal(3, msg2.BasicTypesValues.Count); + Assert.True(msg2.BasicTypesValues[0].BoolValue); + Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); + Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); + Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); + Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); + Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); + Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); + Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); + Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); + Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); + Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); + Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); + Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); + + Assert.False(msg2.BasicTypesValues[1].BoolValue); + Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); + Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); + Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); + Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); + Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); + Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); + Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); + Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); + Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); + Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); + Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); + Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); + + Assert.True(msg2.BasicTypesValues[2].BoolValue); + Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); + Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); + Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); + Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); + Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); + Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); + Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); + Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); + Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); + Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); + Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); + Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); } - ); - - while(!received) - { - chatter_pub.Publish(msg); - - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); - } - - // boolValues - Assert.Equal(3, test_msgs.msg.BoundedSequences.BoolValuesMaxCount); - Assert.Equal(3, msg2.BoolValues.Count); - Assert.True(msg2.BoolValues[0]); - Assert.False(msg2.BoolValues[1]); - Assert.True(msg2.BoolValues[2]); - - // byteValues - Assert.Equal(3, test_msgs.msg.BoundedSequences.ByteValuesMaxCount); - Assert.Equal(3, msg2.ByteValues.Count); - Assert.Equal(0, msg2.ByteValues[0]); - Assert.Equal(1, msg2.ByteValues[1]); - Assert.Equal(2, msg2.ByteValues[2]); - - // charValues - Assert.Equal(3, test_msgs.msg.BoundedSequences.CharValuesMaxCount); - Assert.Equal(3, msg2.CharValues.Count); - Assert.Equal(3, msg2.CharValues[0]); - Assert.Equal(4, msg2.CharValues[1]); - Assert.Equal(5, msg2.CharValues[2]); - - // float32Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Float32ValuesMaxCount); - Assert.Equal(3, msg2.Float32Values.Count); - Assert.Equal(6.1f, msg2.Float32Values[0]); - Assert.Equal(7.1f, msg2.Float32Values[1]); - Assert.Equal(8.1f, msg2.Float32Values[2]); - - // float64Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Float64ValuesMaxCount); - Assert.Equal(3, msg2.Float64Values.Count); - Assert.Equal(9.1, msg2.Float64Values[0]); - Assert.Equal(10.1, msg2.Float64Values[1]); - Assert.Equal(11.1, msg2.Float64Values[2]); - - // int8Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Int8ValuesMaxCount); - Assert.Equal(3, msg2.Int8Values.Count); - Assert.Equal(12, msg2.Int8Values[0]); - Assert.Equal(13, msg2.Int8Values[1]); - Assert.Equal(14, msg2.Int8Values[2]); - - // uint8Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint8ValuesMaxCount); - Assert.Equal(3, msg2.Uint8Values.Count); - Assert.Equal(15, msg2.Uint8Values[0]); - Assert.Equal(16, msg2.Uint8Values[1]); - Assert.Equal(17, msg2.Uint8Values[2]); - - // int16Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Int16ValuesMaxCount); - Assert.Equal(3, msg2.Int16Values.Count); - Assert.Equal(18, msg2.Int16Values[0]); - Assert.Equal(19, msg2.Int16Values[1]); - Assert.Equal(20, msg2.Int16Values[2]); - - // uint16Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint16ValuesMaxCount); - Assert.Equal(3, msg2.Uint16Values.Count); - Assert.Equal(21, msg2.Uint16Values[0]); - Assert.Equal(22, msg2.Uint16Values[1]); - Assert.Equal(23, msg2.Uint16Values[2]); - - // int32Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Int32ValuesMaxCount); - Assert.Equal(3, msg2.Int32Values.Count); - Assert.Equal(24, msg2.Int32Values[0]); - Assert.Equal(25, msg2.Int32Values[1]); - Assert.Equal(26, msg2.Int32Values[2]); - - // uint32Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint32ValuesMaxCount); - Assert.Equal(3, msg2.Uint32Values.Count); - Assert.Equal((uint)27, msg2.Uint32Values[0]); - Assert.Equal((uint)28, msg2.Uint32Values[1]); - Assert.Equal((uint)29, msg2.Uint32Values[2]); - - // int64Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Int64ValuesMaxCount); - Assert.Equal(3, msg2.Int64Values.Count); - Assert.Equal(30, msg2.Int64Values[0]); - Assert.Equal(31, msg2.Int64Values[1]); - Assert.Equal(32, msg2.Int64Values[2]); - - // uint64Values - Assert.Equal(3, test_msgs.msg.BoundedSequences.Uint64ValuesMaxCount); - Assert.Equal(3, msg2.Uint64Values.Count); - Assert.Equal((ulong)33, msg2.Uint64Values[0]); - Assert.Equal((ulong)34, msg2.Uint64Values[1]); - Assert.Equal((ulong)35, msg2.Uint64Values[2]); - - // stringValues - Assert.Equal(3, test_msgs.msg.BoundedSequences.StringValuesMaxCount); - Assert.Equal(3, msg2.StringValues.Count); - Assert.Equal("one", msg2.StringValues[0]); - Assert.Equal("two", msg2.StringValues[1]); - Assert.Equal("three", msg2.StringValues[2]); - - Assert.Equal(3, test_msgs.msg.BoundedSequences.BasicTypesValuesMaxCount); - Assert.Equal(3, msg2.BasicTypesValues.Count); - Assert.True(msg2.BasicTypesValues[0].BoolValue); - Assert.Equal(36, msg2.BasicTypesValues[0].ByteValue); - Assert.Equal(37, msg2.BasicTypesValues[0].CharValue); - Assert.Equal(38.1f, msg2.BasicTypesValues[0].Float32Value); - Assert.Equal(39.1, msg2.BasicTypesValues[0].Float64Value); - Assert.Equal(40, msg2.BasicTypesValues[0].Int8Value); - Assert.Equal(41, msg2.BasicTypesValues[0].Uint8Value); - Assert.Equal(42, msg2.BasicTypesValues[0].Int16Value); - Assert.Equal(43, msg2.BasicTypesValues[0].Uint16Value); - Assert.Equal(44, msg2.BasicTypesValues[0].Int32Value); - Assert.Equal((uint)45, msg2.BasicTypesValues[0].Uint32Value); - Assert.Equal(46, msg2.BasicTypesValues[0].Int64Value); - Assert.Equal((ulong)47, msg2.BasicTypesValues[0].Uint64Value); - - Assert.False(msg2.BasicTypesValues[1].BoolValue); - Assert.Equal(48, msg2.BasicTypesValues[1].ByteValue); - Assert.Equal(49, msg2.BasicTypesValues[1].CharValue); - Assert.Equal(50.1f, msg2.BasicTypesValues[1].Float32Value); - Assert.Equal(51.1, msg2.BasicTypesValues[1].Float64Value); - Assert.Equal(52, msg2.BasicTypesValues[1].Int8Value); - Assert.Equal(53, msg2.BasicTypesValues[1].Uint8Value); - Assert.Equal(54, msg2.BasicTypesValues[1].Int16Value); - Assert.Equal(55, msg2.BasicTypesValues[1].Uint16Value); - Assert.Equal(56, msg2.BasicTypesValues[1].Int32Value); - Assert.Equal((uint)57, msg2.BasicTypesValues[1].Uint32Value); - Assert.Equal(58, msg2.BasicTypesValues[1].Int64Value); - Assert.Equal((ulong)59, msg2.BasicTypesValues[1].Uint64Value); - - Assert.True(msg2.BasicTypesValues[2].BoolValue); - Assert.Equal(60, msg2.BasicTypesValues[2].ByteValue); - Assert.Equal(61, msg2.BasicTypesValues[2].CharValue); - Assert.Equal(62.1f, msg2.BasicTypesValues[2].Float32Value); - Assert.Equal(63.1, msg2.BasicTypesValues[2].Float64Value); - Assert.Equal(64, msg2.BasicTypesValues[2].Int8Value); - Assert.Equal(65, msg2.BasicTypesValues[2].Uint8Value); - Assert.Equal(66, msg2.BasicTypesValues[2].Int16Value); - Assert.Equal(67, msg2.BasicTypesValues[2].Uint16Value); - Assert.Equal(68, msg2.BasicTypesValues[2].Int32Value); - Assert.Equal((uint)69, msg2.BasicTypesValues[2].Uint32Value); - Assert.Equal(70, msg2.BasicTypesValues[2].Int64Value); - Assert.Equal((ulong)71, msg2.BasicTypesValues[2].Uint64Value); - } - [Fact] - public void TestPublishBoundedSequencesSizeCheck() - { - RCLdotnet.Init(); - var nodeBoundedSequencesSizeCheck = RCLdotnet.CreateNode("test_bounded_sequences_size_check"); - var chatterPub = nodeBoundedSequencesSizeCheck.CreatePublisher("topic_bounded_sequences_size_check"); - - var msg = new test_msgs.msg.BoundedSequences(); - msg.StringValues = new List - { - "0", - "1", - "2", - "3", - }; - - var exception = Assert.Throws(() => chatterPub.Publish(msg)); - Assert.Equal("Invalid size of bounded sequence 'StringValues'.", exception.Message); - } + [Fact] + public void TestPublishBoundedSequencesSizeCheck() + { + RCLdotnet.Init(); + var nodeBoundedSequencesSizeCheck = RCLdotnet.CreateNode("test_bounded_sequences_size_check"); + var chatterPub = nodeBoundedSequencesSizeCheck.CreatePublisher("topic_bounded_sequences_size_check"); + + var msg = new test_msgs.msg.BoundedSequences(); + msg.StringValues = new List + { + "0", + "1", + "2", + "3", + }; + + var exception = Assert.Throws(() => chatterPub.Publish(msg)); + Assert.Equal("Invalid size of bounded sequence 'StringValues'.", exception.Message); + } - [Fact] - public void TestDefaults() - { - var defaultsMsg = new test_msgs.msg.Defaults(); - - Assert.Equal(true, defaultsMsg.BoolValue); - Assert.Equal(50, defaultsMsg.ByteValue); - Assert.Equal(100, defaultsMsg.CharValue); - Assert.Equal(1.125f, defaultsMsg.Float32Value); - Assert.Equal(1.125, defaultsMsg.Float64Value); - Assert.Equal(-50, defaultsMsg.Int8Value); - Assert.Equal(200, defaultsMsg.Uint8Value); - Assert.Equal(-1000, defaultsMsg.Int16Value); - Assert.Equal(2000, defaultsMsg.Uint16Value); - Assert.Equal(-30000, defaultsMsg.Int32Value); - Assert.True(60000 == defaultsMsg.Uint32Value); - Assert.Equal(-40000000, defaultsMsg.Int64Value); - Assert.True(50000000 == defaultsMsg.Uint64Value); - - var stringsMsg = new test_msgs.msg.Strings(); - Assert.Equal("", stringsMsg.StringValue); - Assert.Equal("Hello world!", stringsMsg.StringValueDefault1); - Assert.Equal("Hello'world!", stringsMsg.StringValueDefault2); - Assert.Equal("Hello\"world!", stringsMsg.StringValueDefault3); - Assert.Equal("Hello'world!", stringsMsg.StringValueDefault4); - Assert.Equal("Hello\"world!", stringsMsg.StringValueDefault5); - } + [Fact] + public void TestDefaults() + { + var defaultsMsg = new test_msgs.msg.Defaults(); + + Assert.Equal(true, defaultsMsg.BoolValue); + Assert.Equal(50, defaultsMsg.ByteValue); + Assert.Equal(100, defaultsMsg.CharValue); + Assert.Equal(1.125f, defaultsMsg.Float32Value); + Assert.Equal(1.125, defaultsMsg.Float64Value); + Assert.Equal(-50, defaultsMsg.Int8Value); + Assert.Equal(200, defaultsMsg.Uint8Value); + Assert.Equal(-1000, defaultsMsg.Int16Value); + Assert.Equal(2000, defaultsMsg.Uint16Value); + Assert.Equal(-30000, defaultsMsg.Int32Value); + Assert.True(60000 == defaultsMsg.Uint32Value); + Assert.Equal(-40000000, defaultsMsg.Int64Value); + Assert.True(50000000 == defaultsMsg.Uint64Value); + + var stringsMsg = new test_msgs.msg.Strings(); + Assert.Equal("", stringsMsg.StringValue); + Assert.Equal("Hello world!", stringsMsg.StringValueDefault1); + Assert.Equal("Hello'world!", stringsMsg.StringValueDefault2); + Assert.Equal("Hello\"world!", stringsMsg.StringValueDefault3); + Assert.Equal("Hello'world!", stringsMsg.StringValueDefault4); + Assert.Equal("Hello\"world!", stringsMsg.StringValueDefault5); + } - [Fact] - public void TestDefaultsArrays() - { - var msg = new test_msgs.msg.Arrays(); + [Fact] + public void TestDefaultsArrays() + { + var msg = new test_msgs.msg.Arrays(); - Assert.IsType(msg.BoolValues); - Assert.Equal(new bool[3], msg.BoolValues); + Assert.IsType(msg.BoolValues); + Assert.Equal(new bool[3], msg.BoolValues); - Assert.IsType(msg.ByteValues); - Assert.Equal(new byte[3], msg.ByteValues); - - Assert.IsType(msg.CharValues); - Assert.Equal(new byte[3], msg.CharValues); + Assert.IsType(msg.ByteValues); + Assert.Equal(new byte[3], msg.ByteValues); + + Assert.IsType(msg.CharValues); + Assert.Equal(new byte[3], msg.CharValues); - Assert.IsType(msg.Float32Values); - Assert.Equal(new float[3], msg.Float32Values); + Assert.IsType(msg.Float32Values); + Assert.Equal(new float[3], msg.Float32Values); - Assert.IsType(msg.Float64Values); - Assert.Equal(new double[3], msg.Float64Values); - - Assert.IsType(msg.Int8Values); - Assert.Equal(new sbyte[3], msg.Int8Values); - - Assert.IsType(msg.Uint8Values); - Assert.Equal(new byte[3], msg.Uint8Values); - - Assert.IsType(msg.Int16Values); - Assert.Equal(new short[3], msg.Int16Values); - - Assert.IsType(msg.Uint16Values); - Assert.Equal(new ushort[3], msg.Uint16Values); - - Assert.IsType(msg.Int32Values); - Assert.Equal(new int[3], msg.Int32Values); - - Assert.IsType(msg.Uint32Values); - Assert.Equal(new uint[3], msg.Uint32Values); - - Assert.IsType(msg.Int64Values); - Assert.Equal(new long[3], msg.Int64Values); - - Assert.IsType(msg.Uint64Values); - Assert.Equal(new ulong[3], msg.Uint64Values); - - Assert.IsType(msg.StringValues); - Assert.Equal( - Enumerable.Repeat("", 3).ToArray(), - msg.StringValues); - - Assert.IsType(msg.BasicTypesValues); - Assert.Equal(3, msg.BasicTypesValues.Length); - Assert.NotNull(msg.BasicTypesValues[0]); - Assert.NotNull(msg.BasicTypesValues[1]); - Assert.NotNull(msg.BasicTypesValues[2]); - - Assert.IsType(msg.ConstantsValues); - Assert.Equal(3, msg.ConstantsValues.Length); - Assert.NotNull(msg.ConstantsValues[0]); - Assert.NotNull(msg.ConstantsValues[1]); - Assert.NotNull(msg.ConstantsValues[2]); - - Assert.IsType(msg.DefaultsValues); - Assert.Equal(3, msg.DefaultsValues.Length); - Assert.NotNull(msg.DefaultsValues[0]); - Assert.NotNull(msg.DefaultsValues[1]); - Assert.NotNull(msg.DefaultsValues[2]); - - Assert.IsType(msg.BoolValuesDefault); - Assert.Equal( - new bool[] { false, true, false }, - msg.BoolValuesDefault); - - Assert.IsType(msg.ByteValuesDefault); - Assert.Equal( - new byte[] { 0, 1, 255 }, - msg.ByteValuesDefault); - - Assert.IsType(msg.CharValuesDefault); - Assert.Equal( - new byte[] { 0, 1, 127 }, - msg.CharValuesDefault); - - Assert.IsType(msg.Float32ValuesDefault); - Assert.Equal( - new float[] { 1.125f, 0.0f, -1.125f}, - msg.Float32ValuesDefault); - - Assert.IsType(msg.Float64ValuesDefault); - Assert.Equal( - new double[] { 3.1415, 0.0, -3.1415 }, - msg.Float64ValuesDefault); - - Assert.IsType(msg.Int8ValuesDefault); - Assert.Equal( - new sbyte[] { 0, 127, -128 }, - msg.Int8ValuesDefault); - - Assert.IsType(msg.Uint8ValuesDefault); - Assert.Equal( - new byte[] { 0, 1, 255 }, - msg.Uint8ValuesDefault); - - Assert.IsType(msg.Int16ValuesDefault); - Assert.Equal( - new short[] { 0, 32767, -32768 }, - msg.Int16ValuesDefault); - - Assert.IsType(msg.Uint16ValuesDefault); - Assert.Equal( - new ushort[] { 0, 1, 65535 }, - msg.Uint16ValuesDefault); - - Assert.IsType(msg.Int32ValuesDefault); - Assert.Equal( - new int[] { 0, 2147483647, -2147483648 }, - msg.Int32ValuesDefault); - - Assert.IsType(msg.Uint32ValuesDefault); - Assert.Equal( - new uint[] { 0, 1, 4294967295 }, - msg.Uint32ValuesDefault); - - Assert.IsType(msg.Int64ValuesDefault); - Assert.Equal( - new long[] { 0, 9223372036854775807, -9223372036854775808 }, - msg.Int64ValuesDefault); - - Assert.IsType(msg.Uint64ValuesDefault); - Assert.Equal( - new ulong[] { 0, 1, 18446744073709551615 }, - msg.Uint64ValuesDefault); - - Assert.IsType(msg.StringValuesDefault); - Assert.Equal( - new string[] { "", "max value", "min value" }, - msg.StringValuesDefault); - } + Assert.IsType(msg.Float64Values); + Assert.Equal(new double[3], msg.Float64Values); + + Assert.IsType(msg.Int8Values); + Assert.Equal(new sbyte[3], msg.Int8Values); + + Assert.IsType(msg.Uint8Values); + Assert.Equal(new byte[3], msg.Uint8Values); + + Assert.IsType(msg.Int16Values); + Assert.Equal(new short[3], msg.Int16Values); + + Assert.IsType(msg.Uint16Values); + Assert.Equal(new ushort[3], msg.Uint16Values); + + Assert.IsType(msg.Int32Values); + Assert.Equal(new int[3], msg.Int32Values); + + Assert.IsType(msg.Uint32Values); + Assert.Equal(new uint[3], msg.Uint32Values); + + Assert.IsType(msg.Int64Values); + Assert.Equal(new long[3], msg.Int64Values); + + Assert.IsType(msg.Uint64Values); + Assert.Equal(new ulong[3], msg.Uint64Values); + + Assert.IsType(msg.StringValues); + Assert.Equal( + Enumerable.Repeat("", 3).ToArray(), + msg.StringValues); + + Assert.IsType(msg.BasicTypesValues); + Assert.Equal(3, msg.BasicTypesValues.Length); + Assert.NotNull(msg.BasicTypesValues[0]); + Assert.NotNull(msg.BasicTypesValues[1]); + Assert.NotNull(msg.BasicTypesValues[2]); + + Assert.IsType(msg.ConstantsValues); + Assert.Equal(3, msg.ConstantsValues.Length); + Assert.NotNull(msg.ConstantsValues[0]); + Assert.NotNull(msg.ConstantsValues[1]); + Assert.NotNull(msg.ConstantsValues[2]); + + Assert.IsType(msg.DefaultsValues); + Assert.Equal(3, msg.DefaultsValues.Length); + Assert.NotNull(msg.DefaultsValues[0]); + Assert.NotNull(msg.DefaultsValues[1]); + Assert.NotNull(msg.DefaultsValues[2]); + + Assert.IsType(msg.BoolValuesDefault); + Assert.Equal( + new bool[] { false, true, false }, + msg.BoolValuesDefault); + + Assert.IsType(msg.ByteValuesDefault); + Assert.Equal( + new byte[] { 0, 1, 255 }, + msg.ByteValuesDefault); + + Assert.IsType(msg.CharValuesDefault); + Assert.Equal( + new byte[] { 0, 1, 127 }, + msg.CharValuesDefault); + + Assert.IsType(msg.Float32ValuesDefault); + Assert.Equal( + new float[] { 1.125f, 0.0f, -1.125f }, + msg.Float32ValuesDefault); + + Assert.IsType(msg.Float64ValuesDefault); + Assert.Equal( + new double[] { 3.1415, 0.0, -3.1415 }, + msg.Float64ValuesDefault); + + Assert.IsType(msg.Int8ValuesDefault); + Assert.Equal( + new sbyte[] { 0, 127, -128 }, + msg.Int8ValuesDefault); + + Assert.IsType(msg.Uint8ValuesDefault); + Assert.Equal( + new byte[] { 0, 1, 255 }, + msg.Uint8ValuesDefault); + + Assert.IsType(msg.Int16ValuesDefault); + Assert.Equal( + new short[] { 0, 32767, -32768 }, + msg.Int16ValuesDefault); + + Assert.IsType(msg.Uint16ValuesDefault); + Assert.Equal( + new ushort[] { 0, 1, 65535 }, + msg.Uint16ValuesDefault); + + Assert.IsType(msg.Int32ValuesDefault); + Assert.Equal( + new int[] { 0, 2147483647, -2147483648 }, + msg.Int32ValuesDefault); + + Assert.IsType(msg.Uint32ValuesDefault); + Assert.Equal( + new uint[] { 0, 1, 4294967295 }, + msg.Uint32ValuesDefault); + + Assert.IsType(msg.Int64ValuesDefault); + Assert.Equal( + new long[] { 0, 9223372036854775807, -9223372036854775808 }, + msg.Int64ValuesDefault); + + Assert.IsType(msg.Uint64ValuesDefault); + Assert.Equal( + new ulong[] { 0, 1, 18446744073709551615 }, + msg.Uint64ValuesDefault); + + Assert.IsType(msg.StringValuesDefault); + Assert.Equal( + new string[] { "", "max value", "min value" }, + msg.StringValuesDefault); + } - [Fact] - public void TestDefaultsUnboundedSequences() - { - var msg = new test_msgs.msg.UnboundedSequences(); + [Fact] + public void TestDefaultsUnboundedSequences() + { + var msg = new test_msgs.msg.UnboundedSequences(); - Assert.IsType>(msg.BoolValues); - Assert.Equal(new List(), msg.BoolValues); + Assert.IsType>(msg.BoolValues); + Assert.Equal(new List(), msg.BoolValues); - Assert.IsType>(msg.ByteValues); - Assert.Equal(new List(), msg.ByteValues); + Assert.IsType>(msg.ByteValues); + Assert.Equal(new List(), msg.ByteValues); - Assert.IsType>(msg.CharValues); - Assert.Equal(new List(), msg.CharValues); + Assert.IsType>(msg.CharValues); + Assert.Equal(new List(), msg.CharValues); - Assert.IsType>(msg.Float32Values); - Assert.Equal(new List(), msg.Float32Values); + Assert.IsType>(msg.Float32Values); + Assert.Equal(new List(), msg.Float32Values); - Assert.IsType>(msg.Float64Values); - Assert.Equal(new List(), msg.Float64Values); + Assert.IsType>(msg.Float64Values); + Assert.Equal(new List(), msg.Float64Values); - Assert.IsType>(msg.Int8Values); - Assert.Equal(new List(), msg.Int8Values); + Assert.IsType>(msg.Int8Values); + Assert.Equal(new List(), msg.Int8Values); - Assert.IsType>(msg.Uint8Values); - Assert.Equal(new List(), msg.Uint8Values); + Assert.IsType>(msg.Uint8Values); + Assert.Equal(new List(), msg.Uint8Values); - Assert.IsType>(msg.Int16Values); - Assert.Equal(new List(), msg.Int16Values); + Assert.IsType>(msg.Int16Values); + Assert.Equal(new List(), msg.Int16Values); - Assert.IsType>(msg.Uint16Values); - Assert.Equal(new List(), msg.Uint16Values); + Assert.IsType>(msg.Uint16Values); + Assert.Equal(new List(), msg.Uint16Values); - Assert.IsType>(msg.Int32Values); - Assert.Equal(new List(), msg.Int32Values); + Assert.IsType>(msg.Int32Values); + Assert.Equal(new List(), msg.Int32Values); - Assert.IsType>(msg.Uint32Values); - Assert.Equal(new List(), msg.Uint32Values); + Assert.IsType>(msg.Uint32Values); + Assert.Equal(new List(), msg.Uint32Values); - Assert.IsType>(msg.Int64Values); - Assert.Equal(new List(), msg.Int64Values); + Assert.IsType>(msg.Int64Values); + Assert.Equal(new List(), msg.Int64Values); - Assert.IsType>(msg.Uint64Values); - Assert.Equal(new List(), msg.Uint64Values); + Assert.IsType>(msg.Uint64Values); + Assert.Equal(new List(), msg.Uint64Values); - Assert.IsType>(msg.StringValues); - Assert.Equal(new List(), msg.StringValues); + Assert.IsType>(msg.StringValues); + Assert.Equal(new List(), msg.StringValues); - Assert.IsType>(msg.BasicTypesValues); - Assert.Equal(new List(), msg.BasicTypesValues); + Assert.IsType>(msg.BasicTypesValues); + Assert.Equal(new List(), msg.BasicTypesValues); - Assert.IsType>(msg.ConstantsValues); - Assert.Equal(new List(), msg.ConstantsValues); + Assert.IsType>(msg.ConstantsValues); + Assert.Equal(new List(), msg.ConstantsValues); - Assert.IsType>(msg.DefaultsValues); - Assert.Equal(new List(), msg.DefaultsValues); + Assert.IsType>(msg.DefaultsValues); + Assert.Equal(new List(), msg.DefaultsValues); - Assert.IsType>(msg.BoolValuesDefault); - Assert.Equal( - new List { false, true, false }, - msg.BoolValuesDefault); + Assert.IsType>(msg.BoolValuesDefault); + Assert.Equal( + new List { false, true, false }, + msg.BoolValuesDefault); - Assert.IsType>(msg.ByteValuesDefault); - Assert.Equal( - new List { 0, 1, 255 }, - msg.ByteValuesDefault); + Assert.IsType>(msg.ByteValuesDefault); + Assert.Equal( + new List { 0, 1, 255 }, + msg.ByteValuesDefault); - Assert.IsType>(msg.CharValuesDefault); - Assert.Equal( - new List { 0, 1, 127 }, - msg.CharValuesDefault); + Assert.IsType>(msg.CharValuesDefault); + Assert.Equal( + new List { 0, 1, 127 }, + msg.CharValuesDefault); - Assert.IsType>(msg.Float32ValuesDefault); - Assert.Equal( - new List { 1.125f, 0.0f, -1.125f}, - msg.Float32ValuesDefault); + Assert.IsType>(msg.Float32ValuesDefault); + Assert.Equal( + new List { 1.125f, 0.0f, -1.125f }, + msg.Float32ValuesDefault); - Assert.IsType>(msg.Float64ValuesDefault); - Assert.Equal( - new List { 3.1415, 0.0, -3.1415 }, - msg.Float64ValuesDefault); + Assert.IsType>(msg.Float64ValuesDefault); + Assert.Equal( + new List { 3.1415, 0.0, -3.1415 }, + msg.Float64ValuesDefault); - Assert.IsType>(msg.Int8ValuesDefault); - Assert.Equal( - new List { 0, 127, -128 }, - msg.Int8ValuesDefault); + Assert.IsType>(msg.Int8ValuesDefault); + Assert.Equal( + new List { 0, 127, -128 }, + msg.Int8ValuesDefault); - Assert.IsType>(msg.Uint8ValuesDefault); - Assert.Equal( - new List { 0, 1, 255 }, - msg.Uint8ValuesDefault); + Assert.IsType>(msg.Uint8ValuesDefault); + Assert.Equal( + new List { 0, 1, 255 }, + msg.Uint8ValuesDefault); - Assert.IsType>(msg.Int16ValuesDefault); - Assert.Equal( - new List { 0, 32767, -32768 }, - msg.Int16ValuesDefault); + Assert.IsType>(msg.Int16ValuesDefault); + Assert.Equal( + new List { 0, 32767, -32768 }, + msg.Int16ValuesDefault); - Assert.IsType>(msg.Uint16ValuesDefault); - Assert.Equal( - new List { 0, 1, 65535 }, - msg.Uint16ValuesDefault); + Assert.IsType>(msg.Uint16ValuesDefault); + Assert.Equal( + new List { 0, 1, 65535 }, + msg.Uint16ValuesDefault); - Assert.IsType>(msg.Int32ValuesDefault); - Assert.Equal( - new List { 0, 2147483647, -2147483648 }, - msg.Int32ValuesDefault); + Assert.IsType>(msg.Int32ValuesDefault); + Assert.Equal( + new List { 0, 2147483647, -2147483648 }, + msg.Int32ValuesDefault); - Assert.IsType>(msg.Uint32ValuesDefault); - Assert.Equal( - new List { 0, 1, 4294967295 }, - msg.Uint32ValuesDefault); + Assert.IsType>(msg.Uint32ValuesDefault); + Assert.Equal( + new List { 0, 1, 4294967295 }, + msg.Uint32ValuesDefault); - Assert.IsType>(msg.Int64ValuesDefault); - Assert.Equal( - new List { 0, 9223372036854775807, -9223372036854775808 }, - msg.Int64ValuesDefault); + Assert.IsType>(msg.Int64ValuesDefault); + Assert.Equal( + new List { 0, 9223372036854775807, -9223372036854775808 }, + msg.Int64ValuesDefault); - Assert.IsType>(msg.Uint64ValuesDefault); - Assert.Equal( - new List { 0, 1, 18446744073709551615 }, - msg.Uint64ValuesDefault); - - Assert.IsType>(msg.StringValuesDefault); - Assert.Equal( - new List { "", "max value", "min value" }, - msg.StringValuesDefault); - } + Assert.IsType>(msg.Uint64ValuesDefault); + Assert.Equal( + new List { 0, 1, 18446744073709551615 }, + msg.Uint64ValuesDefault); + + Assert.IsType>(msg.StringValuesDefault); + Assert.Equal( + new List { "", "max value", "min value" }, + msg.StringValuesDefault); + } - [Fact] - public void TestDefaultsBoundedSequences() - { - var msg = new test_msgs.msg.BoundedSequences(); + [Fact] + public void TestDefaultsBoundedSequences() + { + var msg = new test_msgs.msg.BoundedSequences(); - Assert.IsType>(msg.BoolValues); - Assert.Equal(new List(), msg.BoolValues); + Assert.IsType>(msg.BoolValues); + Assert.Equal(new List(), msg.BoolValues); - Assert.IsType>(msg.ByteValues); - Assert.Equal(new List(), msg.ByteValues); + Assert.IsType>(msg.ByteValues); + Assert.Equal(new List(), msg.ByteValues); - Assert.IsType>(msg.CharValues); - Assert.Equal(new List(), msg.CharValues); + Assert.IsType>(msg.CharValues); + Assert.Equal(new List(), msg.CharValues); - Assert.IsType>(msg.Float32Values); - Assert.Equal(new List(), msg.Float32Values); + Assert.IsType>(msg.Float32Values); + Assert.Equal(new List(), msg.Float32Values); - Assert.IsType>(msg.Float64Values); - Assert.Equal(new List(), msg.Float64Values); + Assert.IsType>(msg.Float64Values); + Assert.Equal(new List(), msg.Float64Values); - Assert.IsType>(msg.Int8Values); - Assert.Equal(new List(), msg.Int8Values); + Assert.IsType>(msg.Int8Values); + Assert.Equal(new List(), msg.Int8Values); - Assert.IsType>(msg.Uint8Values); - Assert.Equal(new List(), msg.Uint8Values); + Assert.IsType>(msg.Uint8Values); + Assert.Equal(new List(), msg.Uint8Values); - Assert.IsType>(msg.Int16Values); - Assert.Equal(new List(), msg.Int16Values); + Assert.IsType>(msg.Int16Values); + Assert.Equal(new List(), msg.Int16Values); - Assert.IsType>(msg.Uint16Values); - Assert.Equal(new List(), msg.Uint16Values); + Assert.IsType>(msg.Uint16Values); + Assert.Equal(new List(), msg.Uint16Values); - Assert.IsType>(msg.Int32Values); - Assert.Equal(new List(), msg.Int32Values); + Assert.IsType>(msg.Int32Values); + Assert.Equal(new List(), msg.Int32Values); - Assert.IsType>(msg.Uint32Values); - Assert.Equal(new List(), msg.Uint32Values); + Assert.IsType>(msg.Uint32Values); + Assert.Equal(new List(), msg.Uint32Values); - Assert.IsType>(msg.Int64Values); - Assert.Equal(new List(), msg.Int64Values); + Assert.IsType>(msg.Int64Values); + Assert.Equal(new List(), msg.Int64Values); - Assert.IsType>(msg.Uint64Values); - Assert.Equal(new List(), msg.Uint64Values); + Assert.IsType>(msg.Uint64Values); + Assert.Equal(new List(), msg.Uint64Values); - Assert.IsType>(msg.StringValues); - Assert.Equal(new List(), msg.StringValues); + Assert.IsType>(msg.StringValues); + Assert.Equal(new List(), msg.StringValues); - Assert.IsType>(msg.BasicTypesValues); - Assert.Equal(new List(), msg.BasicTypesValues); + Assert.IsType>(msg.BasicTypesValues); + Assert.Equal(new List(), msg.BasicTypesValues); - Assert.IsType>(msg.ConstantsValues); - Assert.Equal(new List(), msg.ConstantsValues); + Assert.IsType>(msg.ConstantsValues); + Assert.Equal(new List(), msg.ConstantsValues); - Assert.IsType>(msg.DefaultsValues); - Assert.Equal(new List(), msg.DefaultsValues); + Assert.IsType>(msg.DefaultsValues); + Assert.Equal(new List(), msg.DefaultsValues); - Assert.IsType>(msg.BoolValuesDefault); - Assert.Equal( - new List { false, true, false }, - msg.BoolValuesDefault); + Assert.IsType>(msg.BoolValuesDefault); + Assert.Equal( + new List { false, true, false }, + msg.BoolValuesDefault); - Assert.IsType>(msg.ByteValuesDefault); - Assert.Equal( - new List { 0, 1, 255 }, - msg.ByteValuesDefault); + Assert.IsType>(msg.ByteValuesDefault); + Assert.Equal( + new List { 0, 1, 255 }, + msg.ByteValuesDefault); - Assert.IsType>(msg.CharValuesDefault); - Assert.Equal( - new List { 0, 1, 127 }, - msg.CharValuesDefault); + Assert.IsType>(msg.CharValuesDefault); + Assert.Equal( + new List { 0, 1, 127 }, + msg.CharValuesDefault); - Assert.IsType>(msg.Float32ValuesDefault); - Assert.Equal( - new List { 1.125f, 0.0f, -1.125f}, - msg.Float32ValuesDefault); + Assert.IsType>(msg.Float32ValuesDefault); + Assert.Equal( + new List { 1.125f, 0.0f, -1.125f }, + msg.Float32ValuesDefault); - Assert.IsType>(msg.Float64ValuesDefault); - Assert.Equal( - new List { 3.1415, 0.0, -3.1415 }, - msg.Float64ValuesDefault); + Assert.IsType>(msg.Float64ValuesDefault); + Assert.Equal( + new List { 3.1415, 0.0, -3.1415 }, + msg.Float64ValuesDefault); - Assert.IsType>(msg.Int8ValuesDefault); - Assert.Equal( - new List { 0, 127, -128 }, - msg.Int8ValuesDefault); + Assert.IsType>(msg.Int8ValuesDefault); + Assert.Equal( + new List { 0, 127, -128 }, + msg.Int8ValuesDefault); - Assert.IsType>(msg.Uint8ValuesDefault); - Assert.Equal( - new List { 0, 1, 255 }, - msg.Uint8ValuesDefault); + Assert.IsType>(msg.Uint8ValuesDefault); + Assert.Equal( + new List { 0, 1, 255 }, + msg.Uint8ValuesDefault); - Assert.IsType>(msg.Int16ValuesDefault); - Assert.Equal( - new List { 0, 32767, -32768 }, - msg.Int16ValuesDefault); + Assert.IsType>(msg.Int16ValuesDefault); + Assert.Equal( + new List { 0, 32767, -32768 }, + msg.Int16ValuesDefault); - Assert.IsType>(msg.Uint16ValuesDefault); - Assert.Equal( - new List { 0, 1, 65535 }, - msg.Uint16ValuesDefault); + Assert.IsType>(msg.Uint16ValuesDefault); + Assert.Equal( + new List { 0, 1, 65535 }, + msg.Uint16ValuesDefault); - Assert.IsType>(msg.Int32ValuesDefault); - Assert.Equal( - new List { 0, 2147483647, -2147483648 }, - msg.Int32ValuesDefault); + Assert.IsType>(msg.Int32ValuesDefault); + Assert.Equal( + new List { 0, 2147483647, -2147483648 }, + msg.Int32ValuesDefault); - Assert.IsType>(msg.Uint32ValuesDefault); - Assert.Equal( - new List { 0, 1, 4294967295 }, - msg.Uint32ValuesDefault); + Assert.IsType>(msg.Uint32ValuesDefault); + Assert.Equal( + new List { 0, 1, 4294967295 }, + msg.Uint32ValuesDefault); - Assert.IsType>(msg.Int64ValuesDefault); - Assert.Equal( - new List { 0, 9223372036854775807, -9223372036854775808 }, - msg.Int64ValuesDefault); + Assert.IsType>(msg.Int64ValuesDefault); + Assert.Equal( + new List { 0, 9223372036854775807, -9223372036854775808 }, + msg.Int64ValuesDefault); - Assert.IsType>(msg.Uint64ValuesDefault); - Assert.Equal( - new List { 0, 1, 18446744073709551615 }, - msg.Uint64ValuesDefault); - - Assert.IsType>(msg.StringValuesDefault); - Assert.Equal( - new List { "", "max value", "min value" }, - msg.StringValuesDefault); + Assert.IsType>(msg.Uint64ValuesDefault); + Assert.Equal( + new List { 0, 1, 18446744073709551615 }, + msg.Uint64ValuesDefault); + + Assert.IsType>(msg.StringValuesDefault); + Assert.Equal( + new List { "", "max value", "min value" }, + msg.StringValuesDefault); + } } - } } diff --git a/rcldotnet/test/test_services.cs b/rcldotnet/test/test_services.cs index 7712d86b..511dbcf5 100644 --- a/rcldotnet/test/test_services.cs +++ b/rcldotnet/test/test_services.cs @@ -29,11 +29,11 @@ public void TestServiceAndClient() test_msgs.srv.BasicTypes_Request serviceReceivedRequest = null; test_msgs.srv.BasicTypes_Response clientReceivedResponse = null; - + var service = serviceNode.CreateService("unittest_dotnet_service", HandleRequest); var client = clientNode.CreateClient("unittest_dotnet_service"); - + var request = new test_msgs.srv.BasicTypes_Request(); request.BoolValue = true; request.ByteValue = 36; diff --git a/rcldotnet_common/DllLoadUtils.cs b/rcldotnet_common/DllLoadUtils.cs index 6aff8e38..6ce14ee9 100644 --- a/rcldotnet_common/DllLoadUtils.cs +++ b/rcldotnet_common/DllLoadUtils.cs @@ -16,273 +16,329 @@ // Based on http://dimitry-i.blogspot.com.es/2013/01/mononet-how-to-dynamically-load-native.html using System; -using System.Runtime; using System.Runtime.InteropServices; -namespace ROS2 { - namespace Utils { - public class UnsatisfiedLinkError : System.Exception { - public UnsatisfiedLinkError () : base () { } - public UnsatisfiedLinkError (string message) : base (message) { } - public UnsatisfiedLinkError (string message, System.Exception inner) : base (message, inner) { } - } - - public class UnknownPlatformError : System.Exception { - public UnknownPlatformError () : base () { } - public UnknownPlatformError (string message) : base (message) { } - public UnknownPlatformError (string message, System.Exception inner) : base (message, inner) { } - } - - public enum Platform { - Unix, - MacOSX, - WindowsDesktop, - UWP, - Unknown - } - - public class DllLoadUtilsFactory { - [DllImport ("api-ms-win-core-libraryloader-l2-1-0.dll", EntryPoint = "LoadPackagedLibrary", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr LoadPackagedLibrary ([MarshalAs (UnmanagedType.LPWStr)] string fileName, int reserved = 0); - - [DllImport ("api-ms-win-core-libraryloader-l1-2-0.dll", EntryPoint = "FreeLibrary", SetLastError = true, ExactSpelling = true)] - private static extern int FreeLibraryUWP (IntPtr handle); - - [DllImport ("kernel32.dll", EntryPoint = "LoadLibraryA", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr LoadLibraryA (string fileName, int reserved = 0); - - [DllImport ("kernel32.dll", EntryPoint = "FreeLibrary", SetLastError = true, ExactSpelling = true)] - private static extern int FreeLibraryDesktop (IntPtr handle); - - [DllImport ("libdl.so.2", EntryPoint = "dlopen")] - private static extern IntPtr dlopen_unix (String fileName, int flags); - - [DllImport ("libdl.so.2", EntryPoint = "dlclose")] - private static extern int dlclose_unix (IntPtr handle); - - [DllImport ("libdl.dylib", EntryPoint = "dlopen")] - private static extern IntPtr dlopen_macosx (String fileName, int flags); - - [DllImport ("libdl.dylib", EntryPoint = "dlclose")] - private static extern int dlclose_macosx (IntPtr handle); - - const int RTLD_NOW = 2; - - public static DllLoadUtils GetDllLoadUtils () { - switch (CheckPlatform ()) { - case Platform.Unix: - return new DllLoadUtilsUnix (); - case Platform.MacOSX: - return new DllLoadUtilsMacOSX (); - case Platform.WindowsDesktop: - return new DllLoadUtilsWindowsDesktop (); - case Platform.UWP: - return new DllLoadUtilsUWP (); - case Platform.Unknown: - default: - throw new UnknownPlatformError (); - } - } - - private static bool IsUWP () { - try { - IntPtr ptr = LoadPackagedLibrary ("api-ms-win-core-libraryloader-l2-1-0.dll"); - FreeLibraryUWP (ptr); - return true; - } catch (TypeLoadException) { - return false; - } - } - - private static bool IsWindowsDesktop () { - try { - IntPtr ptr = LoadLibraryA ("kernel32.dll"); - FreeLibraryDesktop (ptr); - return true; - } catch (TypeLoadException) { - return false; - } - } - - private static bool IsUnix () { - try { - IntPtr ptr = dlopen_unix ("libdl.so.2", RTLD_NOW); - dlclose_unix (ptr); - return true; - } catch (TypeLoadException) { - return false; +namespace ROS2 +{ + namespace Utils + { + public class UnsatisfiedLinkError : System.Exception + { + public UnsatisfiedLinkError() : base() { } + public UnsatisfiedLinkError(string message) : base(message) { } + public UnsatisfiedLinkError(string message, System.Exception inner) : base(message, inner) { } } - } - - private static bool IsMacOSX () { - try { - IntPtr ptr = dlopen_macosx ("libdl.dylib", RTLD_NOW); - dlclose_macosx (ptr); - return true; - } catch (TypeLoadException) { - return false; - } - } - - private static Platform CheckPlatform () { - if (IsUnix ()) { - return Platform.Unix; - } else if (IsMacOSX ()) { - return Platform.MacOSX; - } else if (IsWindowsDesktop ()) { - return Platform.WindowsDesktop; - } else if (IsUWP ()) { - return Platform.UWP; - } else { - return Platform.Unknown; - } - } - } - - public interface DllLoadUtils { - IntPtr LoadLibrary (string fileName); - void FreeLibrary (IntPtr handle); - IntPtr GetProcAddress (IntPtr dllHandle, string name); - } - - public class DllLoadUtilsUWP : DllLoadUtils { - - [DllImport ("api-ms-win-core-libraryloader-l2-1-0.dll", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr LoadPackagedLibrary ([MarshalAs (UnmanagedType.LPWStr)] string fileName, int reserved = 0); - - [DllImport ("api-ms-win-core-libraryloader-l1-2-0.dll", SetLastError = true, ExactSpelling = true)] - private static extern int FreeLibrary (IntPtr handle); - - [DllImport ("api-ms-win-core-libraryloader-l1-2-0.dll", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr GetProcAddress (IntPtr handle, string procedureName); - void DllLoadUtils.FreeLibrary (IntPtr handle) { - FreeLibrary (handle); - } - - IntPtr DllLoadUtils.GetProcAddress (IntPtr dllHandle, string name) { - return GetProcAddress (dllHandle, name); - } - - IntPtr DllLoadUtils.LoadLibrary (string fileName) { - string libraryName = fileName + "_native.dll"; - IntPtr ptr = LoadPackagedLibrary (libraryName); - if (ptr == IntPtr.Zero) { - throw new UnsatisfiedLinkError (libraryName); + public class UnknownPlatformError : System.Exception + { + public UnknownPlatformError() : base() { } + public UnknownPlatformError(string message) : base(message) { } + public UnknownPlatformError(string message, System.Exception inner) : base(message, inner) { } } - return ptr; - } - } - - public class DllLoadUtilsWindowsDesktop : DllLoadUtils { - - [DllImport ("kernel32.dll", EntryPoint = "LoadLibraryA", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr LoadLibraryA (string fileName, int reserved = 0); - - [DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern int FreeLibrary (IntPtr handle); - - [DllImport ("kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern IntPtr GetProcAddress (IntPtr handle, string procedureName); - void DllLoadUtils.FreeLibrary (IntPtr handle) { - FreeLibrary (handle); - } - - IntPtr DllLoadUtils.GetProcAddress (IntPtr dllHandle, string name) { - return GetProcAddress (dllHandle, name); - } - - IntPtr DllLoadUtils.LoadLibrary (string fileName) { - string libraryName = fileName + "_native.dll"; - IntPtr ptr = LoadLibraryA (libraryName); - if (ptr == IntPtr.Zero) { - throw new UnsatisfiedLinkError (libraryName); + public enum Platform + { + Unix, + MacOSX, + WindowsDesktop, + UWP, + Unknown } - return ptr; - } - } - - internal class DllLoadUtilsUnix : DllLoadUtils { - - [DllImport ("libdl.so.2", ExactSpelling = true)] - private static extern IntPtr dlopen (String fileName, int flags); - - [DllImport ("libdl.so.2", ExactSpelling = true)] - private static extern IntPtr dlsym (IntPtr handle, String symbol); - - [DllImport ("libdl.so.2", ExactSpelling = true)] - private static extern int dlclose (IntPtr handle); - [DllImport ("libdl.so.2", ExactSpelling = true)] - private static extern IntPtr dlerror (); - - const int RTLD_NOW = 2; - - public void FreeLibrary (IntPtr handle) { - dlclose (handle); - } - - public IntPtr GetProcAddress (IntPtr dllHandle, string name) { - // clear previous errors if any - dlerror (); - var res = dlsym (dllHandle, name); - var errPtr = dlerror (); - if (errPtr != IntPtr.Zero) { - throw new Exception ("dlsym: " + Marshal.PtrToStringAnsi (errPtr)); - } - return res; - } - - public IntPtr LoadLibrary (string fileName) { - string libraryName = "lib" + fileName + "_native.so"; - IntPtr ptr = dlopen (libraryName, RTLD_NOW); - if (ptr == IntPtr.Zero) { - throw new UnsatisfiedLinkError (libraryName); + public class DllLoadUtilsFactory + { + [DllImport("api-ms-win-core-libraryloader-l2-1-0.dll", EntryPoint = "LoadPackagedLibrary", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr LoadPackagedLibrary([MarshalAs(UnmanagedType.LPWStr)] string fileName, int reserved = 0); + + [DllImport("api-ms-win-core-libraryloader-l1-2-0.dll", EntryPoint = "FreeLibrary", SetLastError = true, ExactSpelling = true)] + private static extern int FreeLibraryUWP(IntPtr handle); + + [DllImport("kernel32.dll", EntryPoint = "LoadLibraryA", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr LoadLibraryA(string fileName, int reserved = 0); + + [DllImport("kernel32.dll", EntryPoint = "FreeLibrary", SetLastError = true, ExactSpelling = true)] + private static extern int FreeLibraryDesktop(IntPtr handle); + + [DllImport("libdl.so.2", EntryPoint = "dlopen")] + private static extern IntPtr dlopen_unix(string fileName, int flags); + + [DllImport("libdl.so.2", EntryPoint = "dlclose")] + private static extern int dlclose_unix(IntPtr handle); + + [DllImport("libdl.dylib", EntryPoint = "dlopen")] + private static extern IntPtr dlopen_macosx(string fileName, int flags); + + [DllImport("libdl.dylib", EntryPoint = "dlclose")] + private static extern int dlclose_macosx(IntPtr handle); + + private const int RTLD_NOW = 2; + + public static DllLoadUtils GetDllLoadUtils() + { + switch (CheckPlatform()) + { + case Platform.Unix: + return new DllLoadUtilsUnix(); + case Platform.MacOSX: + return new DllLoadUtilsMacOSX(); + case Platform.WindowsDesktop: + return new DllLoadUtilsWindowsDesktop(); + case Platform.UWP: + return new DllLoadUtilsUWP(); + case Platform.Unknown: + default: + throw new UnknownPlatformError(); + } + } + + private static bool IsUWP() + { + try + { + IntPtr ptr = LoadPackagedLibrary("api-ms-win-core-libraryloader-l2-1-0.dll"); + FreeLibraryUWP(ptr); + return true; + } + catch (TypeLoadException) + { + return false; + } + } + + private static bool IsWindowsDesktop() + { + try + { + IntPtr ptr = LoadLibraryA("kernel32.dll"); + FreeLibraryDesktop(ptr); + return true; + } + catch (TypeLoadException) + { + return false; + } + } + + private static bool IsUnix() + { + try + { + IntPtr ptr = dlopen_unix("libdl.so.2", RTLD_NOW); + dlclose_unix(ptr); + return true; + } + catch (TypeLoadException) + { + return false; + } + } + + private static bool IsMacOSX() + { + try + { + IntPtr ptr = dlopen_macosx("libdl.dylib", RTLD_NOW); + dlclose_macosx(ptr); + return true; + } + catch (TypeLoadException) + { + return false; + } + } + + private static Platform CheckPlatform() + { + if (IsUnix()) + { + return Platform.Unix; + } + else if (IsMacOSX()) + { + return Platform.MacOSX; + } + else if (IsWindowsDesktop()) + { + return Platform.WindowsDesktop; + } + else if (IsUWP()) + { + return Platform.UWP; + } + else + { + return Platform.Unknown; + } + } } - return ptr; - } - } - - internal class DllLoadUtilsMacOSX : DllLoadUtils { - - [DllImport ("libdl.dylib", ExactSpelling = true)] - private static extern IntPtr dlopen (String fileName, int flags); - [DllImport ("libdl.dylib", ExactSpelling = true)] - private static extern IntPtr dlsym (IntPtr handle, String symbol); - - [DllImport ("libdl.dylib", ExactSpelling = true)] - private static extern int dlclose (IntPtr handle); - - [DllImport ("libdl.dylib", ExactSpelling = true)] - private static extern IntPtr dlerror (); + public interface DllLoadUtils + { + IntPtr LoadLibrary(string fileName); + void FreeLibrary(IntPtr handle); + IntPtr GetProcAddress(IntPtr dllHandle, string name); + } - const int RTLD_NOW = 2; + public class DllLoadUtilsUWP : DllLoadUtils + { + + [DllImport("api-ms-win-core-libraryloader-l2-1-0.dll", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr LoadPackagedLibrary([MarshalAs(UnmanagedType.LPWStr)] string fileName, int reserved = 0); + + [DllImport("api-ms-win-core-libraryloader-l1-2-0.dll", SetLastError = true, ExactSpelling = true)] + private static extern int FreeLibrary(IntPtr handle); + + [DllImport("api-ms-win-core-libraryloader-l1-2-0.dll", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr GetProcAddress(IntPtr handle, string procedureName); + + void DllLoadUtils.FreeLibrary(IntPtr handle) + { + FreeLibrary(handle); + } + + IntPtr DllLoadUtils.GetProcAddress(IntPtr dllHandle, string name) + { + return GetProcAddress(dllHandle, name); + } + + IntPtr DllLoadUtils.LoadLibrary(string fileName) + { + string libraryName = fileName + "_native.dll"; + IntPtr ptr = LoadPackagedLibrary(libraryName); + if (ptr == IntPtr.Zero) + { + throw new UnsatisfiedLinkError(libraryName); + } + return ptr; + } + } - public void FreeLibrary (IntPtr handle) { - dlclose (handle); - } + public class DllLoadUtilsWindowsDesktop : DllLoadUtils + { + + [DllImport("kernel32.dll", EntryPoint = "LoadLibraryA", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr LoadLibraryA(string fileName, int reserved = 0); + + [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] + private static extern int FreeLibrary(IntPtr handle); + + [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] + private static extern IntPtr GetProcAddress(IntPtr handle, string procedureName); + + void DllLoadUtils.FreeLibrary(IntPtr handle) + { + FreeLibrary(handle); + } + + IntPtr DllLoadUtils.GetProcAddress(IntPtr dllHandle, string name) + { + return GetProcAddress(dllHandle, name); + } + + IntPtr DllLoadUtils.LoadLibrary(string fileName) + { + string libraryName = fileName + "_native.dll"; + IntPtr ptr = LoadLibraryA(libraryName); + if (ptr == IntPtr.Zero) + { + throw new UnsatisfiedLinkError(libraryName); + } + return ptr; + } + } - public IntPtr GetProcAddress (IntPtr dllHandle, string name) { - // clear previous errors if any - dlerror (); - var res = dlsym (dllHandle, name); - var errPtr = dlerror (); - if (errPtr != IntPtr.Zero) { - throw new Exception ("dlsym: " + Marshal.PtrToStringAnsi (errPtr)); + internal class DllLoadUtilsUnix : DllLoadUtils + { + + [DllImport("libdl.so.2", ExactSpelling = true)] + private static extern IntPtr dlopen(string fileName, int flags); + + [DllImport("libdl.so.2", ExactSpelling = true)] + private static extern IntPtr dlsym(IntPtr handle, string symbol); + + [DllImport("libdl.so.2", ExactSpelling = true)] + private static extern int dlclose(IntPtr handle); + + [DllImport("libdl.so.2", ExactSpelling = true)] + private static extern IntPtr dlerror(); + + private const int RTLD_NOW = 2; + + public void FreeLibrary(IntPtr handle) + { + dlclose(handle); + } + + public IntPtr GetProcAddress(IntPtr dllHandle, string name) + { + // clear previous errors if any + dlerror(); + var res = dlsym(dllHandle, name); + var errPtr = dlerror(); + if (errPtr != IntPtr.Zero) + { + throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr)); + } + return res; + } + + public IntPtr LoadLibrary(string fileName) + { + string libraryName = "lib" + fileName + "_native.so"; + IntPtr ptr = dlopen(libraryName, RTLD_NOW); + if (ptr == IntPtr.Zero) + { + throw new UnsatisfiedLinkError(libraryName); + } + return ptr; + } } - return res; - } - - public IntPtr LoadLibrary (string fileName) { - string libraryName = "lib" + fileName + "_native.dylib"; - IntPtr ptr = dlopen (libraryName, RTLD_NOW); - if (ptr == IntPtr.Zero) { - throw new UnsatisfiedLinkError (libraryName); + + internal class DllLoadUtilsMacOSX : DllLoadUtils + { + + [DllImport("libdl.dylib", ExactSpelling = true)] + private static extern IntPtr dlopen(string fileName, int flags); + + [DllImport("libdl.dylib", ExactSpelling = true)] + private static extern IntPtr dlsym(IntPtr handle, string symbol); + + [DllImport("libdl.dylib", ExactSpelling = true)] + private static extern int dlclose(IntPtr handle); + + [DllImport("libdl.dylib", ExactSpelling = true)] + private static extern IntPtr dlerror(); + + private const int RTLD_NOW = 2; + + public void FreeLibrary(IntPtr handle) + { + dlclose(handle); + } + + public IntPtr GetProcAddress(IntPtr dllHandle, string name) + { + // clear previous errors if any + dlerror(); + var res = dlsym(dllHandle, name); + var errPtr = dlerror(); + if (errPtr != IntPtr.Zero) + { + throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr)); + } + return res; + } + + public IntPtr LoadLibrary(string fileName) + { + string libraryName = "lib" + fileName + "_native.dylib"; + IntPtr ptr = dlopen(libraryName, RTLD_NOW); + if (ptr == IntPtr.Zero) + { + throw new UnsatisfiedLinkError(libraryName); + } + return ptr; + } } - return ptr; - } } - } } diff --git a/rcldotnet_common/IRosMessage.cs b/rcldotnet_common/IRosMessage.cs index 87dc0751..30a04576 100644 --- a/rcldotnet_common/IRosMessage.cs +++ b/rcldotnet_common/IRosMessage.cs @@ -23,7 +23,7 @@ public interface IRosMessage // (static abstract interface members are not supported yet.) // public static abstract IntPtr __GetTypeSupport(); // public static abstract SafeHandle __CreateMessageHandle(); - + void __ReadFromHandle(IntPtr messageHandle); void __WriteToHandle(IntPtr messageHandle); diff --git a/rcldotnet_examples/RCLDotnetClient.cs b/rcldotnet_examples/RCLDotnetClient.cs index 08868ced..f8b538ee 100644 --- a/rcldotnet_examples/RCLDotnetClient.cs +++ b/rcldotnet_examples/RCLDotnetClient.cs @@ -1,9 +1,5 @@ using System; -using System.Reflection; -using System.Runtime; -using System.Runtime.InteropServices; using System.Threading; -using System.Threading.Tasks; using ROS2; namespace ConsoleApplication @@ -16,21 +12,21 @@ public static void Main(string[] args) var node = RCLdotnet.CreateNode("client"); var client = node.CreateClient("test_dotnet_service_name"); - + // TODO: (sh) Add WaitForService(timeout) method that observes the node graph. Console.WriteLine("Waiting for service..."); while (RCLdotnet.Ok() && !client.ServiceIsReady()) { Thread.Sleep(500); } - + var request = new std_srvs.srv.SetBool_Request(); request.Data = true; var task = client.SendRequestAsync(request); Console.WriteLine("Sent request."); - + while (RCLdotnet.Ok()) { RCLdotnet.SpinOnce(node, 500); diff --git a/rcldotnet_examples/RCLDotnetListener.cs b/rcldotnet_examples/RCLDotnetListener.cs index 34a56589..62da2ed6 100644 --- a/rcldotnet_examples/RCLDotnetListener.cs +++ b/rcldotnet_examples/RCLDotnetListener.cs @@ -1,22 +1,21 @@ using System; -using System.Reflection; -using System.Runtime; -using System.Runtime.InteropServices; -using System.Threading; using ROS2; -namespace ConsoleApplication { - public class RCLDotnetListener { - public static void Main (string[] args) { - RCLdotnet.Init (); +namespace ConsoleApplication +{ + public class RCLDotnetListener + { + public static void Main(string[] args) + { + RCLdotnet.Init(); - Node node = RCLdotnet.CreateNode ("listener"); + Node node = RCLdotnet.CreateNode("listener"); - Subscription chatter_sub = node.CreateSubscription ( - "chatter", msg => Console.WriteLine ("I heard: [" + msg.Data + "]")); + Subscription chatter_sub = node.CreateSubscription( + "chatter", msg => Console.WriteLine("I heard: [" + msg.Data + "]")); - RCLdotnet.Spin (node); + RCLdotnet.Spin(node); + } } - } } diff --git a/rcldotnet_examples/RCLDotnetService.cs b/rcldotnet_examples/RCLDotnetService.cs index a74c7d5b..af2b3333 100644 --- a/rcldotnet_examples/RCLDotnetService.cs +++ b/rcldotnet_examples/RCLDotnetService.cs @@ -1,8 +1,4 @@ using System; -using System.Reflection; -using System.Runtime; -using System.Runtime.InteropServices; -using System.Threading; using ROS2; namespace ConsoleApplication diff --git a/rcldotnet_examples/RCLDotnetTalker.cs b/rcldotnet_examples/RCLDotnetTalker.cs index 8744bf07..9208f2d7 100644 --- a/rcldotnet_examples/RCLDotnetTalker.cs +++ b/rcldotnet_examples/RCLDotnetTalker.cs @@ -1,34 +1,34 @@ using System; -using System.Reflection; -using System.Runtime; -using System.Runtime.InteropServices; using System.Threading; using ROS2; -using ROS2.Utils; -namespace ConsoleApplication { - public class RCLDotnetTalker { - public static void Main (string[] args) { - RCLdotnet.Init (); +namespace ConsoleApplication +{ + public class RCLDotnetTalker + { + public static void Main(string[] args) + { + RCLdotnet.Init(); - Node node = RCLdotnet.CreateNode ("talker"); + Node node = RCLdotnet.CreateNode("talker"); - Publisher chatter_pub = node.CreatePublisher ("chatter"); + Publisher chatter_pub = node.CreatePublisher("chatter"); - std_msgs.msg.String msg = new std_msgs.msg.String (); + std_msgs.msg.String msg = new std_msgs.msg.String(); - int i = 1; + int i = 1; - while (RCLdotnet.Ok ()) { - msg.Data = "Hello World: " + i; - i++; - Console.WriteLine ("Publishing: \"" + msg.Data + "\""); - chatter_pub.Publish (msg); + while (RCLdotnet.Ok()) + { + msg.Data = "Hello World: " + i; + i++; + Console.WriteLine("Publishing: \"" + msg.Data + "\""); + chatter_pub.Publish(msg); - // Sleep a little bit between each message - Thread.Sleep (1000); - } + // Sleep a little bit between each message + Thread.Sleep(1000); + } + } } - } } From f4a03f274daadcff6f8e95f6768526c25b975d68 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Wed, 15 Jun 2022 15:51:12 +0200 Subject: [PATCH 3/4] fix naming of internal variables --- rcldotnet/Client.cs | 12 +- rcldotnet/Node.cs | 78 ++--- rcldotnet/Publisher.cs | 8 +- rcldotnet/RCLdotnet.cs | 57 ++-- rcldotnet/Subscription.cs | 6 +- rcldotnet/test/test_messages.cs | 376 ++++++++++++------------ rcldotnet_examples/RCLDotnetListener.cs | 2 +- rcldotnet_examples/RCLDotnetTalker.cs | 4 +- 8 files changed, 271 insertions(+), 272 deletions(-) diff --git a/rcldotnet/Client.cs b/rcldotnet/Client.cs index 695c8ec4..d0710861 100644 --- a/rcldotnet/Client.cs +++ b/rcldotnet/Client.cs @@ -23,11 +23,11 @@ namespace ROS2 { internal static class ClientDelegates { - internal static readonly DllLoadUtils dllLoadUtils; + internal static readonly DllLoadUtils _dllLoadUtils; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLSendRequestType( - SafeClientHandle clientHandle, SafeHandle requestHandle, out long seqneceNumber); + SafeClientHandle clientHandle, SafeHandle requestHandle, out long sequenceNumber); internal static NativeRCLSendRequestType native_rcl_send_request = null; @@ -39,14 +39,14 @@ internal delegate RCLRet NativeRCLServiceServerIsAvailableType( static ClientDelegates() { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); - IntPtr nativelibrary = dllLoadUtils.LoadLibrary("rcldotnet_client"); + _dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativeLibrary = _dllLoadUtils.LoadLibrary("rcldotnet_client"); - IntPtr native_rcl_send_request_ptr = dllLoadUtils.GetProcAddress(nativelibrary, "native_rcl_send_request"); + IntPtr native_rcl_send_request_ptr = _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_send_request"); ClientDelegates.native_rcl_send_request = (NativeRCLSendRequestType)Marshal.GetDelegateForFunctionPointer( native_rcl_send_request_ptr, typeof(NativeRCLSendRequestType)); - IntPtr native_rcl_service_server_is_available_ptr = dllLoadUtils.GetProcAddress(nativelibrary, "native_rcl_service_server_is_available"); + IntPtr native_rcl_service_server_is_available_ptr = _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_service_server_is_available"); ClientDelegates.native_rcl_service_server_is_available = (NativeRCLServiceServerIsAvailableType)Marshal.GetDelegateForFunctionPointer( native_rcl_service_server_is_available_ptr, typeof(NativeRCLServiceServerIsAvailableType)); } diff --git a/rcldotnet/Node.cs b/rcldotnet/Node.cs index 342dbb6b..8a3c585b 100644 --- a/rcldotnet/Node.cs +++ b/rcldotnet/Node.cs @@ -22,7 +22,7 @@ namespace ROS2 { internal static class NodeDelegates { - private static readonly DllLoadUtils dllLoadUtils; + private static readonly DllLoadUtils _dllLoadUtils; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLCreatePublisherHandleType( @@ -74,60 +74,60 @@ internal delegate RCLRet NativeRCLDestroyClientHandleType( static NodeDelegates() { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); - IntPtr nativelibrary = dllLoadUtils.LoadLibrary("rcldotnet_node"); + _dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativeLibrary = _dllLoadUtils.LoadLibrary("rcldotnet_node"); - IntPtr native_rcl_create_publisher_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_create_publisher_handle"); + IntPtr native_rcl_create_publisher_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_create_publisher_handle"); NodeDelegates.native_rcl_create_publisher_handle = (NativeRCLCreatePublisherHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_publisher_handle_ptr, typeof(NativeRCLCreatePublisherHandleType)); - IntPtr native_rcl_destroy_publisher_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_destroy_publisher_handle"); + IntPtr native_rcl_destroy_publisher_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_destroy_publisher_handle"); NodeDelegates.native_rcl_destroy_publisher_handle = (NativeRCLDestroyPublisherHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_publisher_handle_ptr, typeof(NativeRCLDestroyPublisherHandleType)); - IntPtr native_rcl_create_subscription_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_create_subscription_handle"); + IntPtr native_rcl_create_subscription_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_create_subscription_handle"); NodeDelegates.native_rcl_create_subscription_handle = (NativeRCLCreateSubscriptionHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_subscription_handle_ptr, typeof(NativeRCLCreateSubscriptionHandleType)); - IntPtr native_rcl_destroy_subscription_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_destroy_subscription_handle"); + IntPtr native_rcl_destroy_subscription_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_destroy_subscription_handle"); NodeDelegates.native_rcl_destroy_subscription_handle = (NativeRCLDestroySubscriptionHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_subscription_handle_ptr, typeof(NativeRCLDestroySubscriptionHandleType)); - IntPtr native_rcl_create_service_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_create_service_handle"); + IntPtr native_rcl_create_service_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_create_service_handle"); NodeDelegates.native_rcl_create_service_handle = (NativeRCLCreateServiceHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_service_handle_ptr, typeof(NativeRCLCreateServiceHandleType)); - IntPtr native_rcl_destroy_service_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_destroy_service_handle"); + IntPtr native_rcl_destroy_service_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_destroy_service_handle"); NodeDelegates.native_rcl_destroy_service_handle = (NativeRCLDestroyServiceHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_service_handle_ptr, typeof(NativeRCLDestroyServiceHandleType)); - IntPtr native_rcl_create_client_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_create_client_handle"); + IntPtr native_rcl_create_client_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_create_client_handle"); NodeDelegates.native_rcl_create_client_handle = (NativeRCLCreateClientHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_client_handle_ptr, typeof(NativeRCLCreateClientHandleType)); - IntPtr native_rcl_destroy_client_handle_ptr = dllLoadUtils.GetProcAddress( - nativelibrary, "native_rcl_destroy_client_handle"); + IntPtr native_rcl_destroy_client_handle_ptr = _dllLoadUtils.GetProcAddress( + nativeLibrary, "native_rcl_destroy_client_handle"); NodeDelegates.native_rcl_destroy_client_handle = (NativeRCLDestroyClientHandleType)Marshal.GetDelegateForFunctionPointer( @@ -138,28 +138,28 @@ static NodeDelegates() public sealed class Node { - private readonly IList subscriptions_; + private readonly IList _subscriptions; - private readonly IList services_; + private readonly IList _services; - private readonly IList clients_; + private readonly IList _clients; internal Node(SafeNodeHandle handle) { Handle = handle; - subscriptions_ = new List(); - services_ = new List(); - clients_ = new List(); + _subscriptions = new List(); + _services = new List(); + _clients = new List(); } - public IList Subscriptions => subscriptions_; + public IList Subscriptions => _subscriptions; // TODO: (sh) wrap in readonly collection // TODO: (sh) Add posibility to remove Subscriptions/Services/Clients from Node (if this is a thing in ROS) // Now there is no Api to remove these Objects, and there is a strong reference from these fileds to them so they dont't get collected. - public IList Services => services_; + public IList Services => _services; - public IList Clients => clients_; + public IList Clients => _clients; // Node does intentionaly (for now) not implement IDisposable as this // needs some extra consideration how the type works after its @@ -170,10 +170,10 @@ internal Node(SafeNodeHandle handle) public Publisher CreatePublisher(string topic) where T : IRosMessage { - IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); + IntPtr typeSupport = MessageStaticMemberCache.GetTypeSupport(); var publisherHandle = new SafePublisherHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_publisher_handle(ref publisherHandle, Handle, topic, typesupport); + RCLRet ret = NodeDelegates.native_rcl_create_publisher_handle(ref publisherHandle, Handle, topic, typeSupport); publisherHandle.SetParent(Handle); if (ret != RCLRet.Ok) { @@ -188,10 +188,10 @@ public Publisher CreatePublisher(string topic) where T : IRosMessage public Subscription CreateSubscription(string topic, Action callback) where T : IRosMessage, new() { - IntPtr typesupport = MessageStaticMemberCache.GetTypeSupport(); + IntPtr typeSupport = MessageStaticMemberCache.GetTypeSupport(); var subscriptionHandle = new SafeSubscriptionHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_subscription_handle(ref subscriptionHandle, Handle, topic, typesupport); + RCLRet ret = NodeDelegates.native_rcl_create_subscription_handle(ref subscriptionHandle, Handle, topic, typeSupport); subscriptionHandle.SetParent(Handle); if (ret != RCLRet.Ok) { @@ -201,7 +201,7 @@ public Publisher CreatePublisher(string topic) where T : IRosMessage // TODO: (sh) Add topic as propety to Subscription. Subscription subscription = new Subscription(subscriptionHandle, callback); - subscriptions_.Add(subscription); + _subscriptions.Add(subscription); return subscription; } @@ -210,10 +210,10 @@ public Service CreateService.GetTypeSupport(); + IntPtr typeSupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); var serviceHandle = new SafeServiceHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_service_handle(ref serviceHandle, Handle, serviceName, typesupport); + RCLRet ret = NodeDelegates.native_rcl_create_service_handle(ref serviceHandle, Handle, serviceName, typeSupport); serviceHandle.SetParent(Handle); if (ret != RCLRet.Ok) { @@ -223,7 +223,7 @@ public Service CreateService(serviceHandle, callback); - services_.Add(service); + _services.Add(service); return service; } @@ -232,10 +232,10 @@ public Client CreateClient.GetTypeSupport(); + IntPtr typeSupport = ServiceDefinitionStaticMemberCache.GetTypeSupport(); var clientHandle = new SafeClientHandle(); - RCLRet ret = NodeDelegates.native_rcl_create_client_handle(ref clientHandle, Handle, serviceName, typesupport); + RCLRet ret = NodeDelegates.native_rcl_create_client_handle(ref clientHandle, Handle, serviceName, typeSupport); clientHandle.SetParent(Handle); if (ret != RCLRet.Ok) { @@ -245,7 +245,7 @@ public Client CreateClient(clientHandle, this); - clients_.Add(client); + _clients.Add(client); return client; } } diff --git a/rcldotnet/Publisher.cs b/rcldotnet/Publisher.cs index 6edaa285..a0e55378 100644 --- a/rcldotnet/Publisher.cs +++ b/rcldotnet/Publisher.cs @@ -21,7 +21,7 @@ namespace ROS2 { internal static class PublisherDelegates { - internal static readonly DllLoadUtils dllLoadUtils; + internal static readonly DllLoadUtils _dllLoadUtils; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLPublishType( @@ -31,10 +31,10 @@ internal delegate RCLRet NativeRCLPublishType( static PublisherDelegates() { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); - IntPtr nativelibrary = dllLoadUtils.LoadLibrary("rcldotnet_publisher"); + _dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativeLibrary = _dllLoadUtils.LoadLibrary("rcldotnet_publisher"); - IntPtr native_rcl_publish_ptr = dllLoadUtils.GetProcAddress(nativelibrary, "native_rcl_publish"); + IntPtr native_rcl_publish_ptr = _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_publish"); PublisherDelegates.native_rcl_publish = (NativeRCLPublishType)Marshal.GetDelegateForFunctionPointer( native_rcl_publish_ptr, typeof(NativeRCLPublishType)); } diff --git a/rcldotnet/RCLdotnet.cs b/rcldotnet/RCLdotnet.cs index 585b1ab1..8fb16a25 100644 --- a/rcldotnet/RCLdotnet.cs +++ b/rcldotnet/RCLdotnet.cs @@ -21,7 +21,7 @@ namespace ROS2 { internal static class RCLdotnetDelegates { - internal static readonly DllLoadUtils dllLoadUtils; + internal static readonly DllLoadUtils _dllLoadUtils; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate RCLRet NativeRCLInitType(); @@ -137,132 +137,131 @@ internal delegate RCLRet NativeRCLCreateRequestIdHandleType( static RCLdotnetDelegates() { - dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); - string library_name = "rcldotnet"; - IntPtr pDll = dllLoadUtils.LoadLibrary(library_name); + _dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils(); + IntPtr nativeLibrary = _dllLoadUtils.LoadLibrary("rcldotnet"); IntPtr native_rcl_init_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_init"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_init"); RCLdotnetDelegates.native_rcl_init = (NativeRCLInitType)Marshal.GetDelegateForFunctionPointer( native_rcl_init_ptr, typeof(NativeRCLInitType)); IntPtr native_rcl_get_error_string_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_get_error_string"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_get_error_string"); RCLdotnetDelegates.native_rcl_get_error_string = (NativeRCLGetErrorStringType)Marshal.GetDelegateForFunctionPointer( native_rcl_get_error_string_ptr, typeof(NativeRCLGetErrorStringType)); IntPtr native_rcl_reset_error_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_reset_error"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_reset_error"); RCLdotnetDelegates.native_rcl_reset_error = (NativeRCLResetErrorType)Marshal.GetDelegateForFunctionPointer( native_rcl_reset_error_ptr, typeof(NativeRCLResetErrorType)); IntPtr native_rcl_get_rmw_identifier_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_get_rmw_identifier"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_get_rmw_identifier"); RCLdotnetDelegates.native_rcl_get_rmw_identifier = (NativeRCLGetRMWIdentifierType)Marshal.GetDelegateForFunctionPointer( native_rcl_get_rmw_identifier_ptr, typeof(NativeRCLGetRMWIdentifierType)); IntPtr native_rcl_ok_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_ok"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_ok"); RCLdotnetDelegates.native_rcl_ok = (NativeRCLOkType)Marshal.GetDelegateForFunctionPointer( native_rcl_ok_ptr, typeof(NativeRCLOkType)); IntPtr native_rcl_create_node_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_node_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_create_node_handle"); RCLdotnetDelegates.native_rcl_create_node_handle = (NativeRCLCreateNodeHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_node_handle_ptr, typeof(NativeRCLCreateNodeHandleType)); IntPtr native_rcl_destroy_node_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_node_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_destroy_node_handle"); RCLdotnetDelegates.native_rcl_destroy_node_handle = (NativeRCLDestroyNodeHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_node_handle_ptr, typeof(NativeRCLDestroyNodeHandleType)); IntPtr native_rcl_create_wait_set_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_wait_set_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_create_wait_set_handle"); RCLdotnetDelegates.native_rcl_create_wait_set_handle = (NativeRCLCreateWaitSetHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_wait_set_handle_ptr, typeof(NativeRCLCreateWaitSetHandleType)); IntPtr native_rcl_destroy_wait_set_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_wait_set_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_destroy_wait_set_handle"); RCLdotnetDelegates.native_rcl_destroy_wait_set_handle = (NativeRCLDestroyWaitSetType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_wait_set_handle_ptr, typeof(NativeRCLDestroyWaitSetType)); IntPtr native_rcl_wait_set_clear_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_clear"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_wait_set_clear"); RCLdotnetDelegates.native_rcl_wait_set_clear = (NativeRCLWaitSetClearType)Marshal.GetDelegateForFunctionPointer( native_rcl_wait_set_clear_ptr, typeof(NativeRCLWaitSetClearType)); IntPtr native_rcl_wait_set_add_subscription_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_subscription"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_wait_set_add_subscription"); RCLdotnetDelegates.native_rcl_wait_set_add_subscription = (NativeRCLWaitSetAddSubscriptionType)Marshal.GetDelegateForFunctionPointer( native_rcl_wait_set_add_subscription_ptr, typeof(NativeRCLWaitSetAddSubscriptionType)); IntPtr native_rcl_wait_set_add_service_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_service"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_wait_set_add_service"); RCLdotnetDelegates.native_rcl_wait_set_add_service = (NativeRCLWaitSetAddServiceType)Marshal.GetDelegateForFunctionPointer( native_rcl_wait_set_add_service_ptr, typeof(NativeRCLWaitSetAddServiceType)); IntPtr native_rcl_wait_set_add_client_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait_set_add_client"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_wait_set_add_client"); RCLdotnetDelegates.native_rcl_wait_set_add_client = (NativeRCLWaitSetAddClientType)Marshal.GetDelegateForFunctionPointer( native_rcl_wait_set_add_client_ptr, typeof(NativeRCLWaitSetAddClientType)); IntPtr native_rcl_wait_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_wait"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_wait"); RCLdotnetDelegates.native_rcl_wait = (NativeRCLWaitType)Marshal.GetDelegateForFunctionPointer( native_rcl_wait_ptr, typeof(NativeRCLWaitType)); IntPtr native_rcl_take_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_take"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_take"); RCLdotnetDelegates.native_rcl_take = (NativeRCLTakeType)Marshal.GetDelegateForFunctionPointer( native_rcl_take_ptr, typeof(NativeRCLTakeType)); IntPtr native_rcl_create_request_id_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_create_request_id_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_create_request_id_handle"); RCLdotnetDelegates.native_rcl_create_request_id_handle = (NativeRCLCreateRequestIdHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_create_request_id_handle_ptr, typeof(NativeRCLCreateRequestIdHandleType)); IntPtr native_rcl_destroy_request_id_handle_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_destroy_request_id_handle"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_destroy_request_id_handle"); RCLdotnetDelegates.native_rcl_destroy_request_id_handle = (NativeRCLDestroyRequestIdHandleType)Marshal.GetDelegateForFunctionPointer( native_rcl_destroy_request_id_handle_ptr, typeof(NativeRCLDestroyRequestIdHandleType)); IntPtr native_rcl_request_id_get_sequence_number_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_request_id_get_sequence_number"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_request_id_get_sequence_number"); RCLdotnetDelegates.native_rcl_request_id_get_sequence_number = (NativeRCLRequestIdGetSequenceNumberType)Marshal.GetDelegateForFunctionPointer( native_rcl_request_id_get_sequence_number_ptr, typeof(NativeRCLRequestIdGetSequenceNumberType)); IntPtr native_rcl_take_request_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_take_request"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_take_request"); RCLdotnetDelegates.native_rcl_take_request = (NativeRCLTakeRequestType)Marshal.GetDelegateForFunctionPointer( native_rcl_take_request_ptr, typeof(NativeRCLTakeRequestType)); IntPtr native_rcl_send_response_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_send_response"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_send_response"); RCLdotnetDelegates.native_rcl_send_response = (NativeRCLSendResponseType)Marshal.GetDelegateForFunctionPointer( native_rcl_send_response_ptr, typeof(NativeRCLSendResponseType)); IntPtr native_rcl_take_response_ptr = - dllLoadUtils.GetProcAddress(pDll, "native_rcl_take_response"); + _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_take_response"); RCLdotnetDelegates.native_rcl_take_response = (NativeRCLTakeResponseType)Marshal.GetDelegateForFunctionPointer( native_rcl_take_response_ptr, typeof(NativeRCLTakeResponseType)); @@ -316,8 +315,8 @@ private static SafeWaitSetHandle CreateWaitSet( { var waitSetHandle = new SafeWaitSetHandle(); RCLRet ret = RCLdotnetDelegates.native_rcl_create_wait_set_handle( - ref waitSetHandle, numberOfSubscriptions, numberOfGuardConditions, - numberOfTimers, numberOfClients, numberOfServices, numberOfEvents); + ref waitSetHandle, numberOfSubscriptions, numberOfGuardConditions, + numberOfTimers, numberOfClients, numberOfServices, numberOfEvents); if (ret != RCLRet.Ok) { waitSetHandle.Dispose(); @@ -359,8 +358,8 @@ private static void WaitSetAddClient(SafeWaitSetHandle waitSetHandle, SafeClient /// True if wait set is ready, False on timeout. private static bool Wait(SafeWaitSetHandle waitSetHandle, long timeout) { - long ns_timeout = timeout * 1000000; - RCLRet ret = RCLdotnetDelegates.native_rcl_wait(waitSetHandle, ns_timeout); + long nsTimeout = timeout * 1000000; + RCLRet ret = RCLdotnetDelegates.native_rcl_wait(waitSetHandle, nsTimeout); if (ret == RCLRet.Ok || ret == RCLRet.Timeout) { return ret == RCLRet.Ok; diff --git a/rcldotnet/Subscription.cs b/rcldotnet/Subscription.cs index 0cd7211a..cc639f37 100644 --- a/rcldotnet/Subscription.cs +++ b/rcldotnet/Subscription.cs @@ -46,12 +46,12 @@ internal Subscription() public class Subscription : Subscription where T : IRosMessage, new() { - private readonly Action callback_; + private readonly Action _callback; internal Subscription(SafeSubscriptionHandle handle, Action callback) { Handle = handle; - callback_ = callback; + _callback = callback; } internal override SafeSubscriptionHandle Handle { get; } @@ -62,7 +62,7 @@ internal Subscription(SafeSubscriptionHandle handle, Action callback) internal override void TriggerCallback(IRosMessage message) { - callback_((T)message); + _callback((T)message); } } } diff --git a/rcldotnet/test/test_messages.cs b/rcldotnet/test/test_messages.cs index a344152f..39d27eb3 100644 --- a/rcldotnet/test/test_messages.cs +++ b/rcldotnet/test/test_messages.cs @@ -12,29 +12,29 @@ public class TestMessages public void TestPublishString() { RCLdotnet.Init(); - Node node_string_1 = RCLdotnet.CreateNode("test_string_1"); - Node node_string_2 = RCLdotnet.CreateNode("test_string_2"); - Publisher chatter_pub = node_string_1.CreatePublisher("topic_string"); + Node nodeString1 = RCLdotnet.CreateNode("test_string_1"); + Node nodeString2 = RCLdotnet.CreateNode("test_string_2"); + Publisher chatterPub = nodeString1.CreatePublisher("topic_string"); std_msgs.msg.String msg = new std_msgs.msg.String(); std_msgs.msg.String msg2 = new std_msgs.msg.String(); msg.Data = "Hello"; bool received = false; - Subscription chatter_sub = node_string_2.CreateSubscription( - "topic_string", rcv_msg => + Subscription chatter_sub = nodeString2.CreateSubscription( + "topic_string", rcvMsg => { received = true; - msg2 = rcv_msg; + msg2 = rcvMsg; } ); while (!received) { - chatter_pub.Publish(msg); + chatterPub.Publish(msg); - RCLdotnet.SpinOnce(node_string_1, 500); - RCLdotnet.SpinOnce(node_string_2, 500); + RCLdotnet.SpinOnce(nodeString1, 500); + RCLdotnet.SpinOnce(nodeString2, 500); } Assert.Equal("Hello", msg2.Data); } @@ -43,9 +43,9 @@ public void TestPublishString() public void TestPublishBuiltins() { RCLdotnet.Init(); - Node node_builtins_1 = RCLdotnet.CreateNode("test_builtins_1"); - Node node_builtins_2 = RCLdotnet.CreateNode("test_builtins_2"); - Publisher chatter_pub = node_builtins_1.CreatePublisher("topic_builtins"); + Node nodeBuiltins1 = RCLdotnet.CreateNode("test_builtins_1"); + Node nodeBuiltins2 = RCLdotnet.CreateNode("test_builtins_2"); + Publisher chatterPub = nodeBuiltins1.CreatePublisher("topic_builtins"); test_msgs.msg.Builtins msg = new test_msgs.msg.Builtins(); test_msgs.msg.Builtins msg2 = new test_msgs.msg.Builtins(); @@ -55,20 +55,20 @@ public void TestPublishBuiltins() msg.TimeValue.Nanosec = 4u; bool received = false; - Subscription chatter_sub = node_builtins_2.CreateSubscription( - "topic_builtins", rcv_msg => + Subscription chatterSub = nodeBuiltins2.CreateSubscription( + "topic_builtins", rcvMsg => { received = true; - msg2 = rcv_msg; + msg2 = rcvMsg; } ); while (!received) { - chatter_pub.Publish(msg); + chatterPub.Publish(msg); - RCLdotnet.SpinOnce(node_builtins_1, 500); - RCLdotnet.SpinOnce(node_builtins_2, 500); + RCLdotnet.SpinOnce(nodeBuiltins1, 500); + RCLdotnet.SpinOnce(nodeBuiltins2, 500); } Assert.Equal(1, msg2.DurationValue.Sec); @@ -81,9 +81,9 @@ public void TestPublishBuiltins() public void TestPublishArrays() { RCLdotnet.Init(); - Node node_array_1 = RCLdotnet.CreateNode("test_arrays_1"); - Node node_array_2 = RCLdotnet.CreateNode("test_arrays_2"); - Publisher chatter_pub = node_array_1.CreatePublisher("topic_array"); + Node nodeArray1 = RCLdotnet.CreateNode("test_arrays_1"); + Node nodeArray2 = RCLdotnet.CreateNode("test_arrays_2"); + Publisher chatterPub = nodeArray1.CreatePublisher("topic_array"); test_msgs.msg.Arrays msg = new test_msgs.msg.Arrays(); test_msgs.msg.Arrays msg2 = new test_msgs.msg.Arrays(); @@ -159,70 +159,70 @@ public void TestPublishArrays() msg.StringValues[2] = "three"; // basicTypesValues - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues[0] = basic_type_1; - msg.BasicTypesValues[1] = basic_type_2; - msg.BasicTypesValues[2] = basic_type_3; + test_msgs.msg.BasicTypes basicType1 = new test_msgs.msg.BasicTypes(); + basicType1.BoolValue = true; + basicType1.ByteValue = 36; + basicType1.CharValue = 37; + basicType1.Float32Value = 38.1f; + basicType1.Float64Value = 39.1; + basicType1.Int8Value = 40; + basicType1.Uint8Value = 41; + basicType1.Int16Value = 42; + basicType1.Uint16Value = 43; + basicType1.Int32Value = 44; + basicType1.Uint32Value = 45; + basicType1.Int64Value = 46; + basicType1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basicType2 = new test_msgs.msg.BasicTypes(); + basicType2.BoolValue = false; + basicType2.ByteValue = 48; + basicType2.CharValue = 49; + basicType2.Float32Value = 50.1f; + basicType2.Float64Value = 51.1; + basicType2.Int8Value = 52; + basicType2.Uint8Value = 53; + basicType2.Int16Value = 54; + basicType2.Uint16Value = 55; + basicType2.Int32Value = 56; + basicType2.Uint32Value = 57; + basicType2.Int64Value = 58; + basicType2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basicType3 = new test_msgs.msg.BasicTypes(); + basicType3.BoolValue = true; + basicType3.ByteValue = 60; + basicType3.CharValue = 61; + basicType3.Float32Value = 62.1f; + basicType3.Float64Value = 63.1; + basicType3.Int8Value = 64; + basicType3.Uint8Value = 65; + basicType3.Int16Value = 66; + basicType3.Uint16Value = 67; + basicType3.Int32Value = 68; + basicType3.Uint32Value = 69; + basicType3.Int64Value = 70; + basicType3.Uint64Value = 71; + + msg.BasicTypesValues[0] = basicType1; + msg.BasicTypesValues[1] = basicType2; + msg.BasicTypesValues[2] = basicType3; bool received = false; - Subscription chatter_sub = node_array_2.CreateSubscription( - "topic_array", rcv_msg => + Subscription chatterSub = nodeArray2.CreateSubscription( + "topic_array", rcvMsg => { received = true; - msg2 = rcv_msg; + msg2 = rcvMsg; } ); while (!received) { - chatter_pub.Publish(msg); + chatterPub.Publish(msg); - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); + RCLdotnet.SpinOnce(nodeArray1, 500); + RCLdotnet.SpinOnce(nodeArray2, 500); } // boolValues @@ -412,9 +412,9 @@ public void TestPublishArraysSizeCheckToMuch() public void TestPublishUnboundedSequences() { RCLdotnet.Init(); - Node node_array_1 = RCLdotnet.CreateNode("test_unbounded_sequences_1"); - Node node_array_2 = RCLdotnet.CreateNode("test_unbounded_sequences_2"); - Publisher chatter_pub = node_array_1.CreatePublisher("topic_unbounded_sequences"); + Node nodeArray1 = RCLdotnet.CreateNode("test_unbounded_sequences_1"); + Node nodeArray2 = RCLdotnet.CreateNode("test_unbounded_sequences_2"); + Publisher chatterPub = nodeArray1.CreatePublisher("topic_unbounded_sequences"); test_msgs.msg.UnboundedSequences msg = new test_msgs.msg.UnboundedSequences(); test_msgs.msg.UnboundedSequences msg2 = new test_msgs.msg.UnboundedSequences(); @@ -489,70 +489,70 @@ public void TestPublishUnboundedSequences() msg.StringValues.Add("two"); msg.StringValues.Add("three"); - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues.Add(basic_type_1); - msg.BasicTypesValues.Add(basic_type_2); - msg.BasicTypesValues.Add(basic_type_3); + test_msgs.msg.BasicTypes basicType1 = new test_msgs.msg.BasicTypes(); + basicType1.BoolValue = true; + basicType1.ByteValue = 36; + basicType1.CharValue = 37; + basicType1.Float32Value = 38.1f; + basicType1.Float64Value = 39.1; + basicType1.Int8Value = 40; + basicType1.Uint8Value = 41; + basicType1.Int16Value = 42; + basicType1.Uint16Value = 43; + basicType1.Int32Value = 44; + basicType1.Uint32Value = 45; + basicType1.Int64Value = 46; + basicType1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basicType2 = new test_msgs.msg.BasicTypes(); + basicType2.BoolValue = false; + basicType2.ByteValue = 48; + basicType2.CharValue = 49; + basicType2.Float32Value = 50.1f; + basicType2.Float64Value = 51.1; + basicType2.Int8Value = 52; + basicType2.Uint8Value = 53; + basicType2.Int16Value = 54; + basicType2.Uint16Value = 55; + basicType2.Int32Value = 56; + basicType2.Uint32Value = 57; + basicType2.Int64Value = 58; + basicType2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basicType3 = new test_msgs.msg.BasicTypes(); + basicType3.BoolValue = true; + basicType3.ByteValue = 60; + basicType3.CharValue = 61; + basicType3.Float32Value = 62.1f; + basicType3.Float64Value = 63.1; + basicType3.Int8Value = 64; + basicType3.Uint8Value = 65; + basicType3.Int16Value = 66; + basicType3.Uint16Value = 67; + basicType3.Int32Value = 68; + basicType3.Uint32Value = 69; + basicType3.Int64Value = 70; + basicType3.Uint64Value = 71; + + msg.BasicTypesValues.Add(basicType1); + msg.BasicTypesValues.Add(basicType2); + msg.BasicTypesValues.Add(basicType3); bool received = false; - Subscription chatter_sub = node_array_2.CreateSubscription( - "topic_unbounded_sequences", rcv_msg => + Subscription chatterSub = nodeArray2.CreateSubscription( + "topic_unbounded_sequences", rcvMsg => { received = true; - msg2 = rcv_msg; + msg2 = rcvMsg; } ); while (!received) { - chatter_pub.Publish(msg); + chatterPub.Publish(msg); - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); + RCLdotnet.SpinOnce(nodeArray1, 500); + RCLdotnet.SpinOnce(nodeArray2, 500); } // boolValues @@ -687,9 +687,9 @@ public void TestPublishUnboundedSequences() public void TestPublishBoundedSequences() { RCLdotnet.Init(); - Node node_array_1 = RCLdotnet.CreateNode("test_bounded_sequences_1"); - Node node_array_2 = RCLdotnet.CreateNode("test_bounded_sequences_2"); - Publisher chatter_pub = node_array_1.CreatePublisher("topic_bounded_sequences"); + Node nodeBoundedSequences1 = RCLdotnet.CreateNode("test_bounded_sequences_1"); + Node nodeBoundedSequences2 = RCLdotnet.CreateNode("test_bounded_sequences_2"); + Publisher chatter_pub = nodeBoundedSequences1.CreatePublisher("topic_bounded_sequences"); test_msgs.msg.BoundedSequences msg = new test_msgs.msg.BoundedSequences(); test_msgs.msg.BoundedSequences msg2 = new test_msgs.msg.BoundedSequences(); @@ -764,61 +764,61 @@ public void TestPublishBoundedSequences() msg.StringValues.Add("two"); msg.StringValues.Add("three"); - test_msgs.msg.BasicTypes basic_type_1 = new test_msgs.msg.BasicTypes(); - basic_type_1.BoolValue = true; - basic_type_1.ByteValue = 36; - basic_type_1.CharValue = 37; - basic_type_1.Float32Value = 38.1f; - basic_type_1.Float64Value = 39.1; - basic_type_1.Int8Value = 40; - basic_type_1.Uint8Value = 41; - basic_type_1.Int16Value = 42; - basic_type_1.Uint16Value = 43; - basic_type_1.Int32Value = 44; - basic_type_1.Uint32Value = 45; - basic_type_1.Int64Value = 46; - basic_type_1.Uint64Value = 47; - - test_msgs.msg.BasicTypes basic_type_2 = new test_msgs.msg.BasicTypes(); - basic_type_2.BoolValue = false; - basic_type_2.ByteValue = 48; - basic_type_2.CharValue = 49; - basic_type_2.Float32Value = 50.1f; - basic_type_2.Float64Value = 51.1; - basic_type_2.Int8Value = 52; - basic_type_2.Uint8Value = 53; - basic_type_2.Int16Value = 54; - basic_type_2.Uint16Value = 55; - basic_type_2.Int32Value = 56; - basic_type_2.Uint32Value = 57; - basic_type_2.Int64Value = 58; - basic_type_2.Uint64Value = 59; - - test_msgs.msg.BasicTypes basic_type_3 = new test_msgs.msg.BasicTypes(); - basic_type_3.BoolValue = true; - basic_type_3.ByteValue = 60; - basic_type_3.CharValue = 61; - basic_type_3.Float32Value = 62.1f; - basic_type_3.Float64Value = 63.1; - basic_type_3.Int8Value = 64; - basic_type_3.Uint8Value = 65; - basic_type_3.Int16Value = 66; - basic_type_3.Uint16Value = 67; - basic_type_3.Int32Value = 68; - basic_type_3.Uint32Value = 69; - basic_type_3.Int64Value = 70; - basic_type_3.Uint64Value = 71; - - msg.BasicTypesValues.Add(basic_type_1); - msg.BasicTypesValues.Add(basic_type_2); - msg.BasicTypesValues.Add(basic_type_3); + test_msgs.msg.BasicTypes basicType1 = new test_msgs.msg.BasicTypes(); + basicType1.BoolValue = true; + basicType1.ByteValue = 36; + basicType1.CharValue = 37; + basicType1.Float32Value = 38.1f; + basicType1.Float64Value = 39.1; + basicType1.Int8Value = 40; + basicType1.Uint8Value = 41; + basicType1.Int16Value = 42; + basicType1.Uint16Value = 43; + basicType1.Int32Value = 44; + basicType1.Uint32Value = 45; + basicType1.Int64Value = 46; + basicType1.Uint64Value = 47; + + test_msgs.msg.BasicTypes basicType2 = new test_msgs.msg.BasicTypes(); + basicType2.BoolValue = false; + basicType2.ByteValue = 48; + basicType2.CharValue = 49; + basicType2.Float32Value = 50.1f; + basicType2.Float64Value = 51.1; + basicType2.Int8Value = 52; + basicType2.Uint8Value = 53; + basicType2.Int16Value = 54; + basicType2.Uint16Value = 55; + basicType2.Int32Value = 56; + basicType2.Uint32Value = 57; + basicType2.Int64Value = 58; + basicType2.Uint64Value = 59; + + test_msgs.msg.BasicTypes basicType3 = new test_msgs.msg.BasicTypes(); + basicType3.BoolValue = true; + basicType3.ByteValue = 60; + basicType3.CharValue = 61; + basicType3.Float32Value = 62.1f; + basicType3.Float64Value = 63.1; + basicType3.Int8Value = 64; + basicType3.Uint8Value = 65; + basicType3.Int16Value = 66; + basicType3.Uint16Value = 67; + basicType3.Int32Value = 68; + basicType3.Uint32Value = 69; + basicType3.Int64Value = 70; + basicType3.Uint64Value = 71; + + msg.BasicTypesValues.Add(basicType1); + msg.BasicTypesValues.Add(basicType2); + msg.BasicTypesValues.Add(basicType3); bool received = false; - Subscription chatter_sub = node_array_2.CreateSubscription( - "topic_bounded_sequences", rcv_msg => + Subscription chatterSub = nodeBoundedSequences2.CreateSubscription( + "topic_bounded_sequences", rcvMsg => { received = true; - msg2 = rcv_msg; + msg2 = rcvMsg; } ); @@ -826,8 +826,8 @@ public void TestPublishBoundedSequences() { chatter_pub.Publish(msg); - RCLdotnet.SpinOnce(node_array_1, 500); - RCLdotnet.SpinOnce(node_array_2, 500); + RCLdotnet.SpinOnce(nodeBoundedSequences1, 500); + RCLdotnet.SpinOnce(nodeBoundedSequences2, 500); } // boolValues diff --git a/rcldotnet_examples/RCLDotnetListener.cs b/rcldotnet_examples/RCLDotnetListener.cs index 62da2ed6..9a98330e 100644 --- a/rcldotnet_examples/RCLDotnetListener.cs +++ b/rcldotnet_examples/RCLDotnetListener.cs @@ -12,7 +12,7 @@ public static void Main(string[] args) Node node = RCLdotnet.CreateNode("listener"); - Subscription chatter_sub = node.CreateSubscription( + Subscription chatterSub = node.CreateSubscription( "chatter", msg => Console.WriteLine("I heard: [" + msg.Data + "]")); RCLdotnet.Spin(node); diff --git a/rcldotnet_examples/RCLDotnetTalker.cs b/rcldotnet_examples/RCLDotnetTalker.cs index 9208f2d7..89de127c 100644 --- a/rcldotnet_examples/RCLDotnetTalker.cs +++ b/rcldotnet_examples/RCLDotnetTalker.cs @@ -13,7 +13,7 @@ public static void Main(string[] args) Node node = RCLdotnet.CreateNode("talker"); - Publisher chatter_pub = node.CreatePublisher("chatter"); + Publisher chatterPub = node.CreatePublisher("chatter"); std_msgs.msg.String msg = new std_msgs.msg.String(); @@ -24,7 +24,7 @@ public static void Main(string[] args) msg.Data = "Hello World: " + i; i++; Console.WriteLine("Publishing: \"" + msg.Data + "\""); - chatter_pub.Publish(msg); + chatterPub.Publish(msg); // Sleep a little bit between each message Thread.Sleep(1000); From 217d522c2e6743c0af827154343163ba0de87ee9 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Wed, 15 Jun 2022 15:52:07 +0200 Subject: [PATCH 4/4] fix xunit waring --- rcldotnet/test/test_messages.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcldotnet/test/test_messages.cs b/rcldotnet/test/test_messages.cs index 39d27eb3..0b82d71e 100644 --- a/rcldotnet/test/test_messages.cs +++ b/rcldotnet/test/test_messages.cs @@ -998,7 +998,7 @@ public void TestDefaults() { var defaultsMsg = new test_msgs.msg.Defaults(); - Assert.Equal(true, defaultsMsg.BoolValue); + Assert.True(defaultsMsg.BoolValue); Assert.Equal(50, defaultsMsg.ByteValue); Assert.Equal(100, defaultsMsg.CharValue); Assert.Equal(1.125f, defaultsMsg.Float32Value);