Skip to content

Commit

Permalink
Strip non-mcap-related from the McapHandlerConfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed May 10, 2024
1 parent 62edba4 commit dddbc7c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@

#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include <mcap/mcap.hpp>

#include <ddsrecorder_participants/recorder/output/BaseHandlerConfiguration.hpp>
#include <ddsrecorder_participants/recorder/output/OutputSettings.hpp>

namespace eprosima {
Expand All @@ -33,61 +30,35 @@ namespace participants {
/**
* Structure encapsulating all of \c McapHandler configuration options.
*/
struct McapHandlerConfiguration
struct McapHandlerConfiguration : public BaseHandlerConfiguration
{
McapHandlerConfiguration(
const OutputSettings& output_settings,
const int& max_pending_samples,
const unsigned int& buffer_size,
const unsigned int& event_window,
const unsigned int& cleanup_period,
const bool& log_publishTime,
const bool& only_with_schema,
const int max_pending_samples,
const unsigned int buffer_size,
const unsigned int event_window,
const unsigned int cleanup_period,
const bool log_publishTime,
const bool only_with_schema,
const mcap::McapWriterOptions& mcap_writer_options,
const bool& record_types,
const bool& ros2_types)
: output_settings(output_settings)
, max_pending_samples(max_pending_samples)
, buffer_size(buffer_size)
, event_window(event_window)
, cleanup_period(cleanup_period)
, log_publishTime(log_publishTime)
, only_with_schema(only_with_schema)
const bool record_types,
const bool ros2_types)
: BaseHandlerConfiguration(
output_settings,
max_pending_samples,
buffer_size,
event_window,
cleanup_period,
log_publishTime,
only_with_schema,
record_types,
ros2_types)
, mcap_writer_options(mcap_writer_options)
, record_types(record_types)
, ros2_types(ros2_types)
{
}

//! Configuration settings for MCAP file where data is to be written
OutputSettings output_settings;

//! Max number of messages to store in memory when schema not yet available
unsigned int max_pending_samples;

//! Max number of elements to keep in memory prior to writing in disk (applies to started state)
unsigned int buffer_size;

//! Keep in memory samples received in time frame [s], to be stored when event triggered (applies to paused state)
unsigned int event_window;

//! Remove from buffer samples older than *now - event_window* with this period [s] (applies to paused state)
unsigned int cleanup_period;

//! Store messages with logTime set to sample publication timestamp
bool log_publishTime;

//! Only write messages whose schema is registered (i.e. discard pending samples when leaving RUNNING state)
bool only_with_schema;

//! Mcap writer configuration options
mcap::McapWriterOptions mcap_writer_options;

//! Whether to store received dynamic types in output MCAP file
bool record_types;

//! Whether to generate schemas as OMG IDL or ROS2 msg
bool ros2_types;
};

} /* namespace participants */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#include <ddspipe_participants/participant/dynamic_types/ISchemaHandler.hpp>

#include <ddsrecorder_participants/library/library_dll.h>
#include <ddsrecorder_participants/recorder/mcap/McapHandlerConfiguration.hpp>
#include <ddsrecorder_participants/recorder/message/BaseMessage.hpp>
#include <ddsrecorder_participants/recorder/output/BaseHandlerConfiguration.hpp>

#if FASTRTPS_VERSION_MAJOR <= 2 && FASTRTPS_VERSION_MINOR < 13
#include <ddsrecorder_participants/common/types/dynamic_types_collection/v1/DynamicTypesCollection.hpp>
Expand All @@ -56,8 +56,15 @@ ENUMERATION_BUILDER(
);

/**
* Class that manages the interaction between DDS Pipe (\c SchemaParticipant) and MCAP files through mcap library.
* Payloads are efficiently passed from DDS Pipe to mcap without copying data (only references).
* @brief Base class with generic methods to interact with the \c DdsPipe ( \c SchemaParticipant ).
*
* More concretely, the \c BaseHandler manages:
* - state transitions (start, stop, pause, trigger_event),
* - buffer management (storing, discarding and dumping samples),
* - pending samples management (samples received before the type is known),
* - dynamic types collection (storing and serializing types).
*
* Payloads are efficiently passed from DDS Pipe to the output file without copying data (only references).
*
* @implements ISchemaHandler
*/
Expand All @@ -66,37 +73,31 @@ class BaseHandler : public ddspipe::participants::ISchemaHandler
public:

