LivoxProto1: registerUdpHandler: enforce overwriting
Enforce handler overwriting in the devicesUnderConstruction collection, for combos of cmd_set+cmd_id that pre-exist the current invocation
This commit is contained in:
@@ -1896,12 +1896,25 @@ void Device::registerUdpCommandHandler(
|
||||
*/
|
||||
if (!deviceIP.empty())
|
||||
{
|
||||
// Add command-specific handler to the list for this device IP
|
||||
auto& handlers = devicesUnderConstruction[deviceIP];
|
||||
auto it = std::find_if(handlers.begin(), handlers.end(),
|
||||
[cmd_set, cmd_id](const CommandHandler& existing) {
|
||||
return existing.cmd_set == cmd_set && existing.cmd_id == cmd_id;
|
||||
});
|
||||
|
||||
// Create the new command handler
|
||||
CommandHandler cmdHandler;
|
||||
cmdHandler.cmd_set = cmd_set;
|
||||
cmdHandler.cmd_id = cmd_id;
|
||||
cmdHandler.handler = std::move(handler);
|
||||
devicesUnderConstruction[deviceIP].push_back(std::move(cmdHandler));
|
||||
|
||||
if (it != handlers.end()) {
|
||||
// Replace existing handler
|
||||
*it = std::move(cmdHandler);
|
||||
} else {
|
||||
// Add new handler
|
||||
handlers.push_back(std::move(cmdHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user