Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
0b360f23
提交
0b360f23
authored
9月 08, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor communitation archtecture to use evdamon only
上级
69badb46
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
58 行增加
和
13 行删除
+58
-13
database.cpp
opencv-motion-detect/database.cpp
+0
-1
evdaemon.cpp
opencv-motion-detect/evdaemon.cpp
+42
-9
evmgr.cpp
opencv-motion-detect/evmgr.cpp
+0
-0
utils.hpp
opencv-motion-detect/inc/utils.hpp
+16
-3
没有找到文件。
opencv-motion-detect/database.cpp
浏览文件 @
0b360f23
...
@@ -386,7 +386,6 @@ togo_end:
...
@@ -386,7 +386,6 @@ togo_end:
spdlog
::
warn
(
"no local sn set. create a new one: {}"
,
sn
);
spdlog
::
warn
(
"no local sn set. create a new one: {}"
,
sn
);
auto
tsNow
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
auto
tsNow
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
info
[
"lastboot"
]
=
tsNow
;
info
[
"lastboot"
]
=
tsNow
;
info
[
"updatetime"
]
=
tsNow
;
ret
=
setSn
(
info
,
fileName
);
ret
=
setSn
(
info
,
fileName
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to save new generated sn"
);
spdlog
::
error
(
"failed to save new generated sn"
);
...
...
opencv-motion-detect/evdaemon.cpp
浏览文件 @
0b360f23
...
@@ -52,29 +52,55 @@ class EvDaemon{
...
@@ -52,29 +52,55 @@ class EvDaemon{
this
->
devSn
=
this
->
info
[
"sn"
];
this
->
devSn
=
this
->
info
[
"sn"
];
/// req config
/// req config
json
jret
=
cloudutils
::
reqConfig
(
this
->
info
);
json
jret
=
cloudutils
::
reqConfig
(
this
->
info
);
spdlog
::
info
(
"evmgr {} got cloud config:
\n
{}"
,
devSn
,
jret
.
dump
(
4
));
// apply config
// apply config
try
{
try
{
if
(
jret
[
"code"
]
!=
0
)
{
if
(
jret
[
"code"
]
!=
0
)
{
spdlog
::
error
(
"evdaemon {} req
Config
error: {}"
,
this
->
devSn
,
jret
[
"msg"
].
get
<
string
>
());
spdlog
::
error
(
"evdaemon {} req
uest cloud configration
error: {}"
,
this
->
devSn
,
jret
[
"msg"
].
get
<
string
>
());
return
2
;
return
2
;
}
}
spdlog
::
info
(
"evmgr {} got cloud config:
\n
{}"
,
devSn
,
jret
.
dump
(
4
));
json
&
data
=
jret
[
"data"
];
json
&
data
=
jret
[
"data"
];
for
(
auto
&
[
k
,
v
]
:
data
.
items
())
{
for
(
auto
&
[
k
,
v
]
:
data
.
items
())
{
if
(
k
==
this
->
devSn
)
{
if
(
k
==
this
->
devSn
)
{
// startup evmgr
// startup evmgr
pid_t
pid
=
fork
();
pid_t
pid
;
if
(
(
pid
=
fork
())
==
-
1
)
{
ret
=
system
(
"./evmgr"
);
spdlog
::
error
(
"evdamon {} failed to fork subsytem - evmgr"
,
this
->
devSn
);
if
(
ret
==
-
1
)
{
}
else
if
(
pid
==
0
)
{
spdlog
::
error
(
"evdaemon {} failed to start evmgr"
,
this
->
devSn
);
// child
break
;
// execl("./evmgr", "arg1", "arg2", (char *)0);
ret
=
setenv
(
"ADDR"
,
v
[
"addr"
].
get
<
string
>
().
c_str
(),
1
);
ret
+=
setenv
(
"SN"
,
v
[
"sn"
].
get
<
string
>
().
c_str
(),
1
);
ret
+=
setenv
(
"PORT_ROUTER"
,
to_string
(
v
[
"port-router"
].
get
<
int
>
()).
c_str
(),
1
);
ret
+=
setenv
(
"PORT_CLOUD"
,
to_string
(
v
[
"port-cloud"
].
get
<
int
>
()).
c_str
(),
1
);
ret
+=
setenv
(
"ADDR_CLOUD"
,
v
[
"mqtt-cloud"
].
get
<
string
>
().
c_str
(),
1
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evdaemon {} failed to set env"
,
this
->
devSn
);
return
-
3
;
}
execl
(
"./evmgr"
,
NULL
,
NULL
,
NULL
);
spdlog
::
error
(
"evdaemon {} failed to startup evmgr"
,
this
->
devSn
);
}
else
{
// parent
spdlog
::
info
(
"evdaemon {} created evmgr"
,
this
->
devSn
);
}
}
// startup other submodules
json
&
ipcs
=
v
[
"ipcs"
];
for
(
auto
&
ipc
:
ipcs
)
{
json
&
modules
=
ipc
[
"modules"
];
for
(
auto
&
[
mn
,
ml
]
:
modules
.
items
())
{
//
if
()
}
}
}
}
}
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evdaemon {} exception
to reload and apply configuration:
\n
{}"
,
this
->
devSn
,
jret
.
dump
(
4
));
spdlog
::
error
(
"evdaemon {} exception
{} to reload and apply configuration:
\n
{}"
,
this
->
devSn
,
e
.
what
()
,
jret
.
dump
(
4
));
return
-
1
;
return
-
1
;
}
}
...
@@ -89,6 +115,7 @@ class EvDaemon{
...
@@ -89,6 +115,7 @@ class EvDaemon{
spdlog
::
error
(
"evdaemon {} failed to setup subsystems, please check log for more info"
,
this
->
devSn
);
spdlog
::
error
(
"evdaemon {} failed to setup subsystems, please check log for more info"
,
this
->
devSn
);
}
}
this_thread
::
sleep_for
(
chrono
::
seconds
(
5
));
this_thread
::
sleep_for
(
chrono
::
seconds
(
5
));
break
;
}
}
});
});
}
}
...
@@ -184,7 +211,13 @@ class EvDaemon{
...
@@ -184,7 +211,13 @@ class EvDaemon{
~
EvDaemon
(){};
~
EvDaemon
(){};
};
};
void
cleanup
(
int
signal
)
{
int
status
;
while
(
waitpid
((
pid_t
)
(
-
1
),
0
,
WNOHANG
)
>
0
)
{}
}
int
main
(){
int
main
(){
signal
(
SIGCHLD
,
cleanup
);
json
info
;
json
info
;
LVDB
::
getSn
(
info
);
LVDB
::
getSn
(
info
);
spdlog
::
info
(
"evdaemon:
\n
{}"
,
info
.
dump
(
4
));
spdlog
::
info
(
"evdaemon:
\n
{}"
,
info
.
dump
(
4
));
...
...
opencv-motion-detect/evmgr.cpp
浏览文件 @
0b360f23
差异被折叠。
点击展开。
opencv-motion-detect/inc/utils.hpp
浏览文件 @
0b360f23
...
@@ -73,7 +73,7 @@ json reqConfig(json &info){
...
@@ -73,7 +73,7 @@ json reqConfig(json &info){
Uri
uri
=
Uri
::
Parse
(
api
);
Uri
uri
=
Uri
::
Parse
(
api
);
string
sn
=
info
.
at
(
"sn"
).
get
<
string
>
();
string
sn
=
info
.
at
(
"sn"
).
get
<
string
>
();
if
(
uri
.
Host
.
empty
()
||
uri
.
Port
.
empty
()
||
uri
.
Protocol
.
find
(
"http"
)
==
string
::
npos
)
{
if
(
uri
.
Host
.
empty
()
||
uri
.
Port
.
empty
()
||
uri
.
Protocol
.
find
(
"http"
)
==
string
::
npos
)
{
string
msg
=
"reqConfig
error. invalid api-cloud in info: "
+
api
;
string
msg
=
string
(
__FILE__
)
+
":"
+
to_string
(
__LINE__
)
+
": request cloud configuration
error. invalid api-cloud in info: "
+
api
;
ret
[
"code"
]
=
1
;
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
spdlog
::
error
(
msg
);
spdlog
::
error
(
msg
);
...
@@ -85,8 +85,21 @@ json reqConfig(json &info){
...
@@ -85,8 +85,21 @@ json reqConfig(json &info){
Client
cli
(
uri
.
Host
.
c_str
(),
stoi
(
uri
.
Port
));
Client
cli
(
uri
.
Host
.
c_str
(),
stoi
(
uri
.
Port
));
auto
res
=
cli
.
Get
(
"/config"
,
Headers
(),
params
);
auto
res
=
cli
.
Get
(
"/config"
,
Headers
(),
params
);
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
res
->
body
);
if
(
res
==
nullptr
||
res
->
status
!=
200
)
{
ret
=
json
::
parse
(
res
->
body
);
const
char
*
msg
=
NULL
;
if
(
res
==
nullptr
)
{
msg
=
(
string
(
"error to connect to server: "
)
+
api
+
"/config"
).
c_str
();
ret
[
"code"
]
=
-
2
;
}
else
{
msg
=
httplib
::
detail
::
status_message
(
res
->
status
);
ret
[
"code"
]
=
res
->
status
;
}
spdlog
::
debug
(
"failed to reqConfig. {}"
,
msg
);
ret
[
"msg"
]
=
msg
;
}
else
{
spdlog
::
debug
(
"{} {} registry res from cloud : {}"
,
__FILE__
,
__LINE__
,
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
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论