Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
5410bdb0
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,发现更多精彩内容 >>
提交
5410bdb0
编写于
11月 09, 2018
作者:
X
Xiangquan Xiao
提交者:
Jiangtao Hu
12月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Perception: Retire redundant FileUtil::GetFileContent. (#1700)
上级
f1033da0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
15 addition
and
92 deletion
+15
-92
modules/perception/common/sensor_manager/sensor_manager.cc
modules/perception/common/sensor_manager/sensor_manager.cc
+6
-12
modules/perception/lib/config_manager/config_manager.cc
modules/perception/lib/config_manager/config_manager.cc
+9
-26
modules/perception/lib/io/file_util.cc
modules/perception/lib/io/file_util.cc
+0
-35
modules/perception/lib/io/file_util.h
modules/perception/lib/io/file_util.h
+0
-2
modules/perception/lib/io/file_util_test.cc
modules/perception/lib/io/file_util_test.cc
+0
-17
未找到文件。
modules/perception/common/sensor_manager/sensor_manager.cc
浏览文件 @
5410bdb0
...
...
@@ -17,18 +17,19 @@
#include <string>
#include <utility>
#include "google/protobuf/text_format.h"
#include "cyber/common/log.h"
#include "modules/common/util/file.h"
#include "modules/perception/common/io/io_util.h"
#include "modules/perception/lib/config_manager/config_manager.h"
#include "modules/perception/lib/io/file_util.h"
#include "modules/perception/common/io/io_util.h"
#include "modules/perception/proto/sensor_meta_schema.pb.h"
namespace
apollo
{
namespace
perception
{
namespace
common
{
using
apollo
::
common
::
util
::
GetProtoFromASCIIFile
;
using
apollo
::
perception
::
base
::
BrownCameraDistortionModel
;
using
apollo
::
perception
::
base
::
SensorInfo
;
using
apollo
::
perception
::
base
::
SensorOrientation
;
...
...
@@ -52,17 +53,10 @@ bool SensorManager::Init() {
std
::
string
file_path
=
lib
::
FileUtil
::
GetAbsolutePath
(
config_manager
->
work_root
(),
FLAGS_obs_sensor_meta_path
);
std
::
string
content
;
if
(
!
lib
::
FileUtil
::
GetFileContent
(
file_path
,
&
content
))
{
AERROR
<<
"Failed to get SensorManager config path: "
<<
FLAGS_obs_sensor_meta_path
;
return
false
;
}
MultiSensorMeta
sensor_list_proto
;
if
(
!
google
::
protobuf
::
TextFormat
::
ParseFromString
(
content
,
&
sensor_list_proto
))
{
AERROR
<<
"Invalid MultiSensorMeta file!"
;
if
(
!
GetProtoFromASCIIFile
(
file_path
,
&
sensor_list_proto
))
{
AERROR
<<
"Invalid MultiSensorMeta file: "
<<
FLAGS_obs_sensor_meta_path
;
return
false
;
}
...
...
modules/perception/lib/config_manager/config_manager.cc
浏览文件 @
5410bdb0
...
...
@@ -18,8 +18,7 @@
#include <utility>
#include "cyber/common/log.h"
#include "google/protobuf/text_format.h"
#include "modules/common/util/file.h"
#include "modules/perception/common/perception_gflags.h"
#include "modules/perception/lib/io/file_util.h"
...
...
@@ -27,7 +26,7 @@ namespace apollo {
namespace
perception
{
namespace
lib
{
using
google
::
protobuf
::
TextFormat
;
using
apollo
::
common
::
util
::
GetProtoFromASCIIFile
;
ConfigManager
::
ConfigManager
()
{
work_root_
=
FLAGS_work_root
;
...
...
@@ -70,36 +69,20 @@ bool ConfigManager::InitInternal() {
return
false
;
}
for
(
auto
&
model_config_file
:
model_config_files
)
{
std
::
string
content
;
if
(
!
FileUtil
::
GetFileContent
(
model_config_file
,
&
content
))
{
AERROR
<<
"failed to get ConfigManager config path: "
<<
model_config_file
;
return
false
;
}
for
(
const
auto
&
model_config_file
:
model_config_files
)
{
ModelConfigFileListProto
file_list_proto
;
if
(
!
TextFormat
::
ParseFromString
(
content
,
&
file_list_proto
))
{
if
(
!
GetProtoFromASCIIFile
(
model_config_file
,
&
file_list_proto
))
{
AERROR
<<
"invalid ModelConfigFileListProto file: "
<<
FLAGS_config_manager_path
;
<<
model_config_file
;
return
false
;
}
for
(
const
std
::
string
&
model_config_file
:
for
(
const
std
::
string
&
model_config_path
:
file_list_proto
.
model_config_path
())
{
std
::
string
abs_path
=
FileUtil
::
GetAbsolutePath
(
work_root_
,
model_config_file
);
std
::
string
config_content
;
if
(
!
FileUtil
::
GetFileContent
(
abs_path
,
&
config_content
))
{
AERROR
<<
"failed to get file content: "
<<
abs_path
;
return
false
;
}
const
std
::
string
abs_path
=
FileUtil
::
GetAbsolutePath
(
work_root_
,
model_config_path
);
MultiModelConfigProto
multi_model_config_proto
;
if
(
!
TextFormat
::
ParseFromString
(
config_content
,
&
multi_model_config_proto
))
{
if
(
!
GetProtoFromASCIIFile
(
abs_path
,
&
multi_model_config_proto
))
{
AERROR
<<
"invalid MultiModelConfigProto file: "
<<
abs_path
;
return
false
;
}
...
...
modules/perception/lib/io/file_util.cc
浏览文件 @
5410bdb0
...
...
@@ -161,41 +161,6 @@ bool FileUtil::CreateDir(const string &dir) {
return
true
;
}
bool
FileUtil
::
GetFileContent
(
const
string
&
path
,
string
*
content
)
{
if
(
content
==
nullptr
)
{
return
false
;
}
int
fd
=
::
open
(
path
.
c_str
(),
O_RDONLY
);
if
(
fd
<
0
)
{
AWARN
<<
"failed to open file: "
<<
path
;
return
false
;
}
struct
stat
buf
;
if
(
::
fstat
(
fd
,
&
buf
)
!=
0
)
{
AWARN
<<
"failed to lstat file: "
<<
path
;
::
close
(
fd
);
return
false
;
}
size_t
fsize
=
buf
.
st_size
;
content
->
resize
(
fsize
);
char
*
data
=
const_cast
<
char
*>
(
content
->
data
());
int
size
=
0
;
size_t
has_read
=
0
;
do
{
size
=
::
read
(
fd
,
data
+
has_read
,
fsize
-
has_read
);
if
(
size
<
0
)
{
AWARN
<<
"failed to read file: "
<<
path
;
::
close
(
fd
);
return
false
;
}
has_read
+=
size
;
}
while
(
size
>
0
);
::
close
(
fd
);
return
true
;
}
bool
FileUtil
::
ReadLines
(
const
string
&
path
,
vector
<
string
>
*
lines
)
{
std
::
ifstream
fin
(
path
);
if
(
!
fin
.
good
())
{
...
...
modules/perception/lib/io/file_util.h
浏览文件 @
5410bdb0
...
...
@@ -49,8 +49,6 @@ class FileUtil {
// create folder
static
bool
CreateDir
(
const
std
::
string
&
dir
);
static
bool
GetFileContent
(
const
std
::
string
&
path
,
std
::
string
*
content
);
static
bool
ReadLines
(
const
std
::
string
&
path
,
std
::
vector
<
std
::
string
>
*
lines
);
...
...
modules/perception/lib/io/file_util_test.cc
浏览文件 @
5410bdb0
...
...
@@ -179,23 +179,6 @@ TEST(FileUtilTest, TestRenameFile) {
"/apollo/modules/perception/testdata/lib/data2/222.txt"
));
}
TEST
(
FileUtilTest
,
TestGetFileContent
)
{
std
::
string
path
=
"/apollo/modules/perception/testdata/lib/data/1.txt"
;
std
::
string
content
;
EXPECT_FALSE
(
FileUtil
::
GetFileContent
(
path
,
nullptr
));
EXPECT_FALSE
(
FileUtil
::
GetFileContent
(
"/apollo/modules/perception/testdata/lib/data/2.txt"
,
&
content
));
EXPECT_TRUE
(
FileUtil
::
GetFileContent
(
path
,
&
content
));
ASSERT_EQ
(
system
(
"chmod a-r /apollo/modules/perception/testdata/lib/data3/1.txt"
),
0
);
ASSERT_FALSE
(
FileUtil
::
GetFileContent
(
"/apollo/modules/perception/testdata/lib/data3/1.txt"
,
&
content
));
ASSERT_EQ
(
system
(
"chmod a+r /apollo/modules/perception/testdata/lib/data3/1.txt"
),
0
);
}
}
// namespace lib
}
// namespace perception
}
// namespace apollo
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录