提交 7f32fb3f authored 作者: blu's avatar blu

big refacting of communitation architect

上级 19083d73
...@@ -239,19 +239,15 @@ private: ...@@ -239,19 +239,15 @@ private:
return ret; return ret;
} }
int handleMsg(vector<vector<uint8_t> > &body) //
{ bool handleConnection(string selfId) {
int ret = 0; bool ret = false;
// ID_SENDER, ID_TARGET, meta ,MSG int state = zmq_socket_get_peer_state(pRouter, selfId.data(), selfId.size());
string selfId, peerId, meta; spdlog::info("{} state: {}", selfId, state);
if(body.size() == 2 && body[1].size() == 0) {
selfId = body2str(body[0]);
bool eventConn = false;
if(peerData["status"].count(selfId) == 0 || peerData["status"][selfId] == 0) { if(peerData["status"].count(selfId) == 0 || peerData["status"][selfId] == 0) {
peerData["status"][selfId] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); peerData["status"][selfId] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
spdlog::info("evcloudsvc peer connected: {}", selfId); spdlog::info("evcloudsvc peer connected: {}", selfId);
eventConn = true; ret = true;
spdlog::debug("evcloudsvc update status of {} to 1 and send config", selfId); spdlog::debug("evcloudsvc update status of {} to 1 and send config", selfId);
json data = getConfigForDevice(selfId); json data = getConfigForDevice(selfId);
if(data["code"] != 0) { if(data["code"] != 0) {
...@@ -264,7 +260,19 @@ private: ...@@ -264,7 +260,19 @@ private:
peerData["status"][selfId] = 0; peerData["status"][selfId] = 0;
spdlog::warn("evcloudsvc {} peer disconnected: {}", devSn, selfId); spdlog::warn("evcloudsvc {} peer disconnected: {}", devSn, selfId);
} }
return ret;
}
int handleMsg(vector<vector<uint8_t> > &body)
{
int ret = 0;
// ID_SENDER, ID_TARGET, meta ,MSG
string selfId, peerId, meta;
if(body.size() == 2 && body[1].size() == 0) {
selfId = body2str(body[0]);
bool eventConn = handleConnection(selfId);
// TODO
// event // event
json jEvt; json jEvt;
jEvt["type"] = EV_MSG_TYPE_CONN_STAT; jEvt["type"] = EV_MSG_TYPE_CONN_STAT;
...@@ -338,6 +346,7 @@ private: ...@@ -338,6 +346,7 @@ private:
if(meta == "pong"||meta == "ping") { if(meta == "pong"||meta == "ping") {
// update status // update status
spdlog::info("evcloudsvc {}, ping msg from {}", devSn, selfId); spdlog::info("evcloudsvc {}, ping msg from {}", devSn, selfId);
handleConnection(selfId);
if(meta=="ping") { if(meta=="ping") {
if(cachedMsg.find(selfId) != cachedMsg.end()) { if(cachedMsg.find(selfId) != cachedMsg.end()) {
while(!cachedMsg[selfId].empty()) { while(!cachedMsg[selfId].empty()) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论