1 /*
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 
17 #pragma once
18 
19 #include <android-base/macros.h>
20 
21 // General interface to allow the fastboot protocol to be used over different
22 // types of transports.
23 class 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     virtual int Reset() = 0;
40 
41     // Blocks until the transport disconnects. Transports that don't support
42     // this will return immediately. Returns 0 on success.
WaitForDisconnect()43     virtual int WaitForDisconnect() { return 0; }
44 
45   private:
46     DISALLOW_COPY_AND_ASSIGN(Transport);
47 };
48