Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
dfd41c6b
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dfd41c6b
编写于
8月 06, 2019
作者:
muleisheng
提交者:
Calvin Miao
8月 06, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bridge: use shared_ptr to replace pointer
上级
2814c18f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
19 deletion
+37
-19
modules/bridge/common/bridge_proto_diser_buf_factory.h
modules/bridge/common/bridge_proto_diser_buf_factory.h
+5
-3
modules/bridge/common/util.h
modules/bridge/common/util.h
+17
-0
modules/bridge/udp_bridge_multi_receiver_component.cc
modules/bridge/udp_bridge_multi_receiver_component.cc
+12
-14
modules/bridge/udp_bridge_multi_receiver_component.h
modules/bridge/udp_bridge_multi_receiver_component.h
+3
-2
未找到文件。
modules/bridge/common/bridge_proto_diser_buf_factory.h
浏览文件 @
dfd41c6b
...
...
@@ -17,6 +17,7 @@
#pragma once
#include <string>
#include <memory>
#include "modules/bridge/common/bridge_proto_diserialized_buf.h"
#include "modules/canbus/proto/chassis.pb.h"
#include "modules/common/adapters/adapter_gflags.h"
...
...
@@ -26,10 +27,11 @@ namespace bridge {
class
ProtoDiserializedBufBaseFactory
{
public:
static
ProtoDiserializedBufBase
*
CreateObj
(
const
BridgeHeader
&
header
)
{
ProtoDiserializedBufBase
*
obj
=
nullptr
;
static
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
CreateObj
(
const
BridgeHeader
&
header
)
{
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
obj
;
if
(
strcmp
(
"Chassis"
,
header
.
GetMsgName
().
c_str
())
==
0
)
{
obj
=
new
BridgeProtoDiserializedBuf
<
canbus
::
Chassis
>
(
obj
=
std
::
make_shared
<
BridgeProtoDiserializedBuf
<
canbus
::
Chassis
>
>
(
FLAGS_chassis_topic
);
}
return
obj
;
...
...
modules/bridge/common/util.h
浏览文件 @
dfd41c6b
...
...
@@ -59,6 +59,23 @@ bool RemoveItem(std::vector<T *> *list, const T *t) {
}
return
true
;
}
template
<
typename
T
>
bool
RemoveItem
(
std
::
vector
<
std
::
shared_ptr
<
T
>>
*
list
,
std
::
shared_ptr
<
T
>
t
)
{
if
(
!
list
)
{
return
false
;
}
typename
std
::
vector
<
std
::
shared_ptr
<
T
>>::
iterator
itor
=
list
->
begin
();
for
(;
itor
!=
list
->
end
();)
{
if
(
itor
->
get
()
==
t
.
get
())
{
itor
=
list
->
erase
(
itor
);
continue
;
}
++
itor
;
}
return
true
;
}
int
GetProtoSize
(
const
char
*
buf
,
size_t
size
);
}
// namespace bridge
...
...
modules/bridge/udp_bridge_multi_receiver_component.cc
浏览文件 @
dfd41c6b
...
...
@@ -53,22 +53,21 @@ void UDPBridgeMultiReceiverComponent::MsgDispatcher() {
listener_
->
Listen
();
}
ProtoDiserializedBufBase
*
UDPBridgeMultiReceiverComponent
::
CreateBridgeProtoBuf
(
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
UDPBridgeMultiReceiverComponent
::
CreateBridgeProtoBuf
(
const
BridgeHeader
&
header
)
{
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
proto_buf
;
if
(
IsTimeout
(
header
.
GetTimeStamp
()))
{
std
::
vector
<
ProtoDiserializedBufBase
*
>::
iterator
itor
std
::
vector
<
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
>::
iterator
itor
=
proto_list_
.
begin
();
for
(;
itor
!=
proto_list_
.
end
();)
{
if
((
*
itor
)
->
IsTheProto
(
header
))
{
ProtoDiserializedBufBase
*
tmp
=
*
itor
;
FREE_POINTER
(
tmp
);
itor
=
proto_list_
.
erase
(
itor
);
break
;
}
++
itor
;
}
return
nullptr
;
return
proto_buf
;
}
for
(
auto
proto
:
proto_list_
)
{
...
...
@@ -77,10 +76,9 @@ ProtoDiserializedBufBase
}
}
ProtoDiserializedBufBase
*
proto_buf
=
ProtoDiserializedBufBaseFactory
::
CreateObj
(
header
);
proto_buf
=
ProtoDiserializedBufBaseFactory
::
CreateObj
(
header
);
if
(
!
proto_buf
)
{
return
nullptr
;
return
proto_buf
;
}
proto_buf
->
Initialize
(
header
,
node_
);
proto_list_
.
push_back
(
proto_buf
);
...
...
@@ -156,7 +154,8 @@ bool UDPBridgeMultiReceiverComponent::MsgHandle(int fd) {
ADEBUG
<<
"proto frame index: "
<<
header
.
GetIndex
();
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
ProtoDiserializedBufBase
*
proto_buf
=
CreateBridgeProtoBuf
(
header
);
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
proto_buf
=
CreateBridgeProtoBuf
(
header
);
if
(
!
proto_buf
)
{
return
false
;
}
...
...
@@ -178,12 +177,11 @@ bool UDPBridgeMultiReceiverComponent::RemoveInvalidBuf(uint32_t msg_id,
if
(
msg_id
==
0
)
{
return
false
;
}
std
::
vector
<
ProtoDiserializedBufBase
*
>::
iterator
itor
=
std
::
vector
<
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
>::
iterator
itor
=
proto_list_
.
begin
();
for
(;
itor
!=
proto_list_
.
end
();)
{
if
((
*
itor
)
->
GetMsgID
()
<
msg_id
)
{
ProtoDiserializedBufBase
*
tmp
=
*
itor
;
FREE_POINTER
(
tmp
);
if
((
*
itor
)
->
GetMsgID
()
<
msg_id
&&
strcmp
((
*
itor
)
->
GetMsgName
().
c_str
(),
msg_name
.
c_str
())
==
0
)
{
itor
=
proto_list_
.
erase
(
itor
);
continue
;
}
...
...
modules/bridge/udp_bridge_multi_receiver_component.h
浏览文件 @
dfd41c6b
...
...
@@ -46,7 +46,8 @@ class UDPBridgeMultiReceiverComponent final : public cyber::Component<> {
bool
Init
()
override
;
std
::
string
Name
()
const
{
return
FLAGS_bridge_module_name
;
}
ProtoDiserializedBufBase
*
CreateBridgeProtoBuf
(
const
BridgeHeader
&
header
);
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
CreateBridgeProtoBuf
(
const
BridgeHeader
&
header
);
bool
IsProtoExist
(
const
BridgeHeader
&
header
);
bool
IsTimeout
(
double
time_stamp
);
void
MsgDispatcher
();
...
...
@@ -63,7 +64,7 @@ class UDPBridgeMultiReceiverComponent final : public cyber::Component<> {
unsigned
int
bind_port_
=
0
;
bool
enable_timeout_
=
true
;
std
::
mutex
mutex_
;
std
::
vector
<
ProtoDiserializedBufBase
*
>
proto_list_
;
std
::
vector
<
std
::
shared_ptr
<
ProtoDiserializedBufBase
>
>
proto_list_
;
};
}
// namespace bridge
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录