Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
bb359349
提交
bb359349
authored
10月 09, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upload video files
上级
081b0087
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
129 行增加
和
37 行删除
+129
-37
test_regex.cpp
opencv-motion-detect/test_regex.cpp
+129
-37
没有找到文件。
opencv-motion-detect/test_regex.cpp
浏览文件 @
bb359349
...
...
@@ -4,57 +4,149 @@
#include <vector>
#include <string>
#include <set>
#include "inc/json.hpp"
#include "json.hpp"
#include <spdlog/spdlog.h>
#include <fmt/format.h>
using
namespace
std
;
using
namespace
nlohmann
;
json
getModuleActionFromDiff
(
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
json
ret
;
for
(
auto
&
d
:
diff
)
{
if
(
d
.
count
(
"path"
)
!=
0
)
{
string
path_
=
d
[
"path"
];
bool
matched
=
false
;
// match ipc config
// eg: /NMXH73Y2/ipcs/0/addr
// \\w+ could be: addr, user, password, port
set
<
string
>
oprations
{
"add"
,
"replace"
,
"remove"
};
set
<
string
>
pullerTag
{
"addr"
,
"user"
,
"password"
,
"proto"
,
"port"
/*, "sn"*/
};
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
ret
[
"data"
]
=
json
();
bool
hasError
=
false
;
try
{
for
(
auto
&
d
:
diff
)
{
if
(
d
.
count
(
"path"
)
!=
0
)
{
string
path_
=
d
[
"path"
];
bool
matched
=
false
;
// match ipc config
// eg: /NMXH73Y2/ipcs/0/addr
// \\w+ could be: addr, user, password, port
set
<
string
>
oprations
{
"add"
,
"replace"
,
"remove"
};
set
<
string
>
pullerTag
{
"addr"
,
"user"
,
"password"
,
"proto"
,
"port"
/*, "sn"*/
};
string
ipcRegStr
=
string
(
"/"
)
+
this
->
devSn
+
"/ipcs/(
\\
d+)/(
\\
w+)"
;
std
::
smatch
results
;
std
::
regex
ipcRegex
(
ipcRegStr
);
if
(
std
::
regex_match
(
path_
,
results
,
ipcRegex
))
{
if
(
results
.
size
()
==
3
)
{
matched
=
true
;
int
ipcIdx
=
stoi
(
results
[
1
].
str
());
string
tag
=
results
[
2
].
str
();
if
(
pullerTag
.
find
(
tag
)
!=
pullerTag
.
end
())
{
if
(
d
[
"op"
]
==
"add"
)
{
// start
auto
ipc
=
newConfig
[
sn
][
"ipcs"
][
ipcIdx
];
if
(
ipc
.
count
(
"modules"
)
==
0
||
ipc
[
"modules"
].
size
()
==
0
||
ipc
[
"moudles"
].
count
(
"evpuller"
)
==
0
||
ipc
[
"modules"
]
)
string
ipcRegStr
=
string
(
"/"
)
+
sn
+
"/ipcs/(
\\
d+)/(
\\
w+)"
;
std
::
smatch
results
;
std
::
regex
ipcRegex
(
ipcRegStr
);
if
(
std
::
regex_match
(
path_
,
results
,
ipcRegex
))
{
if
(
results
.
size
()
==
3
)
{
matched
=
true
;
int
ipcIdx
=
stoi
(
results
[
1
].
str
());
string
tag
=
results
[
2
].
str
();
if
(
pullerTag
.
find
(
tag
)
!=
pullerTag
.
end
())
{
// TODO: op = remove
if
(
d
[
"op"
]
==
"add"
||
d
[
"op"
]
==
"replace"
)
{
// start
auto
ipc
=
newConfig
[
sn
][
"ipcs"
][
ipcIdx
];
if
(
ipc
.
count
(
"modules"
)
==
0
||
ipc
[
"modules"
].
size
()
==
0
||
ipc
[
"moudles"
].
count
(
"evpuller"
)
==
0
||
ipc
[
"modules"
][
"evpuller"
].
size
()
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid config for ipc[{}]['modules']['evpuller']: {}"
,
ipcIdx
,
newConfig
.
dump
());
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
break
;
}
else
{
auto
&
evpullers
=
ipc
[
"module"
][
"evpuller"
];
int
idx
=
0
;
for
(
auto
&
puller
:
evpullers
)
{
// strutil
if
(
puller
.
count
(
"iid"
)
==
0
||
puller
.
count
(
"addr"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invliad config as of having no iid/addr/enabled field in ipc[{}]['modules']['evpuller'][{}]: {}"
,
ipcIdx
,
idx
,
newConfig
.
dump
());
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
}
else
{
string
gid
=
sn
+
":evpuller:"
+
to_string
(
puller
[
"iid"
].
get
<
int
>
());
if
(
puller
.
count
(
"enabled"
)
==
0
||
puller
[
"enabled"
].
get
<
int
>
()
==
0
)
{
ret
[
"data"
][
gid
]
=
0
;
// stop
}
else
{
ret
[
"data"
][
gid
]
=
2
;
}
}
idx
++
;
}
}
}
}
}
}
}
// match module config
if
(
!
matched
)
{
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
string
moduleRegStr
=
"/NMXH73Y2/ipcs/(
\\
d+)/modules/(
\\
w+)/(
\\
d+)/(
\\
w+)"
;
std
::
regex
moduleRegex
(
moduleRegStr
);
std
::
smatch
results2
;
if
(
std
::
regex_match
(
_path
,
results2
,
moduleRegex
))
{
if
(
results2
.
size
()
==
5
)
{
for
(
auto
&
v
:
results2
)
{
cout
<<
v
.
str
()
<<
endl
;
// match module config
if
(
!
matched
&&
!
hasError
)
{
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
string
moduleRegStr
=
string
(
"/"
)
+
sn
+
"/ipcs/(
\\
d+)/modules/(
\\
w+)/(
\\
d+)/(
\\
w+)"
;
std
::
regex
moduleRegex
(
moduleRegStr
);
std
::
smatch
results2
;
if
(
std
::
regex_match
(
path_
,
results2
,
moduleRegex
))
{
if
(
results2
.
size
()
==
5
)
{
int
ipcIdx
=
stoi
(
results2
[
1
].
str
());
int
modIdx
=
stoi
(
results
[
3
].
str
());
string
modName
=
results
[
2
].
str
();
string
propName
=
results
[
4
].
str
();
if
(
d
[
"op"
]
==
"replace"
||
d
[
"op"
]
==
"add"
)
{
auto
&
oldMod
=
oldConfig
[
sn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modIdx
];
auto
&
newMod
=
newConfig
[
sn
][
"ipcs"
][
ipcIdx
][
"modules"
][
modIdx
];
if
(
oldMod
.
count
(
"iid"
)
==
0
||
newMod
.
count
(
"iid"
)
==
0
)
{
string
msg
=
fmt
::
format
(
"invalid module config ipcs[{}]['modules'][{}][{}] having no iid field"
,
ipcIdx
,
modName
,
modIdx
);
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
hasError
=
true
;
break
;
}
else
{
if
(
modName
==
"evml"
)
{
if
(
newMod
.
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
+
newMod
[
"type"
].
get
<
string
>
();
}
}
string
oldGid
=
sn
+
":"
+
modName
+
":"
+
oldMod
[
"iid"
].
get
<
string
>
();
string
newGid
=
sn
+
":"
+
modName
+
":"
+
newMod
[
"iid"
].
get
<
string
>
();
if
(
oldGid
!=
newGid
)
{
ret
[
"data"
][
oldGid
]
=
0
;
}
if
(
propName
==
"enabled"
)
{
if
(
newMod
[
"enabled"
].
get
<
int
>
()
==
0
)
{
ret
[
"data"
][
newGid
]
=
0
;
}
else
{
ret
[
"data"
][
newGid
]
=
2
;
}
}
else
{
// disabled
if
(
ret
[
"data"
].
count
(
newGid
)
!=
0
&&
ret
[
"data"
][
newGid
].
get
<
int
>
()
==
0
)
{
// nop
}
else
{
// restart
ret
[
"data"
][
newGid
]
=
2
;
}
}
}
}
}
}
}
}
}
if
(
hasError
){
ret
[
"code"
]
=
1
;
}
}
}
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"getModulesOperFromConfDiff exception: {}"
,
e
.
what
());
ret
[
"code"
]
=
-
1
;
ret
[
"msg"
]
=
e
.
what
();
}
return
ret
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论