1 /* 2 * Copyright (C) 2018 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_impl_JsonFakeValueGenerator_H_ 18 #define android_hardware_automotive_vehicle_V2_0_impl_JsonFakeValueGenerator_H_ 19 20 #include <chrono> 21 #include <iostream> 22 23 #include <json/json.h> 24 25 #include "FakeValueGenerator.h" 26 27 namespace android { 28 namespace hardware { 29 namespace automotive { 30 namespace vehicle { 31 namespace V2_0 { 32 33 namespace impl { 34 35 class JsonFakeValueGenerator : public FakeValueGenerator { 36 private: 37 struct GeneratorCfg { 38 size_t index; 39 std::vector<VehiclePropValue> events; 40 }; 41 42 public: 43 JsonFakeValueGenerator(const VehiclePropValue& request); 44 JsonFakeValueGenerator(std::string path); 45 46 ~JsonFakeValueGenerator() = default; 47 48 VehiclePropValue nextEvent(); 49 std::vector<VehiclePropValue> getAllEvents(); 50 51 bool hasNext(); 52 53 private: 54 std::vector<VehiclePropValue> parseFakeValueJson(std::istream& is); 55 void copyMixedValueJson(VehiclePropValue::RawValue& dest, const Json::Value& jsonValue); 56 57 template <typename T> 58 void copyJsonArray(hidl_vec<T>& dest, const Json::Value& jsonArray); 59 60 bool isDiagnosticProperty(int32_t prop); 61 hidl_vec<uint8_t> generateDiagnosticBytes(const VehiclePropValue::RawValue& diagnosticValue); 62 void setBit(hidl_vec<uint8_t>& bytes, size_t idx); 63 64 private: 65 GeneratorCfg mGenCfg; 66 int32_t mNumOfIterations; 67 }; 68 69 } // namespace impl 70 71 } // namespace V2_0 72 } // namespace vehicle 73 } // namespace automotive 74 } // namespace hardware 75 } // namespace android 76 77 #endif // android_hardware_automotive_vehicle_V2_0_impl_JsonFakeValueGenerator_H_ 78