| David Pursell | 0b15663 | 2015-10-30 11:22:01 -0700 | [diff] [blame] | 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 |  | 
| Elliott Hughes | 6ebec93 | 2018-04-10 14:22:13 -0700 | [diff] [blame] | 17 | #pragma once | 
| David Pursell | 0b15663 | 2015-10-30 11:22:01 -0700 | [diff] [blame] | 18 |  | 
| Elliott Hughes | 4f71319 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 19 | #include <android-base/macros.h> | 
| David Pursell | 0b15663 | 2015-10-30 11:22:01 -0700 | [diff] [blame] | 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 |     // 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 | }; |