blob: 2807f2875031dbb0413a83e6ac26e6866f444970 [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(
Pavel Maltsevdb179c52016-10-27 15:43:06 -070039 StatusCode errorCode, VehicleProperty property, int32_t areaId)>;
Pavel Maltseve2603e32016-10-25 16:03:23 -070040
41 virtual ~VehicleHal() {}
42
43 virtual std::vector<VehiclePropConfig> listProperties() = 0;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070044 virtual VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue,
45 StatusCode* outStatus) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070046
Pavel Maltsevdb179c52016-10-27 15:43:06 -070047 virtual StatusCode set(const VehiclePropValue& propValue) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070048
49 /**
50 * Subscribe to HAL property events. This method might be called multiple
51 * times for the same vehicle property to update subscribed areas or sample
52 * rate.
53 *
54 * @param property to subscribe
55 * @param areas a bitwise vehicle areas or 0 for all supported areas
56 * @param sampleRate sample rate in Hz for properties that support sample
57 * rate, e.g. for properties with
58 * VehiclePropertyChangeMode::CONTINUOUS
59 */
Pavel Maltsevdb179c52016-10-27 15:43:06 -070060 virtual StatusCode subscribe(VehicleProperty property,
Pavel Maltseve2603e32016-10-25 16:03:23 -070061 int32_t areas,
62 float sampleRate) = 0;
63
64 /**
65 * Unsubscribe from HAL events for given property
66 *
67 * @param property vehicle property to unsubscribe
68 */
Pavel Maltsevdb179c52016-10-27 15:43:06 -070069 virtual StatusCode unsubscribe(VehicleProperty property) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070070
71 /**
72 * Override this method if you need to do one-time initialization.
73 */
74 virtual void onCreate() {}
75
76 void init(
77 VehiclePropValuePool* valueObjectPool,
78 const HalEventFunction& onHalEvent,
79 const HalErrorFunction& onHalError) {
80 mValuePool = valueObjectPool;
81 mOnHalEvent = onHalEvent;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070082 mOnHalPropertySetError = onHalError;
Pavel Maltseve2603e32016-10-25 16:03:23 -070083
84 onCreate();
85 }
86
87 VehiclePropValuePool* getValuePool() {
88 return mValuePool;
89 }
90protected:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070091 /* Propagates property change events to vehicle HAL clients. */
Pavel Maltseve2603e32016-10-25 16:03:23 -070092 void doHalEvent(VehiclePropValuePtr v) {
93 mOnHalEvent(std::move(v));
94 }
95
Pavel Maltsevdb179c52016-10-27 15:43:06 -070096 /* Propagates error during set operation to the vehicle HAL clients. */
97 void doHalPropertySetError(StatusCode errorCode,
98 VehicleProperty propId, int32_t areaId) {
99 mOnHalPropertySetError(errorCode, propId, areaId);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700100 }
101
102private:
103 HalEventFunction mOnHalEvent;
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700104 HalErrorFunction mOnHalPropertySetError;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700105 VehiclePropValuePool* mValuePool;
106};
107
108} // namespace V2_0
109} // namespace vehicle
110} // namespace hardware
111} // namespace android
112
113#endif //android_hardware_vehicle_V2_0_VehicleHal_H_