common/networking/subscription_objects.rs
1use std::fmt;
2use std::fmt::Formatter;
3use serde::{Deserialize, Serialize};
4use crate::fixture::PropertyType;
5
6/// Represents the full DMX patch configuration mapped out for the client,
7/// structured as a 2D array (universes containing individual channels).
8pub type DMXConfigForClientState = Vec<Vec<DMXConfigurationForClient>>;
9
10/// Defines the available data streams or engine states that a client can subscribe to.
11#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
12pub enum SubscribeTopic {
13 /// The current DMX channel allocation and patch state.
14 DMXConfiguration,
15}
16
17/// Container for the actual data payload dispatched during a topic update.
18#[derive(Serialize, Deserialize, Debug, Clone)]
19pub enum TopicPayload {
20 /// Payload carrying the synchronized DMX configuration state.
21 DMXConfiguration(DMXConfigForClientState),
22}
23
24/// Specifies the frequency and condition under which the server transmits topic updates.
25#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
26pub enum UpdateMode {
27 /// Updates are only transmitted when the underlying data actually changes.
28 OnChange,
29 /// Updates are transmitted continuously at a set interval, regardless of state changes.
30 Continuous,
31}
32
33/// Represents the state of a single DMX channel tailored specifically for clear visual representation
34/// in the client's GUI DMX overview.
35#[derive(Serialize, Deserialize, Debug, Clone)]
36pub enum DMXConfigurationForClient {
37 /// The DMX channel is currently unassigned.
38 Empty,
39 /// The DMX channel is allocated to a fixture property, providing necessary details for the UI.
40 Reserved{
41 /// The unique name of the fixture occupying this channel.
42 fixture_name: String,
43 /// The specific property type (e.g., Dimmer, Pan) mapped to this channel to display its function.
44 property_type: PropertyType,
45 /// The resolution layer of this channel (e.g., 0 for coarse, 1 for fine, 2 for ultra, ...).
46 fine_degree: usize,
47 /// A lightweight hash used by the GUI to assign consistent color coding to fixtures of the same type,
48 /// keeping the DMX overview visually organized without cluttering it with full type names.
49 fixture_type_hash: u8,
50 },
51}
52
53impl TopicPayload {
54 /// Retrieves the corresponding [`SubscribeTopic`] associated with this data payload.
55 pub fn get_topic(&self) -> SubscribeTopic {
56 match self {
57 TopicPayload::DMXConfiguration(..) => SubscribeTopic::DMXConfiguration,
58 }
59 }
60}
61
62
63impl fmt::Display for SubscribeTopic {
64 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
65 match self {
66 SubscribeTopic::DMXConfiguration => f.write_str("DMXConfiguration"),
67 }
68 }
69}
70