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 | |
| 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 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace vehicle { |
| 27 | namespace V2_0 { |
| 28 | |
| 29 | /** |
| 30 | * This is a low-level vehicle hal interface that should be implemented by |
| 31 | * Vendor. |
| 32 | */ |
| 33 | class VehicleHal { |
| 34 | public: |
| 35 | using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>; |
| 36 | |
| 37 | using HalEventFunction = std::function<void(VehiclePropValuePtr)>; |
| 38 | using HalErrorFunction = std::function<void( |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 39 | StatusCode errorCode, VehicleProperty property, int32_t areaId)>; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 40 | |
| 41 | virtual ~VehicleHal() {} |
| 42 | |
| 43 | virtual std::vector<VehiclePropConfig> listProperties() = 0; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 44 | virtual VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue, |
| 45 | StatusCode* outStatus) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 46 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 47 | virtual StatusCode set(const VehiclePropValue& propValue) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 48 | |
| 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 60 | virtual StatusCode subscribe(VehicleProperty property, |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 61 | 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 69 | virtual StatusCode unsubscribe(VehicleProperty property) = 0; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 70 | |
| 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 82 | mOnHalPropertySetError = onHalError; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 83 | |
| 84 | onCreate(); |
| 85 | } |
| 86 | |
| 87 | VehiclePropValuePool* getValuePool() { |
| 88 | return mValuePool; |
| 89 | } |
| 90 | protected: |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 91 | /* Propagates property change events to vehicle HAL clients. */ |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 92 | void doHalEvent(VehiclePropValuePtr v) { |
| 93 | mOnHalEvent(std::move(v)); |
| 94 | } |
| 95 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 96 | /* 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 Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | private: |
| 103 | HalEventFunction mOnHalEvent; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame] | 104 | HalErrorFunction mOnHalPropertySetError; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 105 | 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_ |