Skip to content

Commit

Permalink
Refs #21571: Add review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
  • Loading branch information
Carlosespicur committed Sep 16, 2024
1 parent 7e17042 commit e2ed782
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
2 changes: 1 addition & 1 deletion plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ReaderHandler::ReaderHandler(
{
// Create data so it is not required to create it each time and avoid reallocation if possible
data_ = DynamicDataFactory::get_instance()->create_data(type_);

// Set this object as this reader's listener
reader_->set_listener(this);
}
Expand Down
33 changes: 14 additions & 19 deletions plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* @file dynamic_types_utils.cpp
*/

#include <sstream>
#include <algorithm>
#include <iostream>
#include <random>
#include <limits>
#include <algorithm>
#include <random>
#include <sstream>

#include <nlohmann/json.hpp>

Expand All @@ -35,31 +35,26 @@
#include <fastdds/dds/xtypes/utils.hpp>

#include "dynamic_types_utils.hpp"
#include "utils.hpp"
#include "Exception.hpp"
#include "utils.hpp"

namespace eprosima {
namespace plotjuggler {
namespace utils {
using namespace eprosima::fastdds::dds;
using namespace eprosima::fastdds::rtps;

std::vector<std::string> get_introspection_type_names(
const TypeIntrospectionNumericStruct& numeric_type_names)
{
std::vector<std::string> type_names;
for (const auto& type_name : numeric_type_names)
{
type_names.push_back(type_name.first);
}
return type_names;
}
template std::vector<std::string> get_introspection_type_names<TypeIntrospectionNumericStruct>(
const TypeIntrospectionNumericStruct& type_names_struct);
template std::vector<std::string> get_introspection_type_names<TypeIntrospectionStringStruct>(
const TypeIntrospectionStringStruct& type_names_struct);

template <typename T>
std::vector<std::string> get_introspection_type_names(
const TypeIntrospectionStringStruct& string_type_names)
const T& type_names_struct)
{
std::vector<std::string> type_names;
for (const auto& type_name : string_type_names)
for (const auto& type_name : type_names_struct)
{
type_names.push_back(type_name.first);
}
Expand All @@ -80,7 +75,7 @@ void get_formatted_data(
numeric_data.push_back({base_type_name, data.get<double>()});
return;
}
else if(is_kind_boolean(data))
else if (is_kind_boolean(data))
{
bool value = data.get<bool>();
numeric_data.push_back({base_type_name, static_cast<double>(value)});
Expand Down Expand Up @@ -168,8 +163,8 @@ bool is_kind_string(
}

ReturnCode_t serialize_data (
DynamicData::_ref_type data,
nlohmann::json& serialized_data)
DynamicData::_ref_type data,
nlohmann::json& serialized_data)
{
std::stringstream serializer_output;
ReturnCode_t retcode;
Expand Down
34 changes: 7 additions & 27 deletions plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,21 @@ namespace eprosima {
namespace plotjuggler {
namespace utils {

using SingleDataTypeIntrospectionInfo =
std::tuple<
types::DatumLabel,
std::vector<eprosima::fastdds::dds::MemberId>, // Member Ids of the parents of the data member
std::vector<eprosima::fastdds::dds::TypeKind>, // Kind of the parents of the data member
eprosima::fastdds::dds::TypeKind>; // Kind of this member

using TypeIntrospectionCollection =
std::vector<SingleDataTypeIntrospectionInfo>;

using TypeIntrospectionNumericStruct = std::vector<types::NumericDatum>;
using TypeIntrospectionStringStruct = std::vector<types::TextDatum>;


/**
* @brief Get the names of each label in a \c TypeIntrospectionCollection
* This function is used to obtain all the labels form by topics + data type members
* @brief This function is used to obtain all the names of a given collection of numeric/string data.
*
* Iterate over every \c SingleDataTypeIntrospectionInfo and get the \c DatumLabel .
* Iterate over every member and get name.
*
* @param numeric_type_names collection to get all names
* @return all label names
*/
template <typename T>
std::vector<std::string> get_introspection_type_names(
const TypeIntrospectionNumericStruct& numeric_type_names);

/**
TODO (Carlosespicur): Add description
**/
std::vector<std::string> get_introspection_type_names(
const TypeIntrospectionStringStruct& string_type_names);

/**
TODO (Carlosespicur): Add description
**/
const T& type_names_struct);

void get_formatted_data(
const std::string& base_type_name,
Expand All @@ -84,9 +64,9 @@ bool is_kind_boolean(
bool is_kind_string(
const nlohmann::json& data);

ReturnCode_t serialize_data (
DynamicData::_ref_type data,
nlohmann::json& serialized_data);
eprosima::fastdds::dds::ReturnCode_t serialize_data (
eprosima::fastdds::dds::DynamicData::_ref_type data,
nlohmann::json& serialized_data);

} /* namespace utils */
} /* namespace plotjuggler */
Expand Down

0 comments on commit e2ed782

Please sign in to comment.