提交 58b829b1 authored 作者: blu's avatar blu

big refacting of communitation architect

上级 1416597d
......@@ -29,7 +29,7 @@ using namespace zmqhelper;
class EvCloudSvc {
private:
Server svr;
void *pRouterCtx = NULL, *pRouter = NULL;
void *pRouterCtx = nullptr, *pRouter = nullptr;
string httpPort = "8089";
string msgPort = "5548";
string devSn = "evcloudsvc";
......@@ -557,12 +557,12 @@ public:
int ret = 0;
spdlog::info("evcloudsvc boot");
char *strEnv = getenv("HTTP_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
httpPort = strEnv;
}
strEnv = getenv("MSG_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
msgPort = strEnv;
}
......
......@@ -55,8 +55,8 @@ class EvDaemon{
json mapModsToPids;
// for zmq
void *pRouterCtx = NULL, *pRouter = NULL;
void *pDealerCtx = NULL, *pDealer = NULL;
void *pRouterCtx = nullptr, *pRouter = nullptr;
void *pDealerCtx = nullptr, *pDealer = nullptr;
string cloudAddr = "tcp://127.0.0.1:5548";
/// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc.
......@@ -491,19 +491,19 @@ class EvDaemon{
devSn = info["sn"];
char* strEnv = getenv("BOOTSTRAP");
if(strEnv != NULL && memcmp(strEnv, "false", 5) == 0) {
if(strEnv != nullptr && memcmp(strEnv, "false", 5) == 0) {
bBootstrap = false;
}
// http port
strEnv = getenv("DAEMON_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
port = stoi(strEnv);
}
// zmq router port
strEnv = getenv("ROUTER_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
portRouter = stoi(strEnv);
}
......@@ -533,7 +533,7 @@ class EvDaemon{
// dealer port
strEnv = getenv("CLOUD_ADDR");
if(strEnv != NULL) {
if(strEnv != nullptr) {
cloudAddr = strEnv;
}
......
......@@ -37,9 +37,9 @@ using namespace zmqhelper;
class EvMgr:public TinyThread {
private:
void *pRouterCtx = NULL;
void *pRouter = NULL;
void *pCtxDealer = NULL, *pDealer = NULL;
void *pRouterCtx = nullptr;
void *pRouter = nullptr;
void *pCtxDealer = nullptr, *pDealer = nullptr;
json config;
string devSn, ident;
json peerStatus;
......@@ -127,7 +127,7 @@ private:
return -1;
}
json *mod = LVDB::findConfigModule(config, sp[0], sp[1], stoi(sp[2]));
if(mod == NULL) {
if(mod == nullptr) {
spdlog::warn("evmgr {} failed to find module with id: {}", devSn, selfId);
return -1;
}
......@@ -281,12 +281,12 @@ public:
EvMgr()
{
const char *strEnv = getenv("DR_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
drport = strEnv;
}
strEnv = getenv("PEERID");
if(strEnv != NULL) {
if(strEnv != nullptr) {
ident = strEnv;
auto v = strutils::split(ident, ':');
if(v.size() != 3||v[1] != "evmgr" || v[2] != "0") {
......@@ -318,13 +318,13 @@ public:
}
~EvMgr()
{
if(pRouter != NULL) {
if(pRouter != nullptr) {
zmq_close(pRouter);
pRouter = NULL;
pRouter = nullptr;
}
if(pRouterCtx != NULL) {
if(pRouterCtx != nullptr) {
zmq_ctx_destroy(pRouterCtx);
pRouterCtx = NULL;
pRouterCtx = nullptr;
}
}
};
......
......@@ -67,13 +67,13 @@ enum EventState {
class EvMLMotion: public TinyThread {
private:
void *pSubCtx = NULL, *pDealerCtx = NULL; // for packets relay
void *pSub = NULL, *pDealer = NULL, *pDaemonCtx = NULL, *pDaemon = NULL;
void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay
void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr;
string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid, slicerGid;
int iid;
AVFormatContext *pAVFormatInput = NULL;
AVCodecContext *pCodecCtx = NULL;
AVDictionary *pOptsRemux = NULL;
AVFormatContext *pAVFormatInput = nullptr;
AVCodecContext *pCodecCtx = nullptr;
AVDictionary *pOptsRemux = nullptr;
DetectParam detPara = {25,500,-1,10,3,30, 2};
EventState evtState = EventState::NONE;
chrono::system_clock::time_point evtStartTm, evtStartTmLast;
......@@ -358,12 +358,12 @@ private:
void freeStream()
{
if(pAVFormatInput != NULL) {
if(pAVFormatInput != nullptr) {
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
int decode_packet(bool detect, AVPacket *pPacket, AVCodecContext *pCodecContext, AVFrame *pFrame)
......@@ -652,12 +652,12 @@ public:
{
evtQueue = queue;
const char *strEnv = getenv("DR_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
drport = strEnv;
}
strEnv = getenv("PEERID");
if(strEnv != NULL) {
if(strEnv != nullptr) {
selfId = strEnv;
auto v = strutils::split(selfId, ':');
if(v.size() != 3||v[1] != "evmlmotion") {
......@@ -691,21 +691,21 @@ public:
};
~EvMLMotion()
{
if(pSub != NULL) {
if(pSub != nullptr) {
zmq_close(pSub);
pSub = NULL;
pSub = nullptr;
}
if(pSubCtx != NULL) {
if(pSubCtx != nullptr) {
zmq_ctx_destroy(pSubCtx);
pSubCtx = NULL;
pSubCtx = nullptr;
}
if(pDealer != NULL) {
if(pDealer != nullptr) {
zmq_close(pSub);
pDealer = NULL;
pDealer = nullptr;
}
if(pDealerCtx != NULL) {
if(pDealerCtx != nullptr) {
zmq_ctx_destroy(pSub);
pDealerCtx = NULL;
pDealerCtx = nullptr;
}
};
};
......
......@@ -117,14 +117,14 @@ public:
class EvPuller: public TinyThread {
private:
void *pPubCtx = NULL; // for packets publishing
void *pPub = NULL;
void *pDealerCtx = NULL;
void *pDealer = NULL;
void *pDaemonCtx = NULL, *pDaemon = NULL;
AVFormatContext *pAVFormatInput = NULL;
void *pPubCtx = nullptr; // for packets publishing
void *pPub = nullptr;
void *pDealerCtx = nullptr;
void *pDealer = nullptr;
void *pDaemonCtx = nullptr, *pDaemon = nullptr;
AVFormatContext *pAVFormatInput = nullptr;
string urlIn, urlPub, urlDealer, mgrSn, devSn, selfId, ipcPort;
int *streamList = NULL, numStreams = 0, iid;
int *streamList = nullptr, numStreams = 0, iid;
time_t tsLastBoot, tsUpdateTime;
json config;
string drport = "5549";
......@@ -270,7 +270,7 @@ protected:
}
// serialize formatctx to bytes
char *pBytes = NULL;
char *pBytes = nullptr;
ret = AVFormatCtxSerializer::encode(pAVFormatInput, &pBytes);
auto repSrv = RepSrv(mgrSn, devSn, iid, pBytes, ret, pDealer);
repSrv.detach();
......@@ -325,7 +325,7 @@ protected:
packet.stream_index = streamList[packet.stream_index];
// serialize packet to raw bytes
char * data = NULL;
char * data = nullptr;
int size = AVPacketSerializer::encode(packet, &data);
zmq_msg_init_data(&msg, (void*)data, size, mqPacketFree, NULL);
zmq_send_const(pPub, zmq_msg_data(&msg), size, 0);
......@@ -347,12 +347,12 @@ public:
EvPuller()
{
const char *strEnv = getenv("DR_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
drport = strEnv;
}
strEnv = getenv("PEERID");
if(strEnv != NULL) {
if(strEnv != nullptr) {
selfId = strEnv;
auto v = strutils::split(selfId, ':');
if(v.size() != 3||v[1] != "evpuller") {
......@@ -383,21 +383,21 @@ public:
~EvPuller()
{
if(pPub != NULL) {
if(pPub != nullptr) {
zmq_close(pPub);
pPub = NULL;
pPub = nullptr;
}
if(pPubCtx != NULL) {
if(pPubCtx != nullptr) {
zmq_ctx_destroy(pPubCtx);
pPubCtx = NULL;
pPubCtx = nullptr;
}
if(pDealer != NULL) {
if(pDealer != nullptr) {
zmq_close(pDealer);
pDealer= NULL;
pDealer= nullptr;
}
if(pDealerCtx != NULL) {
if(pDealerCtx != nullptr) {
zmq_ctx_destroy(pPubCtx);
pDealerCtx = NULL;
pDealerCtx = nullptr;
}
}
};
......
......@@ -38,14 +38,14 @@ using namespace zmqhelper;
class EvPusher: public TinyThread {
private:
void *pSubCtx = NULL, *pDealerCtx = NULL; // for packets relay
void *pSub = NULL, *pDealer = NULL, *pDaemonCtx = NULL, *pDaemon = NULL;
void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay
void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr;
string urlOut, urlPub, urlDealer, devSn, pullerGid, mgrSn, selfId;
int iid;
bool enablePush = false;
int *streamList = NULL;
AVFormatContext *pAVFormatRemux = NULL;
AVFormatContext *pAVFormatInput = NULL;
int *streamList = nullptr;
AVFormatContext *pAVFormatRemux = nullptr;
AVFormatContext *pAVFormatInput = nullptr;
time_t tsLastBoot, tsUpdateTime;
json config;
thread thPing;
......@@ -220,7 +220,7 @@ private:
int setupStream()
{
int ret = 0;
AVDictionary *pOptsRemux = NULL;
AVDictionary *pOptsRemux = nullptr;
ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut.c_str());
if (ret < 0) {
......@@ -300,14 +300,14 @@ private:
avformat_free_context(pAVFormatRemux);
}
pAVFormatRemux = NULL;
pAVFormatRemux = nullptr;
// free avformatcontex
if(pAVFormatInput != NULL) {
if(pAVFormatInput != nullptr) {
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
protected:
void run()
......@@ -357,7 +357,7 @@ protected:
spdlog::debug("packet stream indx: {:d}", packet.stream_index);
// relay
AVStream *in_stream =NULL, *out_stream = NULL;
AVStream *in_stream =NULL, *out_stream = nullptr;
in_stream = pAVFormatInput->streams[packet.stream_index];
packet.stream_index = streamList[packet.stream_index];
out_stream = pAVFormatRemux->streams[packet.stream_index];
......@@ -406,12 +406,12 @@ public:
EvPusher()
{
const char *strEnv = getenv("DR_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
drport = strEnv;
}
strEnv = getenv("PEERID");
if(strEnv != NULL) {
if(strEnv != nullptr) {
selfId = strEnv;
auto v = strutils::split(selfId, ':');
if(v.size() != 3||v[1] != "evpusher") {
......@@ -445,21 +445,21 @@ public:
~EvPusher()
{
if(pSub != NULL) {
if(pSub != nullptr) {
zmq_close(pSub);
pSub = NULL;
pSub = nullptr;
}
if(pSubCtx != NULL) {
if(pSubCtx != nullptr) {
zmq_ctx_destroy(pSubCtx);
pSubCtx = NULL;
pSubCtx = nullptr;
}
if(pDealer != NULL) {
if(pDealer != nullptr) {
zmq_close(pSub);
pDealer = NULL;
pDealer = nullptr;
}
if(pDealerCtx != NULL) {
if(pDealerCtx != nullptr) {
zmq_ctx_destroy(pSub);
pDealerCtx = NULL;
pDealerCtx = nullptr;
}
freeStream();
......
......@@ -43,17 +43,17 @@ private:
#define MINUTES_PER_SLICE_DEFAULT 2
// 2 days, 10 minutes per record
#define NUM_SLICES_DEFAULT (24 * NUM_DAYS_DEFAULT * 60 / MINUTES_PER_SLICE_DEFAULT)
void *pSubCtx = NULL, *pDealerCtx = NULL; // for packets relay
void *pSub = NULL, *pDealer = NULL, *pDaemonCtx = NULL, *pDaemon = NULL;
void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay
void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr;
string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid;
int iid, days, minutes, numSlices, lastSliceId;
bool enablePush = false;
AVFormatContext *pAVFormatRemux = NULL;
AVFormatContext *pAVFormatInput = NULL;
AVDictionary *pOptsRemux = NULL;
AVFormatContext *pAVFormatRemux = nullptr;
AVFormatContext *pAVFormatInput = nullptr;
AVDictionary *pOptsRemux = nullptr;
// load from db
vector<int> *sliceIdxToName = NULL;
int *streamList = NULL;
vector<int> *sliceIdxToName = nullptr;
int *streamList = nullptr;
time_t tsLastBoot, tsUpdateTime;
json config;
thread thPing;
......@@ -296,14 +296,14 @@ private:
avformat_free_context(pAVFormatRemux);
}
pAVFormatRemux = NULL;
pAVFormatRemux = nullptr;
// free avformatcontex
if(pAVFormatInput != NULL) {
if(pAVFormatInput != nullptr) {
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
pAVFormatInput = NULL;
pAVFormatInput = nullptr;
}
protected:
......@@ -313,7 +313,7 @@ protected:
int ret = 0;
int idx = 0;
int pktCnt = 0;
AVStream * out_stream = NULL;
AVStream * out_stream = nullptr;
zmq_msg_t msg;
AVPacket packet;
while (true) {
......@@ -386,7 +386,7 @@ protected:
zmq_msg_close(&msg);
AVStream *in_stream =NULL, *out_stream = NULL;
AVStream *in_stream =NULL, *out_stream = nullptr;
in_stream = pAVFormatInput->streams[packet.stream_index];
packet.stream_index = streamList[packet.stream_index];
out_stream = pAVFormatRemux->streams[packet.stream_index];
......@@ -431,8 +431,8 @@ protected:
}// while in slice
// write tail
// close output context
if (pAVFormatRemux != NULL) {
if(pAVFormatRemux->pb != NULL) {
if (pAVFormatRemux != nullptr) {
if(pAVFormatRemux->pb != nullptr) {
avio_closep(&pAVFormatRemux->pb);
}
avformat_free_context(pAVFormatRemux);
......@@ -443,12 +443,12 @@ public:
EvSlicer()
{
const char *strEnv = getenv("DR_PORT");
if(strEnv != NULL) {
if(strEnv != nullptr) {
drport = strEnv;
}
strEnv = getenv("PEERID");
if(strEnv != NULL) {
if(strEnv != nullptr) {
selfId = strEnv;
auto v = strutils::split(selfId, ':');
if(v.size() != 3||v[1] != "evslicer") {
......@@ -481,21 +481,21 @@ public:
};
~EvSlicer()
{
if(pSub != NULL) {
if(pSub != nullptr) {
zmq_close(pSub);
pSub = NULL;
pSub = nullptr;
}
if(pSubCtx != NULL) {
if(pSubCtx != nullptr) {
zmq_ctx_destroy(pSubCtx);
pSubCtx = NULL;
pSubCtx = nullptr;
}
if(pDealer != NULL) {
if(pDealer != nullptr) {
zmq_close(pSub);
pDealer = NULL;
pDealer = nullptr;
}
if(pDealerCtx != NULL) {
if(pDealerCtx != nullptr) {
zmq_ctx_destroy(pSub);
pDealerCtx = NULL;
pDealerCtx = nullptr;
}
freeStream();
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论