1 /* 2 * Copyright (C) 2019 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 #include <android-base/logging.h> 18 #include <android/binder_process.h> 19 #include <hidl/HidlTransportSupport.h> 20 21 #include <vhal_v2_0/EmulatedVehicleConnector.h> 22 #include <vhal_v2_0/EmulatedVehicleHal.h> 23 #include <vhal_v2_0/VehicleHalManager.h> 24 25 #include "GrpcVehicleClient.h" 26 #include "Utils.h" 27 28 using android::OK; 29 using android::status_t; 30 using android::hardware::configureRpcThreadpool; 31 using android::hardware::joinRpcThreadpool; 32 using android::hardware::automotive::vehicle::V2_0::VehicleHalManager; 33 using android::hardware::automotive::vehicle::V2_0::VehiclePropertyStore; 34 35 int main(int argc, char* argv[]) { 36 namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl; 37 38 auto serverInfo = vhal_impl::VirtualizedVhalServerInfo::fromRoPropertyStore(); 39 CHECK(serverInfo.has_value()) << "Invalid server CID/port combination"; 40 LOG(INFO) << "Connecting to vsock server at " << serverInfo->vsock.str(); 41 42 auto store = std::make_unique<VehiclePropertyStore>(); 43 auto connector = vhal_impl::makeGrpcVehicleClient(serverInfo->getServerUri()); 44 auto hal = std::make_unique<vhal_impl::EmulatedVehicleHal>(store.get(), connector.get()); 45 auto emulator = std::make_unique<vhal_impl::VehicleEmulator>(hal.get()); 46 auto service = std::make_unique<VehicleHalManager>(hal.get()); 47 48 configureRpcThreadpool(4, true /* callerWillJoin */); 49 50 LOG(INFO) << "Registering as service..."; 51 status_t status = service->registerAsService(); 52 53 if (status != OK) { 54 LOG(ERROR) << "Unable to register vehicle service (" << status << ")"; 55 return 1; 56 } 57 58 LOG(INFO) << "Ready"; 59 joinRpcThreadpool(); 60 61 // We don't ever actually expect to return, so return an error if we do get here 62 return 1; 63 } 64