blob: 944f97672eed5f77f1801dda3324caaf57072bbf [file] [log] [blame]
// Copyright 2018 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_LIB_INPUT_READER_FDIO_HID_DECODER_H_
#define SRC_UI_LIB_INPUT_READER_FDIO_HID_DECODER_H_
#include <fuchsia/hardware/input/llcpp/fidl.h>
#include <fuchsia/ui/input/cpp/fidl.h>
#include <lib/fdio/cpp/caller.h>
#include <string>
#include <vector>
#include "src/lib/files/unique_fd.h"
#include "src/ui/lib/input_reader/hid_decoder.h"
#include "src/ui/lib/input_reader/mouse.h"
#include "src/ui/lib/input_reader/touch.h"
namespace fzl {
class FdioCaller;
}
namespace hid {
struct ReportField;
}
namespace ui_input {
// This is the "real" FDIO implementation of |HidDecoder|.
// FdioHidDecoder takes ownership of an fd that represents a single Hid device.
// The FdioHidDecoder sends reports to and from the Hid device for the lifetime
// of the Hid device.
class FdioHidDecoder : public HidDecoder {
public:
FdioHidDecoder(const std::string& name, fxl::UniqueFD fd);
~FdioHidDecoder() override;
// |HidDecoder|
const std::string& name() const override { return name_; }
// |HidDecoder|
bool Init() override;
// |HidDecoder|
zx::event GetEvent() override;
// |HidDecoder|
uint32_t GetTraceId() const override { return trace_id_; }
// |HidDecoder|
BootMode ReadBootMode() const override { return boot_mode_; }
// |HidDecoder|
const std::vector<uint8_t>& ReadReportDescriptor(int* bytes_read) override;
// |HidDecoder|
zx_status_t Read(uint8_t* data, size_t data_size, size_t* report_size,
zx_time_t* timestamp) override;
// |HidDecoder|
zx_status_t Send(ReportType type, uint8_t report_id, const std::vector<uint8_t>& report) override;
// |HidDecoder|
zx_status_t GetReport(ReportType type, uint8_t report_id, std::vector<uint8_t>* report) override;
private:
llcpp::fuchsia::hardware::input::Device::SyncClient device_;
const std::string name_;
BootMode boot_mode_ = BootMode::NONE;
std::vector<uint8_t> report_descriptor_;
uint32_t trace_id_ = 0;
// This is only here to take the fd from the constructor and pass it to device_ during
// Init.
fxl::UniqueFD fd_;
};
} // namespace ui_input
#endif // SRC_UI_LIB_INPUT_READER_FDIO_HID_DECODER_H_