Skip to content

Commit

Permalink
iox-eclipse-iceoryx#65 Clang format + refactor for cleanliness.
Browse files Browse the repository at this point in the history
Signed-off-by: Ithier Jeff (CC-AD/EYF1) <[email protected]>
  • Loading branch information
orecham committed Jul 7, 2020
1 parent 1d1a4c2 commit 9c19805
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 54 deletions.
4 changes: 2 additions & 2 deletions iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef IOX_DDS_DDS_DATA_READER_HPP
#define IOX_DDS_DDS_DATA_READER_HPP

#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/cxx/expected.hpp"
#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/cxx/string.hpp"

namespace iox
Expand Down Expand Up @@ -66,7 +66,7 @@ class DataReader
/// @param maxSamples The maximum number of samples to request from the network.
/// @return Number of samples taken if successful. Number of samples will be in the sange [0,maxSamples].
///
/// @note Sample size must be known ahead of time & can be checked using @ref peekNext() .
/// @note Sample size must be known ahead of time & can be checked using @ref peekNextSize() .
///
virtual iox::cxx::expected<uint64_t, DataReaderError>
take(uint8_t* const buffer, const uint64_t& bufferSize, const iox::cxx::optional<uint64_t>& maxSamples) = 0;
Expand Down
1 change: 0 additions & 1 deletion iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class Channel
iox::capro::ServiceDescription m_service;
IceoryxTerminalPtr m_iceoryxTerminal;
DDSTerminalPtr m_ddsTerminal;

};

} // namespace dds
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class DDS2IceoryxGateway : public gateway_t

private:
void* m_reservedChunk = nullptr;
iox::cxx::expected<channel_t, iox::dds::GatewayError> setupChannel(const iox::capro::ServiceDescription& service) noexcept;
iox::cxx::expected<channel_t, iox::dds::GatewayError>
setupChannel(const iox::capro::ServiceDescription& service) noexcept;
};

} // namespace dds
Expand Down
24 changes: 13 additions & 11 deletions iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ inline void DDS2IceoryxGateway<channel_t, gateway_t>::loadConfiguration(const Ga
}

template <typename channel_t, typename gateway_t>
inline void DDS2IceoryxGateway<channel_t, gateway_t>::discover(const iox::capro::CaproMessage& msg) noexcept
inline void
DDS2IceoryxGateway<channel_t, gateway_t>::discover([[gnu::unused]] const iox::capro::CaproMessage& msg) noexcept
{
/// @note not implemented - requires dds discovery which is currently not implemented in the used dds stack.
}

