Skip to content

Commit

Permalink
Avoid to call getMetadata if the signal is not connected in YarpRobot…
Browse files Browse the repository at this point in the history
…LoggerDevice (#774)
  • Loading branch information
GiulioRomualdi authored Dec 5, 2023
1 parent 83c8257 commit dc9f09f
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions devices/YarpRobotLoggerDevice/src/YarpRobotLoggerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,33 @@ void YarpRobotLoggerDevice::lookForExogenousSignals()
auto connectToExogeneous = [](auto& signals) -> void {
for (auto& [name, signal] : signals)
{
if (!signal.connected)
std::lock_guard<std::mutex> lock(signal.mutex);
if (signal.connected)
{
std::lock_guard<std::mutex> lock(signal.mutex);
signal.connected = signal.connect();
continue;
}

// try to connect to the signal
signal.connected = signal.connect();

// if the connection is successful, get the metadata
// this is required only for the vectors collection signal
if constexpr (std::is_same_v<
std::decay_t<decltype(signal)>,
std::decay_t<decltype(m_vectorsCollectionSignals)::value_type>>)
{
if (!signal.connected)
{
continue;
}

if (!signal.client.getMetadata(signal.metadata))
{
log()->warn("[YarpRobotLoggerDevice::lookForExogenousSignals] Unable to get "
"the metadata for the signal named: {}. The exogenous signal will "
"not contain the metadata.",
name);
}
}
}
};
Expand All @@ -1019,16 +1042,6 @@ void YarpRobotLoggerDevice::lookForExogenousSignals()
connectToExogeneous(m_vectorsCollectionSignals);
connectToExogeneous(m_vectorSignals);

for (auto& [key, signal] : m_vectorsCollectionSignals)
{
if (signal.metadata.vectors.size() != 0)
{
continue;
}
std::lock_guard<std::mutex> lock(signal.mutex);
signal.client.getMetadata(signal.metadata);
}

// release the CPU
BipedalLocomotion::clock().yield();

Expand Down

0 comments on commit dc9f09f

Please sign in to comment.