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#ifndef TRANSPORT_H_
18#define TRANSPORT_H_
19
20#include <android-base/macros.h>
21
22// General interface to allow the fastboot protocol to be used over different
23// types of transports.
24class Transport {
25  public:
26    Transport() = default;
27    virtual ~Transport() = default;
28
29    // Reads |len| bytes into |data|. Returns the number of bytes actually
30    // read or -1 on error.
31    virtual ssize_t Read(void* data, size_t len) = 0;
32
33    // Writes |len| bytes from |data|. Returns the number of bytes actually
34    // written or -1 on error.
35    virtual ssize_t Write(const void* data, size_t len) = 0;
36
37    // Closes the underlying transport. Returns 0 on success.
38    virtual int Close() = 0;
39
40    // Blocks until the transport disconnects. Transports that don't support
41    // this will return immediately. Returns 0 on success.
42    virtual int WaitForDisconnect() { return 0; }
43
44  private:
45    DISALLOW_COPY_AND_ASSIGN(Transport);
46};
47
48#endif  // TRANSPORT_H_
49