• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_automotive_vehicle_V2_0_VehicleUtils_H_
18 #define android_hardware_automotive_vehicle_V2_0_VehicleUtils_H_
19 
20 #include <memory>
21 
22 #include <hidl/HidlSupport.h>
23 
24 #include <android/hardware/automotive/vehicle/2.0/types.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace automotive {
29 namespace vehicle {
30 namespace V2_0 {
31 
32 /** Represents all supported areas for a property. Can be used is  */
33 constexpr int32_t kAllSupportedAreas = 0;
34 
35 /** Returns underlying (integer) value for given enum. */
36 template<typename ENUM, typename U = typename std::underlying_type<ENUM>::type>
toInt(ENUM const value)37 inline constexpr U toInt(ENUM const value) {
38     return static_cast<U>(value);
39 }
40 
getPropType(int32_t prop)41 inline constexpr VehiclePropertyType getPropType(int32_t prop) {
42     return static_cast<VehiclePropertyType>(
43             prop & toInt(VehiclePropertyType::MASK));
44 }
45 
getPropGroup(int32_t prop)46 inline constexpr VehiclePropertyGroup getPropGroup(int32_t prop) {
47     return static_cast<VehiclePropertyGroup>(
48             prop & toInt(VehiclePropertyGroup::MASK));
49 }
50 
getPropArea(int32_t prop)51 inline constexpr VehicleArea getPropArea(int32_t prop) {
52     return static_cast<VehicleArea>(prop & toInt(VehicleArea::MASK));
53 }
54 
isGlobalProp(int32_t prop)55 inline constexpr bool isGlobalProp(int32_t prop) {
56     return getPropArea(prop) == VehicleArea::GLOBAL;
57 }
58 
isSystemProperty(int32_t prop)59 inline constexpr bool isSystemProperty(int32_t prop) {
60     return VehiclePropertyGroup::SYSTEM == getPropGroup(prop);
61 }
62 
63 std::unique_ptr<VehiclePropValue> createVehiclePropValue(
64     VehiclePropertyType type, size_t vecSize);
65 
66 size_t getVehicleRawValueVectorSize(
67     const VehiclePropValue::RawValue& value, VehiclePropertyType type);
68 
69 void copyVehicleRawValue(VehiclePropValue::RawValue* dest,
70                                 const VehiclePropValue::RawValue& src);
71 
72 template<typename T>
73 void shallowCopyHidlVec(hidl_vec<T>* dest, const hidl_vec<T>& src);
74 
75 void shallowCopyHidlStr(hidl_string* dest, const hidl_string& src);
76 
77 void shallowCopy(VehiclePropValue* dest, const VehiclePropValue& src);
78 
79 }  // namespace V2_0
80 }  // namespace vehicle
81 }  // namespace automotive
82 }  // namespace hardware
83 }  // namespace android
84 
85 #endif // android_hardware_automotive_vehicle_V2_0_VehicleUtils_H_
86