forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-eclipse-iceoryx#1142 Add first findService example
Signed-off-by: Marika Lehmann <[email protected]>
- Loading branch information
1 parent
dbc73fd
commit b4a922e
Showing
10 changed files
with
393 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
title: Searching for currently available services | ||
title: Searching for currently available services using C++ | ||
--- | ||
|
||
{! ../iceoryx/iceoryx_examples/icediscovery/README.md !} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Searching for currently available services using C | ||
--- | ||
|
||
{! ../iceoryx/iceoryx_examples/icediscovery/README.md !} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <signal.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <signal.h> | ||
#include <stdbool.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <windows.h> | ||
|
||
void sleep_for(uint32_t milliseconds) | ||
{ | ||
Sleep((uint64_t)milliseconds); | ||
} | ||
|
||
#else | ||
#include <unistd.h> | ||
|
||
void sleep_for(uint32_t milliseconds) | ||
{ | ||
usleep(milliseconds * 1000U); | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.