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 17 #ifndef android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_ 18 #define android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_ 19 20 #include <string> 21 #include <vector> 22 23 namespace android { 24 namespace hardware { 25 namespace automotive { 26 namespace vehicle { 27 namespace V2_0 { 28 29 namespace impl { 30 31 /** 32 * This is the communications base class. It defines the interface used in DefaultVehicleHal to 33 * send and receive data to and from the emulator. 34 */ 35 class CommBase { 36 public: 37 virtual ~CommBase() = default; 38 39 /** 40 * Closes a connection if it is open. 41 */ stop()42 virtual void stop() {} 43 44 /** 45 * Creates a connection to the other side. 46 * 47 * @return int Returns fd or socket number if connection is successful. 48 * Otherwise, returns -1 if no connection is availble. 49 */ connect()50 virtual int connect() { return 0; } 51 52 /** 53 * Opens the communications channel. 54 * 55 * @return int Returns 0 if channel is opened, else -errno if failed. 56 */ 57 virtual int open() = 0; 58 59 /** 60 * Blocking call to read data from the connection. 61 * 62 * @return std::vector<uint8_t> Serialized protobuf data received from emulator. This will be 63 * an empty vector if the connection was closed or some other error occurred. 64 */ 65 virtual std::vector<uint8_t> read() = 0; 66 67 /** 68 * Transmits a string of data to the emulator. 69 * 70 * @param data Serialized protobuf data to transmit. 71 * 72 * @return int Number of bytes transmitted, or -1 if failed. 73 */ 74 virtual int write(const std::vector<uint8_t>& data) = 0; 75 }; 76 77 } // impl 78 79 } // namespace V2_0 80 } // namespace vehicle 81 } // namespace automotive 82 } // namespace hardware 83 } // namespace android 84 85 86 #endif // android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_ 87