Home | History | Annotate | Download | only in vhal_v2_0
      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>
     37 inline constexpr typename std::underlying_type<ENUM>::type toInt(
     38         ENUM const value) {
     39     return static_cast<typename std::underlying_type<ENUM>::type>(value);
     40 }
     41 
     42 inline constexpr VehiclePropertyType getPropType(int32_t prop) {
     43     return static_cast<VehiclePropertyType>(
     44             prop & toInt(VehiclePropertyType::MASK));
     45 }
     46 
     47 inline constexpr VehiclePropertyGroup getPropGroup(int32_t prop) {
     48     return static_cast<VehiclePropertyGroup>(
     49             prop & toInt(VehiclePropertyGroup::MASK));
     50 }
     51 
     52 inline constexpr VehicleArea getPropArea(int32_t prop) {
     53     return static_cast<VehicleArea>(prop & toInt(VehicleArea::MASK));
     54 }
     55 
     56 inline constexpr bool isGlobalProp(int32_t prop) {
     57     return getPropArea(prop) == VehicleArea::GLOBAL;
     58 }
     59 
     60 inline constexpr bool isSystemProperty(int32_t prop) {
     61     return VehiclePropertyGroup::SYSTEM == getPropGroup(prop);
     62 }
     63 
     64 std::unique_ptr<VehiclePropValue> createVehiclePropValue(
     65     VehiclePropertyType type, size_t vecSize);
     66 
     67 size_t getVehicleRawValueVectorSize(
     68     const VehiclePropValue::RawValue& value, VehiclePropertyType type);
     69 
     70 void copyVehicleRawValue(VehiclePropValue::RawValue* dest,
     71                                 const VehiclePropValue::RawValue& src);
     72 
     73 template<typename T>
     74 void shallowCopyHidlVec(hidl_vec<T>* dest, const hidl_vec<T>& src);
     75 
     76 void shallowCopyHidlStr(hidl_string* dest, const hidl_string& src);
     77 
     78 void shallowCopy(VehiclePropValue* dest, const VehiclePropValue& src);
     79 
     80 }  // namespace V2_0
     81 }  // namespace vehicle
     82 }  // namespace automotive
     83 }  // namespace hardware
     84 }  // namespace android
     85 
     86 #endif // android_hardware_automotive_vehicle_V2_0_VehicleUtils_H_
     87