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

init

上级 452d784e
......@@ -41,6 +41,39 @@ namespace LVDB {
#define LVDB_ERROR_HELD -1
#define LVDB_ERROR_OTHER -2
json * findConfigModule(json &config, string sn, string moduleName, int iid) {
json *ret = NULL;
json &data = config["data"];
for(auto &[k,v]: data.items()){
json &mgr = data[k];
if(mgr.count("ipcs") == 0) {
break;
}else{
json &ipcs = mgr["ipcs"];
for(auto &ipc:ipcs) {
if(ipc.count("modules") == 0) {
break;
}else{
json &modules = ipc["modules"];
if(modules.count(moduleName) == 0){
break;
}else{
json &module = modules[moduleName];
for(auto &inst: module) {
if(inst.count("sn") != 0 && inst["sn"] == sn && inst.count("iid") != 0 && inst["iid"] == iid) {
return &inst;
}
}
}
}
}
}
}
return ret;
}
int _getDB(string fileName, DB** pdb) {
static bool bmk = false;
int ret = 0;
......
......@@ -26,10 +26,10 @@ update: 2019/08/23
namespace fs = std::filesystem;
#endif
#include "zmqhelper.hpp"
#include "tinythread.hpp"
#include "common.hpp"
#include "database.h"
#include "inc/zmqhelper.hpp"
#include "inc/tinythread.hpp"
#include "inc/common.hpp"
#include "inc/database.h"
using namespace std;
using namespace zmqhelper;
......@@ -144,15 +144,37 @@ togo_sleep_continue:
if(body.size() == 2 && body[1].size() == 0) {
selfId = body2str(body[0]);
bool eventConn = false;
// XTF2BJR9:evslicer:1
auto sp = cloudutils::split(selfId, ':');
if(sp.size() != 3) {
spdlog::warn("evmg {} inproper peer id: {}", devSn, selfId);
return -1;
}
json *mod = LVDB::findConfigModule(config, sp[0], sp[1], stoi(sp[2]));
if(mod == NULL) {
spdlog::warn("evmgr {} failed to find module with id: {}", devSn, selfId);
return -1;
}
if(peerStatus.count(selfId) == 0||peerStatus[selfId] == 0) {
peerStatus[selfId] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
spdlog::info("evmgr {} peer connected: {}", devSn, selfId);
eventConn = true;
mod->at("status") = 1;
spdlog::debug("evmgr {} update status of {} to 1", devSn, selfId);
}
else {
peerStatus[selfId] = 0;
mod->at("status") = 0;
spdlog::warn("evmgr {} peer disconnected: {}", devSn, selfId);
}
//update config
ret = LVDB::setLocalConfig(config);
if(ret < 0) {
spdlog::error("evmgr {} failed to update localconfig", devSn);
}
// event
json jEvt;
jEvt["type"] = EV_MSG_TYPE_CONN_STAT;
......
......@@ -25,11 +25,11 @@ update: 2019/08/23
namespace fs = std::filesystem;
#endif
#include "zmqhelper.hpp"
#include "tinythread.hpp"
#include "common.hpp"
#include "database.h"
#include "spdlog/spdlog.h"
#include "inc/zmqhelper.hpp"
#include "inc/tinythread.hpp"
#include "inc/common.hpp"
#include "inc/database.h"
#include "inc/spdlog/spdlog.h"
#define MAX_ZMQ_MSG_SIZE 1204 * 1024 * 2
using namespace std;
......
......@@ -17,6 +17,7 @@ extern "C"
#include <libavutil/timestamp.h>
#include <spdlog/spdlog.h>
#include <json.hpp>
#include <sstream>
using json = nlohmann::json;
#undef av_err2str
......@@ -374,8 +375,17 @@ json registry(const char *sn, const json &config)
return json();
}
vector<string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}
} // namespace cloudutils
......
......@@ -22,8 +22,8 @@ namespace LVDB {
#define LVDB_KEY_SN "SN"
#define LVDB_KEY_CONFIG "CONFIG"
//
json * findConfigModule(json &config, string sn, string moduleName, int iid);
//
int delValue(string key, string fileName);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论