blob: fad71451aab0b3c5c7ba958e4064700da65e42f9 [file] [log] [blame]
Lakshman Annadoraib33e2ab2020-07-27 10:42:32 -07001/*
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
26namespace android {
27namespace hardware {
28namespace automotive {
29namespace vehicle {
30namespace V2_0 {
31
32namespace user_hal_helper {
33
Lakshman Annadoraibfdb1ac2020-08-06 14:25:03 -070034// Verify whether the |value| can be casted to the type |T| and return the casted value on success.
35// Otherwise, return the error.
36template <typename T>
37android::base::Result<T> verifyAndCast(int32_t value);
38
Lakshman Annadoraib33e2ab2020-07-27 10:42:32 -070039// 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.
41android::base::Result<InitialUserInfoRequest> toInitialUserInfoRequest(
42 const VehiclePropValue& propValue);
43android::base::Result<SwitchUserRequest> toSwitchUserRequest(const VehiclePropValue& propValue);
44android::base::Result<CreateUserRequest> toCreateUserRequest(const VehiclePropValue& propValue);
45android::base::Result<RemoveUserRequest> toRemoveUserRequest(const VehiclePropValue& propValue);
46android::base::Result<UserIdentificationGetRequest> toUserIdentificationGetRequest(
47 const VehiclePropValue& propValue);
48android::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.
53std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserRequest& request);
54std::unique_ptr<VehiclePropValue> toVehiclePropValue(const InitialUserInfoResponse& response);
55std::unique_ptr<VehiclePropValue> toVehiclePropValue(const SwitchUserResponse& response);
56std::unique_ptr<VehiclePropValue> toVehiclePropValue(const CreateUserResponse& response);
57std::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_