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

Unified Diff: ui/events/ozone/evdev/event_factory_delegate.cc

Issue 28513004: Move evdev events support into EventFactoryDelegateEvdev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add evdev to filename_rules.gypi Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/ozone/evdev/event_factory_delegate.h ('k') | ui/events/ozone/evdev/key_event_converter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/ozone/evdev/event_factory_delegate.cc
diff --git a/ui/events/ozone/evdev/event_factory_delegate.cc b/ui/events/ozone/evdev/event_factory_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..59f2c7261080eb8903cb5bba5322c74a2006036b
--- /dev/null
+++ b/ui/events/ozone/evdev/event_factory_delegate.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/ozone/evdev/event_factory_delegate.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/input.h>
+#include <poll.h>
+#include <unistd.h>
+
+#include "base/strings/stringprintf.h"
+#include "ui/events/ozone/evdev/key_event_converter.h"
+#include "ui/events/ozone/evdev/touch_event_converter.h"
+#include "ui/events/ozone/event_factory_delegate_ozone.h"
+#include "ui/events/ozone/event_factory_ozone.h"
+
+namespace ui {
+
+EventFactoryDelegateEvdev::EventFactoryDelegateEvdev() {}
+
+EventFactoryDelegateEvdev::~EventFactoryDelegateEvdev() {}
+
+void EventFactoryDelegateEvdev::CreateStartupEventConverters(
+ EventFactoryOzone* factory) {
+ // The number of devices in the directory is unknown without reading
+ // the contents of the directory. Further, with hot-plugging, the entries
+ // might decrease during the execution of this loop. So exciting from the
+ // loop on the first failure of open below is both cheaper and more
+ // reliable.
+ for (int id = 0; true; id++) {
+ std::string path = base::StringPrintf("/dev/input/event%d", id);
+ int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ DLOG(ERROR) << "Cannot open '" << path << "': " << strerror(errno);
+ break;
+ }
+ size_t evtype = 0;
+ COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough);
+ if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) {
+ DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path;
+ close(fd);
+ continue;
+ }
+
+ scoped_ptr<EventConverterOzone> converter;
+ // TODO(rjkroege) Add more device types. Support hot-plugging.
+ if (evtype & (1 << EV_ABS))
+ converter.reset(new TouchEventConverterEvdev(fd, id));
+ else if (evtype & (1 << EV_KEY))
+ converter.reset(new KeyEventConverterEvdev());
+
+ if (converter) {
+ factory->AddEventConverter(fd, converter.Pass());
+ } else {
+ close(fd);
+ }
+ }
+}
+
+} // namespace ui
« no previous file with comments | « ui/events/ozone/evdev/event_factory_delegate.h ('k') | ui/events/ozone/evdev/key_event_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698