blob: 76df5b81e856945eccb45b741717f6eeca7094b1 [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
Pavel Maltsev2579fb72017-02-02 12:39:36 -080017#ifndef android_hardware_automotive_vehicle_V2_0_VehicleHal_H
18#define android_hardware_automotive_vehicle_V2_0_VehicleHal_H
Pavel Maltseve2603e32016-10-25 16:03:23 -070019
Pavel Maltsev2579fb72017-02-02 12:39:36 -080020#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
Pavel Maltseve2603e32016-10-25 16:03:23 -070021#include "vehicle_hal_manager/VehicleObjectPool.h"
22
23
24namespace android {
25namespace hardware {
Pavel Maltsev2579fb72017-02-02 12:39:36 -080026namespace automotive {
Pavel Maltseve2603e32016-10-25 16:03:23 -070027namespace vehicle {
28namespace V2_0 {
29
30/**
31 * This is a low-level vehicle hal interface that should be implemented by
32 * Vendor.
33 */
34class VehicleHal {
35public:
36 using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>;
37
38 using HalEventFunction = std::function<void(VehiclePropValuePtr)>;
39 using HalErrorFunction = std::function<void(
Pavel Maltsev8e624b32017-02-01 16:30:25 -080040 StatusCode errorCode, int32_t property, int32_t areaId)>;
Pavel Maltseve2603e32016-10-25 16:03:23 -070041
42 virtual ~VehicleHal() {}
43
44 virtual std::vector<VehiclePropConfig> listProperties() = 0;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070045 virtual VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue,
46 StatusCode* outStatus) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070047
Pavel Maltsevdb179c52016-10-27 15:43:06 -070048 virtual StatusCode set(const VehiclePropValue& propValue) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070049
50 /**
51 * Subscribe to HAL property events. This method might be called multiple
52 * times for the same vehicle property to update subscribed areas or sample
53 * rate.
54 *
55 * @param property to subscribe
56 * @param areas a bitwise vehicle areas or 0 for all supported areas
57 * @param sampleRate sample rate in Hz for properties that support sample
58 * rate, e.g. for properties with
59 * VehiclePropertyChangeMode::CONTINUOUS
60 */
Pavel Maltsev8e624b32017-02-01 16:30:25 -080061 virtual StatusCode subscribe(int32_t property,
62 int32_t areas,
63 float sampleRate) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070064
65 /**
66 * Unsubscribe from HAL events for given property
67 *
68 * @param property vehicle property to unsubscribe
69 */
Pavel Maltsev8e624b32017-02-01 16:30:25 -080070 virtual StatusCode unsubscribe(int32_t property) = 0;
Pavel Maltseve2603e32016-10-25 16:03:23 -070071
72 /**
73 * Override this method if you need to do one-time initialization.
74 */
75 virtual void onCreate() {}
76
77 void init(
78 VehiclePropValuePool* valueObjectPool,
79 const HalEventFunction& onHalEvent,
80 const HalErrorFunction& onHalError) {
81 mValuePool = valueObjectPool;
82 mOnHalEvent = onHalEvent;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070083 mOnHalPropertySetError = onHalError;
Pavel Maltseve2603e32016-10-25 16:03:23 -070084
85 onCreate();
86 }
87
88 VehiclePropValuePool* getValuePool() {
89 return mValuePool;
90 }
91protected:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070092 /* Propagates property change events to vehicle HAL clients. */
Pavel Maltseve2603e32016-10-25 16:03:23 -070093 void doHalEvent(VehiclePropValuePtr v) {
94 mOnHalEvent(std::move(v));
95 }
96
Pavel Maltsevdb179c52016-10-27 15:43:06 -070097 /* Propagates error during set operation to the vehicle HAL clients. */
98 void doHalPropertySetError(StatusCode errorCode,
Pavel Maltsev8e624b32017-02-01 16:30:25 -080099 int32_t propId,
100 int32_t areaId) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700101 mOnHalPropertySetError(errorCode, propId, areaId);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700102 }
103
104private:
105 HalEventFunction mOnHalEvent;
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700106 HalErrorFunction mOnHalPropertySetError;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700107 VehiclePropValuePool* mValuePool;
108};
109
110} // namespace V2_0
111} // namespace vehicle
Pavel Maltsev2579fb72017-02-02 12:39:36 -0800112} // namespace automotive
Pavel Maltseve2603e32016-10-25 16:03:23 -0700113} // namespace hardware
114} // namespace android
115
Pavel Maltsev2579fb72017-02-02 12:39:36 -0800116#endif //android_hardware_automotive_vehicle_V2_0_VehicleHal_H_