Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Maltsev | 2579fb7 | 2017-02-02 12:39:36 -0800 | [diff] [blame] | 17 | #ifndef android_hardware_automotive_vehicle_V2_0_VehicleHal_H |
| 18 | #define android_hardware_automotive_vehicle_V2_0_VehicleHal_H |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 19 | |
Pavel Maltsev | 2579fb7 | 2017-02-02 12:39:36 -0800 | [diff] [blame] | 20 | #include <android/hardware/automotive/vehicle/2.0/IVehicle.h> |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 21 | #include "vehicle_hal_manager/VehicleObjectPool.h" |
| 22 | |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
Pavel Maltsev | 2579fb7 | 2017-02-02 12:39:36 -0800 | [diff] [blame] | 26 | namespace automotive { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 27 | namespace vehicle { |
| 28 | namespace V2_0 { |
| 29 | |
| 30 | /** |
| 31 | * This is a low-level vehicle hal interface that should be implemented by |
| 32 | * Vendor. |
| 33 | */ |
| 34 | class VehicleHal { |
| 35 | public: |
| 36 | using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>; |
| 37 | |
| 38 | using HalEventFunction = std::function<void(VehiclePropValuePtr)>; |
| 39 | using HalErrorFunction = std::function<void( |
Pavel Maltsev | 8e624b3 | 2017-02-01 16:30:25 -0800 | [diff] [blame] | 40 | StatusCode errorCode, int32_t property, int32_t areaId)>; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 41 | |
| 42 | virtual ~VehicleHal() {} |
| 43 | |
| 44 | virtual std::vector<VehiclePropConfig> listProperties() = 0; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 45 | virtual VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue, |
| 46 | StatusCode* outStatus) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 47 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 48 | virtual StatusCode set(const VehiclePropValue& propValue) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 49 | |
| 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 Maltsev | 8e624b3 | 2017-02-01 16:30:25 -0800 | [diff] [blame] | 61 | virtual StatusCode subscribe(int32_t property, |
| 62 | int32_t areas, |
| 63 | float sampleRate) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Unsubscribe from HAL events for given property |
| 67 | * |
| 68 | * @param property vehicle property to unsubscribe |
| 69 | */ |
Pavel Maltsev | 8e624b3 | 2017-02-01 16:30:25 -0800 | [diff] [blame] | 70 | virtual StatusCode unsubscribe(int32_t property) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 71 | |
| 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 83 | mOnHalPropertySetError = onHalError; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 84 | |
| 85 | onCreate(); |
| 86 | } |
| 87 | |
| 88 | VehiclePropValuePool* getValuePool() { |
| 89 | return mValuePool; |
| 90 | } |
| 91 | protected: |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 92 | /* Propagates property change events to vehicle HAL clients. */ |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 93 | void doHalEvent(VehiclePropValuePtr v) { |
| 94 | mOnHalEvent(std::move(v)); |
| 95 | } |
| 96 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 97 | /* Propagates error during set operation to the vehicle HAL clients. */ |
| 98 | void doHalPropertySetError(StatusCode errorCode, |
Pavel Maltsev | 8e624b3 | 2017-02-01 16:30:25 -0800 | [diff] [blame] | 99 | int32_t propId, |
| 100 | int32_t areaId) { |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 101 | mOnHalPropertySetError(errorCode, propId, areaId); |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | private: |
| 105 | HalEventFunction mOnHalEvent; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 106 | HalErrorFunction mOnHalPropertySetError; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 107 | VehiclePropValuePool* mValuePool; |
| 108 | }; |
| 109 | |
| 110 | } // namespace V2_0 |
| 111 | } // namespace vehicle |
Pavel Maltsev | 2579fb7 | 2017-02-02 12:39:36 -0800 | [diff] [blame] | 112 | } // namespace automotive |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 113 | } // namespace hardware |
| 114 | } // namespace android |
| 115 | |
Pavel Maltsev | 2579fb7 | 2017-02-02 12:39:36 -0800 | [diff] [blame] | 116 | #endif //android_hardware_automotive_vehicle_V2_0_VehicleHal_H_ |