提交 af2bc3d7 编写于 作者: G gruminions 提交者: Jiangtao Hu

framework: use default config while user does not write corresponding config

上级 7e35aadd
......@@ -6,30 +6,30 @@ log_conf {
color_log_to_stderr: true
}
transport_conf {
shm_conf {
# "multicast" "condition"
notifier_type: "multicast"
shm_locator {
ip: "239.255.0.100"
port: 8888
}
}
participant_attr {
lease_duration: 12
announcement_period: 3
domain_id_gain: 200
port_base: 10000
}
communication_mode {
same_proc: INTRA
diff_proc: SHM
diff_host: RTPS
}
resource_limit {
max_history_depth: 1000
}
}
# transport_conf {
# shm_conf {
# # "multicast" "condition"
# notifier_type: "multicast"
# shm_locator {
# ip: "239.255.0.100"
# port: 8888
# }
# }
# participant_attr {
# lease_duration: 12
# announcement_period: 3
# domain_id_gain: 200
# port_base: 10000
# }
# communication_mode {
# same_proc: INTRA
# diff_proc: SHM
# diff_host: RTPS
# }
# resource_limit {
# max_history_depth: 1000
# }
# }
run_mode_conf {
run_mode: MODE_REALITY
......
......@@ -20,10 +20,10 @@ message ShmConf {
};
message RtpsParticipantAttr {
optional int32 lease_duration = 1;
optional int32 announcement_period = 2;
optional uint32 domain_id_gain = 3;
optional uint32 port_base = 4;
optional int32 lease_duration = 1 [default = 12];
optional int32 announcement_period = 2 [default = 3];
optional uint32 domain_id_gain = 3 [default = 200];
optional uint32 port_base = 4 [default = 10000];
};
message CommunicationMode {
......@@ -33,7 +33,7 @@ message CommunicationMode {
};
message ResourceLimit {
optional uint32 max_history_depth = 1;
optional uint32 max_history_depth = 1 [default = 1000];
};
message TransportConf {
......
......@@ -51,26 +51,24 @@ class History {
void Add(const MessagePtr& msg, const MessageInfo& msg_info);
void Clear();
void GetCachedMessage(std::vector<CachedMessage>* msgs);
size_t GetSize();
void GetCachedMessage(std::vector<CachedMessage>* msgs) const;
size_t GetSize() const;
uint32_t depth() const { return depth_; }
uint32_t max_depth() const { return max_depth_; }
bool is_full() const { return is_full_; }
private:
bool enabled_;
uint32_t depth_;
uint32_t max_depth_;
bool is_full_;
std::list<CachedMessage> msgs_;
std::mutex msgs_mutex_;
mutable std::mutex msgs_mutex_;
};
template <typename MessageT>
History<MessageT>::History(const HistoryAttributes& attr)
: enabled_(false), max_depth_(1000), is_full_(false) {
auto global_conf = common::GlobalData::Instance()->Config();
: enabled_(false), max_depth_(1000) {
auto& global_conf = common::GlobalData::Instance()->Config();
if (global_conf.has_transport_conf() &&
global_conf.transport_conf().has_resource_limit()) {
max_depth_ =
......@@ -99,16 +97,9 @@ void History<MessageT>::Add(const MessagePtr& msg,
return;
}
std::lock_guard<std::mutex> lock(msgs_mutex_);
if (is_full_) {
msgs_.pop_front();
}
msgs_.emplace_back(msg, msg_info);
if (!is_full_) {
if (msgs_.size() == depth_) {
is_full_ = true;
}
while (msgs_.size() > depth_) {
msgs_.pop_front();
}
}
......@@ -119,22 +110,19 @@ void History<MessageT>::Clear() {
}
template <typename MessageT>
void History<MessageT>::GetCachedMessage(std::vector<CachedMessage>* msgs) {
void History<MessageT>::GetCachedMessage(
std::vector<CachedMessage>* msgs) const {
if (msgs == nullptr) {
return;
}
{
std::lock_guard<std::mutex> lock(msgs_mutex_);
msgs->reserve(msgs_.size());
for (auto& item : msgs_) {
msgs->emplace_back(item);
}
}
std::lock_guard<std::mutex> lock(msgs_mutex_);
msgs->reserve(msgs_.size());
msgs->insert(msgs->begin(), msgs_.begin(), msgs_.end());
}
template <typename MessageT>
size_t History<MessageT>::GetSize() {
size_t History<MessageT>::GetSize() const {
std::lock_guard<std::mutex> lock(msgs_mutex_);
return msgs_.size();
}
......
......@@ -94,7 +94,6 @@ TEST(HistoryTest, history_test) {
history.Add(message, message_info);
EXPECT_EQ(1, history.GetSize());
message_info.set_seq_num(1);
EXPECT_FALSE(history.is_full());
int depth = 10;
HistoryAttributes attr2(proto::QosHistoryPolicy::HISTORY_KEEP_LAST, depth);
......@@ -106,7 +105,6 @@ TEST(HistoryTest, history_test) {
message_info.set_seq_num(i);
history2.Add(message, message_info);
}
EXPECT_TRUE(history2.is_full());
std::vector<History<RawMessage>::CachedMessage> messages;
history2.GetCachedMessage(nullptr);
history2.GetCachedMessage(&messages);
......
......@@ -170,8 +170,12 @@ void HybridReceiver<M>::InitMode() {
template <typename M>
void HybridReceiver<M>::ObtainConfig() {
auto& global_conf = common::GlobalData::Instance()->Config();
RETURN_IF(!global_conf.has_transport_conf());
RETURN_IF(!global_conf.transport_conf().has_communication_mode());
if (!global_conf.has_transport_conf()) {
return;
}
if (!global_conf.transport_conf().has_communication_mode()) {
return;
}
mode_->CopyFrom(global_conf.transport_conf().communication_mode());
mapping_table_[SAME_PROC] = mode_->same_proc();
......
......@@ -81,9 +81,6 @@ void Participant::CreateFastRtpsParticipant(
if (global_conf.has_transport_conf() &&
global_conf.transport_conf().has_participant_attr()) {
part_attr_conf->CopyFrom(global_conf.transport_conf().participant_attr());
} else {
AERROR << "No rtps participant attr conf.";
return;
}
eprosima::fastrtps::ParticipantAttributes attr;
......
......@@ -182,9 +182,12 @@ void HybridTransmitter<M>::InitMode() {
template <typename M>
void HybridTransmitter<M>::ObtainConfig() {
auto& global_conf = common::GlobalData::Instance()->Config();
RETURN_IF(!global_conf.has_transport_conf());
RETURN_IF(!global_conf.transport_conf().has_communication_mode());
if (!global_conf.has_transport_conf()) {
return;
}
if (!global_conf.transport_conf().has_communication_mode()) {
return;
}
mode_->CopyFrom(global_conf.transport_conf().communication_mode());
mapping_table_[SAME_PROC] = mode_->same_proc();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册