1 /* 2 * Copyright (C) 2021 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 <aidl/device/generic/car/emulator/IVehicleBus.h> 20 #include <aidl/device/generic/car/emulator/BnVehicleBusCallback.h> 21 22 #include <vhal_v2_0/DefaultVehicleHalServer.h> 23 24 #include "VehicleEmulator.h" 25 26 namespace android { 27 namespace hardware { 28 namespace automotive { 29 namespace vehicle { 30 namespace V2_0 { 31 32 namespace impl { 33 34 // This contains the server operation for VHAL running in emulator. 35 class EmulatedVehicleHalServer : public DefaultVehicleHalServer, public EmulatedServerIface { 36 public: 37 using AidlVehiclePropValue = ::aidl::android::hardware::automotive::vehicle::VehiclePropValue; 38 using IVehicleBus = ::aidl::device::generic::car::emulator::IVehicleBus; 39 using BnVehicleBusCallback = ::aidl::device::generic::car::emulator::BnVehicleBusCallback; 40 41 EmulatedVehicleHalServer(); 42 ~EmulatedVehicleHalServer(); 43 44 StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override; 45 46 // Methods from EmulatedServerIface 47 bool setPropertyFromVehicle(const VehiclePropValue& propValue); 48 49 std::vector<VehiclePropValue> getAllProperties() const; 50 51 std::vector<VehiclePropConfig> listProperties(); 52 53 VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue, StatusCode* outStatus); 54 55 IVehicleServer::DumpResult debug(const std::vector<std::string>& options); 56 57 private: 58 bool mInQEMU; 59 60 class VehicleBusCallback : public BnVehicleBusCallback { 61 public: VehicleBusCallback(EmulatedVehicleHalServer * vehicleHalServer)62 VehicleBusCallback(EmulatedVehicleHalServer* vehicleHalServer) : 63 mVehicleHalServer(vehicleHalServer) {} 64 65 ::ndk::ScopedAStatus onNewPropValues( 66 const std::vector<AidlVehiclePropValue>& propValues) override; 67 68 private: 69 EmulatedVehicleHalServer* mVehicleHalServer; 70 71 VehiclePropValue makeHidlVehiclePropValue(const AidlVehiclePropValue& aidlPropValue); 72 }; 73 std::shared_ptr<BnVehicleBusCallback> mVehicleBusCallback; 74 std::vector<std::shared_ptr<IVehicleBus>> mVehicleBuses; 75 76 void startVehicleBuses(); 77 void stopVehicleBuses(); 78 }; 79 80 } // namespace impl 81 82 } // namespace V2_0 83 } // namespace vehicle 84 } // namespace automotive 85 } // namespace hardware 86 } // namespace android 87