feat(comms): Stage 1 — CommandBus scaffolding (headers + skeleton)
Adds the core data structures and interfaces for the comms refactor. No behaviour change — old CommandHandler is completely untouched. New files: CommandEnvelope.hpp — universal message wrapper (transport + command + reply lambda) CommandResult.hpp — standardised return type with ok/err/info factories ICommandHandler.hpp — interface every domain handler will implement ITransport.hpp — interface every transport layer will implement CommandBus.hpp/.cpp — registry + dispatcher (std::map, O(log n) lookup) Two minor corrections vs. plan: std::unordered_map → std::map (Arduino String has no std::hash) LOG_WARN → LOG_WARNING (codebase macro name) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../CommandBus/CommandResult.hpp"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ITransport
|
||||
//
|
||||
// Interface every transport layer implements.
|
||||
//
|
||||
// Transports are responsible for:
|
||||
// 1. Receiving raw input from their protocol (MQTT, WebSocket, HTTP, UART)
|
||||
// 2. Parsing it into a CommandEnvelope
|
||||
// 3. Injecting a reply lambda that routes the response back correctly
|
||||
// 4. Calling CommandBus::dispatch()
|
||||
//
|
||||
// The CommandBus never knows which transport originated a command.
|
||||
// The transport never knows what a handler does with it.
|
||||
//
|
||||
// broadcast() is used by CommunicationRouter to push unsolicited events
|
||||
// (telemetry, bell strikes, status changes) to all connected clients of
|
||||
// this transport.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class ITransport {
|
||||
public:
|
||||
virtual ~ITransport() = default;
|
||||
|
||||
// Initialise the transport (called once from CommunicationRouter::begin())
|
||||
virtual void begin() = 0;
|
||||
|
||||
// Service the transport's event loop (called from CommunicationRouter::loop())
|
||||
virtual void loop() = 0;
|
||||
|
||||
// Health check used by HealthMonitor / CommunicationRouter::isHealthy()
|
||||
virtual bool isHealthy() const = 0;
|
||||
|
||||
// Human-readable name for logging (e.g. "MQTT", "WebSocket", "HTTP", "UART")
|
||||
virtual String name() const = 0;
|
||||
|
||||
// Push a pre-serialised JSON string to all clients of this transport.
|
||||
// For connection-less transports (HTTP, UART) this is a no-op.
|
||||
virtual void broadcast(const String& message) = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user