public static TDevice Generic <TDevice>(DeviceState state, IDeviceHost host) where TDevice : IDeviceAdapter, new() { var device = new TDevice(); device.Init(state, host); return(device); }
public override HEADSET_LIMITATIONS Initalize(IDeviceHost host) { this.host = host; device.SetButtonEventHandler(OnButtonEvent); device.SetStateEventHandler(OnStateEvent); host.StatusChanged += HostStatusChanged; return(HEADSET_LIMITATIONS.ONLY_ACTIVE_DURING_CALLS); }
public Holder(object id, IDeviceHost host) { Id = id; Host = host; _scheduler = host.Scheduler; _source = host .GetAndObserveState(this) .Retry(Constants.DefaultRetryDelay, _scheduler) .Publish() .RefCount(); }
public override HEADSET_LIMITATIONS Initalize(IDeviceHost host) { this.host = host; device.DeviceEvents.MuteStateChanged += DeviceEvents_MuteStateChanged; device.DeviceEvents.FlashPressed += DeviceEvents_FlashPressed; device.DeviceEvents.TalkPressed += DeviceEvents_TalkPressed; device.DeviceEvents.AudioStateChanged += DeviceEvents_AudioStateChanged; device.DeviceEvents.ButtonPressed += DeviceEvents_ButtonPressed; host.StatusChanged += HostStatusChanged; return(HEADSET_LIMITATIONS.NO_UNMUTE); }
/// <inheritdoc /> void IDeviceAdapter.Init(DeviceState state, IDeviceHost host) { state = state ?? throw new ArgumentNullException(nameof(state)); host = host ?? throw new ArgumentNullException(nameof(host)); if (Interlocked.CompareExchange(ref _state, state, null) == null) { Host = host; OnInit(); } else { throw new InvalidOperationException("A device is an immutable object that can be init only once."); } }
protected HomeDevice(IDeviceHost host, object id, IObservable <TDevice> source, Func <TDevice, bool> isPersistent, IScheduler scheduler) { Host = host; Id = id; // Here we make sure to cache only the state that are flagged as "persisted" (a.k.a. 'retain' in MQTT) // so we will not replay a "transient" values (e.g. events like button pressed) _source = source .Select(state => { if (isPersistent(state)) { _lastPersisted = state; _hasPersisted = true; } return(state); }) .Retry(TimeSpan.FromSeconds(10) /*Constants.DefaultRetryDelay*/, scheduler) .Multicast(_device); }
public HomeDevice(IDeviceHost host, object id, IObservable <DeviceState> source, Func <DeviceState, IDeviceHost, TDevice> toDevice, IScheduler scheduler) { Host = host; Id = id; // Here we make sure to cache only the state that are flagged as "persisted" (a.k.a. 'retain' in MQTT) // so we will not replay a "transient" values (e.g. events like button pressed) _source = source .Select(state => { var device = toDevice(state, Host); if (state.IsPersistedState) { _lastPersisted = device; _hasPersisted = true; } return(device); }) .Retry(Constants.DefaultRetryDelay, scheduler) // This will retry only for the "toDevice" as the source is already retried .Multicast(_device); }
public override HEADSET_LIMITATIONS Initalize(IDeviceHost host) { this.host = host; host.StatusChanged += HostStatusChanged; return(HEADSET_LIMITATIONS.ONLY_ACTIVE_DURING_CALLS); }
public static ExpandoObject Dynamic(DeviceState state, IDeviceHost host) => state.ToDynamic();
public HomeDevicesManager(IDeviceHost host) { _host = host; }
public void RegisterHost(IDeviceHost host) => _hosts.Add(host);
public DeviceHostAdapter(IDeviceHost inner, IScheduler scheduler) { _inner = inner; Scheduler = scheduler; }
public Dev(IDeviceHost host, object id, IObservable <TState> source, IScheduler scheduler) : base(new DeviceHostAdapter(host, scheduler), id, source, s => s.IsPersistent, scheduler) { }
private static async Task RunVirtualDevice(CancellationTokenSource cts, ServiceProvider serviceProvider, string deviceName, string deviceConnectionString, IDeviceHost module) { // Keep on looking for the new streams on IoT Hub when the previous one closes or aborts. while (!cts.IsCancellationRequested) { try { // Run virtual device var device = serviceProvider.GetServices <IStreamingDevice>() .FirstOrDefault(sd => sd.StreamDeviceName.Equals(deviceName, StringComparison.InvariantCulture)); using (var deviceClient = new DeviceClientWrapper(deviceConnectionString)) { using (var clientWebSocket = new ClientWebSocketWrapper()) { using (var tcpClient = new TcpClientWrapper()) { Console.WriteLine($"{deviceName} awaiting connection..."); await module.OpenDeviceConnectionAsync(device, deviceClient, clientWebSocket, tcpClient, cts) .ConfigureAwait(false); } } } } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } }
public DeviceHostAdapter(IDeviceHost <TIdentifier, TState> inner) => _inner = inner;