提交 dddd65df authored 作者: blu's avatar blu

big refacting of communitation architect

上级 256c4c23
...@@ -44,6 +44,8 @@ class EvDaemon{ ...@@ -44,6 +44,8 @@ class EvDaemon{
thread thCloud; thread thCloud;
bool bReload = false; bool bReload = false;
bool bBootstrap = true; bool bBootstrap = true;
bool bColdStart = true;
// peerData["status"]; // peerData["status"];
// peerData["pids"]; // peerData["pids"];
// peerData["config"]; // peerData["config"];
...@@ -181,23 +183,60 @@ class EvDaemon{ ...@@ -181,23 +183,60 @@ class EvDaemon{
} }
} }
void setupSubSystems() { int startSubSystems() {
// TODO: check configuratin modified subsystem and force start
int ret = 0;
json keyPids = json();
json keyConfig = json();
for(auto &[k,v]: this->peerData["config"].items()) {
keyConfig.push_back(k);
}
for(auto &[k, v]: this->peerData["pids"].items()) {
keyPids.push_back(k);
}
json diff = json::diff(keyPids, keyConfig);
spdlog::info("evdaemon {} key diff: {}", devSn, diff.dump());
// int ret = 0;
// if(this->peerData["pids"].count(peerId) != 0 && force) {
// kill(this->peerData["pids"][peerId], SIGTERM);
// }else if(this->peerData["pids"].count(peerId) == 0) {
// pid_t pid;
// ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
// if(ret != 0) {
// spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
// }
// this->peerData["pids"][peerId] = pid;
// spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
// }else{
// }
return ret;
}
void subSystemsMgr() {
thMon = thread([this](){ thMon = thread([this](){
int ret = 0;
while(true) { while(true) {
if(this->bReload) { if(this->bReload) {
//cleanupSubSystems(); //cleanupSubSystems();
int ret; ret = reloadCfg("");
if(bBootstrap){
ret = reloadCfg("ALL");
}else{
ret = reloadCfg("");
}
if(ret != 0) { if(ret != 0) {
cleanupSubSystems(); //TODO
}else{ }else{
bReload = false; bReload = false;
} }
if(this->bColdStart) {
// TODO:
}
if(this->bBootstrap) {
// todo
startSubSystems();
}
} }
this_thread::sleep_for(chrono::seconds(5)); this_thread::sleep_for(chrono::seconds(5));
...@@ -390,7 +429,11 @@ class EvDaemon{ ...@@ -390,7 +429,11 @@ class EvDaemon{
} }
// TODO: detailed diff on submodules // TODO: detailed diff on submodules
}else{ }else{
spdlog::info("evdaemon {} received same configuration and ignored: {}", devSn, data.dump()); if(this->bColdStart) {
startSubSystems();
}else{
spdlog::info("evdaemon {} received same configuration and ignored: {}", devSn, data.dump());
}
} }
} }
} }
...@@ -410,7 +453,7 @@ class EvDaemon{ ...@@ -410,7 +453,7 @@ class EvDaemon{
public: public:
void run(){ void run(){
setupSubSystems(); subSystemsMgr();
// get config // get config
svr.Get("/info", [this](const Request& req, Response& res){ svr.Get("/info", [this](const Request& req, Response& res){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论