21#include "absl/strings/str_cat.h"
33VehicleManager::VehicleManager() {
35 <<
"Unable to parse VehicleData config file "
36 << FLAGS_vehicle_data_config_filename;
40 return vehicle_data_path_;
44 if (FLAGS_vehicle_changed_use_copy_mode) {
45 return UseVehicleUseCopyMode(vehicle_data_path);
47 return UseVehicleUseSymlinkMode(vehicle_data_path);
51bool VehicleManager::UseVehicleUseCopyMode(
52 const std::string &vehicle_data_path) {
54 AERROR <<
"Cannot find vehicle data: " << vehicle_data_path;
57 vehicle_data_path_ = vehicle_data_path;
59 for (
const auto &data_file : vehicle_data_.data_files()) {
60 const auto source_path =
61 absl::StrCat(vehicle_data_path,
"/", data_file.source_path());
62 const auto &dest_path = data_file.dest_path();
65 AINFO_IF(ret) <<
"Copied " << source_path <<
" to " << dest_path;
67 AINFO <<
"Use vehice [" << vehicle_data_path <<
"] copy config successfully.";
75bool VehicleManager::UseVehicleUseSymlinkMode(
76 const std::string &vehicle_data_path) {
77 std::string vehicle_type = vehicle_data_path;
78 auto pos = vehicle_data_path.find_last_of(
'/');
79 if (pos != std::string::npos) {
80 vehicle_type = vehicle_data_path.substr(pos + 1);
82 std::string cmd =
"aem profile use " + vehicle_type;
83 AINFO <<
"Use vehicle by cmd: " << cmd;
84 const int ret = std::system(cmd.data());
86 AINFO <<
"SUCCESS: use vehicle " << vehicle_type;
92 AERROR <<
"FAILED: use vehicle " << vehicle_type;
static void Init()
Initialize vehicle configurations with default configuration file pointed by gflags FLAGS_vehicle_con...
bool UseVehicle(const std::string &vehicle_data_path)
const std::string & GetVehicleDataPath() const
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
bool Copy(const std::string &from, const std::string &to)
Copy a file or directory.
bool DirectoryExists(const std::string &directory_path)
Check if the directory specified by directory_path exists and is indeed a directory.