blob: bae64fde9f1ed44d69d0f3096efed898c020ea7b [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>
Pavel Maltsev33676522017-03-31 13:45:54 -070026#include <vhal_v2_0/VehiclePropertyStore.h>
27#include <vhal_v2_0/EmulatedVehicleHal.h>
Pavel Maltsevc5344ac2017-02-08 12:33:46 -080028
Pavel Maltsev33676522017-03-31 13:45:54 -070029#include <vhal_v2_1/EmulatedVehicleHal.h>
Pavel Maltsevc5344ac2017-02-08 12:33:46 -080030
31using namespace android;
32using namespace android::hardware;
33
34namespace V2_1 = ::android::hardware::automotive::vehicle::V2_1;
35namespace V2_0 = ::android::hardware::automotive::vehicle::V2_0;
36
37using StatusCode = V2_0::StatusCode;
38using VehiclePropValue = V2_0::VehiclePropValue;
39
40/* Just wrapper that passes all calls to the provided V2_0::IVehicle object */
41struct 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
79private:
80 V2_0::IVehicle* mVehicle20;
81};
82
83int main(int /* argc */, char* /* argv */ []) {
Pavel Maltsev33676522017-03-31 13:45:54 -070084 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 Maltsevc5344ac2017-02-08 12:33:46 -080088
89 Vehicle_V2_1 vehicle21(vehicleManager.get());
90
Pavel Maltsevc5344ac2017-02-08 12:33:46 -080091 configureRpcThreadpool(1, true /* callerWillJoin */);
92
Steven Morelandeb8e1a72017-04-26 11:42:24 -070093 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 Maltsevc5344ac2017-02-08 12:33:46 -0800101 ALOGI("Ready");
102 joinRpcThreadpool();
Steven Morelandeb8e1a72017-04-26 11:42:24 -0700103 return 1;
Pavel Maltsevc5344ac2017-02-08 12:33:46 -0800104}