| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/base/ozone/event_factory_ozone.h" | 5 #include "ui/base/ozone/event_factory_ozone.h" |
| 6 | 6 |
| 7 #include <errno.h> |
| 7 #include <fcntl.h> | 8 #include <fcntl.h> |
| 8 #include <linux/input.h> | 9 #include <linux/input.h> |
| 9 #include <poll.h> | 10 #include <poll.h> |
| 10 #include <unistd.h> | 11 #include <unistd.h> |
| 11 | 12 |
| 12 #include "base/message_loop/message_pump_ozone.h" | 13 #include "base/message_loop/message_pump_ozone.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "ui/base/ozone/evdev/key_event_converter_ozone.h" | 16 #include "ui/base/ozone/evdev/key_event_converter_ozone.h" |
| 16 #include "ui/base/ozone/evdev/touch_event_converter_ozone.h" | 17 #include "ui/base/ozone/evdev/touch_event_converter_ozone.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 38 // If there is no |delegate_| set, read events from /dev/input/* | 39 // If there is no |delegate_| set, read events from /dev/input/* |
| 39 | 40 |
| 40 // The number of devices in the directory is unknown without reading | 41 // The number of devices in the directory is unknown without reading |
| 41 // the contents of the directory. Further, with hot-plugging, the entries | 42 // the contents of the directory. Further, with hot-plugging, the entries |
| 42 // might decrease during the execution of this loop. So exciting from the | 43 // might decrease during the execution of this loop. So exciting from the |
| 43 // loop on the first failure of open below is both cheaper and more | 44 // loop on the first failure of open below is both cheaper and more |
| 44 // reliable. | 45 // reliable. |
| 45 for (int id = 0; true; id++) { | 46 for (int id = 0; true; id++) { |
| 46 std::string path = base::StringPrintf("/dev/input/event%d", id); | 47 std::string path = base::StringPrintf("/dev/input/event%d", id); |
| 47 int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); | 48 int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); |
| 48 if (fd < 0) | 49 if (fd < 0) { |
| 50 DLOG(ERROR) << "Cannot open '" << path << "': " << strerror(errno); |
| 49 break; | 51 break; |
| 52 } |
| 50 size_t evtype = 0; | 53 size_t evtype = 0; |
| 51 COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough); | 54 COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough); |
| 52 if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) { | 55 if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) { |
| 53 DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path; | 56 DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path; |
| 54 close(fd); | 57 close(fd); |
| 55 continue; | 58 continue; |
| 56 } | 59 } |
| 57 | 60 |
| 58 scoped_ptr<EventConverterOzone> converter; | 61 scoped_ptr<EventConverterOzone> converter; |
| 59 // TODO(rjkroege) Add more device types. Support hot-plugging. | 62 // TODO(rjkroege) Add more device types. Support hot-plugging. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 100 |
| 98 void EventFactoryOzone::RemoveEventConverter(int fd) { | 101 void EventFactoryOzone::RemoveEventConverter(int fd) { |
| 99 // Always delete watchers before converters to prevent a possible race. | 102 // Always delete watchers before converters to prevent a possible race. |
| 100 delete watchers_[fd]; | 103 delete watchers_[fd]; |
| 101 delete converters_[fd]; | 104 delete converters_[fd]; |
| 102 watchers_.erase(fd); | 105 watchers_.erase(fd); |
| 103 converters_.erase(fd); | 106 converters_.erase(fd); |
| 104 } | 107 } |
| 105 | 108 |
| 106 } // namespace ui | 109 } // namespace ui |
| OLD | NEW |