summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehiclePropConfigIndex.h')
-rw-r--r--automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehiclePropConfigIndex.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehiclePropConfigIndex.h b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehiclePropConfigIndex.h
new file mode 100644
index 00000000..0528f687
--- /dev/null
+++ b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehiclePropConfigIndex.h
@@ -0,0 +1,80 @@
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_VehiclePropConfigIndex_H_
18#define android_hardware_automotive_vehicle_V2_0_VehiclePropConfigIndex_H_
19
20#include <utils/KeyedVector.h>
21
22#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
23
24namespace android {
25namespace hardware {
26namespace automotive {
27namespace vehicle {
28namespace V2_0 {
29
30/*
31 * This is thread-safe immutable class to hold vehicle property configuration
32 * data.
33 */
34class VehiclePropConfigIndex {
35public:
36 VehiclePropConfigIndex(
37 const std::vector<VehiclePropConfig>& properties)
38 : mConfigs(properties), mPropToConfig(mConfigs)
39 {}
40
41 bool hasConfig(int32_t property) const {
42 return mPropToConfig.indexOfKey(property) >= 0;
43 }
44
45 const VehiclePropConfig& getConfig(int32_t property) const {
46 return *mPropToConfig.valueFor(property);
47 }
48
49 const std::vector<VehiclePropConfig>& getAllConfigs() const {
50 return mConfigs;
51 }
52
53private:
54 typedef KeyedVector<int32_t, const VehiclePropConfig*> PropConfigMap;
55 class ImmutablePropConfigMap : private PropConfigMap {
56 public:
57 ImmutablePropConfigMap(const std::vector<VehiclePropConfig>& configs) {
58 setCapacity(configs.size());
59 for (auto& config : configs) {
60 add(config.prop, &config);
61 }
62 }
63 public:
64 using PropConfigMap::valueFor;
65 using PropConfigMap::indexOfKey;
66 };
67
68private:
69 const std::vector<VehiclePropConfig> mConfigs;
70 const ImmutablePropConfigMap mPropToConfig; // mConfigs must be declared
71 // first.
72};
73
74} // namespace V2_0
75} // namespace vehicle
76} // namespace automotive
77} // namespace hardware
78} // namespace android
79
80#endif // android_hardware_automotive_vehicle_V2_0_VehiclePropConfigIndex_H_