Lifts ControlUnit, UnitRuntime/State, ControlRuntimeStore and unit CRUD
into app_feeder_distributor; their feeder-specific semantics
(DistributorRunning state, run_time/stop_time/acc_time/bl_time pacing)
violated the shared-core invariant.
WsMessage drops the UnitRuntimeChanged variant in favor of a generic
AppEvent(AppWsEvent) carrying {app, event_type, data}. Feeder emits
"feeder"/"unit_runtime_changed"; the web client dispatches by app
namespace, leaving core free of business types. The equipment handler
keeps its friendly unit-exists check by issuing an inline EXISTS query
instead of pulling the unit service.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
After record_event became the primitive for INSERT + broadcast + tracing,
persist_and_broadcast no longer persists or broadcasts directly — it
translates a PlatformEvent into an EventInsert and delegates. The new
name makes the layering explicit (record_event is the primitive,
record_platform_event is the PlatformEvent translator).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add MetadataCache to PlatformContext — a lazy-loaded, cross-app cache
of code fields used when formatting event messages. Each persisted
AppEvent previously did 1-2 extra SELECTs to look up the code for its
human-readable message; after this change the same id hits the cache
on all subsequent events.
Invalidation: the platform-owned equipment handler invalidates its
entry on update/delete; feeder's unit handler does the same for
units. Deletes are invalidated for hygiene only — no further events
should target a deleted id.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
record_event now logs at the matching tracing level (error/warn/info)
using the persisted message — giving every app uniform event logs for
free. Feeder's handle_control_event collapses from a 60-line match
(which just duplicated the persisted message with less-readable UUIDs)
to a single if-let for UnitStateChanged, which is the only AppEvent
that is intentionally not persisted.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Move the INSERT + WebSocket broadcast mechanism out of the feeder app
and into plc_platform_core as pub record_event(pool, ws, EventInsert).
The event table schema is owned by core, so writing to it is a platform
capability — apps (feeder, future ops) should only decide what to emit,
not how to persist it. Also replaces the 7-tuple in core's
persist_and_broadcast with the named EventInsert struct for readability.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- engine.rs: use is_none_or instead of map_or, remove redundant closures
- service/control.rs: move get_equipment_role_points before test module
- event.rs: replace complex 7-element tuple with PersistableEvent struct
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move TelemetryProcessor (PointNewValue batching/dedup/broadcast) from feeder to
plc_platform_core. PlatformBuilder.build() now auto-wires telemetry processing and
reconnect task. PlatformContext.emit_event() handles connection management side effects
(connect/reconnect/disconnect/subscribe/unsubscribe) directly. Simplify PlatformEventSink
trait from 6 methods to single on_event(). Feeder's AppEvent now only contains business
events; FeederPlatformEventSink only handles UnitsChanged for control runtime.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move source/point/equipment/tag/page handlers from feeder to plc_platform_core
using State<PlatformContext>; feeder re-exports via handler modules
- Keep batch_set_point_value in feeder (requires app-specific write key auth)
- Add PlatformEvent enum and persist_and_broadcast() in core for platform event
persistence to DB + WebSocket broadcast
- Add PlatformContext::emit_event() that handles both sink notification and
async persistence in one call
- Add platform_routes<S>() in core for centralized route registration;
both feeder and ops merge it instead of duplicating route definitions
- Implement FromRef<AppState> for PlatformContext in both apps
- Add FeederPlatformEventSink adapter bridging core events to feeder's
EventManager + ControlRuntimeStore
- Add event namespace prefixes: platform.source.created, feeder.unit.fault_locked, etc.
- Register full platform CRUD routes in ops app
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- PlatformContext now holds pool, connection_manager, ws_manager
- bootstrap_platform returns PlatformBuilder for pre-Arc setup
- Feeder AppState embeds PlatformContext (state.platform.pool etc.)
- Ops AppState embeds PlatformContext with real DB connection
- Remove WebSocket type duplication: feeder re-exports from core
- Add subscribe_room/send_to_room/remove_room_if_empty to WebSocketManager
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>