Apollo 10.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.h516 行定义.

成员函数说明

◆ get_active_services()

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

在文件 py_cyber.h518 行定义.

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

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

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