Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
6f1ad9c4
提交
6f1ad9c4
authored
10月 14, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revise getModulesOperFromConfDiff and related applications
上级
7d1a8b8f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
147 行增加
和
56 行删除
+147
-56
utils.cpp
opencv-motion-detect/inc/utils.cpp
+147
-56
没有找到文件。
opencv-motion-detect/inc/utils.cpp
浏览文件 @
6f1ad9c4
...
...
@@ -310,7 +310,7 @@ json *findModuleConfig(string peerId, json &data)
return
ret
;
}
/// return json key: gid; value: 0 -
stop, 1
- start, 3 - restart
/// return json key: gid; value: 0 -
disabled, 1 - removed, 2
- start, 3 - restart
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
)
{
/// key: gid; value: 0 - stop, 1 - start, 3 - restart
json
ret
;
...
...
@@ -331,7 +331,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
set
<
string
>
oprations
{
"add"
,
"replace"
,
"remove"
};
set
<
string
>
pullerTag
{
"addr"
,
"user"
,
"password"
,
"proto"
,
"port"
/*, "sn"*/
};
//
on
e ipc
//
whol
e 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,"portPub":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","videoServerAddr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
...
...
@@ -344,37 +344,103 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
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
oldIpc
,
newIpc
;
json
oldMgr
,
newMgr
;
if
(
oldConfig
[
mgrSn
][
"ipcs"
].
size
()
>=
ipcIdx
+
1
){
oldIpc
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
];
oldMgr
[
mgrSn
]
=
json
();
oldMgr
[
mgrSn
][
"ipcs"
]
=
json
();
oldMgr
[
mgrSn
][
"ipcs"
].
push_back
(
oldIpc
);
}
string
info
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
);
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
info
,
ipcIdx
);
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
break
;
}
else
{
if
(
jret
[
"msg"
]
!=
"ok"
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
}
for
(
auto
&
k
:
jret
[
"data"
])
{
if
(
d
[
"op"
]
==
"remove"
){
ret
[
"data"
][
string
(
k
)]
=
0
;
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
if
(
newConfig
[
mgrSn
][
"ipcs"
].
size
()
>=
ipcIdx
+
1
){
newIpc
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
];
newMgr
[
mgrSn
]
=
json
();
newMgr
[
mgrSn
][
"ipcs"
]
=
json
();
newMgr
[
mgrSn
][
"ipcs"
].
push_back
(
newIpc
);
}
if
(
newIpc
.
size
()
!=
0
&&
newIpc
.
count
(
"modules"
)
!=
0
&&
newIpc
.
count
(
"addr"
)
!=
0
)
{
for
(
auto
&
[
mn
,
v
]
:
newIpc
[
"modules"
].
items
())
{
string
modName
=
mn
;
json
&
mods
=
v
;
int
modIdx
=
0
;
for
(
auto
&
modObj
:
mods
)
{
string
modSn
=
sn
.
empty
()
?
modObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
modName
==
"evml"
)
{
if
(
modObj
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
else
{
modName
=
modName
+
modObj
[
"type"
].
get
<
string
>
();
}
}
if
(
modObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
modObj
[
"iid"
].
get
<
int
>
());
if
(
modObj
.
count
(
"enabled"
)
==
0
||
modObj
[
"enabled"
]
==
0
)
{
ret
[
"data"
][
modGid
]
=
0
;
// disabled
}
else
{
ret
[
"data"
][
modGid
]
=
2
;
// start
}
}
modIdx
++
;
}
}
}
}
if
(
oldIpc
.
size
()
!=
0
&&
oldIpc
.
count
(
"modules"
)
!=
0
&&
oldIpc
.
count
(
"addr"
)
!=
0
)
{
for
(
auto
&
[
mn
,
v
]
:
oldIpc
[
"modules"
].
items
())
{
string
modName
=
mn
;
json
&
mods
=
v
;
int
modIdx
=
0
;
for
(
auto
&
modObj
:
mods
)
{
string
modSn
=
sn
.
empty
()
?
modObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
modName
==
"evml"
)
{
if
(
modObj
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
else
{
modName
=
modName
+
modObj
[
"type"
].
get
<
string
>
();
}
}
if
(
modObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
modObj
[
"iid"
].
get
<
int
>
());
if
(
ret
[
"data"
].
count
(
modGid
)
!=
0
&&
ret
[
"data"
][
modGid
]
==
2
)
{
ret
[
"data"
][
modGid
]
=
3
;
// restart
}
else
{
ret
[
"data"
][
modGid
]
=
1
;
// perm stop
}
}
modIdx
++
;
}
}
}
}
}
}
// match module config
// match module
prop
config
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN/ipcs/0/modules/evslicer/0/videoServerAddr
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
...
...
@@ -390,7 +456,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
int
modIdx
=
stoi
(
results
[
4
].
str
());
string
modName
=
results
[
3
].
str
();
string
propName
=
results
[
5
].
str
();
if
(
d
[
"op"
]
==
"replace"
||
d
[
"op"
]
==
"add"
||
d
[
"op"
]
==
"remove"
)
{
if
(
true
){
//
d["op"] == "replace"||d["op"] == "add" || d["op"] == "remove") {
auto
&
oldMod
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
auto
&
newMod
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
if
(
oldMod
.
count
(
"iid"
)
==
0
||
newMod
.
count
(
"iid"
)
==
0
)
{
...
...
@@ -425,7 +491,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
string
newGid
=
newSn
+
":"
+
modName
+
":"
+
to_string
(
newMod
[
"iid"
].
get
<
int
>
());
if
(
oldGid
!=
newGid
)
{
ret
[
"data"
][
oldGid
]
=
0
;
ret
[
"data"
][
oldGid
]
=
1
;
// perm stop
}
if
(
!
sn
.
empty
()
&&
sn
!=
newSn
)
{
...
...
@@ -434,17 +500,16 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
if
(
propName
==
"enabled"
)
{
if
(
newMod
.
count
(
"enabled"
)
==
0
||
newMod
[
"enabled"
].
get
<
int
>
()
==
0
)
{
ret
[
"data"
][
newGid
]
=
0
;
ret
[
"data"
][
newGid
]
=
0
;
// disable
}
else
{
ret
[
"data"
][
newGid
]
=
1
;
ret
[
"data"
][
newGid
]
=
2
;
// start
}
}
else
{
// other prop modification
// it was disabled. just ignore
if
(
ret
[
"data"
].
count
(
newGid
)
!=
0
&&
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
0
)
{
// nop
if
(
ret
[
"data"
].
count
(
newGid
)
!=
0
&&
(
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
0
||
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
1
)
)
{
// nop
. stopped or disabled
}
else
{
// restart
ret
[
"data"
][
newGid
]
=
2
;
ret
[
"data"
][
newGid
]
=
3
;
// restart
}
}
}
...
...
@@ -468,47 +533,73 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
int
modIdx
=
stoi
(
results
[
4
].
str
());
string
modName
=
results
[
3
].
str
();
json
modObj
;
if
(
d
[
"op"
]
==
"remove"
)
{
modObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
else
{
modObj
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
json
oldModObj
,
newModObj
;
if
(
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
].
size
()
>=
modIdx
+
1
)
{
oldModObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
if
(
modObj
.
count
(
"sn"
)
==
0
)
{
if
(
d
[
"op"
]
!=
"remove"
){
string
msg
=
fmt
::
format
(
"invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}"
,
mgrSn
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
ret
[
"msg"
]
=
msg
;
break
;
}
}
else
{
string
modSn
=
sn
.
empty
()
?
modObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
].
size
()
>=
modIdx
+
1
){
newModObj
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
if
(
newModObj
.
size
()
!=
0
)
{
string
modSn
=
sn
.
empty
()
?
newModObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
newModObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
modName
==
"evml"
)
{
if
(
m
odObj
.
count
(
"type"
)
==
0
)
{
if
(
newM
odObj
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
else
{
modName
=
modName
+
m
odObj
[
"type"
].
get
<
string
>
();
modName
=
modName
+
newM
odObj
[
"type"
].
get
<
string
>
();
}
}
if
(
m
odObj
.
count
(
"iid"
)
==
0
)
{
if
(
newM
odObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
true
;
break
;
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
m
odObj
[
"iid"
].
get
<
int
>
());
if
(
d
[
"op"
]
==
"remove"
)
{
ret
[
"data"
][
modGid
]
=
0
;
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
newM
odObj
[
"iid"
].
get
<
int
>
());
if
(
newModObj
.
count
(
"enabled"
)
==
0
||
newModObj
[
"enabled"
]
==
0
)
{
ret
[
"data"
][
modGid
]
=
0
;
// disabled
}
else
{
ret
[
"data"
][
modGid
]
=
1
;
ret
[
"data"
][
modGid
]
=
2
;
// start
}
}
}
if
(
oldModObj
.
size
()
!=
0
)
{
string
modSn
=
sn
.
empty
()
?
oldModObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
oldModObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
modName
==
"evml"
)
{
if
(
oldModObj
.
count
(
"type"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
false
;
// TODO
continue
;
}
else
{
modName
=
modName
+
oldModObj
[
"type"
].
get
<
string
>
();
}
}
if
(
oldModObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
hasError
=
false
;
continue
;
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
oldModObj
[
"iid"
].
get
<
int
>
());
if
(
ret
[
"data"
].
count
(
modGid
)
!=
0
&&
ret
[
"data"
][
modGid
]
==
2
)
{
ret
[
"data"
][
modGid
]
=
3
;
// restart
}
else
{
ret
[
"data"
][
modGid
]
=
1
;
// perm stop
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论