Skip to content

Commit 8f6905b

Browse files
committed
RTT Process Control opt in implemented
now does ready check now does status reports
1 parent 0f5c0e0 commit 8f6905b

File tree

4 files changed

+133
-41
lines changed

4 files changed

+133
-41
lines changed

HeliosFalcon/Interfaces/FalconInterface.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ public override IEnumerable<StatusReportItem> PerformReadyCheck()
657657

658658
if (Rtt != null)
659659
{
660-
yield return Rtt.OnReadyCheck();
660+
foreach (StatusReportItem statusReportItem in Rtt.OnReadyCheck())
661+
{
662+
yield return statusReportItem;
663+
}
661664
}
662665
}
663666

HeliosFalcon/Interfaces/RTT/ConfigGenerator.cs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Ammo Goettsch
1+
// Copyright 2021 Helios Contributors
22
//
33
// HeliosFalcon is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -48,11 +48,11 @@
4848
- on status report
4949
- if disabled due to no magic cookie on load, show special status asking to enable for consent
5050
- show configuration that will be generated
51-
- warn if profile wants to start/stop RTT but global policy disallows it
51+
- error if profile wants to start/stop RTT but global policy disallows it
5252
- on ready check
5353
- make sure falcon interface is configured
5454
- make sure file either does not exist or is helios owned
55-
- make sure process control we plan to use is actually permitted (warn or error if start/stop is configurable)
55+
- error if profile wants to start/stop RTT but global policy disallows it
5656
- on profile start
5757
- refuse to overwrite non-Helios file
5858
- launch RTT process
@@ -218,7 +218,7 @@ internal IEnumerable<StatusReportItem> OnStatusReport(IEnumerable<ShadowVisual>
218218
Status =
219219
"RTT feature has been disabled, because an existing RTT configuration would be overwritten by this profile",
220220
Recommendation =
221-
"Enable the RTT feature again to back up the existing file and let Helios to generate RTT displays"
221+
"Enable the RTT feature again to back up the existing file and let Helios generate RTT displays"
222222
}.AsReport();
223223
}
224224

@@ -227,7 +227,17 @@ internal IEnumerable<StatusReportItem> OnStatusReport(IEnumerable<ShadowVisual>
227227
return new StatusReportItem[0];
228228
}
229229

