1 /* 2 * Copyright 2020 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 <android-base/logging.h> 18 19 #include "CarModelConfigReader.h" 20 #include "ConfigReader.h" 21 #include "IOModule.h" 22 #include "ObjReader.h" 23 24 namespace android { 25 namespace hardware { 26 namespace automotive { 27 namespace sv { 28 namespace V1_0 { 29 namespace implementation { 30 IOModule(const std::string & svConfigFile)31IOModule::IOModule(const std::string& svConfigFile) : 32 mSvConfigFile(svConfigFile), mIsInitialized(false) {} 33 initialize()34IOStatus IOModule::initialize() { 35 if (mIsInitialized) { 36 LOG(INFO) << "IOModule is already initialized."; 37 return IOStatus::OK; 38 } 39 40 SurroundViewConfig svConfig; 41 IOStatus status; 42 if ((status = ReadSurroundViewConfig(mSvConfigFile, &svConfig)) != IOStatus::OK) { 43 LOG(ERROR) << "ReadSurroundViewConfig() failed."; 44 return status; 45 } 46 47 mIOModuleConfig.cameraConfig = svConfig.cameraConfig; 48 mIOModuleConfig.sv2dConfig = svConfig.sv2dConfig; 49 mIOModuleConfig.sv3dConfig = svConfig.sv3dConfig; 50 51 if (mIOModuleConfig.sv3dConfig.sv3dEnabled) { 52 // Read obj and mtl files. 53 if (!ReadObjFromFile(svConfig.sv3dConfig.carModelObjFile, 54 &mIOModuleConfig.carModelConfig.carModel.partsMap)) { 55 LOG(ERROR) << "ReadObjFromFile() failed."; 56 return IOStatus::ERROR_READ_CAR_MODEL; 57 } 58 // Read animations. 59 if (mIOModuleConfig.sv3dConfig.sv3dAnimationsEnabled) { 60 if ((status = ReadCarModelConfig(svConfig.sv3dConfig.carModelConfigFile, 61 &mIOModuleConfig.carModelConfig.animationConfig)) != 62 IOStatus::OK) { 63 LOG(ERROR) << "ReadObjFromFile() failed."; 64 return status; 65 } 66 } 67 } 68 mIsInitialized = true; 69 return IOStatus::OK; 70 } 71 getConfig(IOModuleConfig * ioModuleConfig)72bool IOModule::getConfig(IOModuleConfig* ioModuleConfig) { 73 if (!mIsInitialized) { 74 LOG(ERROR) << "IOModule not initalized."; 75 return false; 76 } 77 *ioModuleConfig = mIOModuleConfig; 78 return true; 79 } 80 81 } // namespace implementation 82 } // namespace V1_0 83 } // namespace sv 84 } // namespace automotive 85 } // namespace hardware 86 } // namespace android 87