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 个修改的文件
包含
138 行增加
和
47 行删除
+138
-47
utils.cpp
opencv-motion-detect/inc/utils.cpp
+138
-47
没有找到文件。
opencv-motion-detect/inc/utils.cpp
浏览文件 @
6f1ad9c4
...
@@ -310,7 +310,7 @@ json *findModuleConfig(string peerId, json &data)
...
@@ -310,7 +310,7 @@ json *findModuleConfig(string peerId, json &data)
return
ret
;
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
)
{
json
getModulesOperFromConfDiff
(
json
&
oldConfig
,
json
&
newConfig
,
json
&
diff
,
string
sn
)
{
/// key: gid; value: 0 - stop, 1 - start, 3 - restart
/// key: gid; value: 0 - stop, 1 - start, 3 - restart
json
ret
;
json
ret
;
...
@@ -331,7 +331,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -331,7 +331,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
set
<
string
>
oprations
{
"add"
,
"replace"
,
"remove"
};
set
<
string
>
oprations
{
"add"
,
"replace"
,
"remove"
};
set
<
string
>
pullerTag
{
"addr"
,
"user"
,
"password"
,
"proto"
,
"port"
/*, "sn"*/
};
set
<
string
>
pullerTag
{
"addr"
,
"user"
,
"password"
,
"proto"
,
"port"
/*, "sn"*/
};
//
on
e ipc
//
whol
e ipc
if
(
!
matched
&&
!
hasError
)
{
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN/ipcs/0"
// /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"}
// {"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,29 +344,95 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -344,29 +344,95 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
matched
=
true
;
matched
=
true
;
string
mgrSn
=
results
[
1
].
str
();
string
mgrSn
=
results
[
1
].
str
();
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
json
mgr
;
json
oldIpc
,
newIpc
;
if
(
d
[
"op"
]
==
"remove"
){
json
oldMgr
,
newMgr
;
mgr
[
mgrSn
]
=
oldConfig
[
mgrSn
];
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
);
}
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
{
}
else
{
mgr
[
mgrSn
]
=
newConfig
[
mgrSn
];
modName
=
modName
+
modObj
[
"type"
].
get
<
string
>
();
}
}
}
string
info
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
);
if
(
modObj
.
count
(
"iid"
)
==
0
)
{
json
jret
=
cfgutils
::
getModuleGidsFromCfg
(
sn
,
mgr
,
info
,
ipcIdx
);
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
info
(
"jret: {}"
,
jret
.
dump
());
spdlog
::
error
(
msg
);
if
(
jret
[
"code"
]
!=
0
)
{
ret
[
"msg"
]
=
jret
[
"msg"
];
hasError
=
true
;
hasError
=
true
;
break
;
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
{
}
else
{
if
(
jret
[
"msg"
]
!=
"ok"
)
{
ret
[
"data"
][
modGid
]
=
2
;
// start
ret
[
"msg"
]
=
jret
[
"msg"
];
}
}
for
(
auto
&
k
:
jret
[
"data"
])
{
}
if
(
d
[
"op"
]
==
"remove"
){
modIdx
++
;
ret
[
"data"
][
string
(
k
)]
=
0
;
}
}
}
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
{
}
else
{
ret
[
"data"
][
string
(
k
)]
=
2
;
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
++
;
}
}
}
}
}
}
...
@@ -374,7 +440,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -374,7 +440,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
}
}
}
}
// match module config
// match module
prop
config
if
(
!
matched
&&
!
hasError
)
{
if
(
!
matched
&&
!
hasError
)
{
// /PSBV7GKN/ipcs/0/modules/evslicer/0/videoServerAddr
// /PSBV7GKN/ipcs/0/modules/evslicer/0/videoServerAddr
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
...
@@ -390,7 +456,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -390,7 +456,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
int
modIdx
=
stoi
(
results
[
4
].
str
());
int
modIdx
=
stoi
(
results
[
4
].
str
());
string
modName
=
results
[
3
].
str
();
string
modName
=
results
[
3
].
str
();
string
propName
=
results
[
5
].
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
&
oldMod
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
auto
&
newMod
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
auto
&
newMod
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
if
(
oldMod
.
count
(
"iid"
)
==
0
||
newMod
.
count
(
"iid"
)
==
0
)
{
if
(
oldMod
.
count
(
"iid"
)
==
0
||
newMod
.
count
(
"iid"
)
==
0
)
{
...
@@ -425,7 +491,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -425,7 +491,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
string
newGid
=
newSn
+
":"
+
modName
+
":"
+
to_string
(
newMod
[
"iid"
].
get
<
int
>
());
string
newGid
=
newSn
+
":"
+
modName
+
":"
+
to_string
(
newMod
[
"iid"
].
get
<
int
>
());
if
(
oldGid
!=
newGid
)
{
if
(
oldGid
!=
newGid
)
{
ret
[
"data"
][
oldGid
]
=
0
;
ret
[
"data"
][
oldGid
]
=
1
;
// perm stop
}
}
if
(
!
sn
.
empty
()
&&
sn
!=
newSn
)
{
if
(
!
sn
.
empty
()
&&
sn
!=
newSn
)
{
...
@@ -434,17 +500,16 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -434,17 +500,16 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
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
;
// disable
}
else
{
}
else
{
ret
[
"data"
][
newGid
]
=
1
;
ret
[
"data"
][
newGid
]
=
2
;
// start
}
}
}
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
||
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
1
)
)
{
// nop
// nop
. stopped or disabled
}
else
{
}
else
{
// restart
ret
[
"data"
][
newGid
]
=
3
;
// restart
ret
[
"data"
][
newGid
]
=
2
;
}
}
}
}
}
}
...
@@ -468,46 +533,72 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
...
@@ -468,46 +533,72 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
int
ipcIdx
=
stoi
(
results
[
2
].
str
());
int
modIdx
=
stoi
(
results
[
4
].
str
());
int
modIdx
=
stoi
(
results
[
4
].
str
());
string
modName
=
results
[
3
].
str
();
string
modName
=
results
[
3
].
str
();
json
modObj
;
json
oldModObj
,
newModObj
;
if
(
d
[
"op"
]
==
"remove"
)
{
modObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
if
(
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
].
size
()
>=
modIdx
+
1
)
{
oldModObj
=
oldConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
}
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
(
newModObj
.
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
{
}
else
{
modObj
=
newConfig
[
mgrSn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modName
][
modIdx
];
modName
=
modName
+
newModObj
[
"type"
].
get
<
string
>
();
}
}
}
if
(
modObj
.
count
(
"sn"
)
==
0
)
{
if
(
d
[
"op"
]
!=
"remove"
)
{
if
(
newModObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}"
,
mgrSn
,
ipcIdx
,
modName
,
modIdx
);
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
hasError
=
true
;
hasError
=
true
;
ret
[
"msg"
]
=
msg
;
break
;
break
;
}
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
newModObj
[
"iid"
].
get
<
int
>
());
if
(
newModObj
.
count
(
"enabled"
)
==
0
||
newModObj
[
"enabled"
]
==
0
)
{
ret
[
"data"
][
modGid
]
=
0
;
// disabled
}
else
{
}
else
{
string
modSn
=
sn
.
empty
()
?
modObj
[
"sn"
].
get
<
string
>
()
:
sn
;
ret
[
"data"
][
modGid
]
=
2
;
// start
if
(
modObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
}
}
}
if
(
oldModObj
.
size
()
!=
0
)
{
string
modSn
=
sn
.
empty
()
?
oldModObj
[
"sn"
].
get
<
string
>
()
:
sn
;
if
(
oldModObj
[
"sn"
].
get
<
string
>
()
==
modSn
){
if
(
modName
==
"evml"
)
{
if
(
modName
==
"evml"
)
{
if
(
m
odObj
.
count
(
"type"
)
==
0
)
{
if
(
oldM
odObj
.
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
=
false
;
// TODO
break
;
continue
;
}
else
{
}
else
{
modName
=
modName
+
m
odObj
[
"type"
].
get
<
string
>
();
modName
=
modName
+
oldM
odObj
[
"type"
].
get
<
string
>
();
}
}
}
}
if
(
m
odObj
.
count
(
"iid"
)
==
0
)
{
if
(
oldM
odObj
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
string
msg
=
fmt
::
format
(
"invalid evml module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
hasError
=
tru
e
;
hasError
=
fals
e
;
break
;
continue
;
}
}
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
m
odObj
[
"iid"
].
get
<
int
>
());
string
modGid
=
modSn
+
":"
+
modName
+
":"
+
to_string
(
oldM
odObj
[
"iid"
].
get
<
int
>
());
if
(
d
[
"op"
]
==
"remove"
)
{
if
(
ret
[
"data"
].
count
(
modGid
)
!=
0
&&
ret
[
"data"
][
modGid
]
==
2
)
{
ret
[
"data"
][
modGid
]
=
0
;
ret
[
"data"
][
modGid
]
=
3
;
// restart
}
else
{
}
else
{
ret
[
"data"
][
modGid
]
=
1
;
ret
[
"data"
][
modGid
]
=
1
;
// perm stop
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论