Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
1a714cae
提交
1a714cae
authored
9月 03, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
91e87568
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
101 行增加
和
0 行删除
+101
-0
evcloudsvc.cpp
opencv-motion-detect/evcloudsvc.cpp
+101
-0
没有找到文件。
opencv-motion-detect/evcloudsvc.cpp
0 → 100644
浏览文件 @
1a714cae
/*
module: evcloudsvc
description: mqtt & http svc on cloud for evsuits
author: Bruce.Lu <lzbgt@icloud.com>
update: 2019/09/02
*/
#include <chrono>
#include "inc/tinythread.hpp"
#include "inc/httplib.h"
#include "inc/database.h"
#include "inc/json.hpp"
#include "inc/spdlog/spdlog.h"
using
namespace
std
;
using
namespace
httplib
;
using
namespace
nlohmann
;
//
class
HttpSrv
{
private
:
Server
svr
;
json
configMap
;
protected
:
public
:
void
run
(){
svr
.
Get
(
"/config"
,
[
this
](
const
Request
&
req
,
Response
&
res
){
json
ret
;
ret
[
"code"
]
=
0
;
ret
[
"time"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
ret
[
"msg"
]
=
"ok"
;
if
(
!
req
.
has_param
(
"sn"
)
||
!
req
.
has_param
(
"module"
)){
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
"evcloud bad req: no sn/module param"
;
spdlog
::
error
(
"evcloud bad req: {}"
,
req
);
}
else
{
string
sn
=
req
.
get_param_value
(
"sn"
);
string
module
=
req
.
get_param_value
(
"module"
);
string
key
=
sn
+
":"
+
module
;
if
(
this
->
configMap
.
count
(
key
)
!=
0
)
{
json
config
;
ret
=
LVDB
::
getLocalConfig
(
config
,
this
->
configMap
[
key
]);
if
(
ret
<
0
)
{
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
"evcloud failed to get config with k, v:"
+
key
+
" "
+
this
->
configMap
[
key
].
get
<
string
>
();
spdlog
::
error
(
ret
[
"msg"
]);
}
else
{
ret
[
"data"
]
=
config
;
}
}
else
{
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
"no config for sn "
+
sn
,
+
", module "
+
module
;
}
}
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
});
svr
.
Post
(
"/config"
,
[
this
](
const
Request
&
req
,
Response
&
res
){
json
ret
;
ret
[
"time"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
try
{
json
newConfig
=
json
::
parse
(
req
.
body
);
if
(
newConfig
.
count
(
"data"
)
==
0
||
newConfig
[
"data"
].
size
()
==
0
)
{
}
LVDB
::
setLocalConfig
(
newConfig
);
this
->
configMap
=
newConfig
;
// TODO: restart other components
//
}
catch
(
exception
&
e
)
{
ret
.
clear
();
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
e
.
what
();
}
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
});
svr
.
Post
(
"/reset"
,
[](
const
Request
&
req
,
Response
&
res
){
});
svr
.
listen
(
"0.0.0.0"
,
8088
);
}
HttpSrv
(){
};
~
HttpSrv
(){};
};
int
main
()
{
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论