Apollo  6.0
Open source self driving car software
role.h
Go to the documentation of this file.
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 
26 namespace apollo {
27 namespace cyber {
28 namespace service_discovery {
29 
30 class RoleBase;
31 using RolePtr = std::shared_ptr<RoleBase>;
33 using RoleNodePtr = std::shared_ptr<RoleNode>;
34 
35 class RoleWriter;
36 using RoleWriterPtr = std::shared_ptr<RoleWriter>;
38 using RoleReaderPtr = std::shared_ptr<RoleReader>;
39 
40 class RoleServer;
41 using RoleServerPtr = std::shared_ptr<RoleServer>;
43 using RoleClientPtr = std::shared_ptr<RoleClient>;
44 
45 class 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:
62  proto::RoleAttributes attributes_;
63  uint64_t timestamp_ns_;
64 };
65 
66 class 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 
76 class 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_
std::shared_ptr< RoleWriter > RoleWriterPtr
Definition: role.h:36
uint64_t timestamp_ns() const
Definition: role.h:58
std::shared_ptr< RoleServer > RoleServerPtr
Definition: role.h:41
virtual bool Match(const proto::RoleAttributes &target_attr) const
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool IsEarlierThan(const RoleBase &other) const
std::shared_ptr< RoleNode > RoleNodePtr
Definition: role.h:33
void set_attributes(const proto::RoleAttributes &attr)
Definition: role.h:56
std::shared_ptr< RoleBase > RolePtr
Definition: role.h:31
const proto::RoleAttributes & attributes() const
Definition: role.h:55
std::shared_ptr< RoleReader > RoleReaderPtr
Definition: role.h:38
proto::RoleAttributes attributes_
Definition: role.h:62
uint64_t timestamp_ns_
Definition: role.h:63
void set_timestamp_ns(uint64_t timestamp_ns)
Definition: role.h:59
std::shared_ptr< RoleClient > RoleClientPtr
Definition: role.h:43