-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple notification system to alert the user of any important d…
…ata coming in, such as RaceControlMessages. Initial implementation sends a BEL to the console to make a audible alert to the user.
- Loading branch information
1 parent
8399858
commit 5c9e790
Showing
6 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace OpenF1.Data; | ||
|
||
public interface INotifyService | ||
{ | ||
/// <summary> | ||
/// Sends a notification to any registered handlers. | ||
/// This should only be used to alert a user to some important action, and not to transmit any data. | ||
/// </summary> | ||
public void SendNotification(); | ||
|
||
/// <summary> | ||
/// Registers the provided <paramref name="action"/> as a handler for any notification that is sent. | ||
/// </summary> | ||
/// <param name="action">The action to call when a notification has been sent.</param> | ||
public void RegisterNotificationHandler(Action action); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
namespace OpenF1.Data; | ||
|
||
public class NotifyService : INotifyService | ||
{ | ||
private Action? _action; | ||
|
||
/// <inheritdoc /> | ||
public void RegisterNotificationHandler(Action action) => _action = action; | ||
|
||
/// <inheritdoc /> | ||
public void SendNotification() => _action?.Invoke(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
namespace OpenF1.Data; | ||
|
||
public class RaceControlMessageProcessor : IProcessor<RaceControlMessageDataPoint> | ||
public class RaceControlMessageProcessor(INotifyService notifyService) : IProcessor<RaceControlMessageDataPoint> | ||
{ | ||
public RaceControlMessageDataPoint RaceControlMessages { get; private set; } = new(); | ||
|
||
public void Process(RaceControlMessageDataPoint data) | ||
{ | ||
foreach (var message in data.Messages) | ||
{ | ||
RaceControlMessages.Messages.TryAdd(message.Key, message.Value); | ||
var added = RaceControlMessages.Messages.TryAdd(message.Key, message.Value); | ||
if (added) | ||
{ | ||
// New race control messages are important, so alert the user | ||
notifyService.SendNotification(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters