blob: 96b90d2fe7696ec19e0c64cef32a8981d5643425 [file] [log] [blame]
David Pursell0b156632015-10-30 11:22:01 -07001/*
2 * Copyright (C) 2015 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
Elliott Hughes6ebec932018-04-10 14:22:13 -070017#pragma once
David Pursell0b156632015-10-30 11:22:01 -070018
Elliott Hughes4f713192015-12-04 22:00:26 -080019#include <android-base/macros.h>
David Pursell0b156632015-10-30 11:22:01 -070020
21// General interface to allow the fastboot protocol to be used over different
22// types of transports.
23class Transport {
24 public:
25 Transport() = default;
26 virtual ~Transport() = default;
27
28 // Reads |len| bytes into |data|. Returns the number of bytes actually
29 // read or -1 on error.
30 virtual ssize_t Read(void* data, size_t len) = 0;
31
32 // Writes |len| bytes from |data|. Returns the number of bytes actually
33 // written or -1 on error.
34 virtual ssize_t Write(const void* data, size_t len) = 0;
35
36 // Closes the underlying transport. Returns 0 on success.
37 virtual int Close() = 0;
38
39 // Blocks until the transport disconnects. Transports that don't support
40 // this will return immediately. Returns 0 on success.
41 virtual int WaitForDisconnect() { return 0; }
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(Transport);
45};