Ejemplo n.º 1
0
        private void OnDeviceImpDisconnected(object sender, DeviceImpDisconnectedArgs args)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }
            IInputDriverImp driver = sender as IInputDriverImp;

            if (driver == null)
            {
                throw new InvalidOperationException("Device disconnecting from unknown driver " + sender.ToString());
            }

            string      deviceKey = driver.DriverId + "_" + args.Id;
            InputDevice existingDevice;

            if (_inputDevices.TryGetValue(deviceKey, out existingDevice))
            {
                existingDevice.Disconnect();
            }
            else
            {
                throw new InvalidOperationException("Driver " + driver.DriverId + " trying to disconnect unknown device " + args.Id);
            }

            // Bubble up event to user code
            InputDeviceDisconnected?.Invoke(this, new DeviceConnectionArgs {
                InputDevice = existingDevice
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an input driver implementation to the internal list. The input driver is queried about connected
        /// devices. All new devices will then show up in the <see cref="Devices"/> (or <see cref="InputDevices"/>).
        /// list (in addition to the already listed devices.
        /// </summary>
        /// <param name="inputDriver">The new input driver to add.</param>
        /// <remarks>
        /// This is an instance method. Use <see cref="AddDriverImp"/> for a static-over-singleton access
        /// to the same functionality.
        /// </remarks>
        public void AddInputDriverImp(IInputDriverImp inputDriver)
        {
            if (inputDriver == null)
            {
                throw new ArgumentNullException(nameof(inputDriver));
            }

            foreach (var deviceImp in inputDriver.Devices)
            {
                _inputDevices[inputDriver.DriverId + "_" + deviceImp.Id] = CreateInputDevice(deviceImp);
            }

            inputDriver.DeviceDisconnected += OnDeviceImpDisconnected;
            inputDriver.NewDeviceConnected += OnNewDeviceImpConnected;

            _inputDrivers[inputDriver.DriverId] = inputDriver;
        }
Ejemplo n.º 3
0
        private void OnNewDeviceImpConnected(object sender, NewDeviceImpConnectedArgs args)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            IInputDriverImp driver = sender as IInputDriverImp;

            if (driver == null)
            {
                throw new InvalidOperationException("Device connecting from unknown driver " + sender.ToString());
            }

            if (args == null || args.InputDeviceImp == null)
            {
                throw new ArgumentNullException(nameof(args), "Device or InputDeviceImp must not be null");
            }

            string      deviceKey = driver.DriverId + "_" + args.InputDeviceImp.Id;
            InputDevice existingDevice;

            if (_inputDevices.TryGetValue(deviceKey, out existingDevice))
            {
                existingDevice.Reconnect(args.InputDeviceImp);
            }
            else
            {
                existingDevice           = CreateInputDevice(args.InputDeviceImp);
                _inputDevices[deviceKey] = existingDevice;
            }

            // Bubble up event to user code
            InputDeviceConnected?.Invoke(this, new DeviceConnectionArgs {
                InputDevice = existingDevice
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds an input driver implementation to the internal list. The input driver is queried about connected
 /// devices. All new devices will then show up in the <see cref="Devices"/> (or <see cref="InputDevices"/>).
 /// list (in addition to the already listed devices.
 /// </summary>
 /// <param name="inputDriver">The new input driver to add.</param>
 /// <remarks>
 /// This is a static method. Use <see cref="AddInputDriverImp"/> for an instance property
 /// to the same functionality.
 /// </remarks>
 public static void AddDriverImp(IInputDriverImp inputDriver) => Instance.AddInputDriverImp(inputDriver);
        /// <summary>
        /// The RenderCanvas constructor. Depending on the implementation this constructor instantiates a 3D viewing window or connects a 3D 
        /// render context to an existing part of the application window.
        /// </summary>
        public void InitImplementors()
        {
            if (_canvasImp == null)
                _canvasImp = ImpFactory.CreateIRenderCanvasImp();

            if (_renderContextImp == null)
                _renderContextImp = ImpFactory.CreateIRenderContextImp(_canvasImp);

            if (_inputImp == null)
                _inputImp = ImpFactory.CreateIInputImp(_canvasImp);

            if (_audioImp == null)
                _audioImp = ImpFactory.CreateIAudioImp();

            if (_inputDriverImp == null)
                _inputDriverImp = ImpFactory.CreateIInputDriverImp();

            if (_networkImp == null)
                _networkImp = ImpFactory.CreateINetworkImp();
        }