| OLD | NEW |
| 1 // Copyright 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 "ui/events/ozone/evdev/event_converter.h" | 5 #include "ui/events/ozone/evdev/event_converter.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 | 9 |
| 10 #include "ui/events/ozone/evdev/event_modifiers.h" | 10 #include "ui/events/ozone/evdev/event_modifiers.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 | 13 |
| 14 // Number of events to read at a time. | 14 // Number of events to read at a time. |
| 15 const int kEvdevBufferSize = 64; | 15 const int kEvdevBufferSize = 64; |
| 16 | 16 |
| 17 EventConverterEvdev::EventConverterEvdev(int fd, | 17 EventConverterEvdev::EventConverterEvdev(int fd, |
| 18 base::FilePath path, | 18 base::FilePath path, |
| 19 EventModifiersEvdev* modifiers) | 19 EventModifiersEvdev* modifiers) |
| 20 : fd_(fd), path_(path), modifiers_(modifiers) {} | 20 : fd_(fd), path_(path), modifiers_(modifiers) {} |
| 21 | 21 |
| 22 EventConverterEvdev::~EventConverterEvdev() { close(fd_); } | 22 EventConverterEvdev::~EventConverterEvdev() { |
| 23 Stop(); |
| 24 close(fd_); |
| 25 } |
| 26 |
| 27 void EventConverterEvdev::Start() { |
| 28 base::MessagePumpOzone::Current()->WatchFileDescriptor( |
| 29 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); |
| 30 } |
| 31 |
| 32 void EventConverterEvdev::Stop() { controller_.StopWatchingFileDescriptor(); } |
| 23 | 33 |
| 24 void EventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 34 void EventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |
| 25 input_event inputs[kEvdevBufferSize]; | 35 input_event inputs[kEvdevBufferSize]; |
| 26 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 36 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| 27 if (read_size <= 0) { | 37 if (read_size <= 0) { |
| 28 if (errno == EINTR || errno == EAGAIN) | 38 if (errno == EINTR || errno == EAGAIN) |
| 29 return; | 39 return; |
| 30 PLOG(ERROR) << "error reading device " << path_.value(); | 40 PLOG(ERROR) << "error reading device " << path_.value(); |
| 41 Stop(); |
| 31 return; | 42 return; |
| 32 } | 43 } |
| 33 | 44 |
| 34 CHECK_EQ(read_size % sizeof(*inputs), 0u); | 45 CHECK_EQ(read_size % sizeof(*inputs), 0u); |
| 35 ProcessEvents(inputs, read_size / sizeof(*inputs)); | 46 ProcessEvents(inputs, read_size / sizeof(*inputs)); |
| 36 } | 47 } |
| 37 | 48 |
| 38 void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) { | 49 void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) { |
| 39 NOTREACHED(); | 50 NOTREACHED(); |
| 40 } | 51 } |
| 41 | 52 |
| 42 } // namespace ui | 53 } // namespace ui |
| OLD | NEW |