Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
d3db387d
提交
d3db387d
authored
8月 26, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
28260e1d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
209 行增加
和
52 行删除
+209
-52
Makefile
opencv-motion-detect/Makefile
+5
-5
database.cpp
opencv-motion-detect/database.cpp
+147
-3
database.h
opencv-motion-detect/inc/database.h
+30
-3
test_database.cpp
opencv-motion-detect/test_database.cpp
+27
-41
没有找到文件。
opencv-motion-detect/Makefile
浏览文件 @
d3db387d
...
@@ -17,19 +17,19 @@ all: evmgr evpuller evpusher evslicer evmlmotion
...
@@ -17,19 +17,19 @@ all: evmgr evpuller evpusher evslicer evmlmotion
sqlite3.o
:
vendor/sqlite/sqlite3.c
sqlite3.o
:
vendor/sqlite/sqlite3.c
gcc
-D
SQLITE_THREADSAFE
=
1
-c
vendor/sqlite/sqlite3.c
gcc
-D
SQLITE_THREADSAFE
=
1
-c
vendor/sqlite/sqlite3.c
evmgr
:
evmgr.cpp database.cpp inc/common.hpp inc/zmqhelper.hpp inc/tinythread.hpp $(SQLITE)
evmgr
:
evmgr.cpp database.cpp inc/common.hpp inc/
database.h inc/
zmqhelper.hpp inc/tinythread.hpp $(SQLITE)
$(CPP)
$(CPPFLAGS)
-o
evmgr evmgr.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evmgr evmgr.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evpuller
:
evpuller.cpp database.cpp inc/common.hpp inc/zmqhelper.hpp inc/tinythread.hpp $(SQLITE)
evpuller
:
evpuller.cpp database.cpp inc/common.hpp inc/
database.h inc/
zmqhelper.hpp inc/tinythread.hpp $(SQLITE)
$(CPP)
$(CPPFLAGS)
-o
evpuller evpuller.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evpuller evpuller.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evpusher
:
evpusher.cpp inc/common.hpp inc/tinythread.hpp inc/zmqhelper.hpp database.cpp $(SQLITE)
evpusher
:
evpusher.cpp inc/common.hpp inc/tinythread.hpp inc/
database.h inc/
zmqhelper.hpp database.cpp $(SQLITE)
$(CPP)
$(CPPFLAGS)
-o
evpusher evpusher.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evpusher evpusher.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evslicer
:
evslicer.cpp inc/common.hpp inc/tinythread.hpp inc/zmqhelper.hpp database.cpp $(SQLITE)
evslicer
:
evslicer.cpp inc/common.hpp inc/tinythread.hpp inc/
database.h inc/
zmqhelper.hpp database.cpp $(SQLITE)
$(CPP)
$(CPPFLAGS)
-o
evslicer evslicer.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evslicer evslicer.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evmlmotion
:
evmlmotion.cpp inc/common.hpp inc/avcvhelpers.hpp inc/zmqhelper.hpp inc/tinythread.hpp database.cpp $(SQLITE)
evmlmotion
:
evmlmotion.cpp inc/common.hpp inc/avcvhelpers.hpp inc/
database.h inc/
zmqhelper.hpp inc/tinythread.hpp database.cpp $(SQLITE)
$(CPP)
$(CPPFLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
$(LIBOPENCV)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
$(LIBOPENCV)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
rtspr
:
rtsp-relay.cpp
rtspr
:
rtsp-relay.cpp
...
...
opencv-motion-detect/database.cpp
浏览文件 @
d3db387d
#include "inc/database.h"
#include "inc/database.h"
//#include "inc/json.hpp"
#include "spdlog/spdlog.h"
#include <cstdlib>
#include <mutex>
#include <mutex>
#include <map>
#include <map>
using
namespace
leveldb
;
using
namespace
leveldb
;
namespace
LVDB
{
namespace
LVDB
{
map
<
string
,
DB
*>
mappDB
;
DB
*
_getDB
(
string
fileName
)
{
DB
*
pdb
=
NULL
;
int
ret
=
0
;
if
(
mappDB
.
count
(
fileName
)
==
0
)
{
//
string
mk
=
string
(
"mkdir -p "
)
+
LVDB_PATH
;
ret
=
system
(
mk
.
c_str
());
if
(
ret
==
-
1
)
{
spdlog
::
error
(
"failed to create db path: {}"
,
LVDB_PATH
);
}
else
{
Options
options
;
options
.
create_if_missing
=
true
;
Status
s
=
DB
::
Open
(
options
,
fileName
,
&
pdb
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to open db {}: {}"
,
fileName
,
s
.
ToString
());
}
mappDB
[
fileName
]
=
pdb
;
}
}
else
{
pdb
=
mappDB
[
fileName
];
}
assert
(
pdb
!=
NULL
);
return
pdb
;
}
int
clearDB
(
string
fileName
)
{
return
0
;
}
typedef
int
(
*
cb_verify
)(
json
&
);
int
getValue
(
json
&
value
,
string
key
,
string
fileName
,
cb_verify
cb
)
{
DB
*
pdb
=
_getDB
(
fileName
);
string
oldVal
;
int
ret
=
0
;
json
j
;
Status
s
=
pdb
->
Get
(
leveldb
::
ReadOptions
(),
key
,
&
oldVal
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to get {} from {}: {}"
,
key
,
fileName
,
s
.
ToString
());
return
-
1
;
}
try
{
j
=
json
::
parse
(
oldVal
);
if
(
cb
!=
NULL
)
{
ret
=
cb
(
j
);
if
(
ret
<
0
)
{
return
ret
;
}
}
value
=
j
;
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"failed to parse {} -> {} {}: {}"
,
key
,
oldVal
,
fileName
,
e
.
what
());
return
-
2
;
}
return
0
;
}
int
setValue
(
json
&
value
,
string
key
,
string
fileName
,
cb_verify
cb
)
{
int
ret
=
0
;
if
(
cb
!=
NULL
)
{
ret
=
cb
(
value
);
if
(
ret
<
0
)
{
return
ret
;
}
}
DB
*
pdb
=
_getDB
(
fileName
);
string
oldVal
;
Status
s
=
pdb
->
Get
(
ReadOptions
(),
key
,
&
oldVal
);
if
(
!
s
.
ok
())
{
spdlog
::
warn
(
"get old {} error {}:{}"
,
key
,
fileName
,
s
.
ToString
());
}
s
=
pdb
->
Put
(
leveldb
::
WriteOptions
(),
key
,
value
.
dump
());
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to put {} -> {}: {}"
,
key
,
value
.
dump
(),
s
.
ToString
());
return
-
2
;
}
if
(
!
oldVal
.
empty
())
{
s
=
pdb
->
Put
(
leveldb
::
WriteOptions
(),
key
+
LVDB_KEY_SUFFIX_BACK
,
oldVal
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to put backup {} -> {}: {}"
,
key
,
oldVal
,
s
.
ToString
());
return
-
2
;
}
}
return
0
;
}
int
delValue
(
string
key
,
string
fileName
)
{
DB
*
pdb
=
_getDB
(
fileName
);
Status
s
=
pdb
->
Delete
(
WriteOptions
(),
key
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to delete key {}: {} in {}"
,
s
.
ToString
(),
key
,
fileName
);
return
-
1
;
}
return
0
;
}
// sn
// {"sn":string, "updatetime": string, "lastboot": string}
int
_validateSn
(
json
&
info
)
{
if
(
info
.
count
(
"sn"
)
==
0
||
info
.
count
(
"updatetime"
)
==
0
||
info
.
count
(
"lastboot"
)
==
0
)
{
spdlog
::
error
(
"invalid sn config:{}"
,
info
.
dump
());
return
-
1
;
}
return
0
;
}
int
getSn
(
json
&
info
,
string
fileName
){
int
getSn
(
json
&
info
,
string
fileName
){
return
getValue
(
info
,
LVDB_KEY_SN
,
fileName
,
_validateSn
);
};
int
setSn
(
json
&
info
,
string
fileName
){
return
setValue
(
info
,
LVDB_KEY_SN
,
fileName
,
_validateSn
);
};
// config
int
_validateConfig
(
json
&
config
)
{
if
(
config
.
count
(
"data"
)
==
0
||
config
[
"data"
].
size
()
==
0
)
{
spdlog
::
error
(
"invliad config: {}"
,
config
.
dump
());
return
-
1
;
}
return
0
;
return
0
;
}
int
getLocalConfig
(
json
&
config
,
string
fileName
){
return
getValue
(
config
,
LVDB_KEY_CONFIG
,
fileName
,
_validateConfig
);
};
int
setLocalConfig
(
json
&
config
,
string
fileName
){
return
setValue
(
config
,
LVDB_KEY_CONFIG
,
fileName
,
_validateConfig
);
};
};
int
saveSn
(
json
&
info
,
string
fileName
){
// slices
int
saveSlices
(
json
&
slices
,
string
fileName
){
return
0
;
return
0
;
};
};
int
loadLocalConfig
(
json
&
config
,
string
fileName
){
int
loadSlices
(
json
&
slices
,
string
fileName
){
return
0
;
};
// log
int
saveLog
(
json
&
log
,
json
&
writeOptions
,
string
fileName
){
return
0
;
return
0
;
};
};
int
savelocalConfig
(
json
&
config
,
string
fileName
){
int
readLog
(
json
&
log
,
json
&
readOptions
,
string
fileName
){
return
0
;
return
0
;
};
};
...
...
opencv-motion-detect/inc/database.h
浏览文件 @
d3db387d
...
@@ -7,10 +7,36 @@ using namespace nlohmann;
...
@@ -7,10 +7,36 @@ using namespace nlohmann;
using
namespace
std
;
using
namespace
std
;
namespace
LVDB
{
namespace
LVDB
{
#define LVDB_PATH "/opt/lvldb/"
// sn, config
#define LVDB_FILE_GENERAL LVDB_PATH"general.db"
// slices, log
#define LVDB_FILE_LOG LVDB_PATH"log.db"
#define LVDB_KEY_SUFFIX_BACK "_bak"
#define LVDB_KEY_SN "SN"
#define LVDB_KEY_CONFIG "CONFIG"
//
int
delValue
(
string
key
,
string
fileName
);
// sn, updatetime, boottime
int
setSn
(
json
&
info
,
string
fileName
);
int
getSn
(
json
&
info
,
string
fileName
);
int
getSn
(
json
&
info
,
string
fileName
);
int
saveSn
(
json
&
info
,
string
fileName
);
int
loadLocalConfig
(
json
&
config
,
string
fileName
);
// cloudutils::config
int
savelocalConfig
(
json
&
config
,
string
fileName
);
int
getLocalConfig
(
json
&
config
,
string
fileName
);
int
setLocalConfig
(
json
&
config
,
string
fileName
);
// slices
int
getSlices
(
json
&
slices
,
string
fileName
);
int
setSlices
(
json
&
slices
,
string
fileName
);
// log
int
getLog
(
json
&
log
,
json
&
writeOptions
,
string
fileName
);
int
setLog
(
json
&
log
,
json
&
readOptions
,
string
fileName
);
}
}
#endif
#endif
\ No newline at end of file
opencv-motion-detect/test_database.cpp
浏览文件 @
d3db387d
// g++ -std=c++1z test_database.cpp database.cpp -o test_database -lleveldb -Ivendor/include/ -Iinc -Lvendor/lib
#include "inc/database.h"
#include "inc/database.h"
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
int
main
(){
const
char
*
_config
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
ILSEVMGR1
\"
:{
\"
sn
\"
:
\"
ILSEVMGR1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
addr-cloud
\"
:
\"
172.31.0.76
\"
,
\"
proto
\"
:
\"
zmq
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.51
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
FWBWTU
\"
,
\"
status
\"
:1,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
ILSEVPULLER1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:5556,
\"
status
\"
:1}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
ILSEVPUSHER1
\"
,
\"
iid
\"
:1,
\"
urlDest
\"
:
\"
rtsp://40.73.41.176:554/test1
\"
,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
ILSEVSLICER1
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
ILSEVMLMOTION1
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:1}]}}]}}}"
;
int
ret
;
json
j
,
p
;
// case table info
spdlog
::
set_level
(
spdlog
::
level
::
debug
);
ret
=
DB
::
clearTable
(
"info"
,
"aa.db"
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
DB
::
clearTable
(
"info"
,
"a.db"
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
DB
::
setInfo
(
&
p
,
"a.db"
);
spdlog
::
info
(
"ret: {}"
,
ret
);
j
[
"sn"
]
=
"sn-aa"
;
j
[
"lastboot"
]
=
"2019-04-25 10:10:10"
;
ret
=
DB
::
setInfo
(
&
j
,
"a.db"
);
int
main
(){
spdlog
::
info
(
"ret: {}"
,
ret
);
json
j
;
int
ret
=
0
;
ret
=
DB
::
getInfo
(
&
j
,
-
1
,
"a.db"
);
// sn
ret
=
LVDB
::
delValue
(
LVDB_KEY_SN
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
LVDB
::
setSn
(
j
,
LVDB_FILE_GENERAL
);
j
[
"sn"
]
=
"sn-aa"
;
j
[
"lastboot"
]
=
"2019-04-25 10:10:17"
;
ret
=
DB
::
setInfo
(
&
j
,
"a.db"
);
spdlog
::
info
(
"ret: {}"
,
ret
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
DB
::
getInfo
(
&
j
,
-
1
,
"a.db"
);
j
[
"sn"
]
=
"snaaaa"
;
j
[
"lastboot"
]
=
"2019-08-25 10:10:10"
;
j
[
"updatetime"
]
=
"2019-08-25 10:10:11"
;
ret
=
LVDB
::
setSn
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
spdlog
::
info
(
"ret: {}"
,
ret
);
j
.
clear
();
j
[
"sn"
]
=
"sn-ab"
;
ret
=
LVDB
::
getSn
(
j
,
LVDB_FILE_GENERAL
)
;
j
[
"lastboot"
]
=
"2019-04-25 10:10:17"
;
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
())
;
ret
=
DB
::
setInfo
(
&
j
,
"a.db"
);
//
spdlog
::
info
(
"ret: {}"
,
ret
);
json
config
=
json
::
parse
(
_config
);
ret
=
DB
::
getInfo
(
&
p
,
-
1
,
"a.db"
);
j
.
clear
();
ret
=
LVDB
::
delValue
(
LVDB_KEY_CONFIG
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
LVDB
::
getLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
p
.
clear
();
ret
=
LVDB
::
setLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
ret
=
DB
::
getInfo
(
&
p
,
0
,
"a.db"
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
spdlog
::
info
(
"ret: {}"
,
ret
);
p
.
clear
();
ret
=
LVDB
::
setLocalConfig
(
config
,
LVDB_FILE_GENERAL
);
ret
=
DB
::
getInfo
(
&
p
,
1
,
"a.db"
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
config
.
dump
());
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
LVDB
::
getLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
// case table modules
return
0
;
return
0
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论