template <typename channel_t, typename gateway_t>
inline void DDS2IceoryxGateway<channel_t, gateway_t>::forward(const channel_t& channel) noexcept
{

auto publisher = channel.getIceoryxTerminal();
auto reader = channel.getDDSTerminal();

auto peekResult = reader->peekNextSize();
if(peekResult.has_value())
if (peekResult.has_value())
{
// reserve a chunk for the sample
auto size = peekResult.value();
Expand All @@ -67,24 +67,26 @@ inline void DDS2IceoryxGateway<channel_t, gateway_t>::forward(const channel_t& c
// read sample into reserved chunk
auto buffer = static_cast<uint8_t*>(m_reservedChunk);
auto takeResult = reader->takeNext(buffer, size);
if(takeResult.has_error())
if (takeResult.has_error())
{
LogWarn() << "[DDS2IceoryxGateway] Encountered error reading from DDS network: " << iox::dds::DataReaderErrorString[static_cast<uint8_t>(takeResult.get_error())];
LogWarn() << "[DDS2IceoryxGateway] Encountered error reading from DDS network: "
<< iox::dds::DataReaderErrorString[static_cast<uint8_t>(takeResult.get_error())];
}
else
{
// publish the sample
publisher->sendChunk(buffer);
}

// publish the sample
publisher->sendChunk(buffer);
}

}

// ======================================== Private ======================================== //
template <typename channel_t, typename gateway_t>
iox::cxx::expected<channel_t, iox::dds::GatewayError>
DDS2IceoryxGateway<channel_t, gateway_t>::setupChannel(const iox::capro::ServiceDescription& service) noexcept
{
return this->addChannel(service)
.on_success([&service](iox::cxx::expected<channel_t, iox::dds::GatewayError> result) {
return this->addChannel(service).on_success(
[&service](iox::cxx::expected<channel_t, iox::dds::GatewayError> result) {
auto channel = result.get_value();
auto publisher = channel.getIceoryxTerminal();
auto reader = channel.getDDSTerminal();
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_dds/source/dds2iceoryx_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ int main()

iox::dds::DDS2IceoryxGateway<> gw;
auto result = iox::dds::TomlGatewayConfigParser::parse();
if (!result.has_error())
{
gw.loadConfiguration(result.get_value());
}
else
if (result.has_error())
{
iox::dds::LogWarn() << "[Main] Failed to parse gateway config with error: "
<< iox::dds::TomlGatewayConfigParseErrorString[result.get_error()];
Expand All @@ -75,6 +71,10 @@ int main()
defaultConfig.setDefaults();
gw.loadConfiguration(defaultConfig);
}
else
{
gw.loadConfiguration(result.get_value());
}

gw.runMultithreaded();

Expand Down
10 changes: 5 additions & 5 deletions iceoryx_dds/source/iceoryx2dds_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ int main()

iox::dds::Iceoryx2DDSGateway<> gw;
auto result = iox::dds::TomlGatewayConfigParser::parse();
if (!result.has_error())
{
gw.loadConfiguration(result.get_value());
}
else
if (result.has_error())
{
iox::dds::LogWarn() << "[Main] Failed to parse gateway config with error: "
<< iox::dds::TomlGatewayConfigParseErrorString[result.get_error()];
Expand All @@ -67,6 +63,10 @@ int main()
defaultConfig.setDefaults();
gw.loadConfiguration(defaultConfig);
}
else
{
gw.loadConfiguration(result.get_value());
}

gw.runMultithreaded();

Expand Down
32 changes: 11 additions & 21 deletions iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ void iox::dds::CycloneDataReader::connect() noexcept
iox::cxx::optional<uint64_t> iox::dds::CycloneDataReader::peekNextSize()
{
// ensure to only read sample - do not take
auto readSamples = m_impl.select()
.max_samples(1u)
.state(::dds::sub::status::SampleState::any())
.read();
auto readSamples = m_impl.select().max_samples(1u).state(::dds::sub::status::SampleState::any()).read();

if(readSamples.length() > 0)
if (readSamples.length() > 0)
{
auto nextSample = readSamples.begin();
auto nextSampleSize = nextSample->data().payload().size();
Expand All @@ -71,13 +68,11 @@ iox::cxx::optional<uint64_t> iox::dds::CycloneDataReader::peekNextSize()

// no valid samples available
return iox::cxx::nullopt_t();

}

iox::cxx::expected<iox::dds::DataReaderError>
iox::dds::CycloneDataReader::takeNext(uint8_t* const buffer, const uint64_t& bufferSize)
iox::cxx::expected<iox::dds::DataReaderError> iox::dds::CycloneDataReader::takeNext(uint8_t* const buffer,
const uint64_t& bufferSize)
{

// validation checks
if (!m_isConnected.load())
{
Expand All @@ -89,11 +84,8 @@ iox::dds::CycloneDataReader::takeNext(uint8_t* const buffer, const uint64_t& buf
}

// take next sample and copy into buffer
auto takenSamples = m_impl.select()
.max_samples(1u)
.state(::dds::sub::status::SampleState::any())
.take();
if(takenSamples.length() == 0)
auto takenSamples = m_impl.select().max_samples(1u).state(::dds::sub::status::SampleState::any()).take();
if (takenSamples.length() == 0)
{
// no samples available
return iox::cxx::success<>();
Expand All @@ -119,9 +111,8 @@ iox::dds::CycloneDataReader::takeNext(uint8_t* const buffer, const uint64_t& buf
return iox::cxx::success<>();
}

iox::cxx::expected<uint64_t, iox::dds::DataReaderError> iox::dds::CycloneDataReader::take(uint8_t* const buffer,
const uint64_t& bufferSize,
const iox::cxx::optional<uint64_t>& maxSamples)
iox::cxx::expected<uint64_t, iox::dds::DataReaderError> iox::dds::CycloneDataReader::take(
uint8_t* const buffer, const uint64_t& bufferSize, const iox::cxx::optional<uint64_t>& maxSamples)
{
if (!m_isConnected.load())
{
Expand All @@ -134,7 +125,7 @@ iox::cxx::expected<uint64_t, iox::dds::DataReaderError> iox::dds::CycloneDataRea

// get size of the sample
auto peekResult = peekNextSize();
if(peekResult.has_value())
if (peekResult.has_value())
{
uint64_t sampleSize = peekResult.value();
if (sampleSize == 0)
Expand All @@ -151,9 +142,9 @@ iox::cxx::expected<uint64_t, iox::dds::DataReaderError> iox::dds::CycloneDataRea
auto bufferCapacity = bufferSize / sampleSize;

auto numToTake = bufferCapacity;
if(maxSamples.has_value())
if (maxSamples.has_value())
{
if(bufferCapacity > maxSamples.value())
if (bufferCapacity > maxSamples.value())
{
numToTake = maxSamples.value();
}
Expand Down Expand Up @@ -183,7 +174,6 @@ iox::cxx::expected<uint64_t, iox::dds::DataReaderError> iox::dds::CycloneDataRea
{
return iox::cxx::success<uint64_t>(0u);
}

}

iox::dds::IdString iox::dds::CycloneDataReader::getServiceId() const noexcept
Expand Down
1 change: 0 additions & 1 deletion iceoryx_dds/test/helpers/fixture_dds_gateway.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class DDSGatewayTestFixture : public Test
iox::dds::Channel<IceoryxTerminal, DDSTerminal>(
sd, std::move(mockIceoryxTerminal), std::move(mockDataWriter)));
}

};

#endif // TEST_HELPERS_FIXTURE_DDS_GATEWAY_H
2 changes: 0 additions & 2 deletions iceoryx_dds/test/moduletests/test_cyclone_data_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ TEST_F(CycloneDataReaderTest, DoesNotAttemptToReadWhenDisconnected)
auto takeNextResult = reader.takeNext(buffer, bufferSize);
EXPECT_EQ(true, takeNextResult.has_error());
EXPECT_EQ(iox::dds::DataReaderError::NOT_CONNECTED, takeResult.get_error());

}

TEST_F(CycloneDataReaderTest, ReturnsErrorWhenAttemptingToReadIntoANullBuffer)
Expand All @@ -76,6 +75,5 @@ TEST_F(CycloneDataReaderTest, ReturnsErrorWhenAttemptingToReadIntoANullBuffer)
}



} // namespace dds
} // namespace iox
7 changes: 2 additions & 5 deletions iceoryx_dds/test/moduletests/test_dds_to_iox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ TEST_F(DDS2IceoryxGatewayTest, ImmediatelyConnectsConfiguredDataReaders)

TEST_F(DDS2IceoryxGatewayTest, PublishesMemoryChunksContainingSamplesToNetwork)
{

// === Setup
auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"});

// Setup data reader to provide a sample
auto mockDataReader = createMockDDSTerminal(testService);
auto mockPublisher = createMockIceoryxTerminal(testService);

ON_CALL(*mockDataReader, peekNextSize).WillByDefault(Return(ByMove(iox::cxx::make_optional<uint64_t>(static_cast<uint64_t>(8u)))));
ON_CALL(*mockDataReader, peekNextSize)
.WillByDefault(Return(ByMove(iox::cxx::make_optional<uint64_t>(static_cast<uint64_t>(8u)))));
ON_CALL(*mockDataReader, takeNext).WillByDefault(Return(ByMove(iox::cxx::success<>())));
EXPECT_CALL(*mockPublisher, sendChunk).Times(1);

Expand All @@ -112,7 +112,4 @@ TEST_F(DDS2IceoryxGatewayTest, PublishesMemoryChunksContainingSamplesToNetwork)
// === Test
auto testChannel = channelFactory(testService).get_value();
gw.forward(testChannel);

}


0 comments on commit 9c19805

Please sign in to comment.