• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 <memory>
19 #include <stdint.h>
20 
21 #include "common/libs/usbforward/protocol.h"
22 #include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
23 #include "host/commands/virtual_usb_manager/usbip/device.h"
24 
25 namespace vadb {
26 // Execute control transfer.
27 class USBCmdDataTransfer : public USBCommand {
28  public:
29   USBCmdDataTransfer(uint8_t bus_id, uint8_t dev_id, uint8_t endpoint,
30                      bool is_host_to_device, uint32_t timeout,
31                      std::vector<uint8_t> data,
32                      usbip::Device::AsyncTransferReadyCB callback);
33 
34   ~USBCmdDataTransfer() override = default;
35 
36   // Return usbforward command this instance is executing.
Command()37   usb_forward::Command Command() override {
38     return usb_forward::CmdDataTransfer;
39   }
40 
41   // Send request body to the server.
42   // Return false, if communication failed.
43   bool OnRequest(const cvd::SharedFD& data) override;
44 
45   // Receive response data from the server.
46   // Return false, if communication failed.
47   bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
48 
49  private:
50   usb_forward::DataTransfer req_;
51   std::vector<uint8_t> data_;
52   usbip::Device::AsyncTransferReadyCB callback_;
53 
54   USBCmdDataTransfer(const USBCmdDataTransfer& other) = delete;
55   USBCmdDataTransfer& operator=(const USBCmdDataTransfer& other) = delete;
56 };
57 }  // namespace vadb
58