Skip to content

Commit 6c20d46

Browse files
committed
merge: bring in feat/named-routing-slots
2 parents 592ece5 + e0f7fc9 commit 6c20d46

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using PepperDash.Core;
4+
5+
namespace PepperDash.Essentials.Core;
6+
7+
/// <summary>
8+
/// Describes a single named routing slot (input or output) on a device implementing
9+
/// <see cref="IHasNamedRoutingSlots"/>.
10+
/// </summary>
11+
public interface IRoutingSlotInfo : IKeyName
12+
{
13+
/// <summary>Matrix slot number.</summary>
14+
int SlotNumber { get; }
15+
16+
/// <summary>Signal types this slot can carry.</summary>
17+
eRoutingSignalType SupportedSignalTypes { get; }
18+
}
19+
20+
/// <summary>
21+
/// Describes a named output slot, adding per-signal-type current-route feedback (keyed by the
22+
/// routed input slot's key) that <see cref="IRoutingMidpointWithFeedback.CurrentRoutes"/> does not
23+
/// carry.
24+
/// </summary>
25+
public interface IRoutingOutputSlotInfo : IRoutingSlotInfo
26+
{
27+
/// <summary>The key of the input slot currently routed to this output, per signal type.</summary>
28+
IReadOnlyDictionary<eRoutingSignalType, string> CurrentRouteInputKeys { get; }
29+
30+
/// <summary>Raised when the routed input on this output changes.</summary>
31+
event EventHandler OutputSlotChanged;
32+
}
33+
34+
/// <summary>
35+
/// Optional extension to <see cref="IRoutingMidpointWithFeedback"/> for matrix-style routing
36+
/// devices that track named input/output slots (with per-signal-type routing feedback) internally,
37+
/// e.g. plugin-local slot abstractions that replaced the removed core <c>IRoutingInputSlot</c>/
38+
/// <c>IRoutingOutputSlot</c> during the v3 routing refactor. Devices implementing this get a richer
39+
/// mobile-control matrix routing message (names + per-signal-type feedback) instead of the bare
40+
/// key-only ports from <see cref="IRoutingMidpointWithFeedback"/> alone.
41+
/// </summary>
42+
public interface IHasNamedRoutingSlots : IRoutingMidpointWithFeedback
43+
{
44+
/// <summary>Named input slots, keyed by slot key.</summary>
45+
IReadOnlyDictionary<string, IRoutingSlotInfo> InputSlots { get; }
46+
47+
/// <summary>Named output slots, keyed by slot key.</summary>
48+
IReadOnlyDictionary<string, IRoutingOutputSlotInfo> OutputSlots { get; }
49+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
5+
using PepperDash.Core;
6+
using PepperDash.Essentials.Core;
7+
8+
namespace PepperDash.Essentials.AppServer.Messengers
9+
{
10+
/// <summary>
11+
/// Messenger for devices implementing <see cref="IHasNamedRoutingSlots"/> — sends named
12+
/// input/output slots with per-signal-type current-route feedback, which the bare
13+
/// <see cref="IRoutingMidpointWithFeedbackMessenger"/> (registered for every
14+
/// <see cref="IRoutingMidpointWithFeedback"/> device, including this one) cannot provide.
15+
/// </summary>
16+
public class IHasNamedRoutingSlotsMessenger : MessengerBase
17+
{
18+
private readonly IHasNamedRoutingSlots _device;
19+
20+
public IHasNamedRoutingSlotsMessenger(string key, string messagePath, IHasNamedRoutingSlots device)
21+
: base(key, messagePath, device as IKeyName)
22+
{
23+
_device = device;
24+
}
25+
26+
protected override void RegisterActions()
27+
{
28+
base.RegisterActions();
29+
30+
AddAction("/fullStatus", (id, content) => SendFullStatus(id));
31+
32+
foreach (var output in _device.OutputSlots.Values)
33+
{
34+
output.OutputSlotChanged += (sender, args) => SendFullStatus();
35+
}
36+
}
37+
38+
private static RoutingSlotMessage BuildSlotMessage(IRoutingSlotInfo slot) => new RoutingSlotMessage
39+
{
40+
Key = slot.Key,
41+
Name = slot.Name,
42+
SlotNumber = slot.SlotNumber,
43+
SupportedSignalTypes = slot.SupportedSignalTypes.ToString()
44+
};
45+
46+
private void SendFullStatus(string id = null)
47+
{
48+
var inputSlots = _device.InputSlots.ToDictionary(kvp => kvp.Key, kvp => BuildSlotMessage(kvp.Value));
49+
50+
var outputSlots = _device.OutputSlots.ToDictionary(kvp => kvp.Key, kvp =>
51+
{
52+
var message = BuildSlotMessage(kvp.Value);
53+
message.CurrentRouteInputKeys = kvp.Value.CurrentRouteInputKeys
54+
.ToDictionary(r => r.Key.ToString(), r => r.Value);
55+
return message;
56+
});
57+
58+
var content = JToken.FromObject(new
59+
{
60+
inputSlots,
61+
outputSlots
62+
});
63+
64+
PostStatusMessage(content, MessagePath, id);
65+
}
66+
}
67+
68+
public class RoutingSlotMessage
69+
{
70+
[JsonProperty("key")]
71+
public string Key { get; set; }
72+
73+
[JsonProperty("name")]
74+
public string Name { get; set; }
75+
76+
[JsonProperty("slotNumber")]
77+
public int SlotNumber { get; set; }
78+
79+
[JsonProperty("supportedSignalTypes")]
80+
public string SupportedSignalTypes { get; set; }
81+
82+
[JsonProperty("currentRouteInputKeys", NullValueHandling = NullValueHandling.Ignore)]
83+
public Dictionary<string, string> CurrentRouteInputKeys { get; set; }
84+
}
85+
}

src/PepperDash.Essentials.MobileControl/MessengerFactoryRegistry.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ internal static class MessengerFactoryRegistry
374374
(d, mp, _) => new IRoutingMidpointWithFeedbackMessenger(
375375
$"{d.Key}-matrixRouting", mp, (IRoutingMidpointWithFeedback)d)
376376
),
377+
// Devices that also expose named slots (plugin-local IDmInputSlot/INvxInputSlot-
378+
// style abstractions) get a second, richer message with names + per-signal-type
379+
// route feedback the bare messenger above cannot provide.
380+
new MessengerFactoryEntry(
381+
typeof(IHasNamedRoutingSlots),
382+
(d, mp, _) => new IHasNamedRoutingSlotsMessenger(
383+
$"{d.Key}-namedRoutingSlots", mp, (IHasNamedRoutingSlots)d)
384+
),
377385

378386
// ── Environmental sensors ─────────────────────────────────────────────────
379387
// Preserving original key format (no controller key suffix)

0 commit comments

Comments
 (0)