livoxProto1: udpCmdDemux now consults per-device handler registry

Device class objects now have a per-Device unordered_map of handlers
keyed by cmd_set+cmd_id.
This commit is contained in:
2025-10-22 07:28:00 -04:00
parent 10afec2532
commit 8e1d609ca1
3 changed files with 64 additions and 29 deletions
+26
View File
@@ -7,6 +7,7 @@
#include <atomic>
#include <optional>
#include <functional>
#include <unordered_map>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -16,6 +17,16 @@
#include "protocol.h"
#include <callback.h>
// Custom hash function for std::pair<uint8_t, uint8_t>
namespace std {
template<>
struct hash<std::pair<uint8_t, uint8_t>> {
size_t operator()(const std::pair<uint8_t, uint8_t>& p) const noexcept {
return (static_cast<size_t>(p.first) << 8) | static_cast<size_t>(p.second);
}
};
}
// Forward declaration
namespace smo {
class ComponentThread;
@@ -146,10 +157,25 @@ public:
const uint8_t* data, ssize_t bytesReceived,
const struct sockaddr_in& senderAddr);
// Command handler registration
void registerUdpCommandHandler(
uint8_t cmd_set, uint8_t cmd_id,
std::function<void(
const uint8_t* data, ssize_t bytesReceived,
const struct sockaddr_in& senderAddr)> handler);
void unregisterUdpCommandHandler(uint8_t cmd_set, uint8_t cmd_id);
private:
// Point cloud data setup
bool setupPcloudDataSocket();
void cleanupPcloudDataSocket();
// Command handler map
std::unordered_map<
std::pair<uint8_t, uint8_t>,
std::function<void(
const uint8_t* data, ssize_t bytesReceived,
const struct sockaddr_in& senderAddr)>> udpCommandHandlers;
};
} // namespace livoxProto1