Esempio n. 1
0
 DebugProgram(
     JoinableTaskContext taskContext,
     ThreadCreator threadCreator,
     DebugDisassemblyStream.Factory debugDisassemblyStreamFactory,
     DebugDocumentContext.Factory documentContextFactory,
     DebugCodeContext.Factory codeContextFactory,
     ThreadEnumFactory threadEnumFactory,
     ModuleEnumFactory moduleEnumFactory,
     CodeContextEnumFactory codeContextEnumFactory,
     IDebugEngineHandler debugEngineHandler,
     IDebugProcess2 process,
     Guid programId,
     SbProcess lldbProcess,
     RemoteTarget lldbTarget,
     IDebugModuleCache debugModuleCache,
     bool isCoreAttach)
 {
     _id                            = programId;
     _process                       = process;
     _lldbProcess                   = lldbProcess;
     _lldbTarget                    = lldbTarget;
     _threadCache                   = new Dictionary <uint, IDebugThread>();
     _isCoreAttach                  = isCoreAttach;
     _debugEngineHandler            = debugEngineHandler;
     _taskContext                   = taskContext;
     _threadCreator                 = threadCreator;
     _debugDisassemblyStreamFactory = debugDisassemblyStreamFactory;
     _documentContextFactory        = documentContextFactory;
     _codeContextFactory            = codeContextFactory;
     _threadEnumFactory             = threadEnumFactory;
     _moduleEnumFactory             = moduleEnumFactory;
     _codeContextEnumFactory        = codeContextEnumFactory;
     _debugModuleCache              = debugModuleCache;
 }
 public InputValuesMessageHandler(IInputDevice device, SenderFunction <InputValuesMessage> senderFunction)
 {
     this.device          = device;
     this.senderFunction  = senderFunction;
     device.InputChanged += InputChanged;
     threadContext        = ThreadCreator.CreateLoop($"Websocket input value writer {device.DisplayName}", ResponseLoop, 33).Start();
 }
Esempio n. 3
0
        public void Create()
        {
            ThreadContext context = ThreadCreator.Create("test", ThreadAction, true);
            ThreadResult  result  = context.Start().Cancel().Wait();

            Assert.IsNull(result.Error);
        }
Esempio n. 4
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. 5
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. 6
0
 private void DispatchRefreshGameControllers(object sender, DeviceDisconnectedEventArgs e)
 {
     ThreadCreator.Create("Device list refresh delay", (token) =>
     {
         Thread.Sleep(1000);
         dispatcher.Invoke(RefreshGameControllers);
     }).Start();
 }
Esempio n. 7
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. 8
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. 9
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. 10
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. 11
0
 public KeyboardDevice(KeyboardHook hook)
 {
     this.hook             = hook;
     UniqueId              = KeyboardDeviceProvider.DeviceId;
     DisplayName           = KeyboardDeviceProvider.DeviceId;
     sources               = Enum.GetValues(typeof(KeyboardButton)).OfType <KeyboardButton>().Select((b) => new KeyboardSource(this, b.ToString(), (int)b)).ToArray();
     targets               = new ForceFeedbackTarget[0];
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     readThreadContext     = ThreadCreator.CreateLoop($"{DisplayName} input reader", ReadLoop, 1).Start();
 }
