Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
44046321
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,发现更多精彩内容 >>
提交
44046321
编写于
5月 18, 2019
作者:
muleisheng
提交者:
Calvin Miao
5月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bridge: improve bridge buffer as a template class and clean code
上级
085e1d3d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
16 deletion
+26
-16
modules/bridge/common/bridge_buffer.cc
modules/bridge/common/bridge_buffer.cc
+21
-7
modules/bridge/common/bridge_buffer.h
modules/bridge/common/bridge_buffer.h
+3
-2
modules/bridge/common/bridge_buffer_test.cc
modules/bridge/common/bridge_buffer_test.cc
+1
-1
modules/bridge/udp_bridge_component.cc
modules/bridge/udp_bridge_component.cc
+0
-5
modules/bridge/udp_bridge_component.h
modules/bridge/udp_bridge_component.h
+1
-1
未找到文件。
modules/bridge/common/bridge_buffer.cc
浏览文件 @
44046321
...
...
@@ -20,12 +20,19 @@
namespace
apollo
{
namespace
bridge
{
BridgeBuffer
::
BridgeBuffer
()
{}
BridgeBuffer
::
BridgeBuffer
(
unsigned
int
size
)
{
#define BRIDGE_IMPL(type) \
template class BridgeBuffer<type>
template
<
typename
T
>
BridgeBuffer
<
T
>::
BridgeBuffer
()
{}
template
<
typename
T
>
BridgeBuffer
<
T
>::
BridgeBuffer
(
unsigned
int
size
)
{
reset
(
size
);
}
BridgeBuffer
::~
BridgeBuffer
()
{
template
<
typename
T
>
BridgeBuffer
<
T
>::~
BridgeBuffer
()
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex_
);
if
(
buf_
)
{
delete
[]
buf_
;
...
...
@@ -35,22 +42,29 @@ BridgeBuffer::~BridgeBuffer() {
capacity_
=
0
;
}
BridgeBuffer
::
operator
char
*
()
{
template
<
typename
T
>
BridgeBuffer
<
T
>::
operator
T
*
()
{
return
buf_
;
}
void
BridgeBuffer
::
reset
(
unsigned
int
size
)
{
template
<
typename
T
>
void
BridgeBuffer
<
T
>::
reset
(
unsigned
int
size
)
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex_
);
if
(
capacity_
<
size
)
{
if
(
buf_
)
{
delete
[]
buf_
;
}
capacity_
=
size
;
buf_
=
new
char
[
capacity_
];
buf_
=
new
T
[
capacity_
];
}
size_
=
size
;
memset
(
buf_
,
0
,
sizeof
(
char
)
*
capacity_
);
memset
(
buf_
,
0
,
sizeof
(
T
)
*
capacity_
);
}
BRIDGE_IMPL
(
char
);
BRIDGE_IMPL
(
int
);
BRIDGE_IMPL
(
double
);
}
// namespace bridge
}
// namespace apollo
modules/bridge/common/bridge_buffer.h
浏览文件 @
44046321
...
...
@@ -33,19 +33,20 @@ namespace bridge {
DISABLE_COPY(TypeName); \
DISABLE_ASSIGN(TypeName)
template
<
typename
T
>
class
BridgeBuffer
{
public:
BridgeBuffer
();
explicit
BridgeBuffer
(
unsigned
int
size
);
virtual
~
BridgeBuffer
();
operator
char
*
();
operator
T
*
();
void
reset
(
unsigned
int
size
);
unsigned
int
size
()
const
{
return
size_
;}
unsigned
int
capacity
()
const
{
return
capacity_
;}
private:
char
*
buf_
=
nullptr
;
T
*
buf_
=
nullptr
;
unsigned
int
size_
=
0
;
unsigned
int
capacity_
=
0
;
std
::
mutex
mutex_
;
...
...
modules/bridge/common/bridge_buffer_test.cc
浏览文件 @
44046321
...
...
@@ -24,7 +24,7 @@ namespace apollo {
namespace
bridge
{
TEST
(
BridgeBufferTest
,
bridge_buf_test
)
{
BridgeBuffer
buf
;
BridgeBuffer
<
char
>
buf
;
char
*
p
=
buf
;
EXPECT_EQ
(
0
,
buf
.
capacity
());
EXPECT_EQ
(
0
,
buf
.
size
());
...
...
modules/bridge/udp_bridge_component.cc
浏览文件 @
44046321
...
...
@@ -22,11 +22,6 @@ namespace bridge {
#define BRIDGE_IMPL(pb_msg) \
template class UDPBridgeComponent<pb_msg>
/*#define FREE_ARRY(arry) \
if (arry) { \
delete [] arry; \
arry = nullptr; \
}*/
#define _1K 1024
using
apollo
::
cyber
::
io
::
Session
;
...
...
modules/bridge/udp_bridge_component.h
浏览文件 @
44046321
...
...
@@ -59,7 +59,7 @@ class UDPBridgeComponent final
common
::
monitor
::
MonitorLogBuffer
monitor_logger_buffer_
;
unsigned
int
remote_port_
=
0
;
std
::
string
remote_ip_
=
""
;
BridgeBuffer
buf_
;
BridgeBuffer
<
char
>
buf_
;
};
CYBER_REGISTER_COMPONENT
(
UDPBridgeComponent
<
planning
::
ADCTrajectory
>
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录