Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#548 from ApexAI/iox-#350-implement…
Browse files Browse the repository at this point in the history
…-active-call-set

Iox eclipse-iceoryx#350 implement active call set
  • Loading branch information
elfenpiff authored and marthtz committed May 12, 2021
2 parents 42f188b + 2c747a0 commit 036d2ac
Show file tree
Hide file tree
Showing 64 changed files with 3,114 additions and 127 deletions.
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 !}
21 changes: 16 additions & 5 deletions iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PREFIX}>
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
iceoryx_posh::iceoryx_posh
iceoryx_utils::iceoryx_utils
)

if(NOT WIN32)
target_link_libraries(${PROJECT_NAME}
PUBLIC
pthread
PRIVATE
iceoryx_posh::iceoryx_posh
iceoryx_utils::iceoryx_utils
)
else()
target_link_libraries(${PROJECT_NAME}
PRIVATE
iceoryx_posh::iceoryx_posh
iceoryx_utils::iceoryx_utils
)
endif()

target_compile_options(${PROJECT_NAME} PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})

Expand Down
4 changes: 2 additions & 2 deletions iceoryx_binding_c/include/iceoryx_binding_c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct iox_user_trigger_storage_t_
// the value of the array size is the result of the following formula:
// sizeof(UserTrigger) / 8
#if defined(__APPLE__)
uint64_t do_not_touch_me[16];
uint64_t do_not_touch_me[17];
#else
uint64_t do_not_touch_me[14];
#endif
Expand All @@ -51,7 +51,7 @@ struct iox_sub_storage_t_
// the value of the array size is the result of the following formula:
// sizeof(cpp2c_Subscriber) / 8
#if defined(__APPLE__)
uint64_t do_not_touch_me[16];
uint64_t do_not_touch_me[17];
#else
uint64_t do_not_touch_me[14];
#endif
Expand Down
1 change: 1 addition & 0 deletions iceoryx_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cd someExample

| Example | Description |Level |
|:-------------------------------------------------------|:------------|:----:|
|[callbacks](./callbacks/) | Implement callbacks which are triggered by events. | Intermediate |
|[icedelivery](./icedelivery/) | You are new to iceoryx then take a look at this example which demonstrates the basics of iceoryx by sending data from one process to another process. | Beginner |
|[icedelivery_in_c](./icedelivery_in_c/) | Shows the same use case as the ice delivery example but with the iceoryx C API | Beginner |
|[ice_multi_publisher](./ice_multi_publisher/) | Shows how multiple publishers can be used to publish on the same topic. | Intermediate |
Expand Down
53 changes: 53 additions & 0 deletions iceoryx_examples/callbacks/CMakeLists.txt
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
)
2 changes: 2 additions & 0 deletions iceoryx_examples/callbacks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ActiveCallSet - WORK IN PROGRESS -

60 changes: 60 additions & 0 deletions iceoryx_examples/callbacks/ice_callbacks_publisher.cpp
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);
}
77 changes: 77 additions & 0 deletions iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp
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);
}
27 changes: 27 additions & 0 deletions iceoryx_examples/callbacks/topic_data.hpp
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
2 changes: 0 additions & 2 deletions iceoryx_examples/icedelivery_in_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ endif ()
add_executable(iox-c-publisher ./ice_c_publisher.c)
set_source_files_properties(./ice_c_publisher.c PROPERTIES LANGUAGE C)
target_link_libraries(iox-c-publisher
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
set_target_properties(iox-c-publisher PROPERTIES
Expand All @@ -42,7 +41,6 @@ target_compile_options(iox-c-publisher PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SAN
add_executable(iox-c-subscriber ./ice_c_subscriber.c)
set_source_files_properties(./ice_c_subscriber.c PROPERTIES LANGUAGE C)
target_link_libraries(iox-c-subscriber
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
set_target_properties(iox-c-subscriber PROPERTIES
Expand Down
5 changes: 0 additions & 5 deletions iceoryx_examples/waitset_in_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,30 @@ endif ()

add_executable(iox-ex-c-waitset-publisher ./ice_c_waitset_publisher.c)
target_link_libraries(iox-ex-c-waitset-publisher
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
target_compile_options(iox-ex-c-waitset-publisher PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})

add_executable(iox-ex-c-waitset-gateway ./ice_c_waitset_gateway.c)
target_link_libraries(iox-ex-c-waitset-gateway
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
target_compile_options(iox-ex-c-waitset-gateway PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})

add_executable(iox-ex-c-waitset-grouping ./ice_c_waitset_grouping.c)
target_link_libraries(iox-ex-c-waitset-grouping
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
target_compile_options(iox-ex-c-waitset-grouping PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})

add_executable(iox-ex-c-waitset-individual ./ice_c_waitset_individual.c)
target_link_libraries(iox-ex-c-waitset-individual
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
target_compile_options(iox-ex-c-waitset-individual PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})

add_executable(iox-ex-c-waitset-sync ./ice_c_waitset_sync.c)
target_link_libraries(iox-ex-c-waitset-sync
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
)
target_compile_options(iox-ex-c-waitset-sync PRIVATE ${ICEORYX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS})
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_meta/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved.
# Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
# Copyright (c) 2020 - 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.
Expand Down Expand Up @@ -64,6 +65,7 @@ if(EXAMPLES)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/iceperf ${CMAKE_BINARY_DIR}/iceoryx_examples/iceperf)
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)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/singleprocess ${CMAKE_BINARY_DIR}/iceoryx_examples/singleprocess)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../iceoryx_examples/ice_multi_publisher ${CMAKE_BINARY_DIR}/iceoryx_examples/ice_multi_publisher)
endif()
Expand Down
8 changes: 6 additions & 2 deletions iceoryx_posh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ add_library(iceoryx_posh
source/popo/building_blocks/condition_variable_data.cpp
source/popo/building_blocks/condition_variable_signaler.cpp
source/popo/building_blocks/condition_variable_waiter.cpp
source/popo/building_blocks/event_variable_data.cpp
source/popo/building_blocks/event_listener.cpp
source/popo/building_blocks/event_notifier.cpp
source/popo/building_blocks/locking_policy.cpp
source/popo/building_blocks/typed_unique_id.cpp
source/popo/user_trigger.cpp
source/popo/active_call_set.cpp
source/popo/event_info.cpp
source/popo/trigger.cpp
source/popo/trigger_handle.cpp
source/popo/event_info.cpp
source/popo/user_trigger.cpp
source/version/version_info.cpp
source/runtime/ipc_interface_base.cpp
source/runtime/ipc_interface_user.cpp
Expand Down
6 changes: 5 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved.
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// 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.
Expand Down Expand Up @@ -101,6 +102,9 @@ constexpr uint32_t MAX_REQUEST_QUEUE_CAPACITY = 1024;
// Waitset
constexpr uint32_t MAX_NUMBER_OF_CONDITION_VARIABLES = 1024U;
constexpr uint32_t MAX_NUMBER_OF_EVENTS_PER_WAITSET = 128U;
// ActiveCallSet
constexpr uint8_t MAX_NUMBER_OF_EVENT_VARIABLES = 128U;
constexpr uint8_t MAX_NUMBER_OF_EVENTS_PER_ACTIVE_CALL_SET = 128U;
//--------- Communication Resources End---------------------

constexpr uint32_t MAX_APPLICATION_CAPRO_FIFO_SIZE = 128U;
Expand Down
Loading

0 comments on commit 036d2ac

Please sign in to comment.