Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #define LOG_TAG "automotive.vehicle@2.1-service" |
| 18 | #include <android/log.h> |
| 19 | #include <hidl/HidlTransportSupport.h> |
| 20 | |
| 21 | #include <iostream> |
| 22 | |
| 23 | #include <android/hardware/automotive/vehicle/2.1/IVehicle.h> |
| 24 | |
| 25 | #include <vhal_v2_0/VehicleHalManager.h> |
Pavel Maltsev | 3367652 | 2017-03-31 13:45:54 -0700 | [diff] [blame] | 26 | #include <vhal_v2_0/VehiclePropertyStore.h> |
| 27 | #include <vhal_v2_0/EmulatedVehicleHal.h> |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 28 | |
Pavel Maltsev | 3367652 | 2017-03-31 13:45:54 -0700 | [diff] [blame] | 29 | #include <vhal_v2_1/EmulatedVehicleHal.h> |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 30 | |
| 31 | using namespace android; |
| 32 | using namespace android::hardware; |
| 33 | |
| 34 | namespace V2_1 = ::android::hardware::automotive::vehicle::V2_1; |
| 35 | namespace V2_0 = ::android::hardware::automotive::vehicle::V2_0; |
| 36 | |
| 37 | using StatusCode = V2_0::StatusCode; |
| 38 | using VehiclePropValue = V2_0::VehiclePropValue; |
| 39 | |
| 40 | /* Just wrapper that passes all calls to the provided V2_0::IVehicle object */ |
| 41 | struct Vehicle_V2_1 : public V2_1::IVehicle { |
| 42 | |
| 43 | Vehicle_V2_1(V2_0::IVehicle* vehicle20) : mVehicle20(vehicle20) {} |
| 44 | |
| 45 | // Methods derived from IVehicle |
| 46 | Return<void> getAllPropConfigs(getAllPropConfigs_cb _hidl_cb) override { |
| 47 | return mVehicle20->getAllPropConfigs(_hidl_cb); |
| 48 | } |
| 49 | |
| 50 | Return<void> getPropConfigs(const hidl_vec<int32_t>& properties, |
| 51 | getPropConfigs_cb _hidl_cb) override { |
| 52 | return mVehicle20->getPropConfigs(properties, _hidl_cb); |
| 53 | } |
| 54 | |
| 55 | Return<void> get(const V2_0::VehiclePropValue& requestedPropValue, |
| 56 | get_cb _hidl_cb) override { |
| 57 | return mVehicle20->get(requestedPropValue, _hidl_cb); |
| 58 | } |
| 59 | |
| 60 | Return<StatusCode> set(const VehiclePropValue& value) override { |
| 61 | return mVehicle20->set(value); |
| 62 | } |
| 63 | |
| 64 | Return<StatusCode> subscribe(const sp<V2_0::IVehicleCallback>& callback, |
| 65 | const hidl_vec<V2_0::SubscribeOptions>& |
| 66 | options) override { |
| 67 | return mVehicle20->subscribe(callback, options); |
| 68 | } |
| 69 | |
| 70 | Return<StatusCode> unsubscribe(const sp<V2_0::IVehicleCallback>& callback, |
| 71 | int32_t propId) override { |
| 72 | return mVehicle20->unsubscribe(callback, propId); |
| 73 | } |
| 74 | |
| 75 | Return<void> debugDump(debugDump_cb _hidl_cb = nullptr) override { |
| 76 | return mVehicle20->debugDump(_hidl_cb); |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | V2_0::IVehicle* mVehicle20; |
| 81 | }; |
| 82 | |
| 83 | int main(int /* argc */, char* /* argv */ []) { |
Pavel Maltsev | 3367652 | 2017-03-31 13:45:54 -0700 | [diff] [blame] | 84 | auto store = std::make_unique<V2_0::VehiclePropertyStore>(); |
| 85 | auto hal = std::make_unique<V2_1::impl::EmulatedVehicleHal>(store.get()); |
| 86 | auto emulator = std::make_unique<V2_0::impl::VehicleEmulator>(hal.get()); |
| 87 | auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(hal.get()); |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 88 | |
| 89 | Vehicle_V2_1 vehicle21(vehicleManager.get()); |
| 90 | |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 91 | configureRpcThreadpool(1, true /* callerWillJoin */); |
| 92 | |
Steven Moreland | eb8e1a7 | 2017-04-26 11:42:24 -0700 | [diff] [blame] | 93 | ALOGI("Registering as service..."); |
| 94 | status_t status = vehicle21.registerAsService(); |
| 95 | |
| 96 | if (status != OK) { |
| 97 | ALOGE("Unable to register vehicle service (%d).", status); |
| 98 | return 1; |
| 99 | } |
| 100 | |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 101 | ALOGI("Ready"); |
| 102 | joinRpcThreadpool(); |
Steven Moreland | eb8e1a7 | 2017-04-26 11:42:24 -0700 | [diff] [blame] | 103 | return 1; |
Pavel Maltsev | c5344ac | 2017-02-08 12:33:46 -0800 | [diff] [blame] | 104 | } |