forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 1
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#25: first skeletons for chunk receiver and its test
Signed-off-by: Poehnl Michael (CC-AD/ESW1) <[email protected]>
- Loading branch information
Poehnl Michael (CC-AD/ESW1)
committed
Apr 6, 2020
1 parent
5a9fdc7
commit 33548dd
Showing
8 changed files
with
230 additions
and
22 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
75 changes: 75 additions & 0 deletions
75
iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_receiver.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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. | ||
|
||
#ifndef IOX_POSH_POPO_CHUNK_RECEIVER_HPP_ | ||
#define IOX_POSH_POPO_CHUNK_RECEIVER_HPP_ | ||
|
||
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue.hpp" | ||
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver_data.hpp" | ||
#include "iceoryx_posh/mepoo/chunk_header.hpp" | ||
#include "iceoryx_utils/cxx/expected.hpp" | ||
#include "iceoryx_utils/cxx/optional.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace popo | ||
{ | ||
enum class ChunkReceiverError | ||
{ | ||
TOO_MANY_CHUNKS_HELD_IN_PARALLEL | ||
}; | ||
|
||
/// @brief The ChunkReceiver is a building block of the shared memory communication infrastructure. It extends | ||
/// the functionality of a ChunkQueue with the abililty to pass chunks to the user side (user process). | ||
/// Together with the ChunkSender, they are the next abstraction layer on top of ChunkDistributor and ChunkQueue. The | ||
/// ChunkRceiver holds the ownership of the SharedChunks and does a bookkeeping which chunks are currently passed to the | ||
/// user side. | ||
class ChunkReceiver : public ChunkQueue | ||
{ | ||
public: | ||
using MemberType_t = ChunkReceiverData; | ||
|
||
ChunkReceiver(MemberType_t* const chunkReceiverDataPtr) noexcept; | ||
|
||
ChunkReceiver(const ChunkReceiver& other) = delete; | ||
ChunkReceiver& operator=(const ChunkReceiver&) = delete; | ||
ChunkReceiver(ChunkReceiver&& rhs) = default; | ||
ChunkReceiver& operator=(ChunkReceiver&& rhs) = default; | ||
~ChunkReceiver() = default; | ||
|
||
/// @brief Tries to get the next received chunk. If there is a new one the ChunkHeader of this new chunk is received | ||
/// The ownerhip of the SharedChunk remains in the ChunkReceiver for being able to cleanup if the user process | ||
/// disappears | ||
/// @return optional that has a new chunk header or no value if there are no new chunks in the underlying queue, | ||
/// ChunkReceiverError on error | ||
cxx::expected<cxx::optional<const mepoo::ChunkHeader*>, ChunkReceiverError> get() noexcept; | ||
|
||
/// @brief Release a chunk that was obtained with get | ||
/// @param[in] chunkHeader, pointer to the ChunkHeader to free | ||
void release(const mepoo::ChunkHeader* chunkHeader) noexcept; | ||
|
||
/// @brief Release all the chunks that are currently held. Caution: Only call this if the user process is no more | ||
/// running E.g. This cleans up chunks that were held by a user process that died unexpectetly, for avoiding lost | ||
/// chunks in the system | ||
void releaseAll() noexcept; | ||
|
||
private: | ||
const MemberType_t* getMembers() const noexcept; | ||
MemberType_t* getMembers() noexcept; | ||
}; | ||
|
||
} // namespace popo | ||
} // namespace iox | ||
|
||
#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
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
52 changes: 52 additions & 0 deletions
52
iceoryx_posh/source/popo/building_blocks/chunk_receiver.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,52 @@ | ||
// 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. | ||
|
||
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" | ||
|
||
#include "iceoryx_posh/internal/log/posh_logging.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace popo | ||
{ | ||
ChunkReceiver::ChunkReceiver(MemberType_t* const chunkReceiverDataPtr) noexcept | ||
: ChunkQueue(chunkReceiverDataPtr) | ||
{ | ||
} | ||
|
||
const ChunkReceiver::MemberType_t* ChunkReceiver::getMembers() const noexcept | ||
{ | ||
return reinterpret_cast<const MemberType_t*>(ChunkQueue::getMembers()); | ||
} | ||
|
||
ChunkReceiver::MemberType_t* ChunkReceiver::getMembers() noexcept | ||
{ | ||
return reinterpret_cast<MemberType_t*>(ChunkQueue::getMembers()); | ||
} | ||
|
||
cxx::expected<cxx::optional<const mepoo::ChunkHeader*>, ChunkReceiverError> get() noexcept | ||
{ | ||
return cxx::error<ChunkReceiverError>(ChunkReceiverError::TOO_MANY_CHUNKS_HELD_IN_PARALLEL); | ||
} | ||
|
||
void release(const mepoo::ChunkHeader* chunkHeader) noexcept | ||
{ | ||
} | ||
|
||
void releaseAll() noexcept | ||
{ | ||
} | ||
|
||
} // namespace popo | ||
} // namespace iox |
80 changes: 80 additions & 0 deletions
80
iceoryx_posh/test/moduletests/test_popo_chunk_receiver.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,80 @@ | ||
// 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. | ||
|
||
#include "iceoryx_posh/iceoryx_posh_types.hpp" | ||
#include "iceoryx_posh/internal/mepoo/memory_manager.hpp" | ||
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" | ||
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver_data.hpp" | ||
#include "iceoryx_posh/mepoo/mepoo_config.hpp" | ||
#include "iceoryx_utils/error_handling/error_handling.hpp" | ||
#include "iceoryx_utils/internal/posix_wrapper/shared_memory_object/allocator.hpp" | ||
#include "test.hpp" | ||
|
||
#include <memory> | ||
|
||
using namespace ::testing; | ||
|
||
struct DummySample | ||
{ | ||
uint64_t dummy{42}; | ||
}; | ||
|
||
class ChunkReceiver_testBase : public Test | ||
{ | ||
protected: | ||
ChunkReceiver_testBase() | ||
{ | ||
m_mempoolconf.addMemPool({CHUNK_SIZE, NUM_CHUNKS_IN_POOL}); | ||
m_memoryManager.configureMemoryManager(m_mempoolconf, &m_memoryAllocator, &m_memoryAllocator); | ||
} | ||
|
||
~ChunkReceiver_testBase() | ||
{ | ||
} | ||
|
||
void SetUp() | ||
{ | ||
} | ||
|
||
void TearDown() | ||
{ | ||
} | ||
|
||
static constexpr size_t MEMORY_SIZE = 1024 * 1024; | ||
uint8_t m_memory[1024 * 1024]; | ||
static constexpr uint32_t NUM_CHUNKS_IN_POOL = 20; | ||
static constexpr uint32_t CHUNK_SIZE = 128; | ||
|
||
iox::posix::Allocator m_memoryAllocator{m_memory, MEMORY_SIZE}; | ||
iox::mepoo::MePooConfig m_mempoolconf; | ||
iox::mepoo::MemoryManager m_memoryManager; | ||
|
||
iox::popo::ChunkReceiverData m_chunkReceiverData{iox::cxx::VariantQueueTypes::SoFi_SingleProducerSingleConsumer}; | ||
iox::popo::ChunkReceiver m_chunkReceiver{&m_chunkReceiverData}; | ||
}; | ||
|
||
class ChunkReceiver_test : public ChunkReceiver_testBase | ||
{ | ||
public: | ||
ChunkReceiver_test() | ||
: ChunkReceiver_testBase() | ||
{ | ||
} | ||
}; | ||
|
||
TEST_F(ChunkReceiver_test, get_OneChunk) | ||
{ | ||
auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); | ||
EXPECT_TRUE(sharedChunk); | ||
} |
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