提交 5cc5ea4f authored 作者: blu's avatar blu

big refacting of communitation architect

上级 6ee36698
......@@ -5,7 +5,8 @@
"chrono": "cpp",
"optional": "cpp",
"string": "cpp",
"set": "cpp"
"set": "cpp",
"thread": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
\ No newline at end of file
{
"data":{
"W5TA2ZE6":{
"5A5S3CTJ":{
"addr":"127.0.0.1",
"api-cloud":"http://127.0.0.1:8089",
"ipcs":[
......@@ -14,7 +14,7 @@
"iid":1,
"post":30,
"pre":3,
"sn":"W5TA2ZE6",
"sn":"5A5S3CTJ",
"status":0,
"thresh":80,
"type":"motion"
......@@ -24,9 +24,8 @@
{
"addr":"127.0.0.1",
"iid":1,
"enabled": 1,
"port-pub":5556,
"sn":"W5TA2ZE6",
"sn":"5A5S3CTJ",
"status":0
}
],
......@@ -35,7 +34,7 @@
"enabled":1,
"iid":1,
"password":"",
"sn":"W5TA2ZE6",
"sn":"5A5S3CTJ",
"status":0,
"token":"",
"urlDest":"rtsp://40.73.41.176:554/test1",
......@@ -47,7 +46,7 @@
"enabled":1,
"iid":1,
"path":"slices",
"sn":"W5TA2ZE6",
"sn":"5A5S3CTJ",
"status":0
}
]
......@@ -63,7 +62,7 @@
"port-cloud":5556,
"port-router":5550,
"proto":"zmq",
"sn":"W5TA2ZE6",
"sn":"5A5S3CTJ",
"status":1
}
},
......
......@@ -203,10 +203,10 @@ int saveLocalConfigration(json &config, string fileName)
int ret = 0;
string mv = string("mv -f ") + fileName + " " + fileName+".bak";
system(mv.c_str());
if(ret == -1) {
spdlog::error("saveLocalConfigration failed to mv file: {}", mv);
return -1;
}
// if(ret == -1) {
// spdlog::error("saveLocalConfigration failed to mv file: {}", mv);
// return -1;
// }
// write prettified JSON file
try{
......
......@@ -175,10 +175,10 @@ namespace LVDB {
string mkdir_ = "mkdir -p " + fileName;
//spdlog::info("creating directory: {}", mkdir_);
ret = system(mkdir_.c_str());
if(-1 == ret) {
spdlog::error("failed to create directory for {}", fileName);
exit(1);
}
// if(-1 == ret) {
// spdlog::error("failed to create directory for {}", fileName);
// exit(1);
// }
bmk = true;
}
......
......@@ -36,6 +36,7 @@ class EvDaemon{
thread::id thIdMain;
thread thRouter;
json peerData;
bool bReload = true;
// peerData["status"];
// peerData["pids"];
// peerData["config"];
......@@ -88,7 +89,7 @@ class EvDaemon{
if(ret != 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
// TODO: clean up and reload config
exit(1);
return -3;
}
this->peerData["pids"][peerId] = pid;
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
......@@ -122,7 +123,7 @@ class EvDaemon{
if(ret != 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
// TODO: cleanup and reload
exit(1);
return -2;
}
this->peerData["pids"][peerId] = pid;
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
......@@ -143,18 +144,37 @@ class EvDaemon{
}
void setupSubSystems() {
thMon = thread([this](){
thMon = thread([&, this](){
while(true) {
int ret = reloadCfg();
if(ret != 0) {
spdlog::error("evdaemon {} failed to setup subsystems, please check log for more info", this->devSn);
this_thread::sleep_for(chrono::seconds(5));
if(bReload) {
int ret = reloadCfg();
if(ret != 0) {
// cleanup
spdlog::info("evdaemon {} peerData {}", this->devSn, this->peerData.dump());
json &pd = this->peerData;
for(auto &[k,v]: pd["pids"].items()){
//kill(v, SIGTERM);
if(this->peerData["status"].count(k) != 0){
this->peerData["status"].erase(k);
}
if(this->peerData["config"].count(k) != 0){
this->peerData["config"].erase(k);
}
this->peerData["pids"].erase(k);
}
}else{
bReload = false;
}
}
break;
this_thread::sleep_for(chrono::seconds(30));
}
});
thMon.detach();
}
......@@ -419,6 +439,7 @@ void cleanup(int signal) {
int main(){
signal(SIGCHLD, cleanup);
//sigignore(SIGCHLD);
json info;
LVDB::getSn(info);
spdlog::info("evdaemon: \n{}",info.dump(4));
......
......@@ -177,10 +177,10 @@ private:
}
ret = system(("mkdir -p " +urlOut).c_str());
if(ret == -1) {
spdlog::error("failed mkdir {}", urlOut);
return -1;
}
// if(ret == -1) {
// spdlog::error("failed mkdir {}", urlOut);
// return -1;
// }
// detection params
if(evmlmotion.count("thresh") == 0||evmlmotion["thresh"] < 10 ||evmlmotion["thresh"] >= 255) {
......
......@@ -156,10 +156,10 @@ private:
// DB::exec(NULL, "select id, ts, last from slices;", DB::get_slices, sliceIdxToName);
spdlog::info("mkdir -p {}", urlOut);
ret = system((string("mkdir -p ") + urlOut).c_str());
if(ret == -1) {
spdlog::error("failed to create {} dir", urlOut);
exit(1);
}
// if(ret == -1) {
// spdlog::error("failed to create {} dir", urlOut);
// exit(1);
// }
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["port-pub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["port-router"]);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论