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

big refacting of communitation architect

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