blob: aaadf177863a190f556079b10bed6c525e0fed8d [file] [log] [blame]
Pavel Maltsevc5344ac2017-02-08 12:33:46 -08001/*
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>
26#include <vhal_v2_0/DefaultVehicleHal.h>
27
28#include <vhal_v2_1/DefaultVehicleHal.h>
29
30using namespace android;
31using namespace android::hardware;
32
33namespace V2_1 = ::android::hardware::automotive::vehicle::V2_1;
34namespace V2_0 = ::android::hardware::automotive::vehicle::V2_0;
35
36using StatusCode = V2_0::StatusCode;
37using VehiclePropValue = V2_0::VehiclePropValue;
38
39/* Just wrapper that passes all calls to the provided V2_0::IVehicle object */
40struct Vehicle_V2_1 : public V2_1::IVehicle {
41
42 Vehicle_V2_1(V2_0::IVehicle* vehicle20) : mVehicle20(vehicle20) {}
43
44 // Methods derived from IVehicle
45 Return<void> getAllPropConfigs(getAllPropConfigs_cb _hidl_cb) override {
46 return mVehicle20->getAllPropConfigs(_hidl_cb);
47 }
48
49 Return<void> getPropConfigs(const hidl_vec<int32_t>& properties,
50 getPropConfigs_cb _hidl_cb) override {
51 return mVehicle20->getPropConfigs(properties, _hidl_cb);
52 }
53
54 Return<void> get(const V2_0::VehiclePropValue& requestedPropValue,
55 get_cb _hidl_cb) override {
56 return mVehicle20->get(requestedPropValue, _hidl_cb);
57 }
58
59 Return<StatusCode> set(const VehiclePropValue& value) override {
60 return mVehicle20->set(value);
61 }
62
63 Return<StatusCode> subscribe(const sp<V2_0::IVehicleCallback>& callback,
64 const hidl_vec<V2_0::SubscribeOptions>&
65 options) override {
66 return mVehicle20->subscribe(callback, options);
67 }
68
69 Return<StatusCode> unsubscribe(const sp<V2_0::IVehicleCallback>& callback,
70 int32_t propId) override {
71 return mVehicle20->unsubscribe(callback, propId);
72 }
73
74 Return<void> debugDump(debugDump_cb _hidl_cb = nullptr) override {
75 return mVehicle20->debugDump(_hidl_cb);
76 }
77
78private:
79 V2_0::IVehicle* mVehicle20;
80};
81
82int main(int /* argc */, char* /* argv */ []) {
83 auto halImpl20 = std::make_unique<V2_0::impl::DefaultVehicleHal>();
84 auto halImpl21 = std::make_unique<V2_1::impl::DefaultVehicleHal>(halImpl20.get());
85
86 auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(halImpl21.get());
87
88 Vehicle_V2_1 vehicle21(vehicleManager.get());
89
90 ALOGI("Registering as service...");
91 vehicle21.registerAsService("Vehicle");
92
93 configureRpcThreadpool(1, true /* callerWillJoin */);
94
95 ALOGI("Ready");
96 joinRpcThreadpool();
97}