From 06606d60f2b524f28842cca1d5889ceeb25163c6 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Thu, 24 Feb 2022 19:12:15 +0100 Subject: [PATCH 01/12] iox-#1142 Add first findService example Signed-off-by: Marika Lehmann --- doc/website/examples/icediscovery.md | 2 +- doc/website/examples/icediscovery_in_c.md | 5 + iceoryx_examples/README.md | 1 + .../icediscovery_in_c/CMakeLists.txt | 54 ++++++++ .../icediscovery_in_c/iox_c_find_service.c | 83 ++++++++++++ .../icediscovery_in_c/iox_c_offer_service.c | 89 +++++++++++++ .../icediscovery_in_c/sleep_for.h | 37 ++++++ iceoryx_integrationtest/CMakeLists.txt | 3 +- .../test_icediscovery_in_c_example.py | 119 ++++++++++++++++++ iceoryx_meta/CMakeLists.txt | 3 +- 10 files changed, 393 insertions(+), 3 deletions(-) create mode 100644 doc/website/examples/icediscovery_in_c.md create mode 100644 iceoryx_examples/icediscovery_in_c/CMakeLists.txt create mode 100644 iceoryx_examples/icediscovery_in_c/iox_c_find_service.c create mode 100644 iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c create mode 100644 iceoryx_examples/icediscovery_in_c/sleep_for.h create mode 100644 iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py diff --git a/doc/website/examples/icediscovery.md b/doc/website/examples/icediscovery.md index 376287657e..8820cef30a 100644 --- a/doc/website/examples/icediscovery.md +++ b/doc/website/examples/icediscovery.md @@ -1,5 +1,5 @@ --- -title: Searching for currently available services +title: Searching for currently available services using C++ --- {! ../iceoryx/iceoryx_examples/icediscovery/README.md !} diff --git a/doc/website/examples/icediscovery_in_c.md b/doc/website/examples/icediscovery_in_c.md new file mode 100644 index 0000000000..de0d67a29a --- /dev/null +++ b/doc/website/examples/icediscovery_in_c.md @@ -0,0 +1,5 @@ +--- +title: Searching for currently available services using C +--- + +{! ../iceoryx/iceoryx_examples/icediscovery/README.md !} diff --git a/iceoryx_examples/README.md b/iceoryx_examples/README.md index 24c050e6d1..5bbb4dbc26 100644 --- a/iceoryx_examples/README.md +++ b/iceoryx_examples/README.md @@ -18,6 +18,7 @@ |[singleprocess](./singleprocess/) | Communicating in a single process between threads | :star::star: | |[user_header](./user_header/) | Using a user-header for additional meta-information like timestamps | :star::star: | |[icediscovery](./icediscovery) | Searching for currently available services | :star::star: | +|[icediscovery_in_c](./icediscovery_in_c/) | Searching for currently available services using C | :star::star: | |[ice_access_control](./ice_access_control/) | Configuring access rights for shared memory segments | :star::star::star: | |[iceperf](./iceperf/) | Measuring the latency of different IPC mechanisms | :star::star::star: | |[icecrystal](./icecrystal/) | Using the introspection client for debugging | :star::star::star: | diff --git a/iceoryx_examples/icediscovery_in_c/CMakeLists.txt b/iceoryx_examples/icediscovery_in_c/CMakeLists.txt new file mode 100644 index 0000000000..503403cedd --- /dev/null +++ b/iceoryx_examples/icediscovery_in_c/CMakeLists.txt @@ -0,0 +1,54 @@ +# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# Build icediscovery example +cmake_minimum_required(VERSION 3.16) +project(example_icediscovery_in_c) + +include(GNUInstallDirs) + +find_package(iceoryx_posh CONFIG REQUIRED) +find_package(iceoryx_hoofs CONFIG REQUIRED) +find_package(iceoryx_binding_c CONFIG REQUIRED) + +get_target_property(ICEORYX_CXX_STANDARD iceoryx_posh::iceoryx_posh CXX_STANDARD) +include(IceoryxPlatform) + +add_executable(iox-c-offer-service ./iox_c_offer_service.c) +set_source_files_properties(./ice_c_offer_service.c PROPERTIES LANGUAGE C) +target_link_libraries(iox-c-offer-service + iceoryx_binding_c::iceoryx_binding_c +) +set_target_properties(iox-c-offer-service PROPERTIES + POSITION_INDEPENDENT_CODE ON +) +target_compile_options(iox-c-offer-service PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS}) + +add_executable(iox-c-find-service ./iox_c_find_service.c) +set_source_files_properties(./ice_c_find_service.c PROPERTIES LANGUAGE C) +target_link_libraries(iox-c-find-service + iceoryx_binding_c::iceoryx_binding_c +) +set_target_properties(iox-c-offer-service PROPERTIES + POSITION_INDEPENDENT_CODE ON +) +target_compile_options(iox-c-find-service PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS}) + +# ========================================================== // + +install(TARGETS iox-c-offer-service + iox-c-find-service + RUNTIME DESTINATION bin) diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c new file mode 100644 index 0000000000..5455650107 --- /dev/null +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -0,0 +1,83 @@ +// Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_binding_c/runtime.h" +#include "iceoryx_binding_c/service_discovery.h" +#include "sleep_for.h" + +#include +#include +#include + +bool keepRunning = true; + +const char APP_NAME[] = "iox-c-find-service"; + +static void sigHandler(int signalValue) +{ + // Ignore unused variable warning + (void)signalValue; + // caught SIGINT or SIGTERM, now exit gracefully + keepRunning = false; +} + +void printSearchResult(const iox_service_description_t service) +{ + printf( + "- Service: %s, Instance: %s, Event: %s\n", service.serviceString, service.instanceString, service.eventString); +} + +int main() +{ + signal(SIGINT, sigHandler); + signal(SIGTERM, sigHandler); + + iox_runtime_init(APP_NAME); + + iox_service_discovery_storage_t storage; + iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); + + while (keepRunning) + { + printf("\n=========================================\n"); + + printf("\nSearched for {'Radar', 'FrontLeft', 'Image'}. Found the following services:\n"); + iox_service_discovery_find_service_apply_callable( + serviceDiscovery, "Radar", "FrontLeft", "Image", printSearchResult, MessagingPattern_PUB_SUB); + + printf("\nSearched for {'Radar', *, *}. Found the following services:\n"); + iox_service_discovery_find_service_apply_callable( + serviceDiscovery, "Radar", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); + + printf("\nSearched for {*, 'FrontLeft', *}. Found the following services:\n"); + iox_service_discovery_find_service_apply_callable( + serviceDiscovery, NULL, "FrontLeft", NULL, printSearchResult, MessagingPattern_PUB_SUB); + + printf("\nSearched for {*, 'FrontRight', 'Image'}. Found the following services:\n"); + iox_service_discovery_find_service_apply_callable( + serviceDiscovery, NULL, "FrontRight", "Image", printSearchResult, MessagingPattern_PUB_SUB); + + printf("\nSearched for {'Camera', *, *}. Found the following services:\n"); + iox_service_discovery_find_service_apply_callable( + serviceDiscovery, "Camera", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); + + sleep_for(1000); + } + + iox_service_discovery_deinit(serviceDiscovery); + + return 0; +} diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c new file mode 100644 index 0000000000..d12684cdcb --- /dev/null +++ b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c @@ -0,0 +1,89 @@ +// Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_binding_c/publisher.h" +#include "iceoryx_binding_c/runtime.h" +#include "sleep_for.h" + +#include +#include + +bool keepRunning = true; + +const char APP_NAME[] = "iox-c-offer-service"; + +static void sigHandler(int signalValue) +{ + // Ignore unused variable warning + (void)signalValue; + // caught SIGINT or SIGTERM, now exit gracefully + keepRunning = false; +} + +int main() +{ + signal(SIGINT, sigHandler); + signal(SIGTERM, sigHandler); + + iox_runtime_init(APP_NAME); + + iox_pub_storage_t publisherStorage; + iox_pub_options_t options; + iox_pub_options_init(&options); + iox_pub_t radarLeft = iox_pub_init(&publisherStorage, "Radar", "FrontLeft", "Image", &options); + iox_pub_t radarRight = iox_pub_init(&publisherStorage, "Radar", "FrontRight", "Image", &options); + iox_pub_t lidarLeft = iox_pub_init(&publisherStorage, "Lidar", "FrontLeft", "Counter", &options); + + const int numberCameraPublishers = 5; + iox_pub_storage_t cameraPublisherStorage[numberCameraPublishers]; + iox_pub_t cameraPublishers[numberCameraPublishers]; + cameraPublishers[0] = iox_pub_init(&cameraPublisherStorage[0], "Camera", "FrontLeft", "Counter", &options); + cameraPublishers[1] = iox_pub_init(&cameraPublisherStorage[1], "Camera", "FrontLeft", "Image", &options); + cameraPublishers[2] = iox_pub_init(&cameraPublisherStorage[2], "Camera", "FrontRight", "Counter", &options); + cameraPublishers[3] = iox_pub_init(&cameraPublisherStorage[3], "Camera", "FrontRight", "Image", &options); + cameraPublishers[4] = iox_pub_init(&cameraPublisherStorage[4], "Camera", "BackLeft", "Image", &options); + + bool offer = false; + while (keepRunning) + { + if (offer) + { + for (int i = 0; i < numberCameraPublishers; ++i) + { + iox_pub_offer(cameraPublishers[i]); + } + } + else + { + for (int i = 0; i < numberCameraPublishers; ++i) + { + iox_pub_stop_offer(cameraPublishers[i]); + } + } + offer = !offer; + sleep_for(1000); + } + + iox_pub_deinit(radarLeft); + iox_pub_deinit(radarRight); + iox_pub_deinit(lidarLeft); + for (int i = 0; i < numberCameraPublishers; ++i) + { + iox_pub_deinit(cameraPublishers[i]); + } + + return 0; +} diff --git a/iceoryx_examples/icediscovery_in_c/sleep_for.h b/iceoryx_examples/icediscovery_in_c/sleep_for.h new file mode 100644 index 0000000000..1a57d870fd --- /dev/null +++ b/iceoryx_examples/icediscovery_in_c/sleep_for.h @@ -0,0 +1,37 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#ifndef IOX_BINDING_C_SLEEP_FOR_H +#define IOX_BINDING_C_SLEEP_FOR_H + +#ifdef _WIN32 +#include + +void sleep_for(uint32_t milliseconds) +{ + Sleep((uint64_t)milliseconds); +} + +#else +#include + +void sleep_for(uint32_t milliseconds) +{ + usleep(milliseconds * 1000U); +} +#endif + +#endif diff --git a/iceoryx_integrationtest/CMakeLists.txt b/iceoryx_integrationtest/CMakeLists.txt index 211e1114ef..7389e43b49 100644 --- a/iceoryx_integrationtest/CMakeLists.txt +++ b/iceoryx_integrationtest/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +# Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of @@ -41,6 +41,7 @@ if(BUILD_TESTING) add_ros_test(iceoryx_integrationtest/test_request_response_basic.py) add_ros_test(iceoryx_integrationtest/test_request_response_listener.py) add_ros_test(iceoryx_integrationtest/test_request_response_untyped.py) + add_ros_test(iceoryx_integrationtest/test_icediscovery_in_c_example.py) endif() diff --git a/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py b/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py new file mode 100644 index 0000000000..da3dad5d2a --- /dev/null +++ b/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py @@ -0,0 +1,119 @@ +# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +import os + +import unittest + +import launch +from launch_ros.substitutions import ExecutableInPackage +import launch_testing +import launch_testing.actions +from launch_testing.asserts import assertSequentialStdout + +import pytest + +# @brief Test goal: "Integrationtest for the icediscovery in C example of iceoryx" +# @pre setup ROS2 launch executables for RouDi (debug mode) and the example processes +# @post check if all applications return exitcode 0 (success) after test run +@pytest.mark.launch_test +def generate_test_description(): + + proc_env = os.environ.copy() + colcon_prefix_path = os.environ.get('COLCON_PREFIX_PATH', '') + # executable_list = ['iox-offer-service', 'iox-find-service'] + # process_list = [] + + # for exec in executable_list: + # tmp_exec = os.path.join( + # colcon_prefix_path, + # 'example_icediscovery/bin/', + # exec) + # tmp_process = launch.actions.ExecuteProcess( + # cmd=[tmp_exec], + # env=proc_env, output='screen') + # process_list.append(tmp_process) + + # print("Process list:", process_list) + + # roudi_executable = os.path.join( + # colcon_prefix_path, + # 'iceoryx_posh/bin/', + # 'iox-roudi' + # ) + # roudi_process = launch.actions.ExecuteProcess( + # cmd=[roudi_executable, '-l', 'debug'], + # env=proc_env, output='screen', + # sigterm_timeout='20') + + # return launch.LaunchDescription([ + # process_list[0], + # process_list[1], + # roudi_process, + # launch_testing.actions.ReadyToTest() + # ]), {'iox-offer-service': process_list[0], 'iox-find-service': process_list[1], + # 'roudi_process': roudi_process} + +# These tests will run concurrently with the dut process. After this test is done, +# the launch system will shut down RouDi + + +class TestIcediscoveryExample(unittest.TestCase): + def test_roudi_ready(self, proc_output): + proc_output.assertWaitFor( + 'RouDi is ready for clients', timeout=45, stream='stdout') + + def test_find_service(self, proc_output): + # proc_output.assertWaitFor( + # 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {\'Camera\', *, *}. Found the following services:\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Counter\n- Service: Camera, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: BackLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', + # timeout=45, stream='stdout') + + # proc_output.assertWaitFor( + # 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image', + # timeout=45, stream='stdout') + # proc_output.assertWaitFor( + # 'Searched for {\'Camera\', *, *}. Found the following services:', + # timeout=45, stream='stdout') + +# These tests run after shutdown and examine the stdout log + + +@ launch_testing.post_shutdown_test() +class TestIcediscoveryExampleExitCodes(unittest.TestCase): + def test_exit_code(self, proc_info): + launch_testing.asserts.assertExitCodes(proc_info) + diff --git a/iceoryx_meta/CMakeLists.txt b/iceoryx_meta/CMakeLists.txt index aba4024f09..c9aec6e00d 100644 --- a/iceoryx_meta/CMakeLists.txt +++ b/iceoryx_meta/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. -# Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. +# Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -72,6 +72,7 @@ if(EXAMPLES) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/waitset_in_c ${CMAKE_BINARY_DIR}/iceoryx_examples/waitset_in_c) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/request_response_in_c ${CMAKE_BINARY_DIR}/iceoryx_examples/request_response_in_c) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/iceperf ${CMAKE_BINARY_DIR}/iceoryx_examples/iceperf) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/icediscovery_in_c ${CMAKE_BINARY_DIR}/iceoryx_examples/icediscovery_in_c) endif() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/waitset ${CMAKE_BINARY_DIR}/iceoryx_examples/waitset) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/callbacks ${CMAKE_BINARY_DIR}/iceoryx_examples/callbacks) From 29d07cce3085e49bdf04be7982d4f30cd065e4e5 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Thu, 24 Feb 2022 21:50:17 +0100 Subject: [PATCH 02/12] iox-#1142 Extend the example Add findService functions without callable and with callable and context data to example Signed-off-by: Marika Lehmann --- .../icediscovery_in_c/iox_c_find_service.c | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 5455650107..4be699802e 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -21,6 +21,7 @@ #include #include #include +#include bool keepRunning = true; @@ -40,6 +41,14 @@ void printSearchResult(const iox_service_description_t service) "- Service: %s, Instance: %s, Event: %s\n", service.serviceString, service.instanceString, service.eventString); } +void searchFrontCameras(const iox_service_description_t service, void* count) +{ + if (strcmp(service.instanceString, "FrontLeft") == 0 || strcmp(service.instanceString, "FrontRight") == 0) + { + ++*(uint64_t*)count; + } +} + int main() { signal(SIGINT, sigHandler); @@ -50,8 +59,16 @@ int main() iox_service_discovery_storage_t storage; iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); + const uint64_t searchResultCapacity = 10U; + iox_service_description_t searchResult[searchResultCapacity]; + uint64_t missedServices = 0U; + uint64_t numberFoundServices = 0U; + + while (keepRunning) { + uint64_t numberFrontCameras = 0U; + printf("\n=========================================\n"); printf("\nSearched for {'Radar', 'FrontLeft', 'Image'}. Found the following services:\n"); @@ -70,9 +87,28 @@ int main() iox_service_discovery_find_service_apply_callable( serviceDiscovery, NULL, "FrontRight", "Image", printSearchResult, MessagingPattern_PUB_SUB); + numberFoundServices = iox_service_discovery_find_service(serviceDiscovery, + "Camera", + NULL, + NULL, + searchResult, + searchResultCapacity, + &missedServices, + MessagingPattern_PUB_SUB); printf("\nSearched for {'Camera', *, *}. Found the following services:\n"); - iox_service_discovery_find_service_apply_callable( - serviceDiscovery, "Camera", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); + for (uint64_t i = 0; i < numberFoundServices; ++i) + { + printSearchResult(searchResult[i]); + } + + iox_service_discovery_find_service_apply_callable_with_context_data(serviceDiscovery, + "Camera", + NULL, + NULL, + searchFrontCameras, + (void*)&numberFrontCameras, + MessagingPattern_PUB_SUB); + printf("\nFound %lu front cameras\n", numberFrontCameras); sleep_for(1000); } From 7fa46db4fb0701dea443d72fa78a04f38a4bbca4 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Thu, 24 Feb 2022 22:37:10 +0100 Subject: [PATCH 03/12] iox-#1142 Implement integration test Signed-off-by: Marika Lehmann --- .../test_icediscovery_in_c_example.py | 132 +++++++++--------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py b/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py index da3dad5d2a..1935bab4f1 100644 --- a/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py +++ b/iceoryx_integrationtest/iceoryx_integrationtest/test_icediscovery_in_c_example.py @@ -34,38 +34,38 @@ def generate_test_description(): proc_env = os.environ.copy() colcon_prefix_path = os.environ.get('COLCON_PREFIX_PATH', '') - # executable_list = ['iox-offer-service', 'iox-find-service'] - # process_list = [] - - # for exec in executable_list: - # tmp_exec = os.path.join( - # colcon_prefix_path, - # 'example_icediscovery/bin/', - # exec) - # tmp_process = launch.actions.ExecuteProcess( - # cmd=[tmp_exec], - # env=proc_env, output='screen') - # process_list.append(tmp_process) - - # print("Process list:", process_list) - - # roudi_executable = os.path.join( - # colcon_prefix_path, - # 'iceoryx_posh/bin/', - # 'iox-roudi' - # ) - # roudi_process = launch.actions.ExecuteProcess( - # cmd=[roudi_executable, '-l', 'debug'], - # env=proc_env, output='screen', - # sigterm_timeout='20') - - # return launch.LaunchDescription([ - # process_list[0], - # process_list[1], - # roudi_process, - # launch_testing.actions.ReadyToTest() - # ]), {'iox-offer-service': process_list[0], 'iox-find-service': process_list[1], - # 'roudi_process': roudi_process} + executable_list = ['iox-c-offer-service', 'iox-c-find-service'] + process_list = [] + + for exec in executable_list: + tmp_exec = os.path.join( + colcon_prefix_path, + 'example_icediscovery_in_c/bin/', + exec) + tmp_process = launch.actions.ExecuteProcess( + cmd=[tmp_exec], + env=proc_env, output='screen') + process_list.append(tmp_process) + + print("Process list:", process_list) + + roudi_executable = os.path.join( + colcon_prefix_path, + 'iceoryx_posh/bin/', + 'iox-roudi' + ) + roudi_process = launch.actions.ExecuteProcess( + cmd=[roudi_executable, '-l', 'debug'], + env=proc_env, output='screen', + sigterm_timeout='20') + + return launch.LaunchDescription([ + process_list[0], + process_list[1], + roudi_process, + launch_testing.actions.ReadyToTest() + ]), {'iox-c-offer-service': process_list[0], 'iox-c-find-service': process_list[1], + 'roudi_process': roudi_process} # These tests will run concurrently with the dut process. After this test is done, # the launch system will shut down RouDi @@ -77,37 +77,43 @@ def test_roudi_ready(self, proc_output): 'RouDi is ready for clients', timeout=45, stream='stdout') def test_find_service(self, proc_output): - # proc_output.assertWaitFor( - # 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {\'Camera\', *, *}. Found the following services:\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Counter\n- Service: Camera, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: BackLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', - # timeout=45, stream='stdout') - - # proc_output.assertWaitFor( - # 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image', - # timeout=45, stream='stdout') - # proc_output.assertWaitFor( - # 'Searched for {\'Camera\', *, *}. Found the following services:', - # timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {\'Camera\', *, *}. Found the following services:\n- Service: Camera, Instance: FrontLeft, Event: Image\n- Service: Camera, Instance: FrontRight, Event: Counter\n- Service: Camera, Instance: FrontRight, Event: Image\n- Service: Camera, Instance: BackLeft, Event: Image\n- Service: Camera, Instance: FrontLeft, Event: Counter', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Found 4 front cameras', + timeout=45, stream='stdout') + + proc_output.assertWaitFor( + 'Searched for {\'Radar\', \'FrontLeft\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {\'Radar\', *, *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Radar, Instance: FrontRight, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {*, \'FrontLeft\', *}. Found the following services:\n- Service: Radar, Instance: FrontLeft, Event: Image\n- Service: Lidar, Instance: FrontLeft, Event: Counter', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {*, \'FrontRight\', \'Image\'}. Found the following services:\n- Service: Radar, Instance: FrontRight, Event: Image', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Searched for {\'Camera\', *, *}. Found the following services:', + timeout=45, stream='stdout') + proc_output.assertWaitFor( + 'Found 0 front cameras', + timeout=45, stream='stdout') # These tests run after shutdown and examine the stdout log From e0e16b8946474ef382a6166ef9e12947a82d8ebd Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Thu, 24 Feb 2022 22:48:58 +0100 Subject: [PATCH 04/12] iox-#1142 Use #define to define constants Signed-off-by: Marika Lehmann --- .../icediscovery_in_c/iox_c_find_service.c | 7 ++++--- .../icediscovery_in_c/iox_c_offer_service.c | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 4be699802e..49120e1f53 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -23,6 +23,8 @@ #include #include +#define SEARCH_RESULT_CAPACITY 10 + bool keepRunning = true; const char APP_NAME[] = "iox-c-find-service"; @@ -59,8 +61,7 @@ int main() iox_service_discovery_storage_t storage; iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); - const uint64_t searchResultCapacity = 10U; - iox_service_description_t searchResult[searchResultCapacity]; + iox_service_description_t searchResult[SEARCH_RESULT_CAPACITY]; uint64_t missedServices = 0U; uint64_t numberFoundServices = 0U; @@ -92,7 +93,7 @@ int main() NULL, NULL, searchResult, - searchResultCapacity, + SEARCH_RESULT_CAPACITY, &missedServices, MessagingPattern_PUB_SUB); printf("\nSearched for {'Camera', *, *}. Found the following services:\n"); diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c index d12684cdcb..621e74a159 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c @@ -21,6 +21,8 @@ #include #include +#define NUMBER_OF_CAMERA_PUBLISHERS 5 + bool keepRunning = true; const char APP_NAME[] = "iox-c-offer-service"; @@ -47,9 +49,8 @@ int main() iox_pub_t radarRight = iox_pub_init(&publisherStorage, "Radar", "FrontRight", "Image", &options); iox_pub_t lidarLeft = iox_pub_init(&publisherStorage, "Lidar", "FrontLeft", "Counter", &options); - const int numberCameraPublishers = 5; - iox_pub_storage_t cameraPublisherStorage[numberCameraPublishers]; - iox_pub_t cameraPublishers[numberCameraPublishers]; + iox_pub_storage_t cameraPublisherStorage[NUMBER_OF_CAMERA_PUBLISHERS]; + iox_pub_t cameraPublishers[NUMBER_OF_CAMERA_PUBLISHERS]; cameraPublishers[0] = iox_pub_init(&cameraPublisherStorage[0], "Camera", "FrontLeft", "Counter", &options); cameraPublishers[1] = iox_pub_init(&cameraPublisherStorage[1], "Camera", "FrontLeft", "Image", &options); cameraPublishers[2] = iox_pub_init(&cameraPublisherStorage[2], "Camera", "FrontRight", "Counter", &options); @@ -61,14 +62,14 @@ int main() { if (offer) { - for (int i = 0; i < numberCameraPublishers; ++i) + for (int i = 0; i < NUMBER_OF_CAMERA_PUBLISHERS; ++i) { iox_pub_offer(cameraPublishers[i]); } } else { - for (int i = 0; i < numberCameraPublishers; ++i) + for (int i = 0; i < NUMBER_OF_CAMERA_PUBLISHERS; ++i) { iox_pub_stop_offer(cameraPublishers[i]); } @@ -80,7 +81,7 @@ int main() iox_pub_deinit(radarLeft); iox_pub_deinit(radarRight); iox_pub_deinit(lidarLeft); - for (int i = 0; i < numberCameraPublishers; ++i) + for (int i = 0; i < NUMBER_OF_CAMERA_PUBLISHERS; ++i) { iox_pub_deinit(cameraPublishers[i]); } From 20c0303158dafa56a80ecaa439f585f65e5856e1 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Fri, 25 Feb 2022 11:36:11 +0100 Subject: [PATCH 05/12] iox-#1142 Fix macos builds Cast uint64_t to unsigned long to solve macos build failure Signed-off-by: Marika Lehmann --- iceoryx_examples/icediscovery_in_c/iox_c_find_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 49120e1f53..0f25db2f9a 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -109,7 +109,7 @@ int main() searchFrontCameras, (void*)&numberFrontCameras, MessagingPattern_PUB_SUB); - printf("\nFound %lu front cameras\n", numberFrontCameras); + printf("\nFound %lu front cameras\n", (unsigned long)numberFrontCameras); sleep_for(1000); } From 190350b27432e3e51e4043401876b7b57d8c2656 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Fri, 25 Feb 2022 13:49:12 +0100 Subject: [PATCH 06/12] iox-#1142 Use strncmp in example, some renaming Define max string size for service description Signed-off-by: Marika Lehmann --- .../include/iceoryx_binding_c/config.h | 3 +++ .../iceoryx_binding_c/service_description.h | 8 +++++--- .../test/moduletests/test_config.cpp | 2 ++ .../icediscovery_in_c/iox_c_find_service.c | 20 ++++++++----------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/config.h b/iceoryx_binding_c/include/iceoryx_binding_c/config.h index 11128ed6d8..ef23068cf0 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/config.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/config.h @@ -97,4 +97,7 @@ uint32_t iox_cfg_max_runtime_name_length(); /// @brief the maximum size of a node name string + \0 terminator #define IOX_CONFIG_NODE_NAME_SIZE 101 +/// @brief the maximum size of a service description string identifier + \0 terminator +#define IOX_CONFIG_SERVICE_STRING_SIZE 101 + #endif // IOX_BINDING_C_CONFIG_H diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h index 12a5b2bc75..c80f7d2d00 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h @@ -17,13 +17,15 @@ #ifndef IOX_BINDING_C_SERVICE_DESCRIPTION_H #define IOX_BINDING_C_SERVICE_DESCRIPTION_H +#include "iceoryx_binding_c/config.h" + #include typedef struct { - char serviceString[100U]; - char instanceString[100U]; - char eventString[100U]; + char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE]; + char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE]; + char eventString[IOX_CONFIG_SERVICE_STRING_SIZE]; } iox_service_description_t; #endif diff --git a/iceoryx_binding_c/test/moduletests/test_config.cpp b/iceoryx_binding_c/test/moduletests/test_config.cpp index ac738e8e6b..63ae94ba45 100644 --- a/iceoryx_binding_c/test/moduletests/test_config.cpp +++ b/iceoryx_binding_c/test/moduletests/test_config.cpp @@ -58,5 +58,7 @@ TEST(iox_cfg, valuesAreCorrectlyConnected) constexpr uint64_t ZERO_TERMINATOR_SIZE = 1; EXPECT_EQ(IOX_CONFIG_NODE_NAME_SIZE, iox::NodeName_t::capacity() + ZERO_TERMINATOR_SIZE); + + EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity() + ZERO_TERMINATOR_SIZE); } } // namespace diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 0f25db2f9a..177517219d 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -43,11 +43,12 @@ void printSearchResult(const iox_service_description_t service) "- Service: %s, Instance: %s, Event: %s\n", service.serviceString, service.instanceString, service.eventString); } -void searchFrontCameras(const iox_service_description_t service, void* count) +void searchFrontDevices(const iox_service_description_t service, void* count) { - if (strcmp(service.instanceString, "FrontLeft") == 0 || strcmp(service.instanceString, "FrontRight") == 0) + if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0 + || strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0) { - ++*(uint64_t*)count; + ++*(uint32_t*)count; } } @@ -68,7 +69,7 @@ int main() while (keepRunning) { - uint64_t numberFrontCameras = 0U; + uint32_t numberFrontCameras = 0U; printf("\n=========================================\n"); @@ -102,14 +103,9 @@ int main() printSearchResult(searchResult[i]); } - iox_service_discovery_find_service_apply_callable_with_context_data(serviceDiscovery, - "Camera", - NULL, - NULL, - searchFrontCameras, - (void*)&numberFrontCameras, - MessagingPattern_PUB_SUB); - printf("\nFound %lu front cameras\n", (unsigned long)numberFrontCameras); + iox_service_discovery_find_service_apply_callable_with_context_data( + serviceDiscovery, "Camera", NULL, NULL, searchFrontDevices, &numberFrontCameras, MessagingPattern_PUB_SUB); + printf("\nFound %u front cameras\n", numberFrontCameras); sleep_for(1000); } From 671df12a2cec2ec1c89ec20c85c6152d4dae8c37 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Fri, 25 Feb 2022 14:59:05 +0100 Subject: [PATCH 07/12] iox-#1142 Fix service description tests Signed-off-by: Marika Lehmann --- .../test/moduletests/test_service_description.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iceoryx_binding_c/test/moduletests/test_service_description.cpp b/iceoryx_binding_c/test/moduletests/test_service_description.cpp index 7c723963a3..7a17801cb8 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_description.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_description.cpp @@ -34,11 +34,11 @@ TEST(iox_service_description_test, StringSizesAreCorrect) { ::testing::Test::RecordProperty("TEST_ID", "f32a6d19-9ff7-4913-a1d8-39d46267b114"); EXPECT_THAT(sizeof(decltype(std::declval().serviceString)), - Eq(iox::capro::IdString_t().capacity())); + Eq(iox::capro::IdString_t().capacity() + 1U)); EXPECT_THAT(sizeof(decltype(std::declval().instanceString)), - Eq(iox::capro::IdString_t().capacity())); + Eq(iox::capro::IdString_t().capacity() + 1U)); EXPECT_THAT(sizeof(decltype(std::declval().eventString)), - Eq(iox::capro::IdString_t().capacity())); + Eq(iox::capro::IdString_t().capacity() + 1U)); } } // namespace From dab81ba8ae6fd66875d9fd7e2e4b271b03cb1c03 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Fri, 25 Feb 2022 19:43:44 +0100 Subject: [PATCH 08/12] iox-#1142 Add readme Signed-off-by: Marika Lehmann --- iceoryx_examples/icediscovery_in_c/README.md | 131 ++++++++++++++++++ .../icediscovery_in_c/iox_c_find_service.c | 18 +++ 2 files changed, 149 insertions(+) create mode 100644 iceoryx_examples/icediscovery_in_c/README.md diff --git a/iceoryx_examples/icediscovery_in_c/README.md b/iceoryx_examples/icediscovery_in_c/README.md new file mode 100644 index 0000000000..4410acc3fb --- /dev/null +++ b/iceoryx_examples/icediscovery_in_c/README.md @@ -0,0 +1,131 @@ +# icediscovery in C + +## Introduction + +This example demonstrates how to search for specific services using iceoryx's +service discovery. It provides two applications - one offering different +services and one searching for these making different search queries. The +behavior and structure is quite similar to the [icediscovery C++ example](https://github.com/eclipse-iceoryx/iceoryx/tree/v2.0.0/iceoryx_examples/icedelivery). + + + + +## Code walkthrough + +### Offer services + +We create several publisher ports which offer their services on construction by +default. For more dynamism the `cameraPublishers` offer/stop their services +periodically. If you want more information on how to create publisher ports, +have a look at the [icedelivery C example](https://github.com/eclipse-iceoryx/iceoryx/tree/v2.0.0/iceoryx_examples/icedelivery_in_c). + +### Find services + +To be able to search for services, we have to create a service discovery handle +which points to `storage`, the memory location where the service discovery is +stored. + + +```c +iox_service_discovery_storage_t storage; +iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); +``` + +It is included via: + + +```c +#include "iceoryx_binding_c/service_discovery.h" +``` + +We can now call three different find service functions. Let's start with + + +```c +iox_service_discovery_find_service_apply_callable( + serviceDiscovery, "Radar", "FrontLeft", "Image", printSearchResult, MessagingPattern_PUB_SUB); +``` + +which searches for all `{Radar, FrontLeft, Image}` services offered by +publishers and applies the provided function on each of them. The function must +have the signature `void(const iox_service_description_t)`. Here we pass a +function that prints the found services on the console: + + +```c +void printSearchResult(const iox_service_description_t service) +{ + printf( + "- Service: %s, Instance: %s, Event: %s\n", service.serviceString, service.instanceString, service.eventString); +} +``` + +We can not only search for exactly matching services, but also for wildcards +using `NULL`: + + +```c +iox_service_discovery_find_service_apply_callable( + serviceDiscovery, "Radar", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); +``` + +With the above call we look for every `Radar` service with any instance and any +event. + +Let's now search for all `Camera` services and store the results in an array: + + +```c +numberFoundServices = iox_service_discovery_find_service(serviceDiscovery, + "Camera", + NULL, + NULL, + searchResult, + SEARCH_RESULT_CAPACITY, + &missedServices, + MessagingPattern_PUB_SUB); +``` + +`searchResult` is a `iox_service_description_t` array of size +`SEARCH_RESULT_CAPACITY`. The found services are written into this array, but +at maximum `SEARCH_RESULT_CAPACITY`. If the number of found services exceeds +the array's capacity, the number of not stored services is written to +`missedServices`. The number of stored services is returned. Since the +`cameraPublishers` periodically offer/stop their services, you should see +sometimes 5 `Camera` services and sometimes none. + +Finally, let's try out the third find service function. We search again for all +`Camera` services but additionally count the front camera services: + + +```c +iox_service_discovery_find_service_apply_callable_with_context_data( + serviceDiscovery, "Camera", NULL, NULL, searchFrontDevices, &numberFrontCameras, MessagingPattern_PUB_SUB); +``` + +This function is quite similar to the first find service function, but we +pass an additional argument: + + +```c +uint32_t numberFrontCameras = 0U; +``` + +We use this variable to store the number of front cameras and provide it as +second parameter to the function which is applied to all found services: + + +```c +void searchFrontDevices(const iox_service_description_t service, void* count) +{ + if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0 + || strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0) + { + ++*(uint32_t*)count; + } +} +``` + +
+[Check out icediscovery on GitHub :fontawesome-brands-github:](https://github.com/eclipse-iceoryx/iceoryx/tree/v2.0.0/iceoryx_examples/icediscovery_in_c){ .md-button } +
diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 177517219d..3df8abb5cc 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -15,7 +15,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/runtime.h" +//! [include service discovery] #include "iceoryx_binding_c/service_discovery.h" +//! [include service discovery] #include "sleep_for.h" #include @@ -37,12 +39,15 @@ static void sigHandler(int signalValue) keepRunning = false; } +//! [print function to be applied to search results] void printSearchResult(const iox_service_description_t service) { printf( "- Service: %s, Instance: %s, Event: %s\n", service.serviceString, service.instanceString, service.eventString); } +//! [print function to be applied to search results] +//! [search function for all front devices] void searchFrontDevices(const iox_service_description_t service, void* count) { if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0 @@ -51,6 +56,7 @@ void searchFrontDevices(const iox_service_description_t service, void* count) ++*(uint32_t*)count; } } +//! [search function for all front devices] int main() { @@ -59,8 +65,10 @@ int main() iox_runtime_init(APP_NAME); + //! [create service discovery handle] iox_service_discovery_storage_t storage; iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); + //! [create service discovery handle] iox_service_description_t searchResult[SEARCH_RESULT_CAPACITY]; uint64_t missedServices = 0U; @@ -69,17 +77,23 @@ int main() while (keepRunning) { + //! [store number of front cameras] uint32_t numberFrontCameras = 0U; + //! [store number of front cameras] printf("\n=========================================\n"); printf("\nSearched for {'Radar', 'FrontLeft', 'Image'}. Found the following services:\n"); + //! [find service and apply callable] iox_service_discovery_find_service_apply_callable( serviceDiscovery, "Radar", "FrontLeft", "Image", printSearchResult, MessagingPattern_PUB_SUB); + //! [find service and apply callable] printf("\nSearched for {'Radar', *, *}. Found the following services:\n"); + //! [search for all Radar services] iox_service_discovery_find_service_apply_callable( serviceDiscovery, "Radar", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); + //! [search for all Radar services] printf("\nSearched for {*, 'FrontLeft', *}. Found the following services:\n"); iox_service_discovery_find_service_apply_callable( @@ -89,6 +103,7 @@ int main() iox_service_discovery_find_service_apply_callable( serviceDiscovery, NULL, "FrontRight", "Image", printSearchResult, MessagingPattern_PUB_SUB); + //! [search for all Camera services] numberFoundServices = iox_service_discovery_find_service(serviceDiscovery, "Camera", NULL, @@ -97,14 +112,17 @@ int main() SEARCH_RESULT_CAPACITY, &missedServices, MessagingPattern_PUB_SUB); + //! [search for all Camera services] printf("\nSearched for {'Camera', *, *}. Found the following services:\n"); for (uint64_t i = 0; i < numberFoundServices; ++i) { printSearchResult(searchResult[i]); } + //! [search for all front camera services] iox_service_discovery_find_service_apply_callable_with_context_data( serviceDiscovery, "Camera", NULL, NULL, searchFrontDevices, &numberFrontCameras, MessagingPattern_PUB_SUB); + //! [search for all front camera services] printf("\nFound %u front cameras\n", numberFrontCameras); sleep_for(1000); From c342ef337b19ea518142a41b06c39d633b42c3c9 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Mon, 28 Feb 2022 14:19:42 +0100 Subject: [PATCH 09/12] iox-#1142 Exclude null terminator from string size constant Signed-off-by: Marika Lehmann --- iceoryx_binding_c/include/iceoryx_binding_c/config.h | 4 ++-- .../include/iceoryx_binding_c/service_description.h | 6 +++--- iceoryx_binding_c/test/moduletests/test_config.cpp | 4 ++-- .../test/moduletests/test_service_description.cpp | 7 ++++--- iceoryx_examples/icediscovery_in_c/iox_c_find_service.c | 7 ++++--- iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c | 3 ++- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/config.h b/iceoryx_binding_c/include/iceoryx_binding_c/config.h index ef23068cf0..9f99758ebf 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/config.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/config.h @@ -97,7 +97,7 @@ uint32_t iox_cfg_max_runtime_name_length(); /// @brief the maximum size of a node name string + \0 terminator #define IOX_CONFIG_NODE_NAME_SIZE 101 -/// @brief the maximum size of a service description string identifier + \0 terminator -#define IOX_CONFIG_SERVICE_STRING_SIZE 101 +/// @brief the maximum size of a service description string identifier +#define IOX_CONFIG_SERVICE_STRING_SIZE 100 #endif // IOX_BINDING_C_CONFIG_H diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h index c80f7d2d00..acbcaa8065 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h @@ -23,9 +23,9 @@ typedef struct { - char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE]; - char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE]; - char eventString[IOX_CONFIG_SERVICE_STRING_SIZE]; + char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; // +1U for \0 terminator + char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; + char eventString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; } iox_service_description_t; #endif diff --git a/iceoryx_binding_c/test/moduletests/test_config.cpp b/iceoryx_binding_c/test/moduletests/test_config.cpp index 63ae94ba45..bb3abbad80 100644 --- a/iceoryx_binding_c/test/moduletests/test_config.cpp +++ b/iceoryx_binding_c/test/moduletests/test_config.cpp @@ -56,9 +56,9 @@ TEST(iox_cfg, valuesAreCorrectlyConnected) EXPECT_EQ(iox_cfg_max_findservice_result_size(), iox::MAX_FINDSERVICE_RESULT_SIZE); EXPECT_EQ(iox_cfg_max_runtime_name_length(), iox::MAX_RUNTIME_NAME_LENGTH); - constexpr uint64_t ZERO_TERMINATOR_SIZE = 1; + constexpr uint64_t ZERO_TERMINATOR_SIZE = 1U; EXPECT_EQ(IOX_CONFIG_NODE_NAME_SIZE, iox::NodeName_t::capacity() + ZERO_TERMINATOR_SIZE); - EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity() + ZERO_TERMINATOR_SIZE); + EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity()); } } // namespace diff --git a/iceoryx_binding_c/test/moduletests/test_service_description.cpp b/iceoryx_binding_c/test/moduletests/test_service_description.cpp index 7a17801cb8..8ca0656958 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_description.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_description.cpp @@ -32,13 +32,14 @@ using namespace iox::capro; TEST(iox_service_description_test, StringSizesAreCorrect) { + constexpr uint64_t ZERO_TERMINATOR_SIZE = 1U; ::testing::Test::RecordProperty("TEST_ID", "f32a6d19-9ff7-4913-a1d8-39d46267b114"); EXPECT_THAT(sizeof(decltype(std::declval().serviceString)), - Eq(iox::capro::IdString_t().capacity() + 1U)); + Eq(iox::capro::IdString_t().capacity() + ZERO_TERMINATOR_SIZE)); EXPECT_THAT(sizeof(decltype(std::declval().instanceString)), - Eq(iox::capro::IdString_t().capacity() + 1U)); + Eq(iox::capro::IdString_t().capacity() + ZERO_TERMINATOR_SIZE)); EXPECT_THAT(sizeof(decltype(std::declval().eventString)), - Eq(iox::capro::IdString_t().capacity() + 1U)); + Eq(iox::capro::IdString_t().capacity() + ZERO_TERMINATOR_SIZE)); } } // namespace diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 3df8abb5cc..4234776a62 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -50,8 +50,8 @@ void printSearchResult(const iox_service_description_t service) //! [search function for all front devices] void searchFrontDevices(const iox_service_description_t service, void* count) { - if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0 - || strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0) + if (strncmp("FrontLeft", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0 + || strncmp("FrontRight", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0) { ++*(uint32_t*)count; } @@ -74,6 +74,7 @@ int main() uint64_t missedServices = 0U; uint64_t numberFoundServices = 0U; + const uint32_t WAIT_TIME_IN_MS = 1000; while (keepRunning) { @@ -125,7 +126,7 @@ int main() //! [search for all front camera services] printf("\nFound %u front cameras\n", numberFrontCameras); - sleep_for(1000); + sleep_for(WAIT_TIME_IN_MS); } iox_service_discovery_deinit(serviceDiscovery); diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c index 621e74a159..bf3471ed91 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c @@ -57,6 +57,7 @@ int main() cameraPublishers[3] = iox_pub_init(&cameraPublisherStorage[3], "Camera", "FrontRight", "Image", &options); cameraPublishers[4] = iox_pub_init(&cameraPublisherStorage[4], "Camera", "BackLeft", "Image", &options); + const uint32_t WAIT_TIME_IN_MS = 1000; bool offer = false; while (keepRunning) { @@ -75,7 +76,7 @@ int main() } } offer = !offer; - sleep_for(1000); + sleep_for(WAIT_TIME_IN_MS); } iox_pub_deinit(radarLeft); From 1c49ed13f8debb6479c34e9613cfa12f3c2c6f2e Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Mon, 28 Feb 2022 14:20:43 +0100 Subject: [PATCH 10/12] iox-#1142 Small changes in readme Signed-off-by: Marika Lehmann --- iceoryx_examples/icediscovery_in_c/README.md | 55 +++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/iceoryx_examples/icediscovery_in_c/README.md b/iceoryx_examples/icediscovery_in_c/README.md index 4410acc3fb..17d101bd8d 100644 --- a/iceoryx_examples/icediscovery_in_c/README.md +++ b/iceoryx_examples/icediscovery_in_c/README.md @@ -4,7 +4,7 @@ This example demonstrates how to search for specific services using iceoryx's service discovery. It provides two applications - one offering different -services and one searching for these making different search queries. The +services and one searching for those with different search queries. The behavior and structure is quite similar to the [icediscovery C++ example](https://github.com/eclipse-iceoryx/iceoryx/tree/v2.0.0/iceoryx_examples/icedelivery). @@ -21,21 +21,21 @@ have a look at the [icedelivery C example](https://github.com/eclipse-iceoryx/ic ### Find services -To be able to search for services, we have to create a service discovery handle -which points to `storage`, the memory location where the service discovery is -stored. +To be able to search for services, we need to include: - + ```c -iox_service_discovery_storage_t storage; -iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); +#include "iceoryx_binding_c/service_discovery.h" ``` -It is included via: +To get a handle to the service discovery we call `iox_service_discovery_init`. +The service discovery requires memory of the amount of +`sizeof(iox_service_discovery_storage_t)` to be initialized. - + ```c -#include "iceoryx_binding_c/service_discovery.h" +iox_service_discovery_storage_t storage; +iox_service_discovery_t serviceDiscovery = iox_service_discovery_init(&storage); ``` We can now call three different find service functions. Let's start with @@ -47,9 +47,10 @@ iox_service_discovery_find_service_apply_callable( ``` which searches for all `{Radar, FrontLeft, Image}` services offered by -publishers and applies the provided function on each of them. The function must -have the signature `void(const iox_service_description_t)`. Here we pass a -function that prints the found services on the console: +publishers and applies the provided function `printSearchResult` on each of +them. The function must have the signature +`void(const iox_service_description_t)`. Here we pass a function that prints the +found services on the console: ```c @@ -60,8 +61,9 @@ void printSearchResult(const iox_service_description_t service) } ``` -We can not only search for exactly matching services, but also for wildcards -using `NULL`: +We cannot only search for exact matching services. In combination with +wildcards (`NULL`) we can also search for all instances and events with the +service `Radar`: ```c @@ -69,8 +71,8 @@ iox_service_discovery_find_service_apply_callable( serviceDiscovery, "Radar", NULL, NULL, printSearchResult, MessagingPattern_PUB_SUB); ``` -With the above call we look for every `Radar` service with any instance and any -event. +The wildcard can be used for all strings which describe a service, i.e. service, +instance and event. Let's now search for all `Camera` services and store the results in an array: @@ -87,11 +89,11 @@ numberFoundServices = iox_service_discovery_find_service(serviceDiscovery, ``` `searchResult` is a `iox_service_description_t` array of size -`SEARCH_RESULT_CAPACITY`. The found services are written into this array, but -at maximum `SEARCH_RESULT_CAPACITY`. If the number of found services exceeds -the array's capacity, the number of not stored services is written to -`missedServices`. The number of stored services is returned. Since the -`cameraPublishers` periodically offer/stop their services, you should see +`SEARCH_RESULT_CAPACITY`. The matching services are written into this array, up +to a maximum of `SEARCH_RESULT_CAPACITY`. If the number of found services +exceeds the array's capacity, the number of services that could not be stored is +written to `missedServices`. The number of stored services is returned. Since +the `cameraPublishers` periodically offer/stop their services, you should see sometimes 5 `Camera` services and sometimes none. Finally, let's try out the third find service function. We search again for all @@ -104,7 +106,7 @@ iox_service_discovery_find_service_apply_callable_with_context_data( ``` This function is quite similar to the first find service function, but we -pass an additional argument: +pass an additional argument `numberFrontCameras`: ```c @@ -112,14 +114,15 @@ uint32_t numberFrontCameras = 0U; ``` We use this variable to store the number of front cameras and provide it as -second parameter to the function which is applied to all found services: +second argument `count` to the function `searchFrontDevices` which is applied to +all found services: ```c void searchFrontDevices(const iox_service_description_t service, void* count) { - if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0 - || strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE - 1U) == 0) + if (strncmp("FrontLeft", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0 + || strncmp("FrontRight", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0) { ++*(uint32_t*)count; } From 8c39c3fd2acc566a6dfeb024e138a2a0214b003f Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Mon, 28 Feb 2022 17:49:33 +0100 Subject: [PATCH 11/12] iox-#1142 Extend example pages, minor change in readme Signed-off-by: Marika Lehmann --- doc/website/examples/.pages | 4 ++++ iceoryx_examples/icediscovery_in_c/README.md | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/website/examples/.pages b/doc/website/examples/.pages index 9e521390bb..6b8d1a54eb 100644 --- a/doc/website/examples/.pages +++ b/doc/website/examples/.pages @@ -16,3 +16,7 @@ nav: - icecrystal.md - request_response_in_c.md - request_response.md + - complexdata.md + - user_header.md + - icediscovery.md + - icediscovery_in_c.md diff --git a/iceoryx_examples/icediscovery_in_c/README.md b/iceoryx_examples/icediscovery_in_c/README.md index 17d101bd8d..678c60f2f9 100644 --- a/iceoryx_examples/icediscovery_in_c/README.md +++ b/iceoryx_examples/icediscovery_in_c/README.md @@ -28,9 +28,7 @@ To be able to search for services, we need to include: #include "iceoryx_binding_c/service_discovery.h" ``` -To get a handle to the service discovery we call `iox_service_discovery_init`. -The service discovery requires memory of the amount of -`sizeof(iox_service_discovery_storage_t)` to be initialized. +We create some stack storage for the service discovery and initialize it. ```c From 7b20fa75c50e2c44c87a8b75dad881aa5d3f4320 Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Mon, 28 Feb 2022 19:19:59 +0100 Subject: [PATCH 12/12] iox-#1142 Include null terminator in string size constant Signed-off-by: Marika Lehmann --- .clang-tidy | 3 ++- iceoryx_binding_c/include/iceoryx_binding_c/config.h | 4 ++-- .../include/iceoryx_binding_c/service_description.h | 8 ++++---- iceoryx_binding_c/test/moduletests/test_config.cpp | 2 +- .../test/moduletests/test_service_description.cpp | 2 +- iceoryx_examples/icediscovery_in_c/README.md | 2 +- iceoryx_examples/icediscovery_in_c/iox_c_find_service.c | 6 +++--- iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b663ac471a..6ca7b5de33 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -22,6 +22,7 @@ hicpp-*, -bugprone-easily-swappable-parameters, -bugprone-branch-clone, -bugprone-implicit-widening-of-multiplication-result, +-bugprone-not-null-terminated-result, -concurrency-mt-unsafe, -readability-named-parameter, -readability-avoid-const-params-in-decls, @@ -86,7 +87,7 @@ hicpp-*, # -readability-function-cognitive-complexity # ## is it working correctly? produces hard to understand warning -# -clang-analyzer-core.uninitialized.UndefReturn +# -clang-analyzer-core.uninitialized.UndefReturn # -clang-analyzer-optin.cplusplus.VirtualCall # ########################################### diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/config.h b/iceoryx_binding_c/include/iceoryx_binding_c/config.h index 9f99758ebf..ef23068cf0 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/config.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/config.h @@ -97,7 +97,7 @@ uint32_t iox_cfg_max_runtime_name_length(); /// @brief the maximum size of a node name string + \0 terminator #define IOX_CONFIG_NODE_NAME_SIZE 101 -/// @brief the maximum size of a service description string identifier -#define IOX_CONFIG_SERVICE_STRING_SIZE 100 +/// @brief the maximum size of a service description string identifier + \0 terminator +#define IOX_CONFIG_SERVICE_STRING_SIZE 101 #endif // IOX_BINDING_C_CONFIG_H diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h index acbcaa8065..f9b2619339 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/service_description.h @@ -1,4 +1,4 @@ -// Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ typedef struct { - char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; // +1U for \0 terminator - char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; - char eventString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; + char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE]; + char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE]; + char eventString[IOX_CONFIG_SERVICE_STRING_SIZE]; } iox_service_description_t; #endif diff --git a/iceoryx_binding_c/test/moduletests/test_config.cpp b/iceoryx_binding_c/test/moduletests/test_config.cpp index bb3abbad80..4744baaef1 100644 --- a/iceoryx_binding_c/test/moduletests/test_config.cpp +++ b/iceoryx_binding_c/test/moduletests/test_config.cpp @@ -59,6 +59,6 @@ TEST(iox_cfg, valuesAreCorrectlyConnected) constexpr uint64_t ZERO_TERMINATOR_SIZE = 1U; EXPECT_EQ(IOX_CONFIG_NODE_NAME_SIZE, iox::NodeName_t::capacity() + ZERO_TERMINATOR_SIZE); - EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity()); + EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity() + ZERO_TERMINATOR_SIZE); } } // namespace diff --git a/iceoryx_binding_c/test/moduletests/test_service_description.cpp b/iceoryx_binding_c/test/moduletests/test_service_description.cpp index 8ca0656958..26b12c06c1 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_description.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_description.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 - 2022 Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/iceoryx_examples/icediscovery_in_c/README.md b/iceoryx_examples/icediscovery_in_c/README.md index 678c60f2f9..c73501d31f 100644 --- a/iceoryx_examples/icediscovery_in_c/README.md +++ b/iceoryx_examples/icediscovery_in_c/README.md @@ -28,7 +28,7 @@ To be able to search for services, we need to include: #include "iceoryx_binding_c/service_discovery.h" ``` -We create some stack storage for the service discovery and initialize it. +We create some storage for the service discovery and initialize it. ```c diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c index 4234776a62..d58b7d7103 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_find_service.c @@ -50,8 +50,8 @@ void printSearchResult(const iox_service_description_t service) //! [search function for all front devices] void searchFrontDevices(const iox_service_description_t service, void* count) { - if (strncmp("FrontLeft", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0 - || strncmp("FrontRight", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0) + if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE) == 0 + || strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE) == 0) { ++*(uint32_t*)count; } @@ -74,7 +74,7 @@ int main() uint64_t missedServices = 0U; uint64_t numberFoundServices = 0U; - const uint32_t WAIT_TIME_IN_MS = 1000; + const uint32_t WAIT_TIME_IN_MS = 1000U; while (keepRunning) { diff --git a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c index bf3471ed91..dfb79feedb 100644 --- a/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c +++ b/iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c @@ -57,7 +57,7 @@ int main() cameraPublishers[3] = iox_pub_init(&cameraPublisherStorage[3], "Camera", "FrontRight", "Image", &options); cameraPublishers[4] = iox_pub_init(&cameraPublisherStorage[4], "Camera", "BackLeft", "Image", &options); - const uint32_t WAIT_TIME_IN_MS = 1000; + const uint32_t WAIT_TIME_IN_MS = 1000U; bool offer = false; while (keepRunning) {