blob: 4d9ebbc9ec5ba63e5f9e31cee8c7bca8e13c9140 [file] [log] [blame]
Greg Hartman92045f62017-10-31 17:12:24 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <functional>
19#include <vector>
20#include "common/libs/usbforward/protocol.h"
Jorge E. Moreirad8430662018-07-22 23:52:33 -070021#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
Greg Hartman92045f62017-10-31 17:12:24 -070022
23namespace vadb {
24// Request device list from remote host.
25class USBCmdDeviceList : public USBCommand {
26 public:
27 // DeviceDiscoveredCB is a callback function invoked for every new discovered
28 // device.
29 using DeviceDiscoveredCB =
30 std::function<void(const usb_forward::DeviceInfo&,
31 const std::vector<usb_forward::InterfaceInfo>&)>;
32
33 USBCmdDeviceList(DeviceDiscoveredCB cb)
34 : on_device_discovered_(std::move(cb)) {}
35
36 ~USBCmdDeviceList() override = default;
37
38 // Return usbforward command this instance is executing.
39 usb_forward::Command Command() override { return usb_forward::CmdDeviceList; }
40
41 // Send request body to the server.
42 // Return false, if communication failed.
Greg Hartman153b1062017-11-11 12:09:21 -080043 bool OnRequest(const cvd::SharedFD& data) override;
Greg Hartman92045f62017-10-31 17:12:24 -070044
45 // Receive response data from the server.
46 // Return false, if communication failed.
Greg Hartman153b1062017-11-11 12:09:21 -080047 bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
Greg Hartman92045f62017-10-31 17:12:24 -070048
49 private:
50 DeviceDiscoveredCB on_device_discovered_;
51 USBCmdDeviceList(const USBCmdDeviceList& other) = delete;
52 USBCmdDeviceList& operator=(const USBCmdDeviceList& other) = delete;
53};
54} // namespace vadb