This commit is contained in:
2026-03-11 01:40:50 -04:00
parent 894a8131d4
commit 7b34cf468b
4 changed files with 7 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ class Module {
uint8_t m_device_id;
ModuleType m_module_type;
Messaging::ConnectionType m_connection_type;
uint8_t m_leader;
std::atomic<uint8_t> m_leader{0};
std::chrono::time_point<std::chrono::system_clock> m_last_updated;
std::vector<neighbour> m_neighbours;
std::shared_ptr<MessagingInterface> m_messaging_interface;

View File

@@ -123,7 +123,7 @@ class RobotController {
std::thread m_configuration_loop;
std::thread m_sensor_loop;
std::thread m_expiry_looop;
uint8_t m_selected_leader = 0;
std::atomic<uint8_t> m_selected_leader{0};
void metadata_loop();
void transmit_loop();

View File

@@ -170,7 +170,9 @@ LIB_API bool remote_call_c(uint8_t function_tag, uint8_t module, const uint8_t *
}
LIB_API const uint8_t *get_leaders(int *length) {
static const auto leaders = robot_controller->get_leaders();
static std::vector<uint8_t> leaders;
leaders = robot_controller->get_leaders();
*length = leaders.size();
spdlog::info("Returning {} leaders", *length);
return leaders.data();
}

View File

@@ -113,7 +113,7 @@ std::vector<Flatbuffers::ModuleInstance> RobotController::getModuleList() {
std::vector<Flatbuffers::ModuleInstance> out;
std::shared_lock lock(m_module_lock);
for (auto const &[key, value] : m_id_to_module) {
out.push_back({key, value->get_type(), value->get_leader()});
out.push_back({key, value->get_type(), 0, value->get_leader()});
}
return out;
}
@@ -305,6 +305,7 @@ std::vector<uint8_t> RobotController::get_leaders() {
std::shared_lock lock(m_module_lock);
std::unordered_set<uint8_t> out{};
spdlog::info("number of modules {}", m_id_to_module.size());
for (const auto m : map_to_values(m_id_to_module)) {
out.insert(m->get_leader());
}