1 /* 2 * Copyright (C) 2015 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_VEHICLE_NETWORK_PROTO_UTIL_H 18 #define ANDROID_VEHICLE_NETWORK_PROTO_UTIL_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 #include <string.h> 23 24 #include <memory> 25 26 #include <hardware/vehicle.h> 27 28 #include <utils/List.h> 29 #include <utils/RefBase.h> 30 #include <utils/Errors.h> 31 #include <binder/IInterface.h> 32 #include <binder/IMemory.h> 33 #include <binder/Parcel.h> 34 35 #include <VehicleNetworkProto.pb.h> 36 37 namespace android { 38 39 class VehicleNetworkProtoUtil { 40 public: 41 static status_t toVehiclePropValue(const vehicle_prop_value_t& in, 42 VehiclePropValue& out, bool inPlace = false); 43 44 static status_t fromVehiclePropValue(const VehiclePropValue& in, vehicle_prop_value_t& out, 45 bool inPlace = false, bool canIgnoreNoData = false); 46 47 static status_t toVehiclePropValues(const List<vehicle_prop_value_t*>& in, 48 VehiclePropValues& out); 49 50 static status_t fromVehiclePropValues(const VehiclePropValues& in, 51 List<vehicle_prop_value_t*>& out); 52 53 static status_t toVehiclePropConfig(const vehicle_prop_config& in, VehiclePropConfig& out); 54 55 static status_t fromVehiclePropConfig(const VehiclePropConfig& in, vehicle_prop_config& out); 56 57 static status_t toVehiclePropConfigs(List<vehicle_prop_config_t const*> &in, 58 VehiclePropConfigs& out); 59 60 static status_t fromVehiclePropConfigs(const VehiclePropConfigs& in, 61 List<vehicle_prop_config_t const*>& out); 62 }; 63 64 // ---------------------------------------------------------------------------- 65 66 class WritableBlobHolder { 67 public: 68 Parcel::WritableBlob* blob; 69 WritableBlobHolder(Parcel::WritableBlob * aBlob)70 WritableBlobHolder(Parcel::WritableBlob* aBlob) 71 : blob(aBlob) { 72 } 73 ~WritableBlobHolder()74 ~WritableBlobHolder() { 75 if (blob != NULL) { 76 blob->release(); 77 delete blob; 78 } 79 } 80 }; 81 82 // ---------------------------------------------------------------------------- 83 84 // duplicated here is Blob is not public. 85 class ReadableBlobHolder { 86 public: 87 Parcel::ReadableBlob* blob; 88 ReadableBlobHolder(Parcel::ReadableBlob * aBlob)89 ReadableBlobHolder(Parcel::ReadableBlob* aBlob) 90 : blob(aBlob) { 91 } 92 ~ReadableBlobHolder()93 ~ReadableBlobHolder() { 94 if (blob != NULL) { 95 blob->release(); 96 delete blob; 97 } 98 } 99 }; 100 101 class VehiclePropValueBinderUtil { 102 public: 103 static status_t writeToParcel(Parcel& parcel, const vehicle_prop_value_t& value); 104 105 static status_t readFromParcel(const Parcel& parcel, vehicle_prop_value_t* value, 106 bool deleteMembers = true, bool canIgnoreNoData = false); 107 }; 108 109 }; // namespace android 110 111 #endif /* ANDROID_VEHICLE_NETWORK_PROTO_UTIL_H */ 112