#ifndef SERVICES_DEVICE_HID_HID_CONNECTION_IMPL_H_
#define SERVICES_DEVICE_HID_HID_CONNECTION_IMPL_H_
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/hid/hid_connection.h"
#include "services/device/public/mojom/hid.mojom.h"
namespace device {
class HidConnectionImpl final : public mojom::HidConnection,
public HidConnection::Client {
public:
static void Create(
scoped_refptr<device::HidConnection> connection,
mojo::PendingReceiver<mojom::HidConnection> receiver,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
mojo::PendingRemote<mojom::HidConnectionWatcher> watcher);
HidConnectionImpl(const HidConnectionImpl&) = delete;
HidConnectionImpl& operator=(const HidConnectionImpl&) = delete;
void OnInputReport(scoped_refptr<base::RefCountedBytes> buffer,
size_t size) override;
void Read(ReadCallback callback) override;
void Write(uint8_t report_id,
const std::vector<uint8_t>& buffer,
WriteCallback callback) override;
void GetFeatureReport(uint8_t report_id,
GetFeatureReportCallback callback) override;
void SendFeatureReport(uint8_t report_id,
const std::vector<uint8_t>& buffer,
SendFeatureReportCallback callback) override;
private:
friend class HidConnectionImplTest;
HidConnectionImpl(
scoped_refptr<device::HidConnection> connection,
mojo::PendingReceiver<mojom::HidConnection> receiver,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
mojo::PendingRemote<mojom::HidConnectionWatcher> watcher);
~HidConnectionImpl() final;
void OnRead(ReadCallback callback,
bool success,
scoped_refptr<base::RefCountedBytes> buffer,
size_t size);
void OnWrite(WriteCallback callback, bool success);
void OnGetFeatureReport(GetFeatureReportCallback callback,
bool success,
scoped_refptr<base::RefCountedBytes> buffer,
size_t size);
void OnSendFeatureReport(SendFeatureReportCallback callback, bool success);
mojo::Receiver<mojom::HidConnection> receiver_;
scoped_refptr<device::HidConnection> hid_connection_;
mojo::Remote<mojom::HidConnectionClient> client_;
mojo::Remote<mojom::HidConnectionWatcher> watcher_;
base::WeakPtrFactory<HidConnectionImpl> weak_factory_{this};
};
}
#endif