Esempio n. 12
0
        public DirectInputDevice(Joystick joystick, string guid, string productName, bool hasForceFeedbackDevice, string uniqueId, string hardwareId, string interfacePath)
        {
            this.joystick = joystick;
            UniqueId      = uniqueId;
            InterfacePath = interfacePath;
            HardwareID    = hardwareId;
            DisplayName   = productName;
            var buttonObjectInstances = joystick.GetObjects(DeviceObjectTypeFlags.Button).Where(b => b.Usage > 0).OrderBy(b => b.ObjectId.InstanceNumber).Take(128).ToArray();
            var buttons = buttonObjectInstances.Select((b, i) => DirectInputSource.FromButton(this, b, i)).ToArray();
            var axes    = GetAxes().OrderBy(a => a.Usage).Take(24).Select(a => DirectInputSource.FromAxis(this, a));
            var sliders = joystick.GetObjects().Where(o => o.ObjectType == ObjectGuid.Slider).OrderBy(a => a.Usage).Select((s, i) => DirectInputSource.FromSlider(this, s, i));
            IEnumerable <DirectInputSource> dpads = new DirectInputSource[0];

            if (joystick.Capabilities.PovCount > 0)
            {
                dpads = Enumerable.Range(0, joystick.Capabilities.PovCount)
                        .SelectMany(i => DirectInputSource.FromDPad(this, i));
            }
            sources = buttons.Concat(axes).Concat(sliders).Concat(dpads).ToArray();

            EffectInfo force = null;

            if (hasForceFeedbackDevice)
            {
                try
                {
                    joystick.SetCooperativeLevel(WindowHandleStore.Handle, CooperativeLevel.Background | CooperativeLevel.Exclusive);
                }
                catch (Exception)
                {
                    logger.Warn($"Failed to set cooperative level to exclusive for {ToString()}");
                }
                var constantForce = joystick.GetEffects().FirstOrDefault(x => x.Guid == EffectGuid.ConstantForce);
                if (constantForce == null)
                {
                    force = joystick.GetEffects().FirstOrDefault();
                }
                else
                {
                    force = constantForce;
                }
                var actuatorAxes = joystick.GetObjects().Where(doi => doi.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator)).ToArray();
                targets        = actuatorAxes.Select(i => new ForceFeedbackTarget(this, i.Name, i.Offset)).ToArray();
                forceFeedbacks = targets.ToDictionary(t => t, t => new DirectDeviceForceFeedback(joystick, UniqueId, force, actuatorAxes.First(a => a.Offset == t.Offset)));
            }
            else
            {
                targets        = new ForceFeedbackTarget[0];
                forceFeedbacks = new Dictionary <ForceFeedbackTarget, DirectDeviceForceFeedback>();
            }
            joystick.Acquire();
            inputChangedEventArgs      = new DeviceInputChangedEventArgs(this);
            readThreadContext          = ThreadCreator.CreateLoop($"{DisplayName} DirectInput reader", ReadLoop, 1).Start();
            forceFeedbackThreadContext = ThreadCreator.CreateLoop($"{DisplayName} DirectInput force feedback", ForceFeedbackLoop, 10).Start();
        }
Esempio n. 13
0
        protected async Task ConnectAsync(string path, CancellationToken token = default)
        {
            if (started)
            {
                return;
            }
            await client.ConnectAsync(new Uri(baseUri.ToString() + path), token);

            threadContext = ThreadCreator.CreateLoop("Websocket client", async(token) => await ReadIncomingMessagesAsync(token), 0);
            started       = true;
        }
Esempio n. 14
0
        public void Start()
        {
            if (Status != WorkerStatus.Stopped)
            {
                return;
            }

            SetStatus(WorkerStatus.WaitingForJob);

            ThreadCreator.CreateNewThread(ct => WorkLoop(WorkQueue, ct));
        }
Esempio n. 15
0
        protected async Task ConnectAsync(Uri uri, CancellationToken token = default)
        {
            if (started)
            {
                return;
            }
            await client.ConnectAsync(uri, token);

            threadContext = ThreadCreator.CreateLoop("Websocket client", async(token) => await ReadIncomingMessagesAsync(token), 0);
            started       = true;
        }
Esempio n. 16
0
 public InputDeviceManager(InputConfigManager inputConfigManager, List <IInputDeviceProvider> inputDeviceProviders)
 {
     this.inputConfigManager   = inputConfigManager;
     this.inputDeviceProviders = inputDeviceProviders;
     foreach (var inputDeviceProvider in inputDeviceProviders)
     {
         inputDeviceProvider.Connected    += Connected;
         inputDeviceProvider.Disconnected += Disconnected;
     }
     readThreadContext = ThreadCreator.CreateLoop($"Input device manager refresh", RefreshLoop, 5000).Start();
 }
