OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_ |
| 6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_ |
| 7 |
| 8 #include <libevdev/libevdev.h> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "ui/events/ozone/evdev/event_converter_evdev.h" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 // Basic wrapper for libevdev-cros. |
| 17 // |
| 18 // This drives libevdev-cros from a file descriptor and calls delegate |
| 19 // with the updated event state from libevdev-cros. |
| 20 // |
| 21 // The library doesn't support all devices currently. In particular there |
| 22 // is no support for keyboard events. |
| 23 class EventReaderLibevdevCros : public base::MessagePumpLibevent::Watcher, |
| 24 public EventConverterEvdev { |
| 25 public: |
| 26 class Delegate { |
| 27 public: |
| 28 virtual ~Delegate(); |
| 29 |
| 30 // Notifier for open. This is called with the initial event state. |
| 31 virtual void OnLibEvdevCrosOpen(Evdev* evdev, EventStateRec* evstate) = 0; |
| 32 |
| 33 // Notifier for event. This is called with the updated event state. |
| 34 virtual void OnLibEvdevCrosEvent(Evdev* evdev, |
| 35 EventStateRec* state, |
| 36 const timeval& time) = 0; |
| 37 }; |
| 38 |
| 39 EventReaderLibevdevCros(int fd, |
| 40 const base::FilePath& path, |
| 41 scoped_ptr<Delegate> delegate); |
| 42 ~EventReaderLibevdevCros(); |
| 43 |
| 44 // Overridden from ui::EventDeviceEvdev. |
| 45 void Start() OVERRIDE; |
| 46 void Stop() OVERRIDE; |
| 47 |
| 48 // Overidden from MessagePumpLibevent::Watcher. |
| 49 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 50 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 51 |
| 52 private: |
| 53 static void OnSynReport(void* data, |
| 54 EventStateRec* evstate, |
| 55 struct timeval* tv); |
| 56 static void OnLogMessage(void*, int level, const char*, ...); |
| 57 |
| 58 // Libevdev state. |
| 59 Evdev evdev_; |
| 60 |
| 61 // Event state. |
| 62 EventStateRec evstate_; |
| 63 |
| 64 // Path to input device. |
| 65 base::FilePath path_; |
| 66 |
| 67 // Delegate for event processing. |
| 68 scoped_ptr<Delegate> delegate_; |
| 69 |
| 70 // Controller for watching the input fd. |
| 71 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(EventReaderLibevdevCros); |
| 74 }; |
| 75 |
| 76 } // namspace ui |
| 77 |
| 78 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_EVENT_READER_LIBEVDEV_CROS_H_ |
OLD | NEW |