hid_service_mac.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_DEVICE_HID_HID_SERVICE_MAC_H_
  5. #define SERVICES_DEVICE_HID_HID_SERVICE_MAC_H_
  6. #include <CoreFoundation/CoreFoundation.h>
  7. #include <IOKit/IOKitLib.h>
  8. #include <IOKit/hid/IOHIDDevice.h>
  9. #include <string>
  10. #include "base/mac/foundation_util.h"
  11. #include "base/mac/scoped_ionotificationportref.h"
  12. #include "base/mac/scoped_ioobject.h"
  13. #include "base/memory/ref_counted.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "services/device/hid/hid_service.h"
  16. namespace device {
  17. class HidServiceMac : public HidService {
  18. public:
  19. HidServiceMac();
  20. HidServiceMac(const HidServiceMac&) = delete;
  21. HidServiceMac& operator=(const HidServiceMac&) = delete;
  22. ~HidServiceMac() override;
  23. void Connect(const std::string& device_id,
  24. bool allow_protected_reports,
  25. bool allow_fido_reports,
  26. ConnectCallback connect) override;
  27. base::WeakPtr<HidService> GetWeakPtr() override;
  28. private:
  29. static base::ScopedCFTypeRef<IOHIDDeviceRef> OpenOnBlockingThread(
  30. scoped_refptr<HidDeviceInfo> device_info);
  31. void DeviceOpened(scoped_refptr<HidDeviceInfo> device_info,
  32. bool allow_protected_reports,
  33. bool allow_fido_reports,
  34. ConnectCallback callback,
  35. base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device);
  36. // IOService matching callbacks.
  37. static void FirstMatchCallback(void* context, io_iterator_t iterator);
  38. static void TerminatedCallback(void* context, io_iterator_t iterator);
  39. void AddDevices();
  40. void RemoveDevices();
  41. // Platform notification port.
  42. base::mac::ScopedIONotificationPortRef notify_port_;
  43. base::mac::ScopedIOObject<io_iterator_t> devices_added_iterator_;
  44. base::mac::ScopedIOObject<io_iterator_t> devices_removed_iterator_;
  45. base::WeakPtrFactory<HidServiceMac> weak_factory_;
  46. };
  47. } // namespace device
  48. #endif // SERVICES_DEVICE_HID_HID_SERVICE_MAC_H_