Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#1112 from eclipse-iceoryx/iox-#27-…
Browse files Browse the repository at this point in the history
…add-client-and-server-examples

Iox #27 add client and server examples [stacked PR #6]
  • Loading branch information
dkroenke authored Feb 28, 2022
2 parents a8c3a76 + a82f406 commit 1d7366b
Show file tree
Hide file tree
Showing 40 changed files with 1,500 additions and 44 deletions.
1 change: 1 addition & 0 deletions doc/website/examples/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ nav:
- iceperf.md
- icecrystal.md
- request_response_in_c.md
- request_response.md
5 changes: 5 additions & 0 deletions doc/website/examples/request_response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Communication pattern which delivers data on demand (Client/Server)
---

{! ../iceoryx/iceoryx_examples/request_response/README.md !}
5 changes: 5 additions & 0 deletions doc/website/release-notes/iceoryx-v2-0-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
- C binding for service discovery [\#1142](https://github.com/eclipse-iceoryx/iceoryx/issues/1142)
- Introduce `iox::popo::MessagingPattern` to `findService` to allow separate searches for publishers (`MessagingPattern::PUB_SUB`) and
servers (`iox::popo::MessagingPattern::REQ_RES`) [\#27](https://github.com/eclipse-iceoryx/iceoryx/pull/1134)
- Request/Response communication with iceoryx [\#27](https://github.com/eclipse-iceoryx/iceoryx/issues/27)
- For more details how this feature can be used please have a look at the `iceoryx_examples/request_response`
- Limitations
- The port introspection is not aware of the new `Client` and `Server` [\#1128](https://github.com/eclipse-iceoryx/iceoryx/issues/1128)
- The DDS gateway is not aware of the new `Server` [\#1145](https://github.com/eclipse-iceoryx/iceoryx/issues/1145)

**Bugfixes:**

Expand Down
1 change: 1 addition & 0 deletions iceoryx_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
|[callbacks_in_c](./callbacks_in_c/) | Implementing event triggered callbacks using C | :star::star: |
|[waitset](./waitset/) | Waiting for events like arrival of data using C++ | :star::star: |
|[waitset_in_c](./waitset_in_c/) | Waiting for events like arrival of data using C | :star::star: |
|[request_response](./request_response/) | Communication pattern which delivers data on demand (Client/Server) | :star::star: |
|[iceensemble](./iceensemble/) | Using multiple publishers for one topic | :star::star: |
|[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: |
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/complexdata/iox_publisher_complexdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main()
})
.or_else([](auto& error) {
// do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error code: " << error << std::endl;
});

std::this_thread::sleep_for(std::chrono::seconds(1));
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/complexdata/iox_publisher_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main()
})
.or_else([](auto& error) {
// do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error code: " << error << std::endl;
});
++ct;

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/ice_access_control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ iox::mepoo::MePooConfig mepooConfig;
// We only send very small data, just one mempool per segment
mepooConfig.addMemPool({128, 1000});

// Create an Entry for a new Shared Memory Segment from the MempoolConfig and add it to the RouDiConfig
// Create an entry for a new shared memory segment from the mempooConfig and add it to the roudiConfig
// Parameters are {"ReaderGroup", "WriterGroup", MemoryPoolConfig}
roudiConfig.m_sharedMemorySegments.push_back({"unprivileged", "privileged", mepooConfig});
roudiConfig.m_sharedMemorySegments.push_back({"infotainment", "infotainment", mepooConfig});
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/ice_access_control/iox_radar_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main()
{
auto error = loanResult.get_error();
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error: " << error << std::endl;
}

std::cout << APP_NAME << " sent value: " << ct << std::endl;
Expand Down
16 changes: 8 additions & 8 deletions iceoryx_examples/icedelivery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ First off, let's include the publisher, the runtime and the signal handler:

<!--[geoffrey][iceoryx_examples/icedelivery/iox_publisher_untyped.cpp][includes]-->
```cpp
#include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp"
#include "iceoryx_hoofs/posix_wrapper/signal_watcher.hpp"
#include "iceoryx_posh/popo/untyped_publisher.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
```
Expand Down Expand Up @@ -130,7 +130,7 @@ Similar to the publisher, we include the topic data, the subscriber, the runtime
```cpp
#include "topic_data.hpp"

#include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp"
#include "iceoryx_hoofs/posix_wrapper/signal_watcher.hpp"
#include "iceoryx_posh/popo/untyped_subscriber.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
```
Expand Down Expand Up @@ -158,7 +158,7 @@ Again in a while-loop we do the following:

<!--[geoffrey][iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp][[loop] [chunk happy path]]-->
```cpp
while (!killswitch)
while (!iox::posix::hasTerminationRequested())
{
subscriber
.take()
Expand Down Expand Up @@ -245,7 +245,7 @@ publisher.loan()
})
.or_else([](auto& error) {
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error: " << error << std::endl;
});
```

Expand All @@ -262,7 +262,7 @@ publisher.loan(sampleValue2, sampleValue2, sampleValue2)
.and_then([](auto& sample) { sample.publish(); })
.or_else([](auto& error) {
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error: " << error << std::endl;
});
```
Expand All @@ -282,7 +282,7 @@ lead to a larger runtime.
auto object = RadarObject(sampleValue3, sampleValue3, sampleValue3);
publisher.publishCopyOf(object).or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishCopyOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishCopyOf, error: " << error << std::endl;
});
```

Expand All @@ -302,15 +302,15 @@ argument. If loaning was unsuccessful, the callable is not called, but instead t
//
publisher.publishResultOf(getRadarObject, ct).or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishResultOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishResultOf, error: " << error << std::endl;
});
publisher
.publishResultOf([&sampleValue4](RadarObject* object) {
*object = RadarObject(sampleValue4, sampleValue4, sampleValue4);
})
.or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishResultOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishResultOf, error: " << error << std::endl;
});
```
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_examples/icedelivery/iox_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main()
})
.or_else([](auto& error) {
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error: " << error << std::endl;
});
//! [API Usage #1]

Expand All @@ -75,7 +75,7 @@ int main()
.and_then([](auto& sample) { sample.publish(); })
.or_else([](auto& error) {
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error: " << error << std::endl;
});
//! [API Usage #2]

Expand All @@ -85,7 +85,7 @@ int main()
auto object = RadarObject(sampleValue3, sampleValue3, sampleValue3);
publisher.publishCopyOf(object).or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishCopyOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishCopyOf, error: " << error << std::endl;
});
//! [API Usage #3]

Expand All @@ -96,15 +96,15 @@ int main()
//
publisher.publishResultOf(getRadarObject, ct).or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishResultOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishResultOf, error: " << error << std::endl;
});
publisher
.publishResultOf([&sampleValue4](RadarObject* object) {
*object = RadarObject(sampleValue4, sampleValue4, sampleValue4);
})
.or_else([](auto& error) {
// Do something with error.
std::cerr << "Unable to publishResultOf, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to publishResultOf, error: " << error << std::endl;
});
//! [API Usage #4]

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/icedelivery/iox_publisher_untyped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main()
})
.or_else([&](auto& error) {
//! [print error]
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error code: " << error << std::endl;
//! [print error]
});
//! [Loan chunk and provide logic to populate it via a lambda]
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/icehello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ else
{
auto error = loanResult.get_error();
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error code: " << error << std::endl;
}
```

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/icehello/iox_publisher_helloworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main()
{
auto error = loanResult.get_error();
// Do something with error
std::cerr << "Unable to loan sample, error code: " << static_cast<uint64_t>(error) << std::endl;
std::cerr << "Unable to loan sample, error code: " << error << std::endl;
}
//! [error]

