Apollo 11.0
自动驾驶开放平台
role.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "cyber/common/log.h"
20
21namespace apollo {
22namespace cyber {
23namespace service_discovery {
24
25using proto::RoleAttributes;
26
27RoleBase::RoleBase() : timestamp_ns_(0) {}
28
29RoleBase::RoleBase(const RoleAttributes& attr, uint64_t timestamp_ns)
30 : attributes_(attr), timestamp_ns_(timestamp_ns) {}
31
32bool RoleBase::Match(const RoleAttributes& target_attr) const {
33 if (target_attr.has_node_id() &&
34 target_attr.node_id() != attributes_.node_id()) {
35 return false;
36 }
37
38 if (target_attr.has_process_id() &&
39 target_attr.process_id() != attributes_.process_id()) {
40 return false;
41 }
42
43 if (target_attr.has_host_name() &&
44 target_attr.host_name() != attributes_.host_name()) {
45 return false;
46 }
47
48 return true;
49}
50
51bool RoleBase::IsEarlierThan(const RoleBase& other) const {
52 return timestamp_ns_ < other.timestamp_ns();
53}
54
55RoleWriter::RoleWriter(const RoleAttributes& attr, uint64_t timestamp_ns)
56 : RoleBase(attr, timestamp_ns) {}
57
58bool RoleWriter::Match(const RoleAttributes& target_attr) const {
59 if (target_attr.has_channel_id() &&
60 target_attr.channel_id() != attributes_.channel_id()) {
61 return false;
62 }
63
64 if (target_attr.has_id() && target_attr.id() != attributes_.id()) {
65 return false;
66 }
67
68 return RoleBase::Match(target_attr);
69}
70
71RoleServer::RoleServer(const RoleAttributes& attr, uint64_t timestamp_ns)
72 : RoleBase(attr, timestamp_ns) {}
73
74bool RoleServer::Match(const RoleAttributes& target_attr) const {
75 if (target_attr.has_service_id() &&
76 target_attr.service_id() != attributes_.service_id()) {
77 return false;
78 }
79
80 return RoleBase::Match(target_attr);
81}
82
83} // namespace service_discovery
84} // namespace cyber
85} // namespace apollo
virtual bool Match(const proto::RoleAttributes &target_attr) const
Definition role.cc:32
proto::RoleAttributes attributes_
Definition role.h:62
bool IsEarlierThan(const RoleBase &other) const
Definition role.cc:51
bool Match(const proto::RoleAttributes &target_attr) const override
Definition role.cc:74
bool Match(const proto::RoleAttributes &target_attr) const override
Definition role.cc:58
class register implement
Definition arena_queue.h:37