Skip to content

Commit

Permalink
Add auxiliar InternalWriter (#138)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
  • Loading branch information
juanlofer-eprosima authored Dec 19, 2024
1 parent f6fec3c commit efc83a4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <ddspipe_core/efficiency/payload/PayloadPool.hpp>
#include <ddspipe_core/types/participant/ParticipantId.hpp>

#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/reader/auxiliar/BaseReader.hpp>

namespace eprosima {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

#pragma once

#include <functional>

#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/writer/auxiliar/BaseWriter.hpp>

namespace eprosima {
namespace ddspipe {
namespace participants {

/**
* Writer implementation that allow to register a callback to be executed with each data received.
*/
class InternalWriter : public BaseWriter
{
public:

DDSPIPE_PARTICIPANTS_DllAPI
InternalWriter(
const core::types::ParticipantId& participant_id,
const std::function<utils::ReturnCode(core::IRoutingData&)>& callback);

protected:

virtual utils::ReturnCode write_nts_(
core::IRoutingData& data) noexcept override;

const std::function<utils::ReturnCode(core::IRoutingData&)> callback_;
};

} /* namespace participants */
} /* namespace ddspipe */
} /* namespace eprosima */
38 changes: 38 additions & 0 deletions ddspipe_participants/src/cpp/writer/auxiliar/InternalWriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

#include <ddspipe_participants/writer/auxiliar/InternalWriter.hpp>

namespace eprosima {
namespace ddspipe {
namespace participants {

InternalWriter::InternalWriter(
const core::types::ParticipantId& participant_id,
const std::function<utils::ReturnCode(core::IRoutingData&)>& callback)
: BaseWriter(participant_id)
, callback_(callback)
{
// Do nothing
}

utils::ReturnCode InternalWriter::write_nts_(
core::IRoutingData& data) noexcept
{
return callback_(data);
}

} /* namespace participants */
} /* namespace ddspipe */
} /* namespace eprosima */

0 comments on commit efc83a4

Please sign in to comment.