-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core / ZeroCopy: Added Doxygen API documentation and 2 new c++ sample…
…s demonstrating usage of low level zero copy API (#1145) Co-authored-by: Florian Reimold <[email protected]>
- Loading branch information
1 parent
50699d8
commit 942f01d
Showing
8 changed files
with
435 additions
and
31 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
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
38 changes: 38 additions & 0 deletions
38
samples/cpp/pubsub/binary/binary_zero_copy_rec/CMakeLists.txt
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,38 @@ | ||
# ========================= eCAL LICENSE ================================= | ||
# | ||
# Copyright (C) 2016 - 2019 Continental Corporation | ||
# | ||
# 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. | ||
# | ||
# ========================= eCAL LICENSE ================================= | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(binary_zero_copy_rec) | ||
|
||
# set project properties | ||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) | ||
set(binary_zero_copy_rec_src src/binary_zero_copy_rec.cpp) | ||
|
||
# find packages | ||
message("-- Checking for modules 'eCAL'") | ||
find_package(eCAL REQUIRED) | ||
|
||
# add and configure sample project | ||
ecal_add_sample(${PROJECT_NAME} ${binary_zero_copy_rec_src}) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) | ||
target_link_libraries(${PROJECT_NAME} eCAL::core) | ||
|
||
# install and set properties | ||
ecal_install_sample(${PROJECT_NAME}) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/pubsub/binary) |
96 changes: 96 additions & 0 deletions
96
samples/cpp/pubsub/binary/binary_zero_copy_rec/src/binary_zero_copy_rec.cpp
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,96 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* 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. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
#include <ecal/ecal.h> | ||
|
||
#include <iostream> | ||
#include <chrono> | ||
#include <sstream> | ||
#include <thread> | ||
|
||
// a simple struct to demonstrate | ||
// zero copy modifications | ||
struct alignas(4) SSimpleStruct | ||
{ | ||
uint32_t version = 1; | ||
uint16_t rows = 5; | ||
uint16_t cols = 3; | ||
uint32_t clock = 0; | ||
uint8_t bytes[5 * 3] = { 0 }; | ||
}; | ||
|
||
// SSimpleStruct logging | ||
std::ostream& operator<<(std::ostream& os, const SSimpleStruct& s) | ||
{ | ||
os << "Version : " << s.version << std::endl; | ||
os << "Rows : " << s.rows << std::endl; | ||
os << "Cols : " << s.cols << std::endl; | ||
os << "Clock : " << s.clock << std::endl; | ||
|
||
os << "Bytes : " << std::endl; | ||
for (int i = 0; i < s.rows; ++i) { | ||
for (int j = 0; j < s.cols; ++j) { | ||
os << static_cast<int>(s.bytes[i * s.cols + j]) << " "; | ||
} | ||
os << std::endl; | ||
} | ||
return os; | ||
} | ||
|
||
// subscriber callback function | ||
void OnReceive(const char* /*topic_name_*/, const struct eCAL::SReceiveCallbackData* data_) | ||
{ | ||
if (data_->size < 1) return; | ||
|
||
std::cout << "------------------------------------" << std::endl; | ||
std::cout << "Binary buffer header :" << std::endl; | ||
std::cout << "------------------------------------" << std::endl; | ||
std::cout << " Size : " << data_->size << std::endl; | ||
std::cout << " Id : " << data_->id << std::endl; | ||
std::cout << " Time : " << data_->time << std::endl; | ||
std::cout << " Clock : " << data_->clock << std::endl; | ||
std::cout << std::endl; | ||
std::cout << "------------------------------------" << std::endl; | ||
std::cout << "SSimpleStruct :" << std::endl; | ||
std::cout << "------------------------------------" << std::endl; | ||
std::cout << *static_cast<SSimpleStruct*>(data_->buf) << std::endl; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
const char* nodeName = "binary_zero_copy_rec"; | ||
const char* topicName = "simple_struct"; | ||
|
||
// initialize eCAL API | ||
eCAL::Initialize(argc, argv, nodeName); | ||
|
||
// create the subscriber | ||
eCAL::CSubscriber sub(topicName); | ||
|
||
// assign callback | ||
sub.AddReceiveCallback(OnReceive); | ||
|
||
// idle main loop | ||
while (eCAL::Ok()) std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
|
||
// finalize eCAL API | ||
eCAL::Finalize(); | ||
|
||
return 0; | ||
} |
38 changes: 38 additions & 0 deletions
38
samples/cpp/pubsub/binary/binary_zero_copy_snd/CMakeLists.txt
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,38 @@ | ||
# ========================= eCAL LICENSE ================================= | ||
# | ||
# Copyright (C) 2016 - 2019 Continental Corporation | ||
# | ||
# 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. | ||
# | ||
# ========================= eCAL LICENSE ================================= | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(binary_zero_copy_snd) | ||
|
||
# set project properties | ||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) | ||
set(binary_zero_copy_snd_src src/binary_zero_copy_snd.cpp) | ||
|
||
# find packages | ||
message("-- Checking for modules 'eCAL'") | ||
find_package(eCAL REQUIRED) | ||
|
||
# add and configure sample project | ||
ecal_add_sample(${PROJECT_NAME} ${binary_zero_copy_snd_src}) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) | ||
target_link_libraries(${PROJECT_NAME} eCAL::core) | ||
|
||
# install and set properties | ||
ecal_install_sample(${PROJECT_NAME}) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/pubsub/binary) |
Oops, something went wrong.