Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: device/hid/hid_utils_mac.cc

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for reals Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« device/hid/hid_utils_mac.h ('K') | « device/hid/hid_utils_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
Mark Mentovai 2014/02/13 22:37:51 Unused, remove.
Ken Rockot(use gerrit already) 2014/02/18 19:43:09 Done.
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 11
12 #if defined(OS_MACOSX) 12 #if defined(OS_MACOSX)
Mark Mentovai 2014/02/13 22:37:51 This is kinda silly, this file is only compiled on
13 #include <CoreFoundation/CoreFoundation.h> 13 #include <CoreFoundation/CoreFoundation.h>
Mark Mentovai 2014/02/13 22:37:51 Without the #ifdef, you can move these up after hi
Ken Rockot(use gerrit already) 2014/02/18 19:43:09 Done.
14 #include <IOKit/hid/IOHIDManager.h> 14 #include <IOKit/hid/IOHIDManager.h>
15 #endif 15 #endif
16 16
17 namespace device { 17 namespace device {
18 18
19 bool GetHidIntProperty(IOHIDDeviceRef device, 19 int32_t GetHidIntProperty(IOHIDDeviceRef device, CFStringRef key) {
20 CFStringRef key, 20 int32_t value;
21 int32_t* result) { 21 if (TryGetHidIntProperty(device, key, &value))
22 return value;
23 return 0;
24 }
25
26 std::string GetHidStringProperty(IOHIDDeviceRef device, CFStringRef key) {
27 std::string value;
28 TryGetHidStringProperty(device, key, &value);
29 return value;
30 }
31
32 bool TryGetHidIntProperty(IOHIDDeviceRef device,
33 CFStringRef key,
34 int32_t* result) {
22 CFNumberRef ref = base::mac::CFCast<CFNumberRef>( 35 CFNumberRef ref = base::mac::CFCast<CFNumberRef>(
Mark Mentovai 2014/02/13 22:37:51 You might think this is crazy-paranoid (and we can
Ken Rockot(use gerrit already) 2014/02/18 19:43:09 I would be happy to add this, but it does look lik
23 IOHIDDeviceGetProperty(device, key)); 36 IOHIDDeviceGetProperty(device, key));
24 return ref && CFNumberGetValue(ref, kCFNumberSInt32Type, result); 37 return ref && CFNumberGetValue(ref, kCFNumberSInt32Type, result);
25 } 38 }
26 39
27 bool GetHidStringProperty(IOHIDDeviceRef device, 40 bool TryGetHidStringProperty(IOHIDDeviceRef device,
28 CFStringRef key, 41 CFStringRef key,
29 std::string* result) { 42 std::string* result) {
30 CFStringRef ref = base::mac::CFCast<CFStringRef>( 43 CFStringRef ref = base::mac::CFCast<CFStringRef>(
31 IOHIDDeviceGetProperty(device, key)); 44 IOHIDDeviceGetProperty(device, key));
32 if (!ref) { 45 if (!ref) {
33 return false; 46 return false;
34 } 47 }
35 *result = base::SysCFStringRefToUTF8(ref); 48 *result = base::SysCFStringRefToUTF8(ref);
36 return true; 49 return true;
37 } 50 }
38 51
39 } // namespace device 52 } // namespace device
OLDNEW
« device/hid/hid_utils_mac.h ('K') | « device/hid/hid_utils_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698