Files
spore/include/spore/core/NodeContext.h
2025-10-21 09:56:27 +02:00

37 lines
1.1 KiB
C++

#pragma once
#include <WiFiUdp.h>
#include <map>
#include <functional>
#include <string>
#include <initializer_list>
#include <memory>
#include "spore/types/NodeInfo.h"
#include "spore/types/Config.h"
#include "spore/types/ApiTypes.h"
#include "spore/core/Memberlist.h"
class NodeContext {
public:
NodeContext();
NodeContext(std::initializer_list<std::pair<String, String>> initialLabels);
~NodeContext();
WiFiUDP* udp;
String hostname;
IPAddress localIP;
NodeInfo self;
std::unique_ptr<Memberlist> memberList;
::Config config;
std::map<String, String> constructorLabels; // Labels passed to constructor (not persisted)
using EventCallback = std::function<void(void*)>;
std::map<std::string, std::vector<EventCallback>> eventRegistry;
using AnyEventCallback = std::function<void(const std::string&, void*)>;
std::vector<AnyEventCallback> anyEventSubscribers;
void on(const std::string& event, EventCallback cb);
void fire(const std::string& event, void* data);
void onAny(AnyEventCallback cb);
void rebuildLabels(); // Rebuild self.labels from constructorLabels + config.labels
};