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.
Merge pull request eclipse-iceoryx#548 from ApexAI/iox-#350-implement…
…-active-call-set Iox eclipse-iceoryx#350 implement active call set
- Loading branch information
Showing
64 changed files
with
3,114 additions
and
127 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,6 @@ | ||
# Intermediate examples | ||
|
||
{! ./../iceoryx_examples/callbacks/README.md !} | ||
{! ./../iceoryx_examples/waitset/README.md !} | ||
{! ./../iceoryx_examples/waitset_in_c/README.md !} | ||
{! ./../iceoryx_examples/singleprocess/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
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,53 @@ | ||
# Copyright (c) 2021 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 | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
project(example_callbacks) | ||
|
||
include(GNUInstallDirs) | ||
|
||
find_package(iceoryx_posh CONFIG REQUIRED) | ||
|
||
get_target_property(ICEORYX_CXX_STANDARD iceoryx_posh::iceoryx_posh CXX_STANDARD) | ||
if ( NOT ICEORYX_CXX_STANDARD ) | ||
include(IceoryxPlatform) | ||
endif () | ||
|
||
add_executable(iox-ex-callbacks-publisher ./ice_callbacks_publisher.cpp) | ||
target_link_libraries(iox-ex-callbacks-publisher | ||
iceoryx_posh::iceoryx_posh | ||
) | ||
target_compile_options(iox-ex-callbacks-publisher PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS}) | ||
|
||
add_executable(iox-ex-callbacks-subscriber ./ice_callbacks_subscriber.cpp) | ||
target_link_libraries(iox-ex-callbacks-subscriber | ||
iceoryx_posh::iceoryx_posh | ||
) | ||
target_compile_options(iox-ex-callbacks-subscriber PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS}) | ||
|
||
set_target_properties( | ||
iox-ex-callbacks-subscriber | ||
iox-ex-callbacks-publisher | ||
PROPERTIES | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_STANDARD ${ICEORYX_CXX_STANDARD} | ||
POSITION_INDEPENDENT_CODE ON | ||
) | ||
|
||
install( | ||
TARGETS iox-ex-callbacks-publisher iox-ex-callbacks-subscriber | ||
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,2 @@ | ||
# ActiveCallSet - WORK IN PROGRESS - | ||
|
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,60 @@ | ||
// Copyright (c) 2021 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_posh/popo/publisher.hpp" | ||
#include "iceoryx_posh/runtime/posh_runtime.hpp" | ||
#include "iceoryx_utils/posix_wrapper/signal_handler.hpp" | ||
#include "topic_data.hpp" | ||
|
||
#include <chrono> | ||
#include <csignal> | ||
#include <iostream> | ||
|
||
bool killswitch = false; | ||
|
||
static void sigHandler(int f_sig [[gnu::unused]]) | ||
{ | ||
killswitch = true; | ||
} | ||
|
||
void sending() | ||
{ | ||
iox::runtime::PoshRuntime::initRuntime("iox-ex-callbacks-publisher"); | ||
|
||
iox::popo::Publisher<CounterTopic> myPublisher({"Radar", "FrontLeft", "Counter"}); | ||
myPublisher.offer(); | ||
|
||
for (uint32_t counter = 0U; !killswitch; ++counter) | ||
{ | ||
myPublisher.publishCopyOf(CounterTopic{counter}); | ||
std::cout << "Sending: " << counter << std::endl; | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); | ||
} | ||
|
||
myPublisher.stopOffer(); | ||
} | ||
|
||
int main() | ||
{ | ||
auto signalIntGuard = iox::posix::registerSignalHandler(iox::posix::Signal::INT, sigHandler); | ||
auto signalTermGuard = iox::posix::registerSignalHandler(iox::posix::Signal::TERM, sigHandler); | ||
|
||
std::thread tx(sending); | ||
tx.join(); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
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,77 @@ | ||
// Copyright (c) 2021 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_posh/popo/active_call_set.hpp" | ||
#include "iceoryx_posh/popo/subscriber.hpp" | ||
#include "iceoryx_posh/popo/user_trigger.hpp" | ||
#include "iceoryx_posh/runtime/posh_runtime.hpp" | ||
#include "iceoryx_utils/posix_wrapper/semaphore.hpp" | ||
#include "iceoryx_utils/posix_wrapper/signal_handler.hpp" | ||
#include "topic_data.hpp" | ||
|
||
#include <chrono> | ||
#include <csignal> | ||
#include <iostream> | ||
|
||
iox::popo::UserTrigger shutdownTrigger; | ||
iox::posix::Semaphore mainLoopBlocker = | ||
iox::posix::Semaphore::create(iox::posix::CreateUnnamedSingleProcessSemaphore, 0).value(); | ||
|
||
std::atomic_bool keepRunning{true}; | ||
|
||
static void sigHandler(int f_sig [[gnu::unused]]) | ||
{ | ||
shutdownTrigger.trigger(); | ||
} | ||
|
||
void shutdownTriggerCallback(iox::popo::UserTrigger*) | ||
{ | ||
keepRunning.store(false); | ||
} | ||
|
||
void onSampleReceived(iox::popo::Subscriber<CounterTopic>* subscriber) | ||
{ | ||
subscriber->take().and_then([](auto& sample) { printf("received: %d\n", sample->counter); }); | ||
} | ||
|
||
int main() | ||
{ | ||
auto signalIntGuard = iox::posix::registerSignalHandler(iox::posix::Signal::INT, sigHandler); | ||
auto signalTermGuard = iox::posix::registerSignalHandler(iox::posix::Signal::TERM, sigHandler); | ||
|
||
iox::runtime::PoshRuntime::initRuntime("iox-ex-callbacks-subscriber"); | ||
|
||
iox::popo::ActiveCallSet callSet; | ||
|
||
// attach shutdownTrigger to handle CTRL+C | ||
callSet.attachEvent(shutdownTrigger, shutdownTriggerCallback); | ||
|
||
iox::popo::Subscriber<CounterTopic> subscriber({"Radar", "FrontLeft", "Counter"}); | ||
|
||
subscriber.subscribe(); | ||
|
||
callSet.attachEvent(subscriber, iox::popo::SubscriberEvent::HAS_DATA, onSampleReceived); | ||
|
||
while (keepRunning) | ||
{ | ||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
} | ||
|
||
callSet.detachEvent(shutdownTrigger); | ||
callSet.detachEvent(subscriber, iox::popo::SubscriberEvent::HAS_DATA); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
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,27 @@ | ||
// Copyright (c) 2021 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 | ||
|
||
#ifndef IOX_EXAMPLES_WAITSET_TOPIC_DATA_HPP | ||
#define IOX_EXAMPLES_WAITSET_TOPIC_DATA_HPP | ||
|
||
#include <cstdint> | ||
|
||
struct CounterTopic | ||
{ | ||
uint32_t counter; | ||
}; | ||
|
||
#endif // IOX_EXAMPLES_WAITSET_TOPIC_DATA_HPP |
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
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
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.