blob: 89d8ef881679ec51469de9b15f9f1321b4483a85 [file] [log] [blame]
Pavel Maltseve2603e32016-10-25 16:03:23 -07001/*
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#ifndef android_hardware_vehicle_V2_0_VehicleHal_H_
18#define android_hardware_vehicle_V2_0_VehicleHal_H_
19
20#include <android/hardware/vehicle/2.0/IVehicle.h>
21#include "vehicle_hal_manager/VehicleObjectPool.h"
22
23
24namespace android {
25namespace hardware {
26namespace vehicle {
27namespace V2_0 {
28
29/**
30 * This is a low-level vehicle hal interface that should be implemented by
31 * Vendor.
32 */
33class VehicleHal {
34public:
35 using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>;
36
37 using HalEventFunction = std::function<void(VehiclePropValuePtr)>;
38 using HalErrorFunction = std::function<void(
39 VehicleProperty property,
40 status_t errorCode,
41 VehiclePropertyOperation operation)>;
42
43 virtual ~VehicleHal() {}
44
45 virtual std::vector<VehiclePropConfig> listProperties() = 0;
46 virtual VehiclePropValuePtr get(VehicleProperty property,
47 int32_t areaId,
48 status_t* outStatus) = 0;
49
50 virtual status_t set(const VehiclePropValue& propValue) = 0;
51
52 /**
53 * Subscribe to HAL property events. This method might be called multiple
54 * times for the same vehicle property to update subscribed areas or sample
55 * rate.
56 *
57 * @param property to subscribe
58 * @param areas a bitwise vehicle areas or 0 for all supported areas
59 * @param sampleRate sample rate in Hz for properties that support sample
60 * rate, e.g. for properties with
61 * VehiclePropertyChangeMode::CONTINUOUS
62 */
63 virtual status_t subscribe(VehicleProperty property,
64 int32_t areas,
65 float sampleRate) = 0;
66
67 /**
68 * Unsubscribe from HAL events for given property
69 *
70 * @param property vehicle property to unsubscribe
71 */
72 virtual status_t unsubscribe(VehicleProperty property) = 0;
73
74 /**
75 * Override this method if you need to do one-time initialization.
76 */
77 virtual void onCreate() {}
78
79 void init(
80 VehiclePropValuePool* valueObjectPool,
81 const HalEventFunction& onHalEvent,
82 const HalErrorFunction& onHalError) {
83 mValuePool = valueObjectPool;
84 mOnHalEvent = onHalEvent;
85 mOnHalError = onHalError;
86
87 onCreate();
88 }
89
90 VehiclePropValuePool* getValuePool() {
91 return mValuePool;
92 }
93protected:
94 void doHalEvent(VehiclePropValuePtr v) {
95 mOnHalEvent(std::move(v));
96 }
97
98 void doHalError(VehicleProperty property,
99 status_t errorCode,
100 VehiclePropertyOperation operation) {
101 mOnHalError(property, errorCode, operation);
102 }
103
104private:
105 HalEventFunction mOnHalEvent;
106 HalErrorFunction mOnHalError;
107 VehiclePropValuePool* mValuePool;
108};
109
110} // namespace V2_0
111} // namespace vehicle
112} // namespace hardware
113} // namespace android
114
115#endif //android_hardware_vehicle_V2_0_VehicleHal_H_