提交 8b84f720 authored 作者: bruce.lu's avatar bruce.lu

init

上级 4d8be15f
...@@ -39,6 +39,8 @@ evmlmotion: evmlmotion.cpp inc/common.hpp inc/avcvhelpers.hpp inc/database.h inc ...@@ -39,6 +39,8 @@ evmlmotion: evmlmotion.cpp inc/common.hpp inc/avcvhelpers.hpp inc/database.h inc
evdaemon: evdaemon.cpp inc/common.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp database.cpp evdaemon: evdaemon.cpp inc/common.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp database.cpp
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evdaemon evdaemon.cpp database.cpp $(SQLITE) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS) $(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evdaemon evdaemon.cpp database.cpp $(SQLITE) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS)
evcloudsvc: evcloudsvc.cpp inc/utils.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp database.cpp
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evcloudsvc evcloudsvc.cpp inc/utils.hpp database.cpp $(SQLITE) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS)
rtspr: rtsp-relay.cpp rtspr: rtsp-relay.cpp
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o rtspr rtsp-relay.cpp $(LIBFFMPEG) $(LD_FLAGS) $(CPP) $(CPPFLAGS) $(LD_FLAGS) -o rtspr rtsp-relay.cpp $(LIBFFMPEG) $(LD_FLAGS)
......
...@@ -12,6 +12,7 @@ update: 2019/09/02 ...@@ -12,6 +12,7 @@ update: 2019/09/02
#include "inc/json.hpp" #include "inc/json.hpp"
#include "inc/spdlog/spdlog.h" #include "inc/spdlog/spdlog.h"
#include "utils.hpp" #include "utils.hpp"
#include "inc/zmqhelper.hpp"
using namespace std; using namespace std;
using namespace httplib; using namespace httplib;
...@@ -31,7 +32,7 @@ class HttpSrv{ ...@@ -31,7 +32,7 @@ class HttpSrv{
// load configmap // load configmap
json cnfm; json cnfm;
LVDB::getValue(cnfm, "configmap"); LVDB::getValue(cnfm, "configmap");
if(cnfm.size != 0){ if(cnfm.size() != 0){
this->configMap = cnfm; this->configMap = cnfm;
} }
...@@ -40,14 +41,21 @@ class HttpSrv{ ...@@ -40,14 +41,21 @@ class HttpSrv{
ret["code"] = 0; ret["code"] = 0;
ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
ret["msg"] = "ok"; ret["msg"] = "ok";
if(!req.has_param("sn") || !req.has_param("module")){ if(!req.has_param("sn") || !req.has_param("module")||req.get_param_value("module").size()< 4){
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "evcloud bad req: no sn/module param"; ret["msg"] = "evcloud bad req: no sn/module param";
spdlog::error("evcloud bad req: {}", req); spdlog::error(ret["msg"].get<string>());
}else{ }else{
string sn = req.get_param_value("sn"); string sn = req.get_param_value("sn");
string module = req.get_param_value("module"); string module = req.get_param_value("module");
string key = sn + ":" + module; string modname = module.substr(0,4);
if(modname == "evml") {
modname = "evml:" + module.substr(4, module.size());
}else{
modname = module;
}
string key = sn + ":" + modname;
if(this->configMap.count(key) != 0) { if(this->configMap.count(key) != 0) {
json config; json config;
ret = LVDB::getLocalConfig(config, this->configMap[key]); ret = LVDB::getLocalConfig(config, this->configMap[key]);
...@@ -55,7 +63,7 @@ class HttpSrv{ ...@@ -55,7 +63,7 @@ class HttpSrv{
if(ret < 0) { if(ret < 0) {
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "evcloud failed to get config with k, v:" + key + " " + this->configMap[key].get<string>(); ret["msg"] = "evcloud failed to get config with k, v:" + key + " " + this->configMap[key].get<string>();
spdlog::error(ret["msg"]); spdlog::error(ret["msg"].get<string>());
}else{ }else{
ret["data"] = config; ret["data"] = config;
} }
...@@ -78,7 +86,7 @@ class HttpSrv{ ...@@ -78,7 +86,7 @@ class HttpSrv{
if(newConfig.count("data") == 0 || newConfig["data"].size() == 0) { if(newConfig.count("data") == 0 || newConfig["data"].size() == 0) {
ret["code"] = 1; ret["code"] = 1;
ret["msg"] = "evcloudsvc invalid config body received: " + req.body; ret["msg"] = "evcloudsvc invalid config body received: " + req.body;
spdlog::error(ret["msg"]); spdlog::error(ret["msg"].get<string>());
}else{ }else{
json &data = newConfig["data"]; json &data = newConfig["data"];
for(auto &[k, v]: data.items()) { for(auto &[k, v]: data.items()) {
...@@ -86,7 +94,7 @@ class HttpSrv{ ...@@ -86,7 +94,7 @@ class HttpSrv{
if(v.count(k) == 0||v[k].size()==0) { if(v.count(k) == 0||v[k].size()==0) {
ret["code"] = 2; ret["code"] = 2;
ret["msg"] = "evcloudsvc invalid value for key " + k; ret["msg"] = "evcloudsvc invalid value for key " + k;
spdlog::error(ret["msg"]); spdlog::error(ret["msg"].get<string>());
continue; continue;
}else{ }else{
// find all modules // find all modules
...@@ -106,9 +114,9 @@ class HttpSrv{ ...@@ -106,9 +114,9 @@ class HttpSrv{
string modKey; string modKey;
//ml //ml
if(mn == "evml" && ml.count("type") != 0 && ml["type"].size() != 0) { if(mn == "evml" && ml.count("type") != 0 && ml["type"].size() != 0) {
modKey = ml["sn"] + ":evml:" + ml["type"]; modKey = ml["sn"].get<string>() +":evml:" + ml["type"].get<string>();
}else{ }else{
modKey = ml["sn"] + ":" + mn; modKey = ml["sn"].get<string>() + ":" + mn;
} }
this->configMap[modKey] = v; this->configMap[modKey] = v;
} }
...@@ -117,7 +125,7 @@ class HttpSrv{ ...@@ -117,7 +125,7 @@ class HttpSrv{
} // for ipc } // for ipc
} }
} }
// update // update evmgr config
auto lastupdated = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); auto lastupdated = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
json evmgrData; json evmgrData;
v["lastupdated"] = lastupdated; v["lastupdated"] = lastupdated;
......
...@@ -101,7 +101,8 @@ vector<vector<uint8_t> > z_recv_multiple(void *s, bool nowait=false) ...@@ -101,7 +101,8 @@ vector<vector<uint8_t> > z_recv_multiple(void *s, bool nowait=false)
// proto [sender_id(only when no identifier set in setsockopts)] [target_id] [body] // proto [sender_id(only when no identifier set in setsockopts)] [target_id] [body]
int z_send_multiple(void *s, vector<vector<uint8_t> >&body) int z_send_multiple(void *s, vector<vector<uint8_t> >&body)
{ {
int cnt = 0, ret = 0; size_t cnt = 0;
int ret = 0;
zmq_msg_t msg; zmq_msg_t msg;
for(auto &i:body) { for(auto &i:body) {
ret = zmq_msg_init_size(&msg, i.size()); ret = zmq_msg_init_size(&msg, i.size());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论