Apollo
10.0
自动驾驶开放平台
intra_transmitter.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_TRANSPORT_TRANSMITTER_INTRA_TRANSMITTER_H_
18
#define CYBER_TRANSPORT_TRANSMITTER_INTRA_TRANSMITTER_H_
19
20
#include <memory>
21
#include <string>
22
23
#include "
cyber/common/log.h
"
24
#include "
cyber/transport/dispatcher/intra_dispatcher.h
"
25
#include "
cyber/transport/transmitter/transmitter.h
"
26
27
namespace
apollo
{
28
namespace
cyber {
29
namespace
transport {
30
31
template
<
typename
M>
32
class
IntraTransmitter
:
public
Transmitter
<M> {
33
public
:
34
using
MessagePtr
= std::shared_ptr<M>;
35
36
explicit
IntraTransmitter
(
const
RoleAttributes
& attr);
37
virtual
~IntraTransmitter
();
38
39
void
Enable
()
override
;
40
void
Disable
()
override
;
41
42
void
Enable
(
const
RoleAttributes
& opposite_attr)
override
;
43
void
Disable
(
const
RoleAttributes
& opposite_attr)
override
;
44
45
bool
Transmit
(
const
MessagePtr
& msg,
const
MessageInfo
& msg_info)
override
;
46
47
bool
AcquireMessage
(std::shared_ptr<M>& msg);
48
49
private
:
50
uint64_t channel_id_;
51
IntraDispatcherPtr
dispatcher_;
52
};
53
54
template
<
typename
M>
55
bool
IntraTransmitter<M>::AcquireMessage
(std::shared_ptr<M>& msg) {
56
return
false
;
57
}
58
59
template
<
typename
M>
60
IntraTransmitter<M>::IntraTransmitter
(
const
RoleAttributes
& attr)
61
:
Transmitter
<M>(attr),
62
channel_id_(attr.channel_id()),
63
dispatcher_(nullptr) {}
64
65
template
<
typename
M>
66
IntraTransmitter<M>::~IntraTransmitter
() {
67
Disable();
68
}
69
70
template
<
typename
M>
71
void
IntraTransmitter<M>::Enable
(
const
RoleAttributes
& opposite_attr) {
72
(void)opposite_attr;
73
this->Enable();
74
}
75
76
template
<
typename
M>
77
void
IntraTransmitter<M>::Disable
(
const
RoleAttributes
& opposite_attr) {
78
(void)opposite_attr;
79
this->Disable();
80
}
81
82
template
<
typename
M>
83
void
IntraTransmitter<M>::Enable
() {
84
if
(!this->enabled_) {
85
dispatcher_ = IntraDispatcher::Instance();
86
this->enabled_ =
true
;
87
}
88
}
89
90
template
<
typename
M>
91
void
IntraTransmitter<M>::Disable
() {
92
if
(this->enabled_) {
93
dispatcher_ =
nullptr
;
94
this->enabled_ =
false
;
95
}
96
}
97
98
template
<
typename
M>
99
bool
IntraTransmitter<M>::Transmit
(
const
MessagePtr
& msg,
100
const
MessageInfo
& msg_info) {
101
if
(!this->enabled_) {
102
ADEBUG
<<
"not enable."
;
103
return
false
;
104
}
105
106
dispatcher_->OnMessage(channel_id_, msg, msg_info);
107
return
true
;
108
}
109
110
}
// namespace transport
111
}
// namespace cyber
112
}
// namespace apollo
113
114
#endif
// CYBER_TRANSPORT_TRANSMITTER_INTRA_TRANSMITTER_H_
apollo::cyber::transport::IntraDispatcher
Definition
intra_dispatcher.h:253
apollo::cyber::transport::IntraTransmitter
Definition
intra_transmitter.h:32
apollo::cyber::transport::IntraTransmitter::IntraTransmitter
IntraTransmitter(const RoleAttributes &attr)
Definition
intra_transmitter.h:60
apollo::cyber::transport::IntraTransmitter::Transmit
bool Transmit(const MessagePtr &msg, const MessageInfo &msg_info) override
Definition
intra_transmitter.h:99
apollo::cyber::transport::IntraTransmitter::AcquireMessage
bool AcquireMessage(std::shared_ptr< M > &msg)
Definition
intra_transmitter.h:55
apollo::cyber::transport::IntraTransmitter::Disable
void Disable() override
Definition
intra_transmitter.h:91
apollo::cyber::transport::IntraTransmitter::MessagePtr
std::shared_ptr< M > MessagePtr
Definition
intra_transmitter.h:34
apollo::cyber::transport::IntraTransmitter::~IntraTransmitter
virtual ~IntraTransmitter()
Definition
intra_transmitter.h:66
apollo::cyber::transport::IntraTransmitter::Enable
void Enable() override
Definition
intra_transmitter.h:83
apollo::cyber::transport::MessageInfo
Definition
message_info.h:30
apollo::cyber::transport::Transmitter
Definition
transmitter.h:37
intra_dispatcher.h
log.h
ADEBUG
#define ADEBUG
Definition
log.h:41
apollo
class register implement
Definition
arena_queue.h:37
apollo::cyber::proto::RoleAttributes
Definition
role_attributes.proto:12
transmitter.h
cyber
transport
transmitter
intra_transmitter.h