Skip to content

Commit

Permalink
ros2GH-16 Change name of converter interface to include "serialization"
Browse files Browse the repository at this point in the history
- Easier to differentiate between storage format (e.g. sqlite)
  and serialization format (e.g. cdr)
- Closer to naming in ros middleware
  • Loading branch information
Martin-Idel-SI committed Oct 25, 2018
1 parent aef5986 commit 19112b0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion rosbag2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ find_package(rosidl_generator_cpp REQUIRED)

add_library(${PROJECT_NAME} SHARED
src/rosbag2/sequential_reader.cpp
src/rosbag2/format_converter_factory_impl.cpp
src/rosbag2/serialization_format_converter_factory.cpp
src/rosbag2/typesupport_helpers.cpp
src/rosbag2/writer.cpp)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROSBAG2__FORMAT_CONVERTER_FACTORY_IMPL_HPP_
#define ROSBAG2__FORMAT_CONVERTER_FACTORY_IMPL_HPP_
#ifndef ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_HPP_
#define ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_HPP_

#include "rosbag2/format_converter_factory.hpp"
#include "rosbag2/serialization_format_converter_factory_interface.hpp"

#include <memory>
#include <string>

#include "rosbag2/format_converter_interface.hpp"
#include "rosbag2/serialization_format_converter_interface.hpp"
#include "rosbag2/visibility_control.hpp"

// This is necessary because of using stl types here. It is completely safe, because
Expand All @@ -42,17 +42,19 @@ class ClassLoader;
namespace rosbag2
{

class ROSBAG2_PUBLIC FormatConverterFactoryImpl : public FormatConverterFactory
class ROSBAG2_PUBLIC SerializationFormatConverterFactoryImpl
: public SerializationFormatConverterFactoryInterface
{
public:
FormatConverterFactoryImpl();
SerializationFormatConverterFactoryImpl();

~FormatConverterFactoryImpl() override;
~SerializationFormatConverterFactoryImpl() override;

std::shared_ptr<FormatConverterInterface> load_converter(const std::string & format) override;
std::shared_ptr<SerializationFormatConverterInterface>
load_converter(const std::string & format) override;

private:
std::unique_ptr<pluginlib::ClassLoader<FormatConverterInterface>> class_loader_;
std::unique_ptr<pluginlib::ClassLoader<SerializationFormatConverterInterface>> class_loader_;
};

} // namespace rosbag2
Expand All @@ -61,4 +63,4 @@ class ROSBAG2_PUBLIC FormatConverterFactoryImpl : public FormatConverterFactory
# pragma warning(pop)
#endif

#endif // ROSBAG2__FORMAT_CONVERTER_FACTORY_IMPL_HPP_
#endif // ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROSBAG2__FORMAT_CONVERTER_FACTORY_HPP_
#define ROSBAG2__FORMAT_CONVERTER_FACTORY_HPP_
#ifndef ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_INTERFACE_HPP_
#define ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_INTERFACE_HPP_

#include <memory>
#include <string>

#include "rosbag2/format_converter_interface.hpp"
#include "rosbag2/serialization_format_converter_interface.hpp"
#include "rosbag2/visibility_control.hpp"

namespace rosbag2
{

class ROSBAG2_PUBLIC FormatConverterFactory
class ROSBAG2_PUBLIC SerializationFormatConverterFactoryInterface
{
public:
virtual ~FormatConverterFactory() = default;
virtual ~SerializationFormatConverterFactoryInterface() = default;

virtual std::shared_ptr<FormatConverterInterface> load_converter(const std::string & format) = 0;
virtual std::shared_ptr<SerializationFormatConverterInterface>
load_converter(const std::string & format) = 0;
};

} // namespace rosbag2

#endif // ROSBAG2__FORMAT_CONVERTER_FACTORY_HPP_
#endif // ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_FACTORY_INTERFACE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROSBAG2__FORMAT_CONVERTER_INTERFACE_HPP_
#define ROSBAG2__FORMAT_CONVERTER_INTERFACE_HPP_
#ifndef ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_INTERFACE_HPP_
#define ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_INTERFACE_HPP_

#include <memory>
#include <string>

#include "rosbag2/types/ros2_message.hpp"
#include "rosbag2/types.hpp"
#include "rcutils/types.h"
#include "rosbag2_storage/serialized_bag_message.hpp"
#include "rosidl_typesupport_cpp/message_type_support.hpp"

using SerializedBagMessage = rosbag2_storage::SerializedBagMessage;

