endpointhash 1.0
This commit is contained in:
81
src/message_bus/pipeline/discovery/DiscoveryPool.h
Normal file
81
src/message_bus/pipeline/discovery/DiscoveryPool.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
|
||||
#include "core/models/RawBusMessage.h"
|
||||
|
||||
namespace softbus::message_bus::pipeline
|
||||
{
|
||||
|
||||
struct DiscoverySample
|
||||
{
|
||||
std::uint64_t compositeKey{0};
|
||||
std::uint32_t endpointHash{0};
|
||||
softbus::core::models::ProtocolType protocol{softbus::core::models::ProtocolType::UNKNOWN};
|
||||
std::uint8_t slaveId{0};
|
||||
std::uint16_t registerAddress{0};
|
||||
double rawValue{0.0};
|
||||
std::int64_t firstSeenMs{0};
|
||||
std::int64_t lastSeenMs{0};
|
||||
std::uint64_t hitCount{0};
|
||||
};
|
||||
|
||||
class DiscoveryPool
|
||||
{
|
||||
public:
|
||||
struct Config
|
||||
{
|
||||
std::size_t maxEntries{4096};
|
||||
std::int64_t minSampleIntervalMs{200};
|
||||
std::int64_t sniffTtlMs{0};
|
||||
};
|
||||
|
||||
static DiscoveryPool& instance();
|
||||
|
||||
void updateConfig(const Config& cfg);
|
||||
Config config() const;
|
||||
|
||||
void startSniffing(std::int64_t ttlMs = 0);
|
||||
void stopSniffing();
|
||||
bool isSniffingEnabled() const;
|
||||
void tick();
|
||||
|
||||
void reportUnmapped(const DiscoverySample& sample);
|
||||
void clear();
|
||||
|
||||
QJsonObject status() const;
|
||||
QJsonArray listSamples(std::size_t offset,
|
||||
std::size_t limit,
|
||||
std::uint32_t endpointFilter,
|
||||
softbus::core::models::ProtocolType protocolFilter,
|
||||
const std::unordered_map<std::uint64_t, QString>& mappedKeys) const;
|
||||
|
||||
private:
|
||||
DiscoveryPool() = default;
|
||||
void enforceCapacityLocked();
|
||||
static QString protocolToString(softbus::core::models::ProtocolType protocol);
|
||||
|
||||
private:
|
||||
struct Slot
|
||||
{
|
||||
DiscoverySample sample;
|
||||
};
|
||||
|
||||
mutable QMutex m_mtx;
|
||||
std::unordered_map<std::uint64_t, Slot> m_slots;
|
||||
Config m_cfg;
|
||||
std::atomic<bool> m_sniffingEnabled{false};
|
||||
std::int64_t m_sniffStartedAtMs{0};
|
||||
std::int64_t m_sniffExpiresAtMs{0};
|
||||
};
|
||||
|
||||
} // namespace softbus::message_bus::pipeline
|
||||
Reference in New Issue
Block a user