blob: c882defc2808127bd976f964abefbb94ebfd5fc2 [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 Maltsev8e624b32017-02-01 16:30:25 -080039 StatusCode errorCode, int32_t 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 Maltsev8e624b32017-02-01 16:30:25 -080060 virtual StatusCode subscribe(int32_t property,
61 int32_t areas,
62 float sampleRate) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070063
64 /**
65 * Unsubscribe from HAL events for given property
66 *
67 * @param property vehicle property to unsubscribe
68 */
Pavel Maltsev8e624b32017-02-01 16:30:25 -080069 virtual StatusCode unsubscribe(int32_t 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,
Pavel Maltsev8e624b32017-02-01 16:30:25 -080098 int32_t propId,
99 int32_t areaId) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700100 mOnHalPropertySetError(errorCode, propId, areaId);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700101 }
102
103private:
104 HalEventFunction mOnHalEvent;
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700105 HalErrorFunction mOnHalPropertySetError;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700106 VehiclePropValuePool* mValuePool;
107};
108
109} // namespace V2_0
110} // namespace vehicle
111} // namespace hardware
112} // namespace android
113
114#endif //android_hardware_vehicle_V2_0_VehicleHal_H_