Apollo 9.0
自动驾驶开放平台
apollo::cyber::PyServiceUtils类 参考

#include <py_cyber.h>

apollo::cyber::PyServiceUtils 的协作图:

静态 Public 成员函数

static std::vector< std::string > get_active_services (uint8_t sleep_s=2)
 
static std::string get_service_attr (const std::string &service_name, uint8_t sleep_s=2)
 

详细描述

在文件 py_cyber.h 第 515 行定义.

成员函数说明

◆ get_active_services()

static std::vector< std::string > apollo::cyber::PyServiceUtils::get_active_services ( uint8_t  sleep_s = 2)
inlinestatic

在文件 py_cyber.h 第 517 行定义.

517 {
518 auto topology = service_discovery::TopologyManager::Instance();
519 sleep(sleep_s);
520 std::vector<std::string> srv_names;
521 std::vector<RoleAttributes> services;
522 topology->service_manager()->GetServers(&services);
523 if (services.empty()) {
524 AERROR << "no service found.";
525 return srv_names;
526 }
527
528 std::sort(services.begin(), services.end(),
529 [](const RoleAttributes& sa, const RoleAttributes& sb) -> bool {
530 return sa.service_name().compare(sb.service_name()) <= 0;
531 });
532 for (auto& service : services) {
533 srv_names.emplace_back(service.service_name());
534 }
535 return srv_names;
536 }
#define AERROR
Definition log.h:44

◆ get_service_attr()

static std::string apollo::cyber::PyServiceUtils::get_service_attr ( const std::string &  service_name,
uint8_t  sleep_s = 2 
)
inlinestatic

在文件 py_cyber.h 第 538 行定义.

539 {
540 auto topology = service_discovery::TopologyManager::Instance();
541 sleep(sleep_s);
542
543 if (!topology->service_manager()->HasService(service_name)) {
544 AERROR << "no service: " << service_name;
545 return "";
546 }
547
548 std::vector<RoleAttributes> services;
549 topology->service_manager()->GetServers(&services);
550 std::string msgdata;
551 for (auto& service_attr : services) {
552 if (service_attr.service_name() == service_name) {
553 service_attr.SerializeToString(&msgdata);
554 return msgdata;
555 }
556 }
557 return "";
558 }

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