| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #ifndef SRC_UI_INPUT_DRIVERS_VIRTIO_INPUT_DEVICE_H_ |
| #define SRC_UI_INPUT_DRIVERS_VIRTIO_INPUT_DEVICE_H_ |
| |
| #include <fidl/fuchsia.input.report/cpp/wire.h> |
| #include <lib/input_report_reader/reader.h> |
| #include <lib/zx/clock.h> |
| #include <zircon/types.h> |
| |
| #include <virtio/input.h> |
| |
| namespace virtio { |
| |
| class HidDeviceBase { |
| public: |
| virtual ~HidDeviceBase() = default; |
| |
| // Gets the HID Report Descriptor for this device. The memory for the descriptor |
| // is dynamically allocated and placed in |data| with length |len|. |
| virtual fuchsia_input_report::wire::DeviceDescriptor GetDescriptor(fidl::AnyArena& allocator) = 0; |
| |
| // Process a virtio event for this device and update the private HID |
| // report accordingly. |
| virtual void ReceiveEvent(virtio_input_event_t* event) = 0; |
| |
| virtual void GetInputReportsReader( |
| async_dispatcher_t* dispatcher, |
| fidl::ServerEnd<fuchsia_input_report::InputReportsReader> reader) = 0; |
| virtual zx::time SendReportToAllReaders() = 0; |
| }; |
| |
| // Each HidDevice is responsible for taking virtio events and translating them |
| // into HID events. This class should be inherited once for each type of input |
| // device that should be supported (e.g: mice, keyboards, touchscreens). |
| template <typename ReportType> |
| class HidDevice : public HidDeviceBase { |
| public: |
| void GetInputReportsReader( |
| async_dispatcher_t* dispatcher, |
| fidl::ServerEnd<fuchsia_input_report::InputReportsReader> reader) override { |
| readers_.CreateReader(dispatcher, std::move(reader)); |
| } |
| |
| zx::time SendReportToAllReaders() override { |
| report_.event_time = zx::clock::get_monotonic(); |
| readers_.SendReportToAllReaders(report_); |
| return report_.event_time; |
| } |
| |
| protected: |
| ReportType report_; |
| |
| private: |
| input_report_reader::InputReportReaderManager<ReportType> readers_; |
| }; |
| |
| } // namespace virtio |
| |
| #endif // SRC_UI_INPUT_DRIVERS_VIRTIO_INPUT_DEVICE_H_ |