Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
f981a53a
提交
f981a53a
authored
10月 10, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor of delta config
上级
217dce32
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
302 行增加
和
51 行删除
+302
-51
utils.cpp
opencv-motion-detect/inc/utils.cpp
+226
-49
utils.hpp
opencv-motion-detect/inc/utils.hpp
+1
-0
test_regex.cpp
opencv-motion-detect/test_regex.cpp
+75
-2
没有找到文件。
opencv-motion-detect/inc/utils.cpp
浏览文件 @
f981a53a
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
// cloudutils
// cloudutils
namespace
cloudutils
namespace
cloudutils
{
{
/// [deprecated] ref: ../config.json
/// [deprecated] ref: ../config.json
json
registry
(
json
&
conf
,
string
sn
,
string
module
)
{
json
registry
(
json
&
conf
,
string
sn
,
string
module
)
{
json
ret
;
json
ret
;
string
api
;
string
api
;
try
{
try
{
api
=
conf
.
at
(
"data"
).
at
(
sn
).
at
(
"api-cloud"
).
get
<
string
>
()
+
"/register"
;
api
=
conf
.
at
(
"data"
).
at
(
sn
).
at
(
"api-cloud"
).
get
<
string
>
()
+
"/register"
;
Uri
uri
=
Uri
::
Parse
(
api
);
Uri
uri
=
Uri
::
Parse
(
api
);
if
(
uri
.
Host
.
empty
()
||
uri
.
Port
.
empty
()
||
uri
.
Protocol
.
find
(
"http"
)
==
string
::
npos
||
uri
.
Path
.
empty
())
{
if
(
uri
.
Host
.
empty
()
||
uri
.
Port
.
empty
()
||
uri
.
Protocol
.
find
(
"http"
)
==
string
::
npos
||
uri
.
Path
.
empty
())
{
...
@@ -27,7 +27,8 @@ json registry(json &conf, string sn, string module) {
...
@@ -27,7 +27,8 @@ json registry(json &conf, string sn, string module) {
auto
res
=
cli
.
Post
(
"/register"
,
Headers
(),
params
,
conf
.
dump
(),
"text/json"
);
auto
res
=
cli
.
Post
(
"/register"
,
Headers
(),
params
,
conf
.
dump
(),
"text/json"
);
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
res
->
body
);
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
res
->
body
);
ret
=
json
::
parse
(
res
->
body
);
ret
=
json
::
parse
(
res
->
body
);
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
string
msg
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
)
+
string
(
": registry exception - "
)
+
e
.
what
();
string
msg
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
)
+
string
(
": registry exception - "
)
+
e
.
what
();
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
...
@@ -39,10 +40,11 @@ json registry(json &conf, string sn, string module) {
...
@@ -39,10 +40,11 @@ json registry(json &conf, string sn, string module) {
}
}
/// req config
/// req config
json
reqConfig
(
json
&
info
){
json
reqConfig
(
json
&
info
)
{
json
ret
;
json
ret
;
string
api
;
string
api
;
try
{
try
{
api
=
info
.
at
(
"api-cloud"
).
get
<
string
>
();
api
=
info
.
at
(
"api-cloud"
).
get
<
string
>
();
Uri
uri
=
Uri
::
Parse
(
api
);
Uri
uri
=
Uri
::
Parse
(
api
);
string
sn
=
info
.
at
(
"sn"
).
get
<
string
>
();
string
sn
=
info
.
at
(
"sn"
).
get
<
string
>
();
...
@@ -64,17 +66,20 @@ json reqConfig(json &info){
...
@@ -64,17 +66,20 @@ json reqConfig(json &info){
if
(
res
==
nullptr
)
{
if
(
res
==
nullptr
)
{
msg
=
(
string
(
"error to connect to server: "
)
+
api
+
"/config"
).
c_str
();
msg
=
(
string
(
"error to connect to server: "
)
+
api
+
"/config"
).
c_str
();
ret
[
"code"
]
=
EVCLOUD_REQ_E_CONN
;
ret
[
"code"
]
=
EVCLOUD_REQ_E_CONN
;
}
else
{
}
else
{
msg
=
httplib
::
detail
::
status_message
(
res
->
status
);
msg
=
httplib
::
detail
::
status_message
(
res
->
status
);
ret
[
"code"
]
=
res
->
status
;
ret
[
"code"
]
=
res
->
status
;
}
}
spdlog
::
debug
(
"failed to reqConfig. {}"
,
msg
);
spdlog
::
debug
(
"failed to reqConfig. {}"
,
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
}
else
{
}
else
{
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
res
->
body
);
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
res
->
body
);
ret
=
json
::
parse
(
res
->
body
);
ret
=
json
::
parse
(
res
->
body
);
}
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
ret
[
"code"
]
=
EVCLOUD_REQ_E_DATA
;
ret
[
"code"
]
=
EVCLOUD_REQ_E_DATA
;
string
msg
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
)
+
string
(
": registry exception - "
)
+
e
.
what
();
string
msg
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
)
+
string
(
": registry exception - "
)
+
e
.
what
();
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
...
@@ -89,14 +94,13 @@ json reqConfig(json &info){
...
@@ -89,14 +94,13 @@ json reqConfig(json &info){
///
///
namespace
strutils
{
namespace
strutils
{
vector
<
string
>
split
(
const
std
::
string
&
s
,
char
delimiter
)
vector
<
string
>
split
(
const
std
::
string
&
s
,
char
delimiter
)
{
{
std
::
vector
<
std
::
string
>
tokens
;
std
::
vector
<
std
::
string
>
tokens
;
std
::
string
token
;
std
::
string
token
;
std
::
istringstream
tokenStream
(
s
);
std
::
istringstream
tokenStream
(
s
);
while
(
getline
(
tokenStream
,
token
,
delimiter
))
while
(
getline
(
tokenStream
,
token
,
delimiter
))
{
{
tokens
.
push_back
(
token
);
tokens
.
push_back
(
token
);
}
}
return
tokens
;
return
tokens
;
...
@@ -105,28 +109,101 @@ vector<string> split(const std::string& s, char delimiter)
...
@@ -105,28 +109,101 @@ vector<string> split(const std::string& s, char delimiter)
}
//namespace strutils
}
//namespace strutils
namespace
cfgutils
{
namespace
cfgutils
{
int
getPeerId
(
string
modName
,
json
&
modElem
,
string
&
peerId
,
string
&
peerName
)
{
int
getPeerId
(
string
modName
,
json
&
modElem
,
string
&
peerId
,
string
&
peerName
)
{
try
{
try
{
if
(
modName
==
"evmgr"
)
{
if
(
modName
==
"evmgr"
)
{
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":evmgr:0"
;
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":evmgr:0"
;
peerName
=
modName
;
peerName
=
modName
;
}
else
if
(
modName
==
"evml"
)
{
}
else
if
(
modName
==
"evml"
)
{
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":evml"
+
modElem
[
"type"
].
get
<
string
>
()
+
":"
+
to_string
(
modElem
[
"iid"
]);
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":evml"
+
modElem
[
"type"
].
get
<
string
>
()
+
":"
+
to_string
(
modElem
[
"iid"
]);
peerName
=
modName
+
modElem
[
"type"
].
get
<
string
>
();
peerName
=
modName
+
modElem
[
"type"
].
get
<
string
>
();
}
else
{
}
else
{
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":"
+
modName
+
":"
+
to_string
(
modElem
[
"iid"
]);
peerId
=
modElem
[
"sn"
].
get
<
string
>
()
+
":"
+
modName
+
":"
+
to_string
(
modElem
[
"iid"
]);
peerName
=
modName
;
peerName
=
modName
;
}
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"failed to get gid for {} in {}: {}"
,
modName
,
modElem
.
dump
(),
e
.
what
());
spdlog
::
error
(
"failed to get gid for {} in {}: {}"
,
modName
,
modElem
.
dump
(),
e
.
what
());
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
/// ret["data"] is json array contains gids
/// ret["code"], ["msg"] indicates error if not 0.
/// ipcIdx: -1 - all IPCS, otherwise - ipc specified by ipcIdx
json
getModuleGidsFromCfg
(
string
sn
,
json
&
data
,
string
caller
,
int
ipcIdx
)
{
json
ret
;
bool
hasError
=
false
;
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
ret
[
"data"
]
=
json
();
try
{
// lock_guard<mutex> lock(cacheLock);
string
peerId
;
pid_t
pid
;
for
(
auto
&
[
k
,
v
]
:
data
.
items
())
{
if
(
ipcIdx
==
-
1
)
{
if
(
k
==
sn
)
{
peerId
=
v
[
"sn"
].
get
<
string
>
()
+
":evmgr:0"
;
ret
[
"data"
].
push_back
(
peerId
);
}
}
// startup other submodules
json
&
ipcs
=
v
[
"ipcs"
];
int
idx
=
0
;
for
(
auto
&
ipc
:
ipcs
)
{
if
(
ipcIdx
!=
-
1
&&
idx
!=
ipcIdx
)
{
continue
;
}
json
&
modules
=
ipc
[
"modules"
];
for
(
auto
&
[
mn
,
ml
]
:
modules
.
items
())
{
for
(
auto
&
m
:
ml
)
{
if
(
m
[
"sn"
]
!=
sn
)
{
continue
;
}
string
peerName
;
int
iret
=
cfgutils
::
getPeerId
(
mn
,
m
,
peerId
,
peerName
);
if
(
iret
!=
0
)
{
// TODO: do we need to treat it more strictly, to make it fails fast???
spdlog
::
error
(
"{} getModuleGidsFromCfg for {} invalid config found in module {} of {}"
,
caller
,
sn
,
m
.
dump
(),
data
.
dump
());
continue
;
}
else
{
ret
[
"data"
].
push_back
(
peerId
);
}
}
}
}
if
(
ipcIdx
!=
-
1
)
{
break
;
}
json
*
findModuleConfig
(
string
peerId
,
json
&
data
)
{
idx
++
;
}
}
}
catch
(
exception
&
e
)
{
string
msg
=
fmt
::
format
(
"{} getModuleGidsFromCfg exception {} in config {}"
,
caller
,
sn
,
e
.
what
(),
data
.
dump
());
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"code"
]
=
-
1
;
}
return
ret
;
}
json
*
findModuleConfig
(
string
peerId
,
json
&
data
)
{
json
*
ret
=
NULL
;
json
*
ret
=
NULL
;
auto
pp
=
strutils
::
split
(
peerId
,
':'
);
auto
pp
=
strutils
::
split
(
peerId
,
':'
);
if
(
pp
.
size
()
!=
3
)
{
if
(
pp
.
size
()
!=
3
)
{
...
@@ -141,11 +218,12 @@ namespace cfgutils {
...
@@ -141,11 +218,12 @@ namespace cfgutils {
string
subMn
=
modName
.
substr
(
0
,
4
);
string
subMn
=
modName
.
substr
(
0
,
4
);
if
(
subMn
==
"evml"
)
{
if
(
subMn
==
"evml"
)
{
subMn
=
modName
.
substr
(
4
,
modName
.
size
());
subMn
=
modName
.
substr
(
4
,
modName
.
size
());
}
else
{
}
else
{
subMn
=
""
;
subMn
=
""
;
}
}
try
{
try
{
for
(
auto
&
[
k
,
v
]
:
data
.
items
())
{
for
(
auto
&
[
k
,
v
]
:
data
.
items
())
{
// it's evmgr
// it's evmgr
if
(
modName
==
"evmgr"
)
{
if
(
modName
==
"evmgr"
)
{
...
@@ -153,7 +231,8 @@ namespace cfgutils {
...
@@ -153,7 +231,8 @@ namespace cfgutils {
ret
=
&
v
;
ret
=
&
v
;
break
;
break
;
}
}
}
else
{
}
else
{
json
&
ipcs
=
v
[
"ipcs"
];
json
&
ipcs
=
v
[
"ipcs"
];
for
(
auto
&
ipc
:
ipcs
)
{
for
(
auto
&
ipc
:
ipcs
)
{
...
@@ -169,7 +248,8 @@ namespace cfgutils {
...
@@ -169,7 +248,8 @@ namespace cfgutils {
}
}
}
}
}
}
}
else
{
}
else
{
if
(
modules
.
count
(
"evml"
)
!=
0
)
{
if
(
modules
.
count
(
"evml"
)
!=
0
)
{
json
&
ml
=
modules
[
"evml"
];
json
&
ml
=
modules
[
"evml"
];
for
(
auto
&
m
:
ml
)
{
for
(
auto
&
m
:
ml
)
{
...
@@ -185,23 +265,25 @@ namespace cfgutils {
...
@@ -185,23 +265,25 @@ namespace cfgutils {
}
}
}
}
}
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"find module {} in {} exception: {}"
,
peerId
,
data
.
dump
(),
e
.
what
());
spdlog
::
error
(
"find module {} in {} exception: {}"
,
peerId
,
data
.
dump
(),
e
.
what
());
return
NULL
;
return
NULL
;
}
}
return
ret
;
return
ret
;
}
}
/// return json key: gid; value: 0 - stop, 1 - start, 3 - restart
/// return json key: gid; value: 0 - stop, 1 - start, 3 - restart
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
)
{
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
)
{
json
ret
;
json
ret
;
ret
[
"code"
]
=
0
;
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
ret
[
"msg"
]
=
"ok"
;
ret
[
"data"
]
=
json
();
ret
[
"data"
]
=
json
();
bool
hasError
=
false
;
bool
hasError
=
false
;
spdlog
::
info
(
"matching {}, size:{}, type:{}"
,
diff
.
dump
(),
diff
.
size
(),
diff
.
type_name
());
spdlog
::
info
(
"matching {}, size:{}, type:{}"
,
diff
.
dump
(),
diff
.
size
(),
diff
.
type_name
());
try
{
try
{
for
(
auto
&
d
:
diff
)
{
for
(
auto
&
d
:
diff
)
{
spdlog
::
info
(
"d :{}, {}"
,
d
.
dump
(),
d
.
size
());
spdlog
::
info
(
"d :{}, {}"
,
d
.
dump
(),
d
.
size
());
if
(
d
.
count
(
"path"
)
!=
0
)
{
if
(
d
.
count
(
"path"
)
!=
0
)
{
...
@@ -234,7 +316,8 @@ namespace cfgutils {
...
@@ -234,7 +316,8 @@ namespace cfgutils {
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
else
{
}
else
{
auto
&
evpullers
=
ipc
[
"module"
][
"evpuller"
];
auto
&
evpullers
=
ipc
[
"module"
][
"evpuller"
];
int
idx
=
0
;
int
idx
=
0
;
for
(
auto
&
puller
:
evpullers
)
{
for
(
auto
&
puller
:
evpullers
)
{
...
@@ -258,11 +341,13 @@ namespace cfgutils {
...
@@ -258,11 +341,13 @@ namespace cfgutils {
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
else
{
}
else
{
string
gid
=
sn
+
":evpuller:"
+
to_string
(
puller
[
"iid"
].
get
<
int
>
());
string
gid
=
sn
+
":evpuller:"
+
to_string
(
puller
[
"iid"
].
get
<
int
>
());
if
(
puller
.
count
(
"enabled"
)
==
0
||
puller
[
"enabled"
].
get
<
int
>
()
==
0
)
{
if
(
puller
.
count
(
"enabled"
)
==
0
||
puller
[
"enabled"
].
get
<
int
>
()
==
0
)
{
ret
[
"data"
][
gid
]
=
0
;
// stop
ret
[
"data"
][
gid
]
=
0
;
// stop
}
else
{
}
else
{
ret
[
"data"
][
gid
]
=
2
;
ret
[
"data"
][
gid
]
=
2
;
}
}
}
}
...
@@ -300,14 +385,16 @@ namespace cfgutils {
...
@@ -300,14 +385,16 @@ namespace cfgutils {
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
else
{
}
else
{
if
(
modName
==
"evml"
)
{
if
(
modName
==
"evml"
)
{
if
(
newMod
.
count
(
"type"
)
==
0
)
{
if
(
newMod
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
else
{
}
else
{
modName
=
modName
+
newMod
[
"type"
].
get
<
string
>
();
modName
=
modName
+
newMod
[
"type"
].
get
<
string
>
();
}
}
}
}
...
@@ -323,10 +410,12 @@ namespace cfgutils {
...
@@ -323,10 +410,12 @@ namespace cfgutils {
string
oldGid
=
sn
+
":"
+
modName
+
":"
+
to_string
(
oldMod
[
"iid"
].
get
<
int
>
());
string
oldGid
=
sn
+
":"
+
modName
+
":"
+
to_string
(
oldMod
[
"iid"
].
get
<
int
>
());
ret
[
"data"
][
oldGid
]
=
0
;
ret
[
"data"
][
oldGid
]
=
0
;
continue
;
continue
;
}
else
if
(
newMod
[
"sn"
].
get
<
string
>
()
!=
sn
&&
(
oldMod
.
count
(
"sn"
)
==
0
||
(
oldMod
.
count
(
"sn"
)
!=
0
&&
oldMod
[
"sn"
].
get
<
string
>
()
!=
sn
))){
}
else
if
(
newMod
[
"sn"
].
get
<
string
>
()
!=
sn
&&
(
oldMod
.
count
(
"sn"
)
==
0
||
(
oldMod
.
count
(
"sn"
)
!=
0
&&
oldMod
[
"sn"
].
get
<
string
>
()
!=
sn
)))
{
// ignore
// ignore
continue
;
continue
;
}
else
{
}
else
{
// oldSn == newSn == sn, below
// oldSn == newSn == sn, below
}
}
...
@@ -340,14 +429,17 @@ namespace cfgutils {
...
@@ -340,14 +429,17 @@ namespace cfgutils {
if
(
propName
==
"enabled"
)
{
if
(
propName
==
"enabled"
)
{
if
(
newMod
.
count
(
"enabled"
)
==
0
||
newMod
[
"enabled"
].
get
<
int
>
()
==
0
)
{
if
(
newMod
.
count
(
"enabled"
)
==
0
||
newMod
[
"enabled"
].
get
<
int
>
()
==
0
)
{
ret
[
"data"
][
newGid
]
=
0
;
ret
[
"data"
][
newGid
]
=
0
;
}
else
{
}
else
{
ret
[
"data"
][
newGid
]
=
1
;
ret
[
"data"
][
newGid
]
=
1
;
}
}
}
else
{
// other prop modification
}
else
{
// other prop modification
// it was disabled. just ignore
// it was disabled. just ignore
if
(
ret
[
"data"
].
count
(
newGid
)
!=
0
&&
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
0
)
{
if
(
ret
[
"data"
].
count
(
newGid
)
!=
0
&&
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
0
)
{
// nop
// nop
}
else
{
}
else
{
// restart
// restart
ret
[
"data"
][
newGid
]
=
2
;
ret
[
"data"
][
newGid
]
=
2
;
}
}
...
@@ -378,28 +470,32 @@ namespace cfgutils {
...
@@ -378,28 +470,32 @@ namespace cfgutils {
json
modObj
;
json
modObj
;
if
(
d
[
"op"
]
==
"remove"
)
{
if
(
d
[
"op"
]
==
"remove"
)
{
modObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
modObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
else
{
}
else
{
modObj
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
modObj
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
}
if
(
modObj
.
count
(
"sn"
)
==
0
)
{
if
(
modObj
.
count
(
"sn"
)
==
0
)
{
if
(
d
[
"op"
]
!=
"remove"
)
{
if
(
d
[
"op"
]
!=
"remove"
)
{
string
msg
=
fmt
::
format
(
"invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}"
,
mgrSn
,
ipcIdx
,
modName
,
modIdx
);
string
msg
=
fmt
::
format
(
"invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}"
,
mgrSn
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
hasError
=
true
;
hasError
=
true
;
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
break
;
break
;
}
else
{
}
else
{
// nop
// nop
}
}
}
else
{
}
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
sn
){
else
{
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
sn
)
{
if
(
modName
==
"evml"
)
{
if
(
modName
==
"evml"
)
{
if
(
modObj
.
count
(
"type"
)
==
0
)
{
if
(
modObj
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
else
{
}
else
{
modName
=
modName
+
modObj
[
"type"
].
get
<
string
>
();
modName
=
modName
+
modObj
[
"type"
].
get
<
string
>
();
}
}
}
}
...
@@ -414,30 +510,111 @@ namespace cfgutils {
...
@@ -414,30 +510,111 @@ namespace cfgutils {
string
modGid
=
sn
+
":"
+
modName
+
":"
+
to_string
(
modObj
[
"iid"
].
get
<
int
>
());
string
modGid
=
sn
+
":"
+
modName
+
":"
+
to_string
(
modObj
[
"iid"
].
get
<
int
>
());
if
(
d
[
"op"
]
==
"remove"
)
{
if
(
d
[
"op"
]
==
"remove"
)
{
ret
[
"data"
][
modGid
]
=
0
;
ret
[
"data"
][
modGid
]
=
0
;
}
else
{
}
else
{
ret
[
"data"
][
modGid
]
=
1
;
ret
[
"data"
][
modGid
]
=
1
;
}
}
}
else
{
}
else
{
// nop
// nop
}
}
}
}
}
}
}
}
// whole cluster
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN
// "value":{"addr":"127.0.0.1","api-cloud":"http://127.0.0.1:8089","ipcs":[{"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}],"mqtt-cloud":"<cloud_addr>","port-cloud":5556,"port-router":5550,"proto":"zmq","sn":"PSBV7GKN"}
string
clusterRegStr
=
"/(
\\
w+)"
;
std
::
regex
clusterRegex
(
clusterRegStr
);
std
::
smatch
results
;
if
(
std
::
regex_match
(
path_
,
results
,
clusterRegex
))
{
if
(
results
.
size
()
==
2
)
{
matched
=
true
;
string
mgrSn
=
results
[
1
].
str
();
json
mgr
;
if
(
d
[
"op"
]
==
"remove"
)
{
mgr
[
mgrSn
]
=
oldConfig
[
mgrSn
];
}
}
else
{
mgr
[
mgrSn
]
=
newConfig
[
mgrSn
];
}
}
if
(
hasError
){
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
"getModulesOperFromConfDiff"
);
ret
[
"code"
]
=
1
;
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
break
;
}
else
{
for
(
auto
&
k
:
jret
[
"data"
])
{
if
(
d
[
"op"
]
==
"remove"
)
{
ret
[
"data"
][
string
(
k
)]
=
0
;
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
}
}
}
}
}
}
// one ipc
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string
clusterRegStr
=
"/(
\\
w+)/ipcs/(
\\
d+)"
;
std
::
regex
clusterRegex
(
clusterRegStr
);
std
::
smatch
results
;
if
(
std
::
regex_match
(
path_
,
results
,
clusterRegex
))
{
if
(
results
.
size
()
==
3
)
{
matched
=
true
;
string
mgrSn
=
results
[
1
].
str
();
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
json
mgr
;
if
(
d
[
"op"
]
==
"remove"
)
{
mgr
[
mgrSn
]
=
oldConfig
[
mgrSn
];
}
else
{
mgr
[
mgrSn
]
=
newConfig
[
mgrSn
];
}
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
"getModulesOperFromConfDiff"
,
ipcIdx
);
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
break
;
break
;
}
}
else
{
for
(
auto
&
k
:
jret
[
"data"
])
{
if
(
d
[
"op"
]
==
"remove"
)
{
ret
[
"data"
][
string
(
k
)]
=
0
;
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
}
}
}
}
}
}
}
}
}
catch
(
exception
&
e
)
{
}
}
if
(
hasError
)
{
ret
[
"code"
]
=
1
;
}
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"getModulesOperFromConfDiff exception: {}"
,
e
.
what
());
spdlog
::
error
(
"getModulesOperFromConfDiff exception: {}"
,
e
.
what
());
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
ret
[
"msg"
]
=
e
.
what
();
ret
[
"msg"
]
=
e
.
what
();
}
}
return
ret
;
return
ret
;
}
}
}
// cfgutils
}
// cfgutils
opencv-motion-detect/inc/utils.hpp
浏览文件 @
f981a53a
...
@@ -46,6 +46,7 @@ namespace cfgutils {
...
@@ -46,6 +46,7 @@ namespace cfgutils {
int
getPeerId
(
string
modName
,
json
&
modElem
,
string
&
peerId
,
string
&
peerName
);
int
getPeerId
(
string
modName
,
json
&
modElem
,
string
&
peerId
,
string
&
peerName
);
json
*
findModuleConfig
(
string
peerId
,
json
&
data
);
json
*
findModuleConfig
(
string
peerId
,
json
&
data
);
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
);
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
);
json
getModuleGidsFromCfg
(
string
sn
,
json
&
data
,
string
caller
=
""
,
int
ipcIdx
=
-
1
);
}
}
struct
StrException
:
public
std
::
exception
struct
StrException
:
public
std
::
exception
...
...
opencv-motion-detect/test_regex.cpp
浏览文件 @
f981a53a
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include "json.hpp"
#include "json.hpp"
#include <spdlog/spdlog.h>
#include <spdlog/spdlog.h>
#include <fmt/format.h>
#include <fmt/format.h>
#include "utils.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
nlohmann
;
using
namespace
nlohmann
;
...
@@ -241,16 +242,88 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -241,16 +242,88 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
}
}
}
}
}
}
}
}
// whole cluster
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN
// "value":{"addr":"127.0.0.1","api-cloud":"http://127.0.0.1:8089","ipcs":[{"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}],"mqtt-cloud":"<cloud_addr>","port-cloud":5556,"port-router":5550,"proto":"zmq","sn":"PSBV7GKN"}
string
clusterRegStr
=
"/(
\\
w+)"
;
std
::
regex
clusterRegex
(
clusterRegStr
);
std
::
smatch
results
;
if
(
std
::
regex_match
(
path_
,
results
,
clusterRegex
))
{
if
(
results
.
size
()
==
2
)
{
matched
=
true
;
string
mgrSn
=
results
[
1
].
str
();
json
mgr
;
if
(
d
[
"op"
]
==
"remove"
){
mgr
[
mgrSn
]
=
oldConfig
[
mgrSn
];
}
else
{
mgr
[
mgrSn
]
=
newConfig
[
mgrSn
];
}
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
"getModulesOperFromConfDiff"
);
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
break
;
}
else
{
for
(
auto
&
k
:
jret
[
"data"
])
{
if
(
d
[
"op"
]
==
"remove"
){
ret
[
"data"
][
string
(
k
)]
=
0
;
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
}
}
}
}
}
}
}
}
if
(
hasError
){
// one ipc
ret
[
"code"
]
=
1
;
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string
clusterRegStr
=
"/(
\\
w+)/ipcs/(
\\
d+)"
;
std
::
regex
clusterRegex
(
clusterRegStr
);
std
::
smatch
results
;
if
(
std
::
regex_match
(
path_
,
results
,
clusterRegex
))
{
if
(
results
.
size
()
==
3
)
{
matched
=
true
;
string
mgrSn
=
results
[
1
].
str
();
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
json
mgr
;
if
(
d
[
"op"
]
==
"remove"
){
mgr
[
mgrSn
]
=
oldConfig
[
mgrSn
];
}
else
{
mgr
[
mgrSn
]
=
newConfig
[
mgrSn
];
}
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
"getModulesOperFromConfDiff"
,
ipcIdx
);
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
break
;
break
;
}
else
{
for
(
auto
&
k
:
jret
[
"data"
])
{
if
(
d
[
"op"
]
==
"remove"
){
ret
[
"data"
][
string
(
k
)]
=
0
;
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
}
}
}
}
}
}
}
}
}
}
}
if
(
hasError
){
ret
[
"code"
]
=
1
;
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"getModulesOperFromConfDiff exception: {}"
,
e
.
what
());
spdlog
::
error
(
"getModulesOperFromConfDiff exception: {}"
,
e
.
what
());
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论