Esempio n. 1
0
        public void Create()
        {
            ThreadContext context = ThreadCreator.Create("test", ThreadAction, true);
            ThreadResult  result  = context.Start().Cancel().Wait();

            Assert.IsNull(result.Error);
        }
Esempio n. 2
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     if (!HasXOutputInstalled)
     {
         return(0);
     }
     if (controller != null)
     {
         controller.FeedbackReceived -= ControllerFeedbackReceived;
     }
     if (xOutputManager.Stop(controllerCount))
     {
         // Wait for unplugging
         Thread.Sleep(10);
     }
     controllerCount = xOutputManager.Start();
     if (controllerCount != 0)
     {
         threadContext = ThreadCreator.Create($"Emulated controller {controllerCount} output refresher", token => ReadAndReportValues(token, onStop)).Start();
         running       = true;
         logger.Info($"Emulation started on {ToString()}.");
         if (ForceFeedbackSupported)
         {
             logger.Info($"Force feedback mapping is connected on {ToString()}.");
             controller = ((VigemDevice)xOutputManager.XOutputDevice).GetController(controllerCount);
             controller.FeedbackReceived += ControllerFeedbackReceived;
         }
     }
     return(controllerCount);
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a new XDevice.
 /// </summary>
 /// <param name="source">Direct input device</param>
 /// <param name="mapper">DirectInput to XInput mapper</param>
 public WebXOutputDevice(XOutputManager xOutputManager)
 {
     this.xOutputManager = xOutputManager;
     sources             = XInputHelper.Instance.GenerateSources((name, type) => new WebXOutputSource(name, type));
     state = new DeviceState(sources, DPadCount);
     deviceInputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     inputRefresher = ThreadCreator.Create("Keyboard input notification", InputRefresher).Start();
 }
Esempio n. 4
0
 private void DispatchRefreshGameControllers(object sender, DeviceDisconnectedEventArgs e)
 {
     ThreadCreator.Create("Device list refresh delay", (token) =>
     {
         Thread.Sleep(1000);
         dispatcher.Invoke(RefreshGameControllers);
     }).Start();
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a new keyboard device instance.
 /// </summary>
 public Keyboard()
 {
     sources = Enum.GetValues(typeof(Key)).OfType <Key>().Where(x => x != Key.None).OrderBy(x => x.ToString()).Select(x => new KeyboardSource(this, x.ToString(), x)).ToArray();
     state   = new DeviceState(sources, 0);
     deviceInputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     inputConfig    = new InputConfig();
     inputRefresher = ThreadCreator.Create("Keyboard input notification", InputRefresher).SetApartmentState(ApartmentState.STA).Start();
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new keyboard device instance.
 /// </summary>
 public Mouse()
 {
     sources = Enum.GetValues(typeof(MouseButton)).OfType <MouseButton>().Select(x => new MouseSource(this, x.ToString(), x)).ToArray();
     state   = new DeviceState(sources, 0);
     deviceInputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     inputConfig    = new InputConfig();
     inputRefresher = ThreadCreator.Create("Mouse input notification", InputRefresher).Start();
 }
Esempio n. 7
0
 public bool Handle(HttpListenerContext httpContext, CancellationToken cancellationToken)
 {
     if (!httpContext.Request.IsWebSocketRequest)
     {
         return(false);
     }
     ThreadCreator.Create("Websocket listener", (token) => HandleWebSocketAsync(httpContext, cancellationToken)).Start();
     return(true);
 }
Esempio n. 8
0
        public async Task Start(string url, DeviceTypes deviceType, string emulator)
        {
            websocket = new ClientWebSocket();
            cancellationTokenSource = new CancellationTokenSource();
            string fullUrl = $"{url}{deviceType.ToString()}/{emulator}";
            await websocket.ConnectAsync(new Uri(fullUrl), cancellationTokenSource.Token);

            ThreadCreator.Create("Device emulator", HandleWebsocket).Start();
        }
Esempio n. 9
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     Stop();
     client        = xOutputManager.Start();
     threadContext = ThreadCreator.Create($"Emulated controller output refresher", token => ReadAndReportValues(onStop, token)).Start();
     running       = true;
     logger.Info($"Emulation started on {ToString()}.");
     logger.Info($"Force feedback mapping is connected on {ToString()}.");
     client.Feedback += FeedbackReceived;
     // TODO
     return(1);
 }
Esempio n. 10
0
 public void StartNamedPipe()
 {
     notifyThreadContext = ThreadCreator.Create("XOutputRunningAlreadyNamedPipe reader", ReadPipe).Start();
 }