HidSelector.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #region License
  2. /* Copyright 2012-2013 James F. Bellinger <http://www.zer7.com/software/hidsharp>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  13. #endregion
  14. namespace HidSharp.Platform
  15. {
  16. internal sealed class HidSelector
  17. {
  18. public static readonly HidManager Instance;
  19. private static readonly Thread ManagerThread;
  20. static HidSelector()
  21. {
  22. foreach (var hidManager in new HidManager[]
  23. {
  24. new Windows.WinHidManager(),
  25. new Unsupported.UnsupportedHidManager()
  26. })
  27. {
  28. if (hidManager.IsSupported)
  29. {
  30. var readyEvent = new ManualResetEvent(false);
  31. Instance = hidManager;
  32. ManagerThread = new Thread(Instance.RunImpl);
  33. ManagerThread.IsBackground = true;
  34. ManagerThread.Start(readyEvent);
  35. readyEvent.WaitOne();
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. }