/**
* BaseHandler constructor by required values.
*
* Creates BaseHandler instance with given configuration, payload pool and initial state.
* Opens temporal MCAP file where data is to be written.
*
* @throw InitializationException if creation fails (fail to open MCAP file).
*
* @warning Command methods ( \c start , \c pause , \c stop , and \c trigger_event ) are not thread safe
* among themselves. This is, they are expected to be executed sequentially and all in the same thread.
* @brief Creates the \c BaseHandler instance with the given configuration.
*
* @param config: Structure encapsulating all configuration options.
* @param payload_pool: Pool of payloads to be used by the handler.
*/
DDSRECORDER_PARTICIPANTS_DllAPI
BaseHandler(
const McapHandlerConfiguration& config,
const BaseHandlerConfiguration& config,
const std::shared_ptr<ddspipe::core::PayloadPool>& payload_pool);

/**
* @brief Destructor
*
* Closes temporal MCAP file, and renames it with filename given in configuration.
* Before closing file, received dynamic types are serialized and stored as an attachment.
*
* @brief Destructor the \c BaseHandler instance.
*/
DDSRECORDER_PARTICIPANTS_DllAPI
virtual ~BaseHandler();

/**
* @brief Initialize handler instance
*
* @warning Command methods ( \c start , \c pause , \c stop , and \c trigger_event ) are not thread safe
* among themselves. This is, they are expected to be executed sequentially and all in the same thread.
*
* @note This method should be called by a derived class constructor to ensure the purely virtual methods have been
* implemented.
*
* @param [in] init_state Initial state of the handler instance.
*/
DDSRECORDER_PARTICIPANTS_DllAPI
Expand Down Expand Up @@ -309,7 +310,7 @@ class BaseHandler : public ddspipe::participants::ISchemaHandler
const std::string& type_name);

//! Handler configuration
McapHandlerConfiguration configuration_;
const BaseHandlerConfiguration configuration_;

//! Payload pool
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

/**
* @file BaseHandlerConfiguration.hpp
*/

#pragma once

#include <ddsrecorder_participants/recorder/output/OutputSettings.hpp>

namespace eprosima {
namespace ddsrecorder {
namespace participants {

/**
* Structure encapsulating all the \c BaseHandler configuration options.
*/
struct BaseHandlerConfiguration
{
BaseHandlerConfiguration(
const OutputSettings& output_settings,
const unsigned int max_pending_samples,
const unsigned int buffer_size,
const unsigned int event_window,
const unsigned int cleanup_period,
const bool log_publishTime,
const bool only_with_schema,
const bool record_types,
const bool ros2_types)
: output_settings(output_settings)
, max_pending_samples(max_pending_samples)
, buffer_size(buffer_size)
, event_window(event_window)
, cleanup_period(cleanup_period)
, log_publishTime(log_publishTime)
, only_with_schema(only_with_schema)
, record_types(record_types)
{
}

//! Configuration settings for the output file where data is to be written
OutputSettings output_settings;

//! Max number of messages to store in memory when schema not yet available
unsigned int max_pending_samples;

//! Max number of elements to keep in memory prior to writing in disk (applies to started state)
unsigned int buffer_size;

//! Keep in memory samples received in time frame [s], to be stored when event triggered (applies to paused state)
unsigned int event_window;

//! Remove from buffer samples older than *now - event_window* with this period [s] (applies to paused state)
unsigned int cleanup_period;

//! Store messages with logTime set to sample publication timestamp
bool log_publishTime;

//! Only write messages whose schema is registered (i.e. discard pending samples when leaving RUNNING state)
bool only_with_schema;

//! Whether to store received dynamic types in the output file
bool record_types;

//! Whether to generate schemas as OMG IDL or ROS2 msg
bool ros2_types;
};

} /* namespace participants */
} /* namespace ddsrecorder */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace participants {
using namespace eprosima::ddspipe::core::types;

BaseHandler::BaseHandler(
const McapHandlerConfiguration& config,
const BaseHandlerConfiguration& config,
const std::shared_ptr<ddspipe::core::PayloadPool>& payload_pool)
: configuration_(config)
, payload_pool_(payload_pool)
Expand Down

0 comments on commit dddbc7c

Please sign in to comment.