Esempio n. 17
0
 public void Start()
 {
     if (!Running)
     {
         readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start();
         if (!InputConfiguration.Autostart)
         {
             InputConfiguration.Autostart = true;
             inputConfigManager.SaveConfig(this);
         }
     }
 }
Esempio n. 18
0
 public IGgpDebugProgram Create(IDebugEngineHandler debugEngineHandler,
                                ThreadCreator threadCreator,
                                IDebugProcess2 process, Guid programId, SbProcess lldbProcess,
                                RemoteTarget lldbTarget,
                                IDebugModuleCache debugModuleCache, bool isCoreAttach)
 {
     return(new DebugProgram(_taskContext, threadCreator,
                             _debugDisassemblyStreamFactory,
                             _documentContextFactory, _codeContextFactory, _threadsEnumFactory,
                             _moduleEnumFactory, _codeContextEnumFactory, debugEngineHandler, process,
                             programId, lldbProcess, lldbTarget, debugModuleCache, isCoreAttach));
 }
Esempio n. 19
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. 20
0
 public void Start()
 {
     if (!Running)
     {
         readThreadContext          = ThreadCreator.CreateLoop($"{DisplayName} DirectInput reader", ReadLoop, 1).Start();
         forceFeedbackThreadContext = ThreadCreator.CreateLoop($"{DisplayName} DirectInput force feedback", ForceFeedbackLoop, 10).Start();
         if (!InputConfiguration.Autostart)
         {
             InputConfiguration.Autostart = true;
             inputConfigManager.SaveConfig(this);
         }
     }
 }
Esempio n. 21
0
        public SourceValuesMessageHandler(InputDeviceHolder device, SenderFunction <InputValuesMessage> senderFunction)
        {
            this.device         = device;
            this.senderFunction = senderFunction;

            var devices = device.GetInputDevices();

            device.Connected    += InputConnected;
            device.Disconnected += InputDisconnected;
            foreach (var inputDevice in devices)
            {
                inputDevice.InputChanged += InputChanged;
            }
            threadContext = ThreadCreator.CreateLoop($"Websocket input value writer {device.DisplayName}", ResponseLoop, 33).Start();
        }
Esempio n. 22
0
        public void Start()
        {
            for (int i = 0; i < numberOfPlayers; i++)
            {
                PlayerCreator.CreatePlayer();
            }

            var newGame = new StartGame();

            newGame.RegisterHandler(Display.ShowPlayerMoves);

            for (int i = 0; i < numberOfPlayers; i++)
            {
                ThreadCreator.CreateThread(newGame).Start(PlayerCreator.Players[i]);
            }
        }
Esempio n. 23
0
 public RawInputDevice(HidDevice device, ReportDescriptor reportDescriptor, DeviceItem deviceItem, HidStream hidStream, string uniqueId)
 {
     this.device       = device;
     inputReportBuffer = new byte[device.GetMaxInputReportLength()];
     inputReceiver     = reportDescriptor.CreateHidDeviceInputReceiver();
     inputParser       = deviceItem.CreateDeviceItemInputParser();
     inputReceiver.Start(hidStream);
     DisplayName           = device.GetProductName();
     UniqueId              = uniqueId;
     InterfacePath         = device.DevicePath;
     HardwareID            = IdHelper.GetHardwareId(InterfacePath);
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     sources = reportDescriptor.InputReports.SelectMany(ir => ir.DataItems)
               .SelectMany(di => di.Usages.GetAllValues())
               .Select(u => (Usage)u)
               .SelectMany(u => RawInputSource.FromUsage(this, u))
               .ToArray();
     readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start();
 }
Esempio n. 24
0
 public void Start()
 {
     if (!Running)
     {
         InputConfiguration.Sources.ForEach(s => {
             var source = FindSource(s.Offset);
             if (source != null)
             {
                 source.Update(s);
             }
         });
         readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start();
         if (!InputConfiguration.Autostart)
         {
             InputConfiguration.Autostart = true;
             inputConfigManager.SaveConfig(this);
         }
     }
 }
