summaryrefslogtreecommitdiffstats
blob: aaadf177863a190f556079b10bed6c525e0fed8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "automotive.vehicle@2.1-service"
#include <android/log.h>
#include <hidl/HidlTransportSupport.h>

#include <iostream>

#include <android/hardware/automotive/vehicle/2.1/IVehicle.h>

#include <vhal_v2_0/VehicleHalManager.h>
#include <vhal_v2_0/DefaultVehicleHal.h>

#include <vhal_v2_1/DefaultVehicleHal.h>

using namespace android;
using namespace android::hardware;

namespace V2_1 = ::android::hardware::automotive::vehicle::V2_1;
namespace V2_0 = ::android::hardware::automotive::vehicle::V2_0;

using StatusCode = V2_0::StatusCode;
using VehiclePropValue = V2_0::VehiclePropValue;

/* Just wrapper that passes all calls to the provided V2_0::IVehicle object */
struct Vehicle_V2_1 : public V2_1::IVehicle {

    Vehicle_V2_1(V2_0::IVehicle* vehicle20) : mVehicle20(vehicle20) {}

    // Methods derived from IVehicle
    Return<void> getAllPropConfigs(getAllPropConfigs_cb _hidl_cb)  override {
        return mVehicle20->getAllPropConfigs(_hidl_cb);
    }

    Return<void> getPropConfigs(const hidl_vec<int32_t>& properties,
                                getPropConfigs_cb _hidl_cb)  override {
        return mVehicle20->getPropConfigs(properties, _hidl_cb);
    }

    Return<void> get(const V2_0::VehiclePropValue& requestedPropValue,
                     get_cb _hidl_cb)  override {
        return mVehicle20->get(requestedPropValue, _hidl_cb);
    }

    Return<StatusCode> set(const VehiclePropValue& value) override {
        return mVehicle20->set(value);
    }

    Return<StatusCode> subscribe(const sp<V2_0::IVehicleCallback>& callback,
                                 const hidl_vec<V2_0::SubscribeOptions>&
                                 options)  override {
        return mVehicle20->subscribe(callback, options);
    }

    Return<StatusCode> unsubscribe(const sp<V2_0::IVehicleCallback>& callback,
                                   int32_t propId)  override {
        return mVehicle20->unsubscribe(callback, propId);
    }

    Return<void> debugDump(debugDump_cb _hidl_cb = nullptr) override {
        return mVehicle20->debugDump(_hidl_cb);
    }

private:
    V2_0::IVehicle* mVehicle20;
};

int main(int /* argc */, char* /* argv */ []) {
    auto halImpl20 = std::make_unique<V2_0::impl::DefaultVehicleHal>();
    auto halImpl21 = std::make_unique<V2_1::impl::DefaultVehicleHal>(halImpl20.get());

    auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(halImpl21.get());

    Vehicle_V2_1 vehicle21(vehicleManager.get());

    ALOGI("Registering as service...");
    vehicle21.registerAsService("Vehicle");

    configureRpcThreadpool(1, true /* callerWillJoin */);

    ALOGI("Ready");
    joinRpcThreadpool();
}