| 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 #include "device/hid/hid_utils_mac.h" | 5 #include "device/hid/hid_utils_mac.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 11 | 9 |
| 12 #if defined(OS_MACOSX) | |
| 13 #include <CoreFoundation/CoreFoundation.h> | |
| 14 #include <IOKit/hid/IOHIDManager.h> | |
| 15 #endif | |
| 16 | |
| 17 namespace device { | 10 namespace device { |
| 18 | 11 |
| 19 bool GetHidIntProperty(IOHIDDeviceRef device, | 12 int32_t GetHidIntProperty(IOHIDDeviceRef device, CFStringRef key) { |
| 20 CFStringRef key, | 13 int32_t value; |
| 21 int32_t* result) { | 14 if (TryGetHidIntProperty(device, key, &value)) |
| 15 return value; |
| 16 return 0; |
| 17 } |
| 18 |
| 19 std::string GetHidStringProperty(IOHIDDeviceRef device, CFStringRef key) { |
| 20 std::string value; |
| 21 TryGetHidStringProperty(device, key, &value); |
| 22 return value; |
| 23 } |
| 24 |
| 25 bool TryGetHidIntProperty(IOHIDDeviceRef device, |
| 26 CFStringRef key, |
| 27 int32_t* result) { |
| 22 CFNumberRef ref = base::mac::CFCast<CFNumberRef>( | 28 CFNumberRef ref = base::mac::CFCast<CFNumberRef>( |
| 23 IOHIDDeviceGetProperty(device, key)); | 29 IOHIDDeviceGetProperty(device, key)); |
| 24 return ref && CFNumberGetValue(ref, kCFNumberSInt32Type, result); | 30 return ref && CFNumberGetValue(ref, kCFNumberSInt32Type, result); |
| 25 } | 31 } |
| 26 | 32 |
| 27 bool GetHidStringProperty(IOHIDDeviceRef device, | 33 bool TryGetHidStringProperty(IOHIDDeviceRef device, |
| 28 CFStringRef key, | 34 CFStringRef key, |
| 29 std::string* result) { | 35 std::string* result) { |
| 30 CFStringRef ref = base::mac::CFCast<CFStringRef>( | 36 CFStringRef ref = base::mac::CFCast<CFStringRef>( |
| 31 IOHIDDeviceGetProperty(device, key)); | 37 IOHIDDeviceGetProperty(device, key)); |
| 32 if (!ref) { | 38 if (!ref) { |
| 33 return false; | 39 return false; |
| 34 } | 40 } |
| 35 *result = base::SysCFStringRefToUTF8(ref); | 41 *result = base::SysCFStringRefToUTF8(ref); |
| 36 return true; | 42 return true; |
| 37 } | 43 } |
| 38 | 44 |
| 39 } // namespace device | 45 } // namespace device |
| OLD | NEW |