OLD | NEW |
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_connection_linux.h" | 5 #include "device/hid/hid_connection_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <libudev.h> | 9 #include <libudev.h> |
10 #include <linux/hidraw.h> | 10 #include <linux/hidraw.h> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 int flags = base::File::FLAG_OPEN | | 51 int flags = base::File::FLAG_OPEN | |
52 base::File::FLAG_READ | | 52 base::File::FLAG_READ | |
53 base::File::FLAG_WRITE; | 53 base::File::FLAG_WRITE; |
54 | 54 |
55 base::File device_file(base::FilePath(dev_node), flags); | 55 base::File device_file(base::FilePath(dev_node), flags); |
56 if (!device_file.IsValid()) { | 56 if (!device_file.IsValid()) { |
57 base::File::Error file_error = device_file.error_details(); | 57 base::File::Error file_error = device_file.error_details(); |
58 | 58 |
59 if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) { | 59 if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) { |
| 60 VLOG(1) << "Access denied opening device read-write, trying read-only."; |
| 61 |
60 flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 62 flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
61 | 63 |
62 base::File device_file(base::FilePath(dev_node), flags); | 64 device_file = base::File(base::FilePath(dev_node), flags); |
63 if (!device_file.IsValid()) { | |
64 LOG(ERROR) << device_file.error_details(); | |
65 return; | |
66 } | |
67 } else { | |
68 LOG(ERROR) << file_error; | |
69 return; | |
70 } | 65 } |
71 } | 66 } |
| 67 if (!device_file.IsValid()) { |
| 68 LOG(ERROR) << "Failed to open '" << dev_node << "': " |
| 69 << base::File::ErrorToString(device_file.error_details()); |
| 70 return; |
| 71 } |
| 72 |
72 if (fcntl(device_file.GetPlatformFile(), F_SETFL, | 73 if (fcntl(device_file.GetPlatformFile(), F_SETFL, |
73 fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) { | 74 fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) { |
74 PLOG(ERROR) << "Failed to set non-blocking flag to device file."; | 75 PLOG(ERROR) << "Failed to set non-blocking flag to device file."; |
75 return; | 76 return; |
76 } | 77 } |
77 device_file_ = device_file.Pass(); | 78 device_file_ = device_file.Pass(); |
78 | 79 |
79 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 80 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
80 device_file_.GetPlatformFile(), | 81 device_file_.GetPlatformFile(), |
81 true, | 82 true, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 read.callback.Run(false, report.buffer->size()); | 201 read.callback.Run(false, report.buffer->size()); |
201 } else { | 202 } else { |
202 memcpy(read.buffer->data(), report.buffer->data(), report.buffer->size()); | 203 memcpy(read.buffer->data(), report.buffer->data(), report.buffer->size()); |
203 pending_reports_.pop(); | 204 pending_reports_.pop(); |
204 read.callback.Run(true, report.buffer->size()); | 205 read.callback.Run(true, report.buffer->size()); |
205 } | 206 } |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 } // namespace device | 210 } // namespace device |
OLD | NEW |