Greg Hartman | 92045f6 | 2017-10-31 17:12:24 -0700 | [diff] [blame] | 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 | |
Jorge E. Moreira | d843066 | 2018-07-22 23:52:33 -0700 | [diff] [blame] | 18 | #include "host/commands/virtual_usb_manager/vadb/usb_cmd.h" |
Greg Hartman | 92045f6 | 2017-10-31 17:12:24 -0700 | [diff] [blame] | 19 | |
| 20 | namespace vadb { |
| 21 | // Request remote device attach (~open). |
| 22 | class USBCmdHeartbeat : public USBCommand { |
| 23 | public: |
| 24 | // Heartbeat result callback receives a boolean argument indicating whether |
| 25 | // remote device is ready to be attached. |
| 26 | using HeartbeatResultCB = std::function<void(bool)>; |
| 27 | |
| 28 | USBCmdHeartbeat(HeartbeatResultCB callback); |
| 29 | ~USBCmdHeartbeat() override = default; |
| 30 | |
| 31 | // Return usbforward command this instance is executing. |
| 32 | usb_forward::Command Command() override { return usb_forward::CmdHeartbeat; } |
| 33 | |
| 34 | // Send request body to the server. |
| 35 | // Return false, if communication failed. |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame] | 36 | bool OnRequest(const cvd::SharedFD& data) override; |
Greg Hartman | 92045f6 | 2017-10-31 17:12:24 -0700 | [diff] [blame] | 37 | |
| 38 | // Receive response data from the server. |
| 39 | // Return false, if communication failed. |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame] | 40 | bool OnResponse(bool is_success, const cvd::SharedFD& data) override; |
Greg Hartman | 92045f6 | 2017-10-31 17:12:24 -0700 | [diff] [blame] | 41 | |
| 42 | private: |
| 43 | HeartbeatResultCB callback_; |
| 44 | |
| 45 | USBCmdHeartbeat(const USBCmdHeartbeat& other) = delete; |
| 46 | USBCmdHeartbeat& operator=(const USBCmdHeartbeat& other) = delete; |
| 47 | }; |
| 48 | } // namespace vadb |