Apollo 10.0
自动驾驶开放平台
role.h
浏览该文件的文档.
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
17#ifndef CYBER_SERVICE_DISCOVERY_ROLE_ROLE_H_
18#define CYBER_SERVICE_DISCOVERY_ROLE_ROLE_H_
19
20#include <cstdint>
21#include <memory>
22#include <string>
23
24#include "cyber/proto/role_attributes.pb.h"
25
26namespace apollo {
27namespace cyber {
28namespace service_discovery {
29
30class RoleBase;
31using RolePtr = std::shared_ptr<RoleBase>;
33using RoleNodePtr = std::shared_ptr<RoleNode>;
34
35class RoleWriter;
36using RoleWriterPtr = std::shared_ptr<RoleWriter>;
38using RoleReaderPtr = std::shared_ptr<RoleReader>;
39
40class RoleServer;
41using RoleServerPtr = std::shared_ptr<RoleServer>;
43using RoleClientPtr = std::shared_ptr<RoleClient>;
44
45class RoleBase {
46 public:
47 RoleBase();
48 explicit RoleBase(const proto::RoleAttributes& attr,
49 uint64_t timestamp_ns = 0);
50 virtual ~RoleBase() = default;
51
52 virtual bool Match(const proto::RoleAttributes& target_attr) const;
53 bool IsEarlierThan(const RoleBase& other) const;
54
55 const proto::RoleAttributes& attributes() const { return attributes_; }
56 void set_attributes(const proto::RoleAttributes& attr) { attributes_ = attr; }
57
58 uint64_t timestamp_ns() const { return timestamp_ns_; }
60
61 protected:
63 uint64_t timestamp_ns_;
64};
65
66class RoleWriter : public RoleBase {
67 public:
69 explicit RoleWriter(const proto::RoleAttributes& attr,
70 uint64_t timestamp_ns = 0);
71 virtual ~RoleWriter() = default;
72
73 bool Match(const proto::RoleAttributes& target_attr) const override;
74};
75
76class RoleServer : public RoleBase {
77 public:
79 explicit RoleServer(const proto::RoleAttributes& attr,
80 uint64_t timestamp_ns = 0);
81 virtual ~RoleServer() = default;
82
83 bool Match(const proto::RoleAttributes& target_attr) const override;
84};
85
86} // namespace service_discovery
87} // namespace cyber
88} // namespace apollo
89
90#endif // CYBER_SERVICE_DISCOVERY_ROLE_ROLE_H_
virtual bool Match(const proto::RoleAttributes &target_attr) const
Definition role.cc:32
void set_timestamp_ns(uint64_t timestamp_ns)
Definition role.h:59
proto::RoleAttributes attributes_
Definition role.h:62
void set_attributes(const proto::RoleAttributes &attr)
Definition role.h:56
bool IsEarlierThan(const RoleBase &other) const
Definition role.cc:51
const proto::RoleAttributes & attributes() const
Definition role.h:55
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
std::shared_ptr< RoleServer > RoleServerPtr
Definition role.h:41
std::shared_ptr< RoleBase > RolePtr
Definition role.h:31
std::shared_ptr< RoleReader > RoleReaderPtr
Definition role.h:38
std::shared_ptr< RoleClient > RoleClientPtr
Definition role.h:43
std::shared_ptr< RoleNode > RoleNodePtr
Definition role.h:33
std::shared_ptr< RoleWriter > RoleWriterPtr
Definition role.h:36
class register implement
Definition arena_queue.h:37