namespace rosbag2
{

class FormatConverterInterface
class SerializationFormatConverterInterface
{
public:
virtual ~FormatConverterInterface() = default;
virtual ~SerializationFormatConverterInterface() = default;

virtual void deserialize(
std::shared_ptr<rosbag2_ros2_message_t> ros_message,
Expand All @@ -46,4 +45,4 @@ class FormatConverterInterface

} // namespace rosbag2

#endif // ROSBAG2__FORMAT_CONVERTER_INTERFACE_HPP_
#endif // ROSBAG2__SERIALIZATION_FORMAT_CONVERTER_INTERFACE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rosbag2/format_converter_factory_impl.hpp"
#include "rosbag2/serialization_format_converter_factory.hpp"

#include <memory>
#include <string>
Expand All @@ -23,22 +23,21 @@
namespace rosbag2
{

FormatConverterFactoryImpl::FormatConverterFactoryImpl()
SerializationFormatConverterFactoryImpl::SerializationFormatConverterFactoryImpl()
{
try {
class_loader_ = std::make_unique<pluginlib::ClassLoader<FormatConverterInterface>>(
"rosbag2", "rosbag2::FormatConverterInterface");
class_loader_ = std::make_unique<pluginlib::ClassLoader<SerializationFormatConverterInterface>>(
"rosbag2", "rosbag2::SerializationFormatConverterInterface");
} catch (const std::exception & e) {
ROSBAG2_LOG_ERROR_STREAM("Unable to create class loader instance: " << e.what());
throw e;
}
}

// needed explicit destructor because of unique_ptr for pimpl
FormatConverterFactoryImpl::~FormatConverterFactoryImpl() = default;
SerializationFormatConverterFactoryImpl::~SerializationFormatConverterFactoryImpl() = default;

std::shared_ptr<FormatConverterInterface> FormatConverterFactoryImpl::load_converter(
const std::string & format)
std::shared_ptr<SerializationFormatConverterInterface>
SerializationFormatConverterFactoryImpl::load_converter(const std::string & format)
{
auto converter_id = format + "_converter";

Expand All @@ -50,7 +49,7 @@ std::shared_ptr<FormatConverterInterface> FormatConverterFactoryImpl::load_conve
}

try {
return std::shared_ptr<FormatConverterInterface>(
return std::shared_ptr<SerializationFormatConverterInterface>(
class_loader_->createUnmanagedInstance(converter_id));
} catch (const std::runtime_error & ex) {
ROSBAG2_LOG_ERROR_STREAM("Unable to load instance of converter interface: " << ex.what());
Expand Down
9 changes: 4 additions & 5 deletions rosbag2/test/rosbag2/converter_test_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
#include <memory>
#include <string>

#include "pluginlib/class_list_macros.hpp"

#include "converter_test_plugin.hpp"

void ConverterTestPlugin::deserialize(

std::shared_ptr<rosbag2_ros2_message_t> ros_message,
const std::shared_ptr<const SerializedBagMessage> serialized_message,
const std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support)
{
(void) ros_message;
Expand All @@ -32,7 +30,7 @@ void ConverterTestPlugin::deserialize(
}

void ConverterTestPlugin::serialize(
std::shared_ptr<SerializedBagMessage> serialized_message,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message,
const std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
const rosidl_message_type_support_t * type_support)
{
Expand All @@ -41,4 +39,5 @@ void ConverterTestPlugin::serialize(
(void) type_support;
}

PLUGINLIB_EXPORT_CLASS(ConverterTestPlugin, rosbag2::FormatConverterInterface)
#include "pluginlib/class_list_macros.hpp" // NOLINT
PLUGINLIB_EXPORT_CLASS(ConverterTestPlugin, rosbag2::SerializationFormatConverterInterface)
8 changes: 4 additions & 4 deletions rosbag2/test/rosbag2/converter_test_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
#include <memory>
#include <string>

#include "rosbag2/format_converter_interface.hpp"
#include "rosbag2/serialization_format_converter_interface.hpp"

class ConverterTestPlugin : public rosbag2::FormatConverterInterface
class ConverterTestPlugin : public rosbag2::SerializationFormatConverterInterface
{
public:
void deserialize(
std::shared_ptr<rosbag2_ros2_message_t> ros_message,
std::shared_ptr<const SerializedBagMessage> serialized_message,
std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support) override;

void serialize(
std::shared_ptr<SerializedBagMessage> serialized_message,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message,
std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
const rosidl_message_type_support_t * type_support) override;
};
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/test/rosbag2/converter_test_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<class
name="a_converter"
type="ConverterTestPlugin"
base_class_type="rosbag2::FormatConverterInterface"
base_class_type="rosbag2::SerializationFormatConverterInterface"
>
<description>This is a test format converter plugin.</description>
</class>
Expand Down
6 changes: 3 additions & 3 deletions rosbag2/test/rosbag2/test_converter_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#include <memory>
#include <string>

#include "rosbag2/format_converter_factory_impl.hpp"
#include "rosbag2/serialization_format_converter_factory.hpp"

using rosbag2::FormatConverterInterface;
using rosbag2::SerializationFormatConverterInterface;

class ConverterFactoryTest : public ::testing::Test
{
public:
rosbag2::FormatConverterFactoryImpl factory;
rosbag2::SerializationFormatConverterFactoryImpl factory;
};

TEST_F(ConverterFactoryTest, load_test_plugin) {
Expand Down

0 comments on commit 19112b0

Please sign in to comment.