#pragma once
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include "wpi/function_ref.h"
namespace wpi {
class Sendable;
class SendableBuilder;
class SendableRegistry final {
public:
SendableRegistry() = delete;
using UID = size_t;
static void EnsureInitialized();
static void SetLiveWindowBuilderFactory(
std::function<std::unique_ptr<SendableBuilder>()> factory);
static void Add(Sendable* sendable, std::string_view name);
static void Add(Sendable* sendable, std::string_view moduleType, int channel);
static void Add(Sendable* sendable, std::string_view moduleType,
int moduleNumber, int channel);
static void Add(Sendable* sendable, std::string_view subsystem,
std::string_view name);
static void AddLW(Sendable* sendable, std::string_view name);
static void AddLW(Sendable* sendable, std::string_view moduleType,
int channel);
static void AddLW(Sendable* sendable, std::string_view moduleType,
int moduleNumber, int channel);
static void AddLW(Sendable* sendable, std::string_view subsystem,
std::string_view name);
static void AddChild(Sendable* parent, Sendable* child);
static void AddChild(Sendable* parent, void* child);
static bool Remove(Sendable* sendable);
static void Move(Sendable* to, Sendable* from);
static bool Contains(const Sendable* sendable);
static std::string GetName(const Sendable* sendable);
static void SetName(Sendable* sendable, std::string_view name);
static void SetName(Sendable* sendable, std::string_view moduleType,
int channel);
static void SetName(Sendable* sendable, std::string_view moduleType,
int moduleNumber, int channel);
static void SetName(Sendable* sendable, std::string_view subsystem,
std::string_view name);
static std::string GetSubsystem(const Sendable* sendable);
static void SetSubsystem(Sendable* sendable, std::string_view subsystem);
static int GetDataHandle();
static std::shared_ptr<void> SetData(Sendable* sendable, int handle,
std::shared_ptr<void> data);
static std::shared_ptr<void> GetData(Sendable* sendable, int handle);
static void EnableLiveWindow(Sendable* sendable);
static void DisableLiveWindow(Sendable* sendable);
static UID GetUniqueId(Sendable* sendable);
static Sendable* GetSendable(UID uid);
static void Publish(UID sendableUid,
std::unique_ptr<SendableBuilder> builder);
static void Update(UID sendableUid);
struct CallbackData {
CallbackData(Sendable* sendable_, std::string_view name_,
std::string_view subsystem_, wpi::Sendable* parent_,
std::shared_ptr<void>& data_, SendableBuilder& builder_)
: sendable(sendable_),
name(name_),
subsystem(subsystem_),
parent(parent_),
data(data_),
builder(builder_) {}
Sendable* sendable;
std::string_view name;
std::string_view subsystem;
Sendable* parent;
std::shared_ptr<void>& data;
SendableBuilder& builder;
};
static void ForeachLiveWindow(
int dataHandle, wpi::function_ref<void(CallbackData& cbdata)> callback);
};
}