19#include "absl/strings/str_cat.h"
20#include "gflags/gflags.h"
21#include "google/protobuf/descriptor.h"
22#include "google/protobuf/message.h"
23#include "google/protobuf/util/json_util.h"
37using google::protobuf::util::MessageToJsonString;
39using Json = nlohmann::json;
43 node_(cyber::CreateNode(
"progress_monitor")) {
50 task_name_(task_name),
51 node_(cyber::CreateNode(task_name +
"_progress_monitor")) {
58void PreprocessMonitor::InitReaders() {
60 FLAGS_progress_topic, [
this](
const std::shared_ptr<Progress>& progress) {
61 this->OnProgress(progress);
65void PreprocessMonitor::LoadConfiguration() {
66 if (!task_name_.empty()) {
67 const std::string& vehicle_dir =
68 VehicleManager::Instance()->GetVehicleDataPath();
69 std::string config_path = absl::StrCat(
70 vehicle_dir,
"dreamview_conf/", task_name_,
"_preprocess_table.pb.txt");
71 if (!PathExists(config_path)) {
72 AWARN <<
"No corresponding preprocess table file found in " << vehicle_dir
73 <<
". Using default one instead.";
74 config_path = absl::StrCat(
"modules/dreamview/conf/", task_name_,
75 "_preprocess_table.pb.txt");
79 <<
"Unable to parse preprocess configuration from file " << config_path;
81 auto* progress = preprocess_table_.mutable_progress();
82 progress->set_percentage(0.0);
83 progress->set_log_string(
"Click on the button to start preprocessing");
86 std::string json_string;
87 MessageToJsonString(preprocess_table_, &json_string);
88 current_status_json_ = Json::parse(json_string);
90 ADEBUG <<
"Configuration loaded.";
95 current_status_json_.clear();
103void PreprocessMonitor::OnProgress(
const std::shared_ptr<Progress>& progress) {
108 std::string json_string;
109 MessageToJsonString(*progress, &json_string);
111 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
112 current_status_json_[
"progress"] = Json::parse(json_string);
117 boost::unique_lock<boost::shared_mutex> reader_lock(mutex_);
118 return current_status_json_;
@Brief This is a helper class that can load vehicle configurations.
A base class that monitor progress for Fuel client
nlohmann::json GetProgressAsJson() override
return preprocess progress as json
void Stop() override
stop monitoring preprocess progress
PreprocessMonitor()
Constructor of PreprocessMonitor.
void Start() override
start monitoring preprocess progress
bool PathExists(const std::string &path)
Check if the path exists.
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,...