Esempio n. 25
0
 public int SendEmail(MailMsg mailMsg)
 {
     this.debugcount    = 0;
     this.lastErrorCode = ErrorCode.ONGOING;
     ThreadCreator.StartThread(new ParameterizedThreadStart(this.sendMail), mailMsg, true);
     while (this.lastErrorCode == ErrorCode.ONGOING)
     {
         try
         {
             Thread.Sleep(300);
         }
         catch (Exception)
         {
             break;
         }
         this.debugcount++;
     }
     return(this.lastErrorCode);
 }
Esempio n. 26
0
 protected MessageHandler(CloseFunction closeFunction, SenderFunction senderFunction)
 {
     this.closeFunction  = closeFunction;
     this.senderFunction = senderFunction;
     pingThreadContext   = ThreadCreator.CreateLoop("Ping loop", () => {
         try
         {
             var r = new PingRequest {
                 Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
             };
             senderFunction(new PingRequest {
                 Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
             });
         }
         catch (Exception ex)
         {
             logger.Warn(ex, "Ping failed, closing connection");
             closeFunction();
         }
     }, 5000).Start();
 }
 public EmulatedControllerFeedbackHandler(CloseFunction closeFunction, SenderFunction senderFunction, IMappedController emulatedController) : base(closeFunction, senderFunction)
 {
     this.emulatedController = emulatedController;
     threadContext           = ThreadCreator.CreateLoop($"{emulatedController.Id} input device report thread", SendFeedback, 20);
 }
Esempio n. 28
0
 public void StartNamedPipe()
 {
     notifyThreadContext = ThreadCreator.Create("XOutputRunningAlreadyNamedPipe reader", ReadPipe).Start();
 }
Esempio n. 29
0
 public InputDeviceManager(InputConfigManager inputConfigManager, List <IInputDeviceProvider> inputDeviceProviders)
 {
     this.inputConfigManager   = inputConfigManager;
     this.inputDeviceProviders = inputDeviceProviders;
     readThreadContext         = ThreadCreator.CreateLoop($"Input device manager refresh", RefreshLoop, 5000).Start();
 }
Esempio n. 30
0
        private static void MailThreadScheduler(object obj)
        {
            MailMsg mailMsg = null;

            while (true)
            {
                int num = WaitHandle.WaitAny(LogAPI._waitEmailHandles, 100);
                if (num == 258)
                {
                    lock (LogAPI._lockEmail)
                    {
                        TimeSpan timeSpan = DateTime.Now - LogAPI._lastEmailMerge;
                        if (timeSpan.TotalSeconds < 0.0)
                        {
                            LogAPI._lastEmailMerge = DateTime.Now;
                            timeSpan = DateTime.Now - LogAPI._lastEmailMerge;
                        }
                        if (timeSpan.TotalSeconds <= 5.0)
                        {
                            continue;
                        }
                        if (LogAPI._mergedMail == null)
                        {
                            continue;
                        }
                        mailMsg            = LogAPI._mergedMail;
                        LogAPI._mergedMail = null;
                    }
                }
                if (num == 0)
                {
                    break;
                }
                try
                {
                    if (LogAPI._mailerCounter < 10)
                    {
                        lock (LogAPI._lockEmail)
                        {
                            if (mailMsg == null)
                            {
                                if (LogAPI._emailQueue.Count > 0)
                                {
                                    if (LogAPI._emailQueue.TryDequeue(out mailMsg))
                                    {
                                    }
                                }
                                else
                                {
                                    LogAPI._emailEvent.Reset();
                                }
                            }
                        }
                        if (mailMsg != null)
                        {
                            Interlocked.Increment(ref LogAPI._mailerCounter);
                            mailMsg.Body = new StringBuilder("Dear User, ").AppendLine("<br /><br />").Append(mailMsg._mergedBody).ToString();
                            ThreadCreator.StartThread(new ParameterizedThreadStart(LogAPI.sendMailThread), mailMsg, true);
                            mailMsg = null;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }