Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

cmake_minimum_required(VERSION 3.16)
project(robometry LANGUAGES C CXX
VERSION 1.3.0)
VERSION 1.4.0)

include(GNUInstallDirs)
include(FeatureSummary)
Expand Down
6 changes: 6 additions & 0 deletions src/librobometry/include/robometry/BufferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class BufferManager {
*/
bool configure(const BufferConfig& _bufferConfig);

/**
* @brief Clear all channels and data from the BufferManager, stopping the periodic save thread.
* After calling this, the BufferManager must be reconfigured before use.
*/
void clear();

/**
* @brief Get the BufferConfig object representing the actual configuration.
*
Expand Down
23 changes: 23 additions & 0 deletions src/librobometry/src/BufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ bool robometry::BufferManager::configure(const BufferConfig &_bufferConfig) {
return ok;
}

void robometry::BufferManager::clear() {
// Stop the periodic save thread if running
if (m_save_thread.joinable()) {
{
std::unique_lock<std::mutex> lk_cv(m_mutex_cv);
m_should_stop_thread = true;
m_cv.notify_one();
}
m_save_thread.join();
}
m_should_stop_thread = false;

// Reset the tree to clear all channels
m_tree = std::make_shared<TreeNode<BufferInfo>>();

// Clear channel list from config
m_bufferConfig.channels.clear();

// Reset callbacks
m_saveCallback = {};
m_preSaveCallback = {};
}

robometry::BufferConfig robometry::BufferManager::getBufferConfig() const {
return m_bufferConfig;
}
Expand Down
34 changes: 34 additions & 0 deletions test/BufferManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,40 @@ TEST_CASE("Buffer Manager Test")

}

SECTION("Test clear") {
robometry::BufferManager bm;
robometry::BufferConfig bufferConfig;

robometry::ChannelInfo var_one{ "one", {1,1} };
robometry::ChannelInfo var_two{ "two", {1,1} };

// Add channels
REQUIRE(bm.addChannel(var_one));
REQUIRE(bm.addChannel(var_two));

bufferConfig.filename = "buffer_manager_test_clear";
bufferConfig.n_samples = n_samples;
REQUIRE(bm.configure(bufferConfig));

// Add some data
for (int i = 0; i < 3; i++) {
bm.push_back({ i }, "one");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
bm.push_back({ i + 1 }, "two");
}

// Clear the buffer manager
bm.clear();

// Verify channels were cleared - the config should be empty
auto config_after = bm.getBufferConfig();
REQUIRE(config_after.channels.empty());

// Verify we can reconfigure after clear
bufferConfig.filename = "buffer_manager_test_clear_after";
REQUIRE(bm.configure(bufferConfig));
}

#if defined CATCH_CONFIG_ENABLE_BENCHMARKING

SECTION("Benchmarking section scalar int") {
Expand Down
Loading