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_PipeComm_H_
18 #define android_hardware_automotive_vehicle_V2_0_impl_PipeComm_H_
19 
20 #include <mutex>
21 #include <vector>
22 #include "CommConn.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace automotive {
27 namespace vehicle {
28 namespace V2_0 {
29 
30 namespace impl {
31 
32 /**
33  * PipeComm opens a qemu pipe to connect to the emulator, allowing the emulator UI to access the
34  * Vehicle HAL and simulate changing properties.
35  *
36  * Since the pipe is a client, it directly implements CommConn, and only one PipeComm can be open
37  * at a time.
38  */
39 class PipeComm : public CommConn {
40    public:
41     PipeComm(MessageProcessor* messageProcessor);
42 
43     void start() override;
44     void stop() override;
45 
46     std::vector<uint8_t> read() override;
47     int write(const std::vector<uint8_t>& data) override;
48 
isOpen()49     inline bool isOpen() override { return mPipeFd > 0; }
50 
51    private:
52     int mPipeFd;
53 };
54 
55 }  // impl
56 
57 }  // namespace V2_0
58 }  // namespace vehicle
59 }  // namespace automotive
60 }  // namespace hardware
61 }  // namespace android
62 
63 
64 #endif  // android_hardware_automotive_vehicle_V2_0_impl_PipeComm_H_
65