Apollo  6.0
Open source self driving car software
transmitter.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_TRANSPORT_TRANSMITTER_TRANSMITTER_H_
18 #define CYBER_TRANSPORT_TRANSMITTER_TRANSMITTER_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 
27 
28 namespace apollo {
29 namespace cyber {
30 namespace transport {
31 
34 
35 template <typename M>
36 class Transmitter : public Endpoint {
37  public:
38  using MessagePtr = std::shared_ptr<M>;
39 
40  explicit Transmitter(const RoleAttributes& attr);
41  virtual ~Transmitter();
42 
43  virtual void Enable() = 0;
44  virtual void Disable() = 0;
45 
46  virtual void Enable(const RoleAttributes& opposite_attr);
47  virtual void Disable(const RoleAttributes& opposite_attr);
48 
49  virtual bool Transmit(const MessagePtr& msg);
50  virtual bool Transmit(const MessagePtr& msg, const MessageInfo& msg_info) = 0;
51 
52  uint64_t NextSeqNum() { return ++seq_num_; }
53 
54  uint64_t seq_num() const { return seq_num_; }
55 
56  protected:
57  uint64_t seq_num_;
59 };
60 
61 template <typename M>
62 Transmitter<M>::Transmitter(const RoleAttributes& attr)
63  : Endpoint(attr), seq_num_(0) {
66 }
67 
68 template <typename M>
70 
71 template <typename M>
74  PerfEventCache::Instance()->AddTransportEvent(
75  TransPerf::TRANSMIT_BEGIN, attr_.channel_id(), msg_info_.seq_num());
76  return Transmit(msg, msg_info_);
77 }
78 
79 template <typename M>
80 void Transmitter<M>::Enable(const RoleAttributes& opposite_attr) {
81  (void)opposite_attr;
82  Enable();
83 }
84 
85 template <typename M>
86 void Transmitter<M>::Disable(const RoleAttributes& opposite_attr) {
87  (void)opposite_attr;
88  Disable();
89 }
90 
91 } // namespace transport
92 } // namespace cyber
93 } // namespace apollo
94 
95 #endif // CYBER_TRANSPORT_TRANSMITTER_TRANSMITTER_H_
void set_sender_id(const Identity &sender_id)
Definition: message_info.h:50
virtual ~Transmitter()
Definition: transmitter.h:69
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Transmitter(const RoleAttributes &attr)
Definition: transmitter.h:62
MessageInfo msg_info_
Definition: transmitter.h:58
uint64_t seq_num() const
Definition: transmitter.h:54
uint64_t NextSeqNum()
Definition: transmitter.h:52
RoleAttributes attr_
Definition: endpoint.h:47
std::shared_ptr< M > MessagePtr
Definition: transmitter.h:38
void set_seq_num(uint64_t seq_num)
Definition: message_info.h:56
uint64_t seq_num() const
Definition: message_info.h:55
uint64_t seq_num_
Definition: transmitter.h:57
Definition: message_info.h:30
TransPerf
Definition: perf_event.h:34
Definition: perf_event_cache.h:36
Identity id_
Definition: endpoint.h:46
virtual bool Transmit(const MessagePtr &msg)
Definition: transmitter.h:72
Definition: transmitter.h:36
Definition: endpoint.h:36