1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . ComponentModel ;
4+
5+ namespace RDMSharp . RDM . Device ;
6+
7+ public class ParameterMetadata : INotifyPropertyChanged
8+ {
9+ public readonly ERDM_Parameter Parameter ;
10+
11+ public event PropertyChangedEventHandler PropertyChanged ;
12+
13+ private EQueuedParameterCapabilitiesStatus _queuedCapabilitiesStatus = EQueuedParameterCapabilitiesStatus . Unknown ;
14+ public EQueuedParameterCapabilitiesStatus QueuedCapabilitiesStatus
15+ {
16+ get
17+ {
18+ return _queuedCapabilitiesStatus ;
19+ }
20+ internal set
21+ {
22+ if ( _queuedCapabilitiesStatus == value )
23+ return ;
24+ _queuedCapabilitiesStatus = value ;
25+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( QueuedCapabilitiesStatus ) ) ) ;
26+ }
27+ }
28+
29+ private DateTime _lastUpdated = DateTime . MinValue ;
30+ public DateTime LastUpdated
31+ {
32+ get
33+ {
34+ return _lastUpdated ;
35+ }
36+ private set
37+ {
38+ if ( _lastUpdated == value )
39+ return ;
40+ _lastUpdated = value ;
41+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( LastUpdated ) ) ) ;
42+ }
43+ }
44+
45+ private List < PeerToPeerProcess > peerToPeerProcesses = new List < PeerToPeerProcess > ( ) ;
46+ public IReadOnlyCollection < PeerToPeerProcess > PeerToPeerProcesses => peerToPeerProcesses ;
47+
48+ private List < RequestResponseHistoryEntry > requestResponseHistory = new List < RequestResponseHistoryEntry > ( ) ;
49+ public IReadOnlyCollection < RequestResponseHistoryEntry > RequestResponseHistory => requestResponseHistory ;
50+
51+ public event EventHandler < RequestResponseHistoryEntry > OnRequestResponseHistoryAdded ;
52+
53+ public ParameterMetadata ( ERDM_Parameter parameter )
54+ {
55+ Parameter = parameter ;
56+ }
57+
58+ internal void AddPeerToPeerProcess ( PeerToPeerProcess process )
59+ {
60+ process . PropertyChanged += Process_PropertyChanged ;
61+ process . OnRequestResponseHistoryAdded += Process_OnRequestResponseHistoryAdded ;
62+ peerToPeerProcesses . Add ( process ) ;
63+ }
64+
65+ private void Process_OnRequestResponseHistoryAdded ( object sender , RequestResponseHistoryEntry entry )
66+ {
67+ const int maxHistoryEntries = 20 ;
68+ requestResponseHistory . Add ( entry ) ;
69+
70+ if ( requestResponseHistory . Count > maxHistoryEntries )
71+ {
72+ int excessEntries = requestResponseHistory . Count - maxHistoryEntries ;
73+ requestResponseHistory . RemoveRange ( 0 , excessEntries ) ;
74+ }
75+ OnRequestResponseHistoryAdded ? . Invoke ( this , entry ) ;
76+ }
77+
78+ private void Process_PropertyChanged ( object sender , PropertyChangedEventArgs e )
79+ {
80+ PeerToPeerProcess process = sender as PeerToPeerProcess ;
81+ switch ( e . PropertyName )
82+ {
83+ case nameof ( process . State ) :
84+ switch ( process . State )
85+ {
86+ case PeerToPeerProcess . EPeerToPeerProcessState . Finished :
87+ peerToPeerProcesses . Remove ( process ) ;
88+ LastUpdated = DateTime . Now ;
89+ break ;
90+ case PeerToPeerProcess . EPeerToPeerProcessState . Failed :
91+ peerToPeerProcesses . Remove ( process ) ;
92+ break ;
93+ }
94+ break ;
95+
96+ }
97+ }
98+ }
99+ [ Flags ]
100+ public enum EQueuedParameterCapabilitiesStatus : byte
101+ {
102+ Unknown = 0b00000000 ,
103+ ParameterNotSupported = 0b00000010 ,
104+ Try_1 = 0b00000100 ,
105+ Try_2 = 0b00001000 ,
106+ Try_3 = 0b00010000 ,
107+ Pending = 0b00100000 ,
108+ Supported = 0b01000000 ,
109+ NotSupported = 0b10000000 ,
110+ }
0 commit comments