46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
|
||
|
namespace NucuCar.Domain.Telemetry
|
||
|
{
|
||
|
public abstract class TelemetryPublisher : ITelemetryPublisher
|
||
|
{
|
||
|
protected readonly List<ITelemeter> RegisteredTelemeters;
|
||
|
protected ILogger Logger;
|
||
|
|
||
|
protected TelemetryPublisher()
|
||
|
{
|
||
|
RegisteredTelemeters = new List<ITelemeter>(5);
|
||
|
}
|
||
|
|
||
|
public abstract void Start();
|
||
|
|
||
|
public abstract Task StartAsync();
|
||
|
public abstract bool Publish(int timeout);
|
||
|
public abstract Task PublishAsync(CancellationToken cancellationToken);
|
||
|
public abstract void Configure(Dictionary<string, object> config);
|
||
|
|
||
|
public void SetLogger(ILogger logger)
|
||
|
{
|
||
|
Logger = logger;
|
||
|
}
|
||
|
|
||
|
public bool RegisterTelemeter(ITelemeter t)
|
||
|
{
|
||
|
if (RegisteredTelemeters.Contains(t)) return false;
|
||
|
RegisteredTelemeters.Add(t);
|
||
|
return true;
|
||
|
|
||
|
}
|
||
|
|
||
|
public bool UnRegisterTelemeter(ITelemeter t)
|
||
|
{
|
||
|
if (!RegisteredTelemeters.Contains(t)) return false;
|
||
|
RegisteredTelemeters.Remove(t);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|