Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into iox-#590-rename-uti…
Browse files Browse the repository at this point in the history
…ls-to-hoofs
  • Loading branch information
mossmaurice committed May 12, 2021
2 parents 1785870 + dec1f6b commit c2e0eaf
Show file tree
Hide file tree
Showing 27 changed files with 397 additions and 175 deletions.
4 changes: 2 additions & 2 deletions doc/aspice_swe3_4/swe_docu_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To generate the documentation you need to install:
```bash
sudo apt install doxygen graphviz texlive-base texlive-font-utils texlive-latex-extra
```
The documentation we use plantuml for describing dynamic behavior in the code (sequence or activity diagrams).
The documentation we use PlantUML for describing dynamic behavior in the code (sequence or activity diagrams).
Needed package:
```bash
sudo apt install plantuml
Expand Down Expand Up @@ -103,7 +103,7 @@ See the header files under iceoryx/doc/aspice_swe3_4/example.

### PlantUML

if you want to make complex aspects of your implementation visible, you can write plantuml directly into the
if you want to make complex aspects of your implementation visible, you can write PlantUML directly into the
doxygen description of your class. An example can be found at [example_base_class.hpp](example/iceoryx_component/source/example_module/example_base_class.hpp)

Having PlantUML installed is not a must. If you want to use it you need to install it, and the variable `PLANTUML_JAR_PATH` needs to be set.
Expand Down
37 changes: 34 additions & 3 deletions doc/design/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
# Design Documents

In here you can find design documents to all constructs of iceoryx. At the
In here you can find design documents to all constructs of iceoryx. At the
moment those design documents are neither complete nor final.

In [draft](./draft/) are design drafts of current features contained which are under
implementation. The goal is to provide other developers a first idea on how
In [draft](./draft/) are design drafts of current features contained which are under
implementation. The goal is to provide other developers a first idea on how
the feature can be used and how it will be implemented.

## Add diagrams using PlantUML

Diagrams in the design documentation can be done with [PlantUML](https://plantuml.com/).
For using PlantUML we recommend to use the latest version with the following required packages:

```bash
sudo apt install default-jre-headless graphviz
```

A good online-editor with cheat-sheet can be found at [https://plantuml-editor.kkeisuke.com](https://plantuml-editor.kkeisuke.com).
Alternatively you can use extensions in your IDE.

The integration of the generated PlantUML into your design documents is done via *.svg files.
You need to create a .puml file and export it to .svg afterwards for linking it with the markdown. In the tools folder is a helper script for that provided which downloads a defined version of PlantUML to export the vector graphics.
These steps are necessary due to the current support of PlantUML in [Github](https://github.community/t/support-uml-diagrams-in-markdown-with-plantuml-syntax/626).

**NOTE:** Please set in the PlantUML code the background manually to make all textboxes visible to users with dark-mode enabled in the Github-UI.

```plantuml
@startuml
skinparam backgroundColor #EEEBDC
...
@enduml
```

This is an example how to render PlantUML in Github:

workflow using svg file:

![plantuml github workflow](diagrams/puml_github_workflow.svg)
20 changes: 20 additions & 0 deletions doc/design/diagrams/puml_github_workflow.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@startuml

skinparam backgroundColor #EEEBDC

left to right direction

actor Iceoryx_Contributor

Iceoryx_Contributor --> (1. Create Diagram in PlanUML Editor)
Iceoryx_Contributor --> (2. Save it as new .puml file in iceoryx/doc/design/puml)
Iceoryx_Contributor --> (3. Export svg files via script in iceoryx/tools/ folder)
Iceoryx_Contributor --> (4. Create a Link in the Markdown file)
note left
The following snippet can be used to link against a svg file in markdown:
<code>
![your image description](puml/your_exported_vector_graphic.svg)
</code>
end note

@enduml
6 changes: 6 additions & 0 deletions doc/design/diagrams/puml_github_workflow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions iceoryx_examples/singleprocess/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ while (keepRunning.load())
{
publisher.loan().and_then([&](auto& sample) {
sample->counter = counter++;
consoleOutput(std::string("Sending " + greenRightArrow + std::to_string(sample->counter)));
consoleOutput(std::string("Sending " + greenRightArrow + iox::cxx::convert::toString(sample->counter)));
sample.publish();
});
Expand Down Expand Up @@ -139,7 +139,7 @@ while (keepRunning.load())
{
subscriber.take()
.and_then([&](iox::popo::Sample<const TransmissionData_t>& sample) {
consoleOutput(std::string("Receiving " + orangeLeftArrow + std::to_string(sample->counter)));
consoleOutput(std::string("Receiving " + orangeLeftArrow + iox::cxx::convert::toString(sample->counter)));
})
.if_empty([&] { hasMoreSamples = false; })
.or_else([](auto) { std::cout << "Error receiving sample: " << std::endl; });
Expand Down
21 changes: 10 additions & 11 deletions iceoryx_examples/singleprocess/single_process.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 by Robert Bosch GmbH All rights reserved.
// Copyright (c) 2020 - 2021 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");
Expand All @@ -15,15 +15,16 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/convert.hpp"
#include "iceoryx_hoofs/log/logmanager.hpp"
#include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp"
#include "iceoryx_posh/iceoryx_posh_config.hpp"
#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/internal/roudi/roudi.hpp"
#include "iceoryx_posh/popo/publisher.hpp"
#include "iceoryx_posh/popo/subscriber.hpp"
#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp"
#include "iceoryx_posh/runtime/posh_runtime_single_process.hpp"
#include "iceoryx_hoofs/log/logmanager.hpp"
#include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp"

#include <atomic>
#include <chrono>
Expand All @@ -45,12 +46,12 @@ struct TransmissionData_t
uint64_t counter;
};

void consoleOutput(const std::string& output)
void consoleOutput(const char* source, const char* arrow, const uint64_t counter)
{
static std::mutex consoleOutputMutex;

std::lock_guard<std::mutex> lock(consoleOutputMutex);
std::cout << output << std::endl;
std::cout << source << arrow << counter << std::endl;
}

void publisher()
Expand All @@ -60,12 +61,12 @@ void publisher()
iox::popo::Publisher<TransmissionData_t> publisher({"Single", "Process", "Demo"}, publisherOptions);

uint64_t counter{0};
std::string greenRightArrow("\033[32m->\033[m ");
constexpr const char GREEN_RIGHT_ARROW[] = "\033[32m->\033[m ";
while (keepRunning.load())
{
publisher.loan().and_then([&](auto& sample) {
sample->counter = counter++;
consoleOutput(std::string("Sending " + greenRightArrow + std::to_string(sample->counter)));
consoleOutput("Sending ", GREEN_RIGHT_ARROW, sample->counter);
sample.publish();
});

Expand All @@ -80,7 +81,7 @@ void subscriber()
options.historyRequest = 5U;
iox::popo::Subscriber<TransmissionData_t> subscriber({"Single", "Process", "Demo"}, options);

std::string orangeLeftArrow("\033[33m<-\033[m ");
constexpr const char ORANGE_LEFT_ARROW[] = "\033[33m<-\033[m ";
while (keepRunning.load())
{
if (iox::SubscribeState::SUBSCRIBED == subscriber.getSubscriptionState())
Expand All @@ -90,9 +91,7 @@ void subscriber()
do
{
subscriber.take()
.and_then([&](auto& sample) {
consoleOutput(std::string("Receiving " + orangeLeftArrow + std::to_string(sample->counter)));
})
.and_then([&](auto& sample) { consoleOutput("Receiving ", ORANGE_LEFT_ARROW, sample->counter); })
.or_else([&](auto& result) {
hasMoreSamples = false;
if (result != iox::popo::ChunkReceiveResult::NO_CHUNK_AVAILABLE)
Expand Down
17 changes: 17 additions & 0 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/convert.inl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ namespace iox
{
namespace cxx
{
///@brief specialization for uint8_t and int8_t is required since uint8_t is unsigned char and int8_t is signed char
/// and stringstream will not convert these to string as it is already a character.
template <>
inline typename std::enable_if<!std::is_convertible<uint8_t, std::string>::value, std::string>::type
convert::toString(const uint8_t& t)
{
return toString(static_cast<uint16_t>(t));
}

template <>
inline typename std::enable_if<!std::is_convertible<int8_t, std::string>::value, std::string>::type
convert::toString(const int8_t& t)
{
return toString(static_cast<int16_t>(t));
}


template <typename Source>
inline typename std::enable_if<!std::is_convertible<Source, std::string>::value, std::string>::type
convert::toString(const Source& t)
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/include/iceoryx_hoofs/log/logstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef IOX_HOOFS_LOG_LOGSTREAM_HPP
#define IOX_HOOFS_LOG_LOGSTREAM_HPP

#include "iceoryx_hoofs/cxx/convert.hpp"
#include "iceoryx_hoofs/log/logcommon.hpp"

#include <bitset>
Expand Down Expand Up @@ -127,7 +128,7 @@ class LogStream
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
LogStream& operator<<(const T val) noexcept
{
m_logEntry.message.append(std::to_string(val));
m_logEntry.message.append(cxx::convert::toString(val));
m_flushed = false;
return *this;
}
Expand Down
60 changes: 36 additions & 24 deletions iceoryx_hoofs/test/moduletests/test_cxx_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ class convert_test : public Test
};


TEST_F(convert_test, toString_uint8_t)
{
uint8_t data = 131U;
EXPECT_THAT(iox::cxx::convert::toString(data), Eq("131"));
}

TEST_F(convert_test, toString_int8_t)
{
int8_t data = 31;
EXPECT_THAT(iox::cxx::convert::toString(data), Eq("31"));
}

TEST_F(convert_test, toString_Integer)
{
EXPECT_THAT(iox::cxx::convert::toString(123), Eq("123"));
EXPECT_THAT(iox::cxx::convert::toString(33331), Eq("33331"));
}

TEST_F(convert_test, toString_Float)
{
EXPECT_THAT(iox::cxx::convert::toString(12.3f), Eq("12.3"));
EXPECT_THAT(iox::cxx::convert::toString(333.1f), Eq("333.1"));
}

TEST_F(convert_test, toString_LongLongUnsignedInt)
Expand Down Expand Up @@ -122,7 +134,7 @@ TEST_F(convert_test, stringIsNumber_IsZero)

TEST_F(convert_test, stringIsNumber_INTEGERWithSign)
{
EXPECT_THAT(iox::cxx::convert::stringIsNumber("-123", NumberType::INTEGER), Eq(true));
EXPECT_THAT(iox::cxx::convert::stringIsNumber("-521", NumberType::INTEGER), Eq(true));
}

TEST_F(convert_test, stringIsNumber_INTEGERWithSignPlacedWrongly)
Expand All @@ -132,17 +144,17 @@ TEST_F(convert_test, stringIsNumber_INTEGERWithSignPlacedWrongly)

TEST_F(convert_test, stringIsNumber_SimpleFLOAT)
{
EXPECT_THAT(iox::cxx::convert::stringIsNumber("123.123", NumberType::FLOAT), Eq(true));
EXPECT_THAT(iox::cxx::convert::stringIsNumber("123.456", NumberType::FLOAT), Eq(true));
}

TEST_F(convert_test, stringIsNumber_MultiDotFLOAT)
{
EXPECT_THAT(iox::cxx::convert::stringIsNumber("12.3.123", NumberType::FLOAT), Eq(false));
EXPECT_THAT(iox::cxx::convert::stringIsNumber("11.1.123", NumberType::FLOAT), Eq(false));
}

TEST_F(convert_test, stringIsNumber_FLOATWithSign)
{
EXPECT_THAT(iox::cxx::convert::stringIsNumber("+123.123", NumberType::FLOAT), Eq(true));
EXPECT_THAT(iox::cxx::convert::stringIsNumber("+123.321", NumberType::FLOAT), Eq(true));
}

TEST_F(convert_test, stringIsNumber_NumberWithLetters)
Expand Down Expand Up @@ -182,9 +194,9 @@ TEST_F(convert_test, fromString_Double_Fail)

TEST_F(convert_test, fromString_LongDouble_Success)
{
std::string source = "123.01";
std::string source = "121.01";
long double destination;
long double verify = 123.01;
long double verify = 121.01;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Ge(verify - 0.00001));
EXPECT_THAT(destination, Le(verify + 0.00001));
Expand All @@ -199,25 +211,25 @@ TEST_F(convert_test, fromString_LongDouble_Fail)

TEST_F(convert_test, fromString_UNSIGNED_Int_Success)
{
std::string source = "123";
std::string source = "100";
unsigned int destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123u));
EXPECT_THAT(destination, Eq(100u));
}

TEST_F(convert_test, fromString_UNSIGNED_Int_Fail)
{
std::string source = "-123";
std::string source = "-331";
unsigned int destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_UNSIGNED_LongInt_Success)
{
std::string source = "123";
std::string source = "999";
uint64_t destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123lu));
EXPECT_THAT(destination, Eq(999lu));
}

TEST_F(convert_test, fromString_UNSIGNED_LongInt_Fail)
Expand All @@ -229,30 +241,30 @@ TEST_F(convert_test, fromString_UNSIGNED_LongInt_Fail)

TEST_F(convert_test, fromString_Int_Success)
{
std::string source = "123";
std::string source = "3331";
int destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123));
EXPECT_THAT(destination, Eq(3331));
}

TEST_F(convert_test, fromString_Int_Fail)
{
std::string source = "-+123";
std::string source = "-+321";
int destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_ShortInt_Success)
{
std::string source = "123";
std::string source = "12345";
short destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123));
EXPECT_THAT(destination, Eq(12345));
}

TEST_F(convert_test, fromString_ShortInt_Fail)
{
std::string source = "-+123";
std::string source = "-+123321";
short destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}
Expand All @@ -267,22 +279,22 @@ TEST_F(convert_test, fromString_Bool_Success)

TEST_F(convert_test, fromString_Bool_Fail)
{
std::string source = "-+123";
std::string source = "-+222";
bool destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_UShortInt_Success)
{
std::string source = "123";
std::string source = "333";
unsigned short destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123));
EXPECT_THAT(destination, Eq(333));
}

TEST_F(convert_test, fromString_UShortInt_Fail)
{
std::string source = "-+123";
std::string source = "-+111";
unsigned short destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}
Expand All @@ -297,7 +309,7 @@ TEST_F(convert_test, fromString_LongInt_Success)

TEST_F(convert_test, fromString_LongInt_Fail)
{
std::string source = "-a123";
std::string source = "-a121";
int64_t destination;
EXPECT_THAT(iox::cxx::convert::fromString(source.c_str(), destination), Eq(false));
}
Expand Down
Loading

0 comments on commit c2e0eaf

Please sign in to comment.