Apollo 10.0
自动驾驶开放平台
apollo::hdmap::ChannelChecker类 参考

#include <client_channel_checker.h>

apollo::hdmap::ChannelChecker 的协作图:

Public 成员函数

 ChannelChecker (const std::string &stop_flag_file)
 
int SyncStart (const std::string &record_path)
 
int SyncStop ()
 
int PeriodicCheck ()
 
int GrpcStub (ChannelVerifyRequest *request, ChannelVerifyResponse *response)
 

详细描述

在文件 client_channel_checker.h27 行定义.

构造及析构函数说明

◆ ChannelChecker()

apollo::hdmap::ChannelChecker::ChannelChecker ( const std::string &  stop_flag_file)
explicit

在文件 client_channel_checker.cc37 行定义.

38 : stop_flag_file_(stop_flag_file) {
39 YAML::Node node = YAML::LoadFile(FLAGS_client_conf_yaml);
40 std::string server_addr =
41 node["grpc_host_port"]["grpc_host"].as<std::string>() + ":" +
42 node["grpc_host_port"]["grpc_port"].as<std::string>();
43 check_period_ = node["channel_check"]["check_period"].as<int>();
44 service_stub_ = CollectionCheckerService::NewStub(
45 grpc::CreateChannel(server_addr, grpc::InsecureChannelCredentials()));
46}

成员函数说明

◆ GrpcStub()

int apollo::hdmap::ChannelChecker::GrpcStub ( ChannelVerifyRequest request,
ChannelVerifyResponse response 
)

在文件 client_channel_checker.cc91 行定义.

92 {
93 grpc::ClientContext context;
94 grpc::Status status;
95 status = service_stub_->ServiceChannelVerify(&context, *request, response);
96 if (status.error_code() == grpc::StatusCode::UNAVAILABLE) {
97 AERROR << "FATAL Error. Map grpc service is UNAVAILABLE.";
98 fprintf(USER_STREAM, "You should start server first\n");
99 return -1;
100 }
101 ErrorCode error_code = response->code();
102 if (error_code != ErrorCode::SUCCESS) {
103 return ExceptionHandler::ExceptionHandlerFun(error_code);
104 }
105 return 0;
106}
static int ExceptionHandlerFun(ErrorCode error_code)
#define USER_STREAM
#define AERROR
Definition log.h:44

◆ PeriodicCheck()

int apollo::hdmap::ChannelChecker::PeriodicCheck ( )

在文件 client_channel_checker.cc73 行定义.

73 {
74 int ret = 0;
75 while (!boost::filesystem::exists(stop_flag_file_)) {
76 ret = Check();
77 if (ret != 0) {
78 break;
79 }
80 AINFO << "channel checker sleep " << check_period_ << " seconds";
81 std::this_thread::sleep_for(std::chrono::seconds(check_period_));
82 }
83 if (ret == 0) {
84 AINFO << "detected stop flag file, periodically checking will exit";
85 } else {
86 AINFO << "periodically checking will exit because of some errors";
87 }
88 return ret;
89}
#define AINFO
Definition log.h:42

◆ SyncStart()

int apollo::hdmap::ChannelChecker::SyncStart ( const std::string &  record_path)

在文件 client_channel_checker.cc48 行定义.

48 {
49 if (!boost::filesystem::exists(record_path)) {
50 AERROR << "record_path [" << record_path << "]does not exist";
51 return -1;
52 }
53 int ret = Start(record_path);
54 if (ret != 0) {
55 AERROR << "start check channel failed, record_path [" << record_path << "]";
56 return -1;
57 }
58 return PeriodicCheck();
59}

◆ SyncStop()

int apollo::hdmap::ChannelChecker::SyncStop ( )

在文件 client_channel_checker.cc61 行定义.

61 {
62 // stop client
63 std::ofstream ofs(stop_flag_file_);
64 if (!ofs) {
65 AERROR << "Create Flag File [" << stop_flag_file_ << "] Failed";
66 return -1;
67 }
68 ofs.close();
69 // stop server
70 return Stop();
71}

该类的文档由以下文件生成: