Skip to content

Commit

Permalink
[core] monitoring map indices based solely on entity ids (as they are…
Browse files Browse the repository at this point in the history
… unique within the system)
  • Loading branch information
KerstinKeller committed Jan 2, 2025
1 parent 41f1078 commit 6af9ca3
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions ecal/core/src/monitoring/ecal_monitoring_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -232,8 +232,8 @@ namespace eCAL
auto attr = sample_topic.attr;

// try to get topic info
const std::string topic_name_id = topic_name + topic_id;
Monitoring::STopicMon& TopicInfo = (*pTopicMap->map)[topic_name_id];
const std::string& topic_map_key = topic_id;
Monitoring::STopicMon& TopicInfo = (*pTopicMap->map)[topic_map_key];

// set static content
TopicInfo.hname = host_name;
Expand Down Expand Up @@ -292,9 +292,7 @@ namespace eCAL

bool CMonitoringImpl::UnregisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_)
{
const auto& sample_topic = sample_.topic;
const std::string& topic_name = sample_topic.tname;
const std::string& topic_id = sample_.identifier.entity_id;
const std::string& topic_map_key = sample_.identifier.entity_id;

// unregister from topic map
STopicMonMap* pTopicMap = GetMap(pubsub_type_);
Expand All @@ -304,8 +302,7 @@ namespace eCAL
const std::lock_guard<std::mutex> lock(pTopicMap->sync);

// remove topic info
const std::string topic_name_id = topic_name + topic_id;
pTopicMap->map->erase(topic_name_id);
pTopicMap->map->erase(topic_map_key);
}

return(true);
Expand Down Expand Up @@ -395,13 +392,13 @@ namespace eCAL
const uint32_t tcp_port_v1 = sample_service.tcp_port_v1;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const std::string& service_map_key = service_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_server_map.sync);

// try to get service info
Monitoring::SServerMon& ServerInfo = (*m_server_map.map)[service_name_id];
Monitoring::SServerMon& ServerInfo = (*m_server_map.map)[service_map_key];

// set static content
ServerInfo.hname = host_name;
Expand Down Expand Up @@ -433,21 +430,14 @@ namespace eCAL

bool CMonitoringImpl::UnregisterServer(const Registration::Sample& sample_)
{
const auto& sample_service = sample_.service;
const auto& sample_identifier = sample_.identifier;

const std::string& service_name = sample_service.sname;
const std::string& service_id = sample_identifier.entity_id;
const int process_id = sample_identifier.process_id;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const std::string& service_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_server_map.sync);

// remove service info
m_server_map.map->erase(service_name_id);
m_server_map.map->erase(service_map_key);

return(true);
}
Expand All @@ -465,13 +455,13 @@ namespace eCAL
const std::string& unit_name = sample_client.uname;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const std::string& client_map_key = service_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_clients_map.sync);

// try to get service info
Monitoring::SClientMon& ClientInfo = (*m_clients_map.map)[service_name_id];
Monitoring::SClientMon& ClientInfo = (*m_clients_map.map)[client_map_key];

// set static content
ClientInfo.hname = host_name;
Expand Down Expand Up @@ -501,21 +491,14 @@ namespace eCAL

bool CMonitoringImpl::UnregisterClient(const Registration::Sample& sample_)
{
const auto& sample_identifier = sample_.identifier;
const std::string& service_id = sample_identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;

const auto& sample_client = sample_.client;
const std::string& service_name = sample_client.sname;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const std::string& client_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_clients_map.sync);

// remove service info
m_clients_map.map->erase(service_name_id);
m_clients_map.map->erase(client_map_key);

return(true);
}
Expand Down

0 comments on commit 6af9ca3

Please sign in to comment.