1 /*
2  * Copyright (c) 2022, 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 #include "HidlHalPropValue.h"
18 
19 namespace android {
20 namespace frameworks {
21 namespace automotive {
22 namespace vhal {
23 
24 using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus;
25 using ::android::hardware::automotive::vehicle::V2_0::VehiclePropValue;
26 
HidlHalPropValue(int32_t propId)27 HidlHalPropValue::HidlHalPropValue(int32_t propId) {
28     mPropValue = {};
29     mPropValue.prop = propId;
30 }
31 
HidlHalPropValue(int32_t propId,int32_t areaId)32 HidlHalPropValue::HidlHalPropValue(int32_t propId, int32_t areaId) {
33     mPropValue = {};
34     mPropValue.prop = propId;
35     mPropValue.areaId = areaId;
36 }
37 
HidlHalPropValue(VehiclePropValue && value)38 HidlHalPropValue::HidlHalPropValue(VehiclePropValue&& value) {
39     mPropValue = std::move(value);
40 }
41 
getPropId() const42 int32_t HidlHalPropValue::getPropId() const {
43     return mPropValue.prop;
44 }
45 
getAreaId() const46 int32_t HidlHalPropValue::getAreaId() const {
47     return mPropValue.areaId;
48 }
49 
getTimestamp() const50 int64_t HidlHalPropValue::getTimestamp() const {
51     return mPropValue.timestamp;
52 }
53 
getStatus() const54 VehiclePropertyStatus HidlHalPropValue::getStatus() const {
55     return static_cast<VehiclePropertyStatus>(mPropValue.status);
56 }
57 
setInt32Values(const std::vector<int32_t> & values)58 void HidlHalPropValue::setInt32Values(const std::vector<int32_t>& values) {
59     mPropValue.value.int32Values = values;
60 }
61 
getInt32Values() const62 std::vector<int32_t> HidlHalPropValue::getInt32Values() const {
63     return mPropValue.value.int32Values;
64 }
65 
setInt64Values(const std::vector<int64_t> & values)66 void HidlHalPropValue::setInt64Values(const std::vector<int64_t>& values) {
67     mPropValue.value.int64Values = values;
68 }
69 
getInt64Values() const70 std::vector<int64_t> HidlHalPropValue::getInt64Values() const {
71     return mPropValue.value.int64Values;
72 }
73 
setFloatValues(const std::vector<float> & values)74 void HidlHalPropValue::setFloatValues(const std::vector<float>& values) {
75     mPropValue.value.floatValues = values;
76 }
77 
getFloatValues() const78 std::vector<float> HidlHalPropValue::getFloatValues() const {
79     return mPropValue.value.floatValues;
80 }
81 
setByteValues(const std::vector<uint8_t> & values)82 void HidlHalPropValue::setByteValues(const std::vector<uint8_t>& values) {
83     mPropValue.value.bytes = values;
84 }
85 
getByteValues() const86 std::vector<uint8_t> HidlHalPropValue::getByteValues() const {
87     return mPropValue.value.bytes;
88 }
89 
setStringValue(const std::string & value)90 void HidlHalPropValue::setStringValue(const std::string& value) {
91     mPropValue.value.stringValue = value;
92 }
93 
getStringValue() const94 std::string HidlHalPropValue::getStringValue() const {
95     return mPropValue.value.stringValue;
96 }
97 
toVehiclePropValue() const98 const void* HidlHalPropValue::toVehiclePropValue() const {
99     return &mPropValue;
100 }
101 
clone() const102 std::unique_ptr<IHalPropValue> HidlHalPropValue::clone() const {
103     auto propValueCopy = mPropValue;
104     return std::make_unique<HidlHalPropValue>(std::move(propValueCopy));
105 }
106 
107 }  // namespace vhal
108 }  // namespace automotive
109 }  // namespace frameworks
110 }  // namespace android
111