Skip to content

Commit efc83a4

Browse files
Add auxiliar InternalWriter (#138)
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent f6fec3c commit efc83a4

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

ddspipe_participants/include/ddspipe_participants/reader/auxiliar/InternalReader.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <ddspipe_core/efficiency/payload/PayloadPool.hpp>
2727
#include <ddspipe_core/types/participant/ParticipantId.hpp>
2828

29+
#include <ddspipe_participants/library/library_dll.h>
2930
#include <ddspipe_participants/reader/auxiliar/BaseReader.hpp>
3031

3132
namespace eprosima {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <functional>
18+
19+
#include <ddspipe_participants/library/library_dll.h>
20+
#include <ddspipe_participants/writer/auxiliar/BaseWriter.hpp>
21+
22+
namespace eprosima {
23+
namespace ddspipe {
24+
namespace participants {
25+
26+
/**
27+
* Writer implementation that allow to register a callback to be executed with each data received.
28+
*/
29+
class InternalWriter : public BaseWriter
30+
{
31+
public:
32+
33+
DDSPIPE_PARTICIPANTS_DllAPI
34+
InternalWriter(
35+
const core::types::ParticipantId& participant_id,
36+
const std::function<utils::ReturnCode(core::IRoutingData&)>& callback);
37+
38+
protected:
39+
40+
virtual utils::ReturnCode write_nts_(
41+
core::IRoutingData& data) noexcept override;
42+
43+
const std::function<utils::ReturnCode(core::IRoutingData&)> callback_;
44+
};
45+
46+
} /* namespace participants */
47+
} /* namespace ddspipe */
48+
} /* namespace eprosima */
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <ddspipe_participants/writer/auxiliar/InternalWriter.hpp>
16+
17+
namespace eprosima {
18+
namespace ddspipe {
19+
namespace participants {
20+
21+
InternalWriter::InternalWriter(
22+
const core::types::ParticipantId& participant_id,
23+
const std::function<utils::ReturnCode(core::IRoutingData&)>& callback)
24+
: BaseWriter(participant_id)
25+
, callback_(callback)
26+
{
27+
// Do nothing
28+
}
29+
30+
utils::ReturnCode InternalWriter::write_nts_(
31+
core::IRoutingData& data) noexcept
32+
{
33+
return callback_(data);
34+
}
35+
36+
} /* namespace participants */
37+
} /* namespace ddspipe */
38+
} /* namespace eprosima */

0 commit comments

Comments
 (0)