Lakshman Annadorai | b33e2ab | 2020-07-27 10:42:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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_automotive_vehicle_V2_0_impl_UserHalHelper_H_ |
| 18 | #define android_hardware_automotive_vehicle_V2_0_impl_UserHalHelper_H_ |
| 19 | |
| 20 | #include <android-base/result.h> |
| 21 | #include <android/hardware/automotive/vehicle/2.0/types.h> |
| 22 | |
| 23 | #include <functional> |
| 24 | #include <memory> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace automotive { |
| 29 | namespace vehicle { |
| 30 | namespace V2_0 { |
| 31 | |
| 32 | namespace user_hal_helper { |
| 33 | |
Lakshman Annadorai | bfdb1ac | 2020-08-06 14:25:03 -0700 | [diff] [blame^] | 34 | // Verify whether the |value| can be casted to the type |T| and return the casted value on success. |
| 35 | // Otherwise, return the error. |
| 36 | template <typename T> |
| 37 | android::base::Result<T> verifyAndCast(int32_t value); |
| 38 | |
Lakshman Annadorai | b33e2ab | 2020-07-27 10:42:32 -0700 | [diff] [blame] | 39 | // Below functions parse VehiclePropValues to the respective User HAL request structs. On success, |
| 40 | // these functions return the User HAL struct. Otherwise, they return the error. |
| 41 | android::base::Result<InitialUserInfoRequest> toInitialUserInfoRequest( |
| 42 | const VehiclePropValue& propValue); |
| 43 | android::base::Result<SwitchUserRequest> toSwitchUserRequest(const VehiclePropValue& propValue); |
| 44 | android::base::Result<CreateUserRequest> toCreateUserRequest(const VehiclePropValue& propValue); |
| 45 | android::base::Result<RemoveUserRequest> toRemoveUserRequest(const VehiclePropValue& propValue); |
| 46 | android::base::Result<UserIdentificationGetRequest> toUserIdentificationGetRequest( |
| 47 | const VehiclePropValue& propValue); |
| 48 | android::base::Result<UserIdentificationSetRequest> toUserIdentificationSetRequest( |
| 49 | const VehiclePropValue& propValue); |
| 50 | |
| 51 | // Below functions convert the User HAL structs to VehiclePropValues. On success, these functions |
| 52 | // return the pointer to VehiclePropValue. Otherwise, they return nullptr. |
| 53 | std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserRequest& request); |
| 54 | std::unique_ptr<VehiclePropValue> toVehiclePropValue(const InitialUserInfoResponse& response); |
| 55 | std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserResponse& response); |
| 56 | std::unique_ptr<VehiclePropValue> toVehiclePropValue(const CreateUserResponse& response); |
| 57 | std::unique_ptr<VehiclePropValue> toVehiclePropValue(const UserIdentificationResponse& response); |
| 58 | |
| 59 | } // namespace user_hal_helper |
| 60 | |
| 61 | } // namespace V2_0 |
| 62 | } // namespace vehicle |
| 63 | } // namespace automotive |
| 64 | } // namespace hardware |
| 65 | } // namespace android |
| 66 | |
| 67 | #endif // android_hardware_automotive_vehicle_V2_0_impl_UserHalHelper_H_ |