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

big refacting of communitation architect

上级 6abf9c0a
...@@ -31,7 +31,7 @@ private: ...@@ -31,7 +31,7 @@ private:
Server svr; Server svr;
void *pRouterCtx = NULL, *pRouter = NULL; void *pRouterCtx = NULL, *pRouter = NULL;
string httpPort = "8089"; string httpPort = "8089";
string msgPort = "5048"; string msgPort = "5548";
string devSn = "evcloudsvc"; string devSn = "evcloudsvc";
json configMap; json configMap;
...@@ -110,8 +110,12 @@ private: ...@@ -110,8 +110,12 @@ private:
if(this->configMap["sn2mods"].count(sn) == 0) { if(this->configMap["sn2mods"].count(sn) == 0) {
this->configMap["sn2mods"][sn] = json(); this->configMap["sn2mods"][sn] = json();
} }
this->configMap["sn2mods"][sn].push_back(modKey); if(this->configMap["sn2mods"][sn].contains(modKey)){
//nop
}else{
this->configMap["sn2mods"][sn].push_back(modKey);
}
// modkey -> sn_of_evmgr // modkey -> sn_of_evmgr
this->configMap["mod2mgr"][modKey] = k; this->configMap["mod2mgr"][modKey] = k;
} }
...@@ -209,6 +213,7 @@ private: ...@@ -209,6 +213,7 @@ private:
string meta = j.dump(); string meta = j.dump();
vector<vector<uint8_t> > v = {str2body(selfId), str2body(devSn), str2body(meta), str2body(cfg)}; vector<vector<uint8_t> > v = {str2body(selfId), str2body(devSn), str2body(meta), str2body(cfg)};
z_send_multiple(pRouter, v); z_send_multiple(pRouter, v);
spdlog::info("evcloudsvc config sent to {}: {}", selfId, cfg);
} }
else { else {
peerData["status"][selfId] = 0; peerData["status"][selfId] = 0;
...@@ -338,6 +343,18 @@ public: ...@@ -338,6 +343,18 @@ public:
this->configMap = cnfm; this->configMap = cnfm;
} }
// populate peerData
for(auto &[k,v]: this->configMap["sn2mods"].items()){
// load config from database
json cfg;
if(LVDB::getLocalConfig(cfg, k) < 0) {
spdlog::error("evcloudsvc failed to load config for device: {}", k);
}else{
this->peerData["config"][k] = cfg;
spdlog::info("evcloudsvc populated config for device: {}", k);
}
}
// svr.Post("/register", [this](const Request& req, Response& res){ // svr.Post("/register", [this](const Request& req, Response& res){
// json ret; // json ret;
// try{ // try{
......
...@@ -434,7 +434,7 @@ class EvDaemon{ ...@@ -434,7 +434,7 @@ class EvDaemon{
// its configuration message // its configuration message
if(meta == EV_MSG_META_CONFIG) { if(meta == EV_MSG_META_CONFIG) {
json diff = json::diff(config, data); json diff = json::diff(config, data);
spdlog::info("evdaemon {} received cloud config {}", devSn, diff.dump()); spdlog::info("evdaemon {} received cloud config diff:\n{}\nfull\n{}", devSn, diff.dump(4), data.dump(4));
} }
}else{ }else{
// from peer // from peer
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论