1*4d7e907cSAndroid Build Coastguard Worker /* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Worker #ifndef android_hardware_automotive_vehicle_V2_0_impl_UserHalHelper_H_ 18*4d7e907cSAndroid Build Coastguard Worker #define android_hardware_automotive_vehicle_V2_0_impl_UserHalHelper_H_ 19*4d7e907cSAndroid Build Coastguard Worker 20*4d7e907cSAndroid Build Coastguard Worker #include <android-base/result.h> 21*4d7e907cSAndroid Build Coastguard Worker #include <android/hardware/automotive/vehicle/2.0/types.h> 22*4d7e907cSAndroid Build Coastguard Worker 23*4d7e907cSAndroid Build Coastguard Worker #include <functional> 24*4d7e907cSAndroid Build Coastguard Worker #include <memory> 25*4d7e907cSAndroid Build Coastguard Worker 26*4d7e907cSAndroid Build Coastguard Worker namespace android { 27*4d7e907cSAndroid Build Coastguard Worker namespace hardware { 28*4d7e907cSAndroid Build Coastguard Worker namespace automotive { 29*4d7e907cSAndroid Build Coastguard Worker namespace vehicle { 30*4d7e907cSAndroid Build Coastguard Worker namespace V2_0 { 31*4d7e907cSAndroid Build Coastguard Worker 32*4d7e907cSAndroid Build Coastguard Worker namespace user_hal_helper { 33*4d7e907cSAndroid Build Coastguard Worker 34*4d7e907cSAndroid Build Coastguard Worker // Verify whether the |value| can be casted to the type |T| and return the casted value on success. 35*4d7e907cSAndroid Build Coastguard Worker // Otherwise, return the error. 36*4d7e907cSAndroid Build Coastguard Worker template <typename T> 37*4d7e907cSAndroid Build Coastguard Worker android::base::Result<T> verifyAndCast(int32_t value); 38*4d7e907cSAndroid Build Coastguard Worker 39*4d7e907cSAndroid Build Coastguard Worker // Below functions parse VehiclePropValues to the respective User HAL request structs. On success, 40*4d7e907cSAndroid Build Coastguard Worker // these functions return the User HAL struct. Otherwise, they return the error. 41*4d7e907cSAndroid Build Coastguard Worker android::base::Result<InitialUserInfoRequest> toInitialUserInfoRequest( 42*4d7e907cSAndroid Build Coastguard Worker const VehiclePropValue& propValue); 43*4d7e907cSAndroid Build Coastguard Worker android::base::Result<SwitchUserRequest> toSwitchUserRequest(const VehiclePropValue& propValue); 44*4d7e907cSAndroid Build Coastguard Worker android::base::Result<CreateUserRequest> toCreateUserRequest(const VehiclePropValue& propValue); 45*4d7e907cSAndroid Build Coastguard Worker android::base::Result<RemoveUserRequest> toRemoveUserRequest(const VehiclePropValue& propValue); 46*4d7e907cSAndroid Build Coastguard Worker android::base::Result<UserIdentificationGetRequest> toUserIdentificationGetRequest( 47*4d7e907cSAndroid Build Coastguard Worker const VehiclePropValue& propValue); 48*4d7e907cSAndroid Build Coastguard Worker android::base::Result<UserIdentificationSetRequest> toUserIdentificationSetRequest( 49*4d7e907cSAndroid Build Coastguard Worker const VehiclePropValue& propValue); 50*4d7e907cSAndroid Build Coastguard Worker 51*4d7e907cSAndroid Build Coastguard Worker // Below functions convert the User HAL structs to VehiclePropValues. On success, these functions 52*4d7e907cSAndroid Build Coastguard Worker // return the pointer to VehiclePropValue. Otherwise, they return nullptr. 53*4d7e907cSAndroid Build Coastguard Worker std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserRequest& request); 54*4d7e907cSAndroid Build Coastguard Worker std::unique_ptr<VehiclePropValue> toVehiclePropValue(const InitialUserInfoResponse& response); 55*4d7e907cSAndroid Build Coastguard Worker std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserResponse& response); 56*4d7e907cSAndroid Build Coastguard Worker std::unique_ptr<VehiclePropValue> toVehiclePropValue(const CreateUserResponse& response); 57*4d7e907cSAndroid Build Coastguard Worker std::unique_ptr<VehiclePropValue> toVehiclePropValue(const UserIdentificationResponse& response); 58*4d7e907cSAndroid Build Coastguard Worker 59*4d7e907cSAndroid Build Coastguard Worker } // namespace user_hal_helper 60*4d7e907cSAndroid Build Coastguard Worker 61*4d7e907cSAndroid Build Coastguard Worker } // namespace V2_0 62*4d7e907cSAndroid Build Coastguard Worker } // namespace vehicle 63*4d7e907cSAndroid Build Coastguard Worker } // namespace automotive 64*4d7e907cSAndroid Build Coastguard Worker } // namespace hardware 65*4d7e907cSAndroid Build Coastguard Worker } // namespace android 66*4d7e907cSAndroid Build Coastguard Worker 67*4d7e907cSAndroid Build Coastguard Worker #endif // android_hardware_automotive_vehicle_V2_0_impl_UserHalHelper_H_ 68