示例#1
0
            public static TDevice Generic <TDevice>(DeviceState state, IDeviceHost host)
                where TDevice : IDeviceAdapter, new()
            {
                var device = new TDevice();

                device.Init(state, host);
                return(device);
            }
示例#2
0
        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);
        }
示例#3
0
            public Holder(object id, IDeviceHost host)
            {
                Id   = id;
                Host = host;

                _scheduler = host.Scheduler;
                _source    = host
                             .GetAndObserveState(this)
                             .Retry(Constants.DefaultRetryDelay, _scheduler)
                             .Publish()
                             .RefCount();
            }
示例#4
0
        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);
        }
示例#5
0
        /// <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.");
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
 public override HEADSET_LIMITATIONS Initalize(IDeviceHost host)
 {
     this.host           = host;
     host.StatusChanged += HostStatusChanged;
     return(HEADSET_LIMITATIONS.ONLY_ACTIVE_DURING_CALLS);
 }
示例#9
0
 public static ExpandoObject Dynamic(DeviceState state, IDeviceHost host)
 => state.ToDynamic();
示例#10
0
 public HomeDevicesManager(IDeviceHost host)
 {
     _host = host;
 }
示例#11
0
 public void RegisterHost(IDeviceHost host)
 => _hosts.Add(host);
示例#12
0
 public DeviceHostAdapter(IDeviceHost inner, IScheduler scheduler)
 {
     _inner    = inner;
     Scheduler = scheduler;
 }
示例#13
0
 public Dev(IDeviceHost host, object id, IObservable <TState> source, IScheduler scheduler)
     : base(new DeviceHostAdapter(host, scheduler), id, source, s => s.IsPersistent, scheduler)
 {
 }
示例#14
0
        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}");
                }
            }
        }
示例#15
0
 public DeviceHostAdapter(IDeviceHost <TIdentifier, TState> inner)
 => _inner = inner;