-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDDSEnabler.cpp
More file actions
130 lines (105 loc) · 4.19 KB
/
Copy pathDDSEnabler.cpp
File metadata and controls
130 lines (105 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 <cpp_utils/utils.hpp>
#include <ddspipe_core/types/dynamic_types/types.hpp>
#include "ddsenabler/DDSEnabler.hpp"
namespace eprosima {
namespace ddsenabler {
using namespace eprosima::ddspipe::core;
using namespace eprosima::ddspipe::core::types;
using namespace eprosima::ddspipe::participants;
using namespace eprosima::ddspipe::participants::rtps;
using namespace eprosima::ddsenabler::participants;
using namespace eprosima::utils;
DDSEnabler::DDSEnabler(
const yaml::EnablerConfiguration& configuration,
std::shared_ptr<eprosima::utils::event::MultipleEventHandler> event_handler)
: configuration_(configuration)
, event_handler_(event_handler)
{
// Load the Enabler's internal topics from a configuration object.
load_internal_topics_(configuration_);
// Create Discovery Database
discovery_database_ = std::make_shared<DiscoveryDatabase>();
// Create Payload Pool
payload_pool_ = std::make_shared<FastPayloadPool>();
// Create Thread Pool
thread_pool_ = std::make_shared<SlotThreadPool>(configuration_.n_threads);
// Create CB Handler configuration
participants::CBHandlerConfiguration handler_config;
// Create DDS Participant
dds_participant_ = std::make_shared<DdsParticipant>(
configuration_.simple_configuration,
payload_pool_,
discovery_database_);
dds_participant_->init();
// Create CB Handler
cb_handler_ = std::make_shared<participants::CBHandler>(
handler_config,
payload_pool_);
// Create Enabler Participant
enabler_participant_ = std::make_shared<EnablerParticipant>(
configuration_.enabler_configuration,
payload_pool_,
discovery_database_,
cb_handler_);
// Create Participant Database
participants_database_ = std::make_shared<ParticipantsDatabase>();
// Populate Participant Database
participants_database_->add_participant(
dds_participant_->id(),
dds_participant_);
participants_database_->add_participant(
enabler_participant_->id(),
enabler_participant_);
// Create DDS Pipe
pipe_ = std::make_unique<DdsPipe>(
configuration_.ddspipe_configuration,
discovery_database_,
payload_pool_,
participants_database_,
thread_pool_);
}
utils::ReturnCode DDSEnabler::reload_configuration(
yaml::EnablerConfiguration& new_configuration)
{
// Load the Enabler's internal topics from a configuration object.
load_internal_topics_(new_configuration);
// Update the Enabler's configuration
configuration_ = new_configuration;
return pipe_->reload_configuration(new_configuration.ddspipe_configuration);
}
void DDSEnabler::load_internal_topics_(
yaml::EnablerConfiguration& configuration)
{
// Create an internal topic to transmit the dynamic types
configuration.ddspipe_configuration.builtin_topics.insert(
utils::Heritable<DdsTopic>::make_heritable(type_object_topic()));
if (!configuration.ddspipe_configuration.allowlist.empty())
{
// The allowlist is not empty. Add the internal topic.
WildcardDdsFilterTopic internal_topic;
internal_topic.topic_name.set_value(TYPE_OBJECT_TOPIC_NAME);
configuration.ddspipe_configuration.allowlist.insert(
utils::Heritable<WildcardDdsFilterTopic>::make_heritable(internal_topic));
}
}
bool DDSEnabler::publish(
const std::string& topic_name,
const std::string& json)
{
return enabler_participant_->publish(topic_name, json);
}
} /* namespace ddsenabler */
} /* namespace eprosima */