Expand Down
160 changes: 160 additions & 0 deletions iceoryx_examples/request_response/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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 request_response_basic example
cmake_minimum_required(VERSION 3.16)
project(example_request_response)

include(GNUInstallDirs)

find_package(iceoryx_posh REQUIRED)
find_package(iceoryx_hoofs REQUIRED)

get_target_property(ICEORYX_CXX_STANDARD iceoryx_posh::iceoryx_posh CXX_STANDARD)
include(IceoryxPlatform)

## C++ untyped API client
add_executable(
iox-cpp-request-response-untyped-client
client_cxx_untyped.cpp
)
target_link_libraries(
iox-cpp-request-response-untyped-client
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-untyped-client
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## C++ untyped API server
add_executable(
iox-cpp-request-response-untyped-server
server_cxx_untpyed.cpp
)
target_link_libraries(
iox-cpp-request-response-untyped-server
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-untyped-server
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## C++ typed API client
add_executable(
iox-cpp-request-response-basic-client
client_cxx_basic.cpp
)
target_link_libraries(
iox-cpp-request-response-basic-client
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-basic-client
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## C++ typed API client with WaitSet
add_executable(
iox-cpp-request-response-waitset-client
client_cxx_waitset.cpp
)
target_link_libraries(
iox-cpp-request-response-waitset-client
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-waitset-client
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## C++ typed API server
add_executable(
iox-cpp-request-response-basic-server
server_cxx_basic.cpp
)
target_link_libraries(
iox-cpp-request-response-basic-server
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-basic-server
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## C++ typed API server with Listener
add_executable(
iox-cpp-request-response-listener-server
server_cxx_listener.cpp
)
target_link_libraries(
iox-cpp-request-response-listener-server
PRIVATE
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh
)
target_compile_options(
iox-cpp-request-response-listener-server
PRIVATE
${ICEORYX_WARNINGS}
${ICEORYX_SANITIZER_FLAGS}
)

## additional properties
set_target_properties(
iox-cpp-request-response-untyped-client
iox-cpp-request-response-untyped-server
iox-cpp-request-response-basic-client
iox-cpp-request-response-basic-server
iox-cpp-request-response-waitset-client
iox-cpp-request-response-listener-server
PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_STANDARD ${ICEORYX_CXX_STANDARD}
POSITION_INDEPENDENT_CODE ON
)

install(
TARGETS
iox-cpp-request-response-untyped-client
iox-cpp-request-response-untyped-server
iox-cpp-request-response-basic-client
iox-cpp-request-response-basic-server
iox-cpp-request-response-waitset-client
iox-cpp-request-response-listener-server
RUNTIME DESTINATION bin
)
Loading

0 comments on commit 1d7366b

Please sign in to comment.