Hao Chen | 5a97c38 | 2019-12-05 15:53:05 -0800 | [diff] [blame] | 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> |
Hao Chen | 5a97c38 | 2019-12-05 15:53:05 -0800 | [diff] [blame] | 18 | #include <hidl/HidlTransportSupport.h> |
| 19 | |
| 20 | #include <vhal_v2_0/EmulatedVehicleConnector.h> |
| 21 | #include <vhal_v2_0/EmulatedVehicleHal.h> |
| 22 | #include <vhal_v2_0/VehicleHalManager.h> |
| 23 | #include <vhal_v2_0/virtualization/GrpcVehicleClient.h> |
| 24 | #include <vhal_v2_0/virtualization/Utils.h> |
| 25 | |
| 26 | using namespace android; |
| 27 | using namespace android::hardware; |
| 28 | using namespace android::hardware::automotive::vehicle::V2_0; |
| 29 | |
| 30 | int main(int argc, char* argv[]) { |
Enrico Granata | c44909d | 2020-01-24 14:13:52 -0800 | [diff] [blame] | 31 | namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl; |
Hao Chen | 5a97c38 | 2019-12-05 15:53:05 -0800 | [diff] [blame] | 32 | |
Enrico Granata | c44909d | 2020-01-24 14:13:52 -0800 | [diff] [blame] | 33 | auto serverInfo = vhal_impl::VsockServerInfo::fromRoPropertyStore(); |
| 34 | CHECK(serverInfo.has_value()) << "Invalid server CID/port combination"; |
Hao Chen | 5a97c38 | 2019-12-05 15:53:05 -0800 | [diff] [blame] | 35 | |
| 36 | auto store = std::make_unique<VehiclePropertyStore>(); |
Enrico Granata | c44909d | 2020-01-24 14:13:52 -0800 | [diff] [blame] | 37 | auto connector = impl::makeGrpcVehicleClient(serverInfo->toUri()); |
Hao Chen | 5a97c38 | 2019-12-05 15:53:05 -0800 | [diff] [blame] | 38 | auto hal = std::make_unique<impl::EmulatedVehicleHal>(store.get(), connector.get()); |
| 39 | auto emulator = std::make_unique<impl::VehicleEmulator>(hal.get()); |
| 40 | auto service = std::make_unique<VehicleHalManager>(hal.get()); |
| 41 | |
| 42 | configureRpcThreadpool(4, true /* callerWillJoin */); |
| 43 | |
| 44 | LOG(INFO) << "Registering as service..."; |
| 45 | status_t status = service->registerAsService(); |
| 46 | |
| 47 | if (status != OK) { |
| 48 | LOG(ERROR) << "Unable to register vehicle service (" << status << ")"; |
| 49 | return 1; |
| 50 | } |
| 51 | |
| 52 | LOG(INFO) << "Ready"; |
| 53 | joinRpcThreadpool(); |
| 54 | |
| 55 | return 1; |
| 56 | } |