Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_HID_HID_SERVICE_MAC_H_ | 5 #ifndef DEVICE_HID_HID_SERVICE_MAC_H_ |
| 6 #define DEVICE_HID_HID_SERVICE_MAC_H_ | 6 #define DEVICE_HID_HID_SERVICE_MAC_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <CoreFoundation/CoreFoundation.h> |
| 9 #include <IOKit/hid/IOHIDManager.h> | |
| 10 | |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | |
| 11 | 12 |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "device/hid/hid_platform_resource_bidi_map.h" |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/strings/string16.h" | |
| 18 #include "base/synchronization/waitable_event.h" | |
| 19 #include "base/threading/thread.h" | |
| 20 #include "base/threading/thread_checker.h" | |
| 21 #include "build/build_config.h" | |
| 22 #include "device/hid/hid_device_info.h" | |
| 23 #include "device/hid/hid_service.h" | 16 #include "device/hid/hid_service.h" |
| 24 | 17 |
| 25 #include <CoreFoundation/CoreFoundation.h> | 18 namespace base { |
| 26 #include <IOKit/hid/IOHIDManager.h> | 19 class MessageLoopProxy; |
| 20 } | |
| 27 | 21 |
| 28 namespace device { | 22 namespace device { |
| 29 | 23 |
| 30 class HidConnection; | 24 class HidConnection; |
| 31 class HidService; | |
| 32 | 25 |
| 33 class HidServiceMac : public HidService { | 26 class HidServiceMac : public HidService { |
| 34 public: | 27 public: |
| 35 HidServiceMac(); | 28 HidServiceMac(); |
| 36 | 29 |
| 37 virtual scoped_refptr<HidConnection> Connect(std::string device_id) OVERRIDE; | 30 virtual scoped_refptr<HidConnection> Connect(HidDeviceId device_id) OVERRIDE; |
| 38 | 31 |
| 39 private: | 32 private: |
| 40 virtual ~HidServiceMac(); | 33 virtual ~HidServiceMac(); |
| 41 | 34 |
| 42 void ScheduleRunLoop(); | 35 void StartWatchingDevices(); |
| 43 void UnscheduleRunLoop(); | 36 void StopWatchingDevices(); |
| 44 | 37 |
| 45 // Device changing callbacks. | 38 // Device changing callbacks. |
| 46 static void AddDeviceCallback(void* context, | 39 static void AddDeviceCallback(void* context, |
| 47 IOReturn result, | 40 IOReturn result, |
| 48 void* sender, | 41 void* sender, |
| 49 IOHIDDeviceRef ref); | 42 IOHIDDeviceRef hid_device); |
| 50 static void RemoveDeviceCallback(void* context, | 43 static void RemoveDeviceCallback(void* context, |
| 51 IOReturn result, | 44 IOReturn result, |
| 52 void* sender, | 45 void* sender, |
| 53 IOHIDDeviceRef ref); | 46 IOHIDDeviceRef hid_device); |
| 54 static HidServiceMac* InstanceFromContext(void* context); | |
| 55 | |
| 56 IOHIDDeviceRef FindDevice(std::string id); | |
| 57 | 47 |
| 58 void Enumerate(); | 48 void Enumerate(); |
| 59 | 49 |
| 60 void PlatformAddDevice(IOHIDDeviceRef ref); | 50 void PlatformAddDevice(IOHIDDeviceRef hid_device); |
| 61 void PlatformRemoveDevice(IOHIDDeviceRef ref); | 51 void PlatformRemoveDevice(IOHIDDeviceRef hid_device); |
| 62 | 52 |
| 63 // The message loop this object belongs to. | 53 // Platform HID Manager |
| 54 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_; | |
| 55 | |
| 56 // The message loop for the thread on which this service was created. | |
| 64 scoped_refptr<base::MessageLoopProxy> message_loop_; | 57 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 65 | 58 |
| 66 // Platform HID Manager | 59 // A 1:1 mapping between device IDs and IOHIDDeviceRefs. |
|
Mark Mentovai
2014/02/21 17:48:18
Why? Why go to the trouble of inventing our own ha
Ken Rockot(use gerrit already)
2014/02/22 01:17:04
Much simpler. I think the attachment to a consiste
| |
| 67 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; | 60 HidPlatformResourceBidiMap<IOHIDDeviceRef> platform_resource_map_; |
| 68 | |
| 69 // Enumeration thread. | |
| 70 scoped_ptr<base::Thread> enumeration_runloop_thread_; | |
| 71 CFRunLoopRef enumeration_runloop_; | |
| 72 base::WaitableEvent enumeration_runloop_init_; | |
| 73 | |
| 74 bool available_; | |
| 75 | 61 |
| 76 DISALLOW_COPY_AND_ASSIGN(HidServiceMac); | 62 DISALLOW_COPY_AND_ASSIGN(HidServiceMac); |
| 77 }; | 63 }; |
| 78 | 64 |
| 79 } // namespace device | 65 } // namespace device |
| 80 | 66 |
| 81 #endif // DEVICE_HID_HID_SERVICE_MAC_H_ | 67 #endif // DEVICE_HID_HID_SERVICE_MAC_H_ |
| OLD | NEW |