230-
// REVISIT: for now, we show the whole generated file
230+
// gather status from child objects, if any
231+
IEnumerable<StatusReportItem> processControlReport =
232+
ProcessControl?.OnStatusReport() ?? new StatusReportItem[0];
233+
234+
return processControlReport
235+
.Concat(ReportLInes());
236+
}
237+
238+
private IEnumerable<StatusReportItem> ReportLInes()
239+
{
240+
// we show the whole generated file, so it will be in the interface status report
231241
return _lines
232242
.Select(line => new StatusReportItem
233243
{
@@ -309,21 +319,49 @@ internal void OnInteractivelyEnabled(CheckBox source)
309319
}
310320

311321
/// <summary>
312-
/// create a single ready check item for our parent's ReadyCheck
322+
/// create a ready check items for our parent's ReadyCheck
313323
/// </summary>
314324
/// <returns></returns>
315-
internal StatusReportItem OnReadyCheck()
325+
internal IEnumerable<StatusReportItem> OnReadyCheck()
316326
{
327+
if (DisabledUntilConsent)
328+
{
329+
yield return new StatusReportItem
330+
{
331+
Severity = StatusReportItem.SeverityCode.Error,
332+
Status =
333+
"RTT feature has been disabled, because an existing RTT configuration would be overwritten by this profile",
334+
Link = StatusReportItem.ProfileEditor,
335+
Recommendation =
336+
"Enable the RTT feature again to back up the existing file and let Helios generate RTT displays"
337+
};
338+
yield break;
339+
}
340+
317341
if (!Enabled)
318342
{
319-
return new StatusReportItem
343+
yield return new StatusReportItem
320344
{
321345
Status = "RTT client configuration feature is not enabled",
322346
Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate | StatusReportItem.StatusFlags.Verbose
323347

324348
};
349+
yield break;
350+
}
351+
352+
yield return CheckConfigFile();
353+
354+
if (ProcessControl != null)
355+
{
356+
foreach (StatusReportItem statusReportItem in ProcessControl.OnReadyCheck())
357+
{
358+
yield return statusReportItem;
359+
}
325360
}
361+
}
326362

363+
private StatusReportItem CheckConfigFile()
364+
{
327365
if (string.IsNullOrEmpty(Parent.FalconPath))
328366
{
329367
return new StatusReportItem
@@ -388,8 +426,6 @@ internal StatusReportItem OnReadyCheck()
388426

389427
internal void OnProfileStart()
390428
{
391-
StartedProcess = false;
392-
393429
// check for Helios ownership of the RTT file and if it is ours, write the RTT configuration for the current profile,
394430
// which may not be the most recent one we configured in Profile Editor
395431
if (!UpdateRttConfigurationFile())
@@ -398,27 +434,12 @@ internal void OnProfileStart()
398434
return;
399435
}
400436

401-
if (ProcessControl?.StartRtt ?? false)
402-
{
403-
// launch RTT
404-
string selectedClient = ProcessControl.SelectClient(Networked);
405-
StartedProcess =
406-
ProcessControl.StartRTTClient(Path.Combine(Parent.FalconPath, "Tools", "RTTRemote", selectedClient));
407-
Logger.Info($"launching RTT client: {selectedClient}");
408-
}
437+
ProcessControl?.OnProfileStart(Parent, Networked);
409438
}
410439

411440
internal void OnProfileStop()
412441
{
413-
if (!StartedProcess)
414-
{
415-
return;
416-
}
417-
418-
if (ProcessControl?.StopRtt ?? false)
419-
{
420-
ProcessControl.KillRTTCllient(Path.GetFileNameWithoutExtension(ProcessControl.SelectClient(Networked)));
421-
}
442+
ProcessControl?.OnProfileStop(Parent, Networked);
422443
}
423444

424445
/// <summary>
@@ -816,12 +837,6 @@ public ICommand EnabledCommand
816837
[XmlIgnore]
817838
public IRttGeneratorHost Parent { get; internal set; }
818839

819-
/// <summary>
820-
/// if true, we started RTT process on this run
821-
/// </summary>
822-
[XmlIgnore]
823-
public bool StartedProcess { get; private set; }
824-
825840
#endregion
826841

827842
/// <summary>

HeliosFalcon/Interfaces/RTT/InterfaceEditor.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@
246246
Grid.ColumnSpan="2" />
247247
<CheckBox Grid.Column="2"
248248
VerticalAlignment="Center"
249-
IsEnabled="{Binding ProcessControl.Enabled}"
250249
IsChecked="{Binding ProcessControl.StartRtt}"
251250
Margin="0,60,0,85" />
252251
<TextBlock Text="Start the RTT Cllient automatically when the profile starts"
@@ -265,7 +264,6 @@
265264
Grid.ColumnSpan="2" />
266265
<CheckBox Grid.Column="2"
267266
VerticalAlignment="Center"
268-
IsEnabled="{Binding ProcessControl.Enabled}"
269267
IsChecked="{Binding ProcessControl.StopRtt}"
270268
Margin="0,86,0,59" />
271269
<TextBlock Text="Stop the RTT Cllient automatically when the profile stops"

HeliosFalcon/Interfaces/RTT/ProcessControl.cs

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2021 Ammo Goettsch
2-
//
1+
// Copyright 2021 Helios Contributors
2+
//
33
// HeliosFalcon is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
55
// the Free Software Foundation, either version 3 of the License, or
@@ -15,6 +15,7 @@
1515
//
1616

1717
using System;
18+
using System.Collections.Generic;
1819
using System.ComponentModel;
1920
using System.Diagnostics;
2021
using System.IO;
@@ -48,7 +49,76 @@ public class ProcessControl : NotificationObject
4849
/// </summary>
4950
private bool _enabled = ConfigManager.SettingsManager.LoadSetting(CONFIGURATION_GROUP, CONFIGURATION_SETTING_ENABLED, false);
5051

51-
public bool StartRTTClient(string executablePath)
52+
internal IEnumerable<StatusReportItem> OnStatusReport()
53+
{
54+
return CheckCommonItems();
55+
}
56+
57+
internal IEnumerable<StatusReportItem> OnReadyCheck()
58+
{
59+
return CheckCommonItems();
60+
}
61+
62+
internal void OnProfileStart(IRttGeneratorHost parent, bool networked)
63+
{
64+
StartedProcess = false;
65+
66+
if (!StartRtt)
67+
{
68+
return;
69+
}
70+
71+
if (!Enabled)
72+
{
73+
Logger.Warn("Profile requested starting of RTT Client process, but this operation is not permitted on this computer");
74+
return;
75+
}
76+
77+
// launch RTT
78+
string selectedClient = SelectClient(networked);
79+
Logger.Info($"launching RTT client: {selectedClient}");
80+
StartedProcess =
81+
StartRTTClient(Path.Combine(parent.FalconPath, "Tools", "RTTRemote", selectedClient));
82+
}
83+
84+
internal void OnProfileStop(IRttGeneratorHost _, bool networked)
85+
{
86+
if (!StartedProcess)
87+
{
88+
return;
89+
}
90+
91+
if (!StopRtt)
92+
{
93+
return;
94+
}
95+
96+
if (!Enabled)
97+
{
98+
Logger.Warn("Profile requested stopping of RTT Client process, but this operation is not permitted on this computer");
99+
return;
100+
}
101+
102+
KillRTTCllient(Path.GetFileNameWithoutExtension(SelectClient(networked)));
103+
}
104+
105+
private IEnumerable<StatusReportItem> CheckCommonItems()
106+
{
107+
if ((StartRtt || StopRtt) && !Enabled)
108+
{
109+
// nothing will happen, unless the user opts in
110+
yield return new StatusReportItem
111+
{
112+
Status =
113+
"The profile requests starting and/or stopping of the RTT Client process, but you have not allowed Helios to do so",
114+
Severity = StatusReportItem.SeverityCode.Error,
115+
Link = StatusReportItem.ProfileEditor,
116+
Recommendation = "Allow the RTT Process Control feature in the Falcon Interface"
117+
};
118+
}
119+
}
120+
121+
private bool StartRTTClient(string executablePath)
52122
{
53123
if (!File.Exists(executablePath))
54124
{
@@ -65,7 +135,7 @@ public bool StartRTTClient(string executablePath)
65135
return true;
66136
}
67137

68-
public void KillRTTCllient(string processName)
138+
private void KillRTTCllient(string processName)
69139
{
70140
try
71141
{
@@ -88,7 +158,7 @@ public void KillRTTCllient(string processName)
88158
/// </summary>
89159
/// <param name="networked"></param>
90160
/// <returns>selected</returns>
91-
internal string SelectClient(bool networked)
161+
private string SelectClient(bool networked)
92162
{
93163
string selected;
94164
if (Environment.Is64BitProcess)
@@ -168,6 +238,12 @@ public bool Enabled
168238
}
169239
}
170240

241+
/// <summary>
242+
/// if true, we started RTT process on this run
243+
/// </summary>
244+
[XmlIgnore]
245+
public bool StartedProcess { get; private set; }
246+
171247
#endregion
172248
}
173249
}

0 commit comments

Comments
 (0)