From 4fc07d5d891c251a1fe09c17ee16467d961a8f74 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 14 十二月 2022 15:31:12 +0800
Subject: [PATCH] add interface creg add topic and export symbols
---
message.h | 266 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 185 insertions(+), 81 deletions(-)
diff --git a/message.h b/message.h
index 6024a7b..258c135 100644
--- a/message.h
+++ b/message.h
@@ -3,42 +3,20 @@
#include <stddef.h>
-struct cstr{
- char* str;
- size_t size;
-};
-// 杩涚▼淇℃伅
-struct cproc{
- struct cstr name;
- struct cstr id;
- struct cstr info;
-};
+/*
+ 娉ㄥ唽杩涚▼鐨刾roc淇℃伅锛屽寘鎷繘绋嬪悕[name], 杩涚▼[id],绛�
+*/
+typedef struct cproc cproc;
+/*
+ 杩涚▼娉ㄥ唽淇℃伅, 鍖呮嫭杩涚▼鐨刾roc淇℃伅 cproc
+ 寰呮敞鍐岀殑鏈繘绋嬫彁渚涜姹傚搷搴旂殑涓婚 topics[s], char** rep, 涓婚鏁伴噺 repcnt
+ 寰呮敞鍐岀殑鏈繘绋嬪彂甯冪殑涓婚 topics[s], char** pub, 涓婚鏁伴噺 pubcnt
+ 寰呮敞鍐岀殑鏈繘绋嬭闃呯殑涓婚 topics[s], char** sub, 涓婚鏁伴噺 subcnt
+ 寰呮敞鍐岀殑鏈繘绋嬭闃呯殑[缃戠粶銆佽繙绋嬩富鏈篯涓婚 topics[s], char** subnet, 涓婚鏁伴噺 subnetcnt
+*/
+typedef struct creg creg;
-struct cstrarr{
- struct cstr* arr;
- size_t count;
-};
-// 杩涚▼娉ㄥ唽淇℃伅
-struct creg{
- struct cproc* pinfo;
-
- cstrarr channel;
- cstrarr topic_pub;
- cstrarr topic_sub;
- cstrarr topic_sub_net;
-};
-
-// 鍏朵粬杩涚▼淇℃伅
-struct cclient{
- struct creg* rinfo;
-
- int replykey;
- int hbcnt;
- int dcnt;
- int status;
-};
-
-//TableChanged enum
+//TableChanged enum pollcontrol 鎺ユ敹鍒扮殑璁㈤槄娑堟伅锛屾暟鎹簱鐨勫彉鍖�
enum TableChanged {
T_Camera = 0, //鎽勫儚鏈哄彉鍖�
T_CameraRule = 1, //鎽勫儚鏈轰换鍔″弬鏁板彉鍖�
@@ -58,119 +36,245 @@
T_CameraPolygonRelation = 15, //鎽勫儚鏈哄尯鍩熺殑鍏宠仈鍏崇郴
T_Voice = 16, //鎶ヨ澹伴煶鍙戠敓鍙樺寲
};
+// pollcontrol 鎺ユ敹鍒扮殑璁㈤槄娑堟伅锛屾暟鎹簱鐨勬搷浣�
enum DbAction {
- Insert = 0, //Insert
- Update = 1, //Update
- Delete = 2, //Delete
+ Insert = 0, //Insert db
+ Update = 1, //Update db
+ Delete = 2, //Delete db
};
// 鏁版嵁搴撳彉鍖栦俊鎭�
struct DbChangeMsg{
- TableChanged table; //鍙樺寲鐨勮〃
- struct cstr id; //鍙樺寲鏁版嵁id
- DbAction action; //action
- struct cstr info; //鍙樺寲鍐呭
+ TableChanged table; //鍙樺寲鐨勮〃
+ char* id; //鍙樺寲鏁版嵁id
+ size_t idl; // id len
+ DbAction action; //action/ DbAction[Insert/Update/Delete]
+ char* info; //鍙樺寲鍐呭
+ size_t infol;
};
-// 璁㈤槄娑堟伅
+// 璁㈤槄娑堟伅, 鍖呮嫭鏁版嵁搴撴秷鎭拰鍏朵粬杩涚▼鐨勬秷鎭�
struct csubmsg{
- struct cstr topic;
+ char* topic; // 鏀跺埌鐨勮闃呮秷鎭殑涓婚锛屽尯鍒嗛偅绉嶈闃呮秷鎭�
+ size_t topicl;
// private
// enum MsgT {NONE=0, DB, PROCLIST} type;
- struct cstr msg;
+ char* msg; // 鏀跺埌鐨勮闃呮秷鎭殑body
+ size_t msgl;
+};
+
+// 鍏朵粬杩涚▼淇℃伅, pollcontrol鍙兘渚濊禆鍏朵粬杩涚▼鐨勬湇鍔★紝鍙兘闇�瑕佺瓑鍏朵粬杩涚▼鍚姩鍐嶅紑濮嬪伐浣�
+struct cclient{
+ creg* rinfo; // 浠h〃鍏朵粬杩涚▼鐨勮繘绋嬩俊鎭�
+
+ int replykey; // 娌$敤锛屼笂涓�涓増鏈敤鍏变韩鍐呭瓨锛屾涓簁ey
+ int hbcnt; // 蹇冭烦娆℃暟锛熷彲鑳芥病鐢�
+ int dcnt; // deadcount锛屽彲鑳芥病鐢紵
+ int status; // 杩涚▼鐘舵�侊紝鍙兘娌$敤锛�
};
// 鍏朵粬娉ㄥ唽杩涚▼鍒楄〃锛屽鏁版嵁搴撹繘绋嬮渶瑕佸惎鍔ㄥ啀杩愯pollcontrol閫昏緫
struct cproclist{
- struct cclient* cli;
- size_t clientsize;
+ struct cclient* cli; // 鍏朵粬杩涚▼鐨勫垪琛�
+ size_t count; // 鍏朵粬杩涚▼鐨勫垪琛ㄧ殑count
};
//////////////////////////////////////////
// request msg
+/*
+ 姝ゆ秷鎭棦浣滀负鎺ユ敹鐨剅equest msg鐨勭粨鏋勶紝涔熶綔涓哄彂閫乺equest 娑堟伅鐨勭粨鏋�
+ 鎺ユ敹request娑堟伅浼氬甫鏈夊彂鍑簉equest娑堟伅鐨勮繘绋嬬殑id锛宲rocid
+*/
struct creqmsg{
- struct cstr procid;
- struct cstr msg;
+ char* procid; // 鍙戦�乺equest娑堟伅鐨勮繘绋媔d
+ size_t procidl;
+ char* msg; // request娑堟伅浣�
+ size_t msgl;
};
// decode stack err msg
+/*
+ pollcontrol浼氭帴鏀舵暟鎹爤瑙g爜鍙戦�佺殑瑙g爜澶辫触娑堟伅锛岀敤浜庣疆缃戦〉鐘舵��
+*/
struct cstackmsgerr{
- struct cstr stackid;
- struct cstr fileid;
+ char* stackid; // 瑙g爜澶辫触鐨勬暟鎹爤id
+ size_t stackidl;
+ char* fileid; // 瑙g爜澶辫触鐨勬枃浠秈d
+ size_t fileidl;
};
// stack file
+/*
+ 鏁版嵁鏍堢殑鏂囦欢鍒楄〃锛屽搴� protomsg.FileAnalysis 浣嗘槸姝ょ粨鏋勪綋闈炲父闀�
+ 鐪嬩唬鐮佸簲璇ュ彧闇�瑕佽В鏋愬嚭鐨勫嚑涓�
+*/
struct cstackfile{
- struct cstr id;
- struct cstr name;
- struct cstr path;
- int type;
- void* noused;
+ char* id; // 鏂囦欢id
+ size_t idl;
+ char* name; // 鏂囦欢name
+ size_t namel;
+ char* path; // 鏂囦欢璺緞
+ size_t pathl;
+
+ int type; // 鏂囦欢绫诲瀷 1锛歷ideo锛�2锛歱icture
+ void* noused; // 鏈娇鐢�
};
// decode stack success msg
+/*
+ pollcontrol浼氭帴鏀舵暟鎹爤瑙g爜瀹屾垚鐨勬秷鎭紝鐒跺悗涓嬪彂鏂扮殑鏁版嵁鏍堜换鍔�
+*/
struct cstackmsg{
- int procnum;
- struct cstr stackid;
- struct cstr stackname;
- int type;
- int shmkey;
- int width;
+ int procnum; // decoder 鍚姩鐨勮繘绋嬪彿锛屾暟鎹爤鍙兘浼氭湁鏁颁釜decoder鍚屾椂杩愯
+ char* stackid; // 鏁版嵁鏍� id
+ size_t stackidl;
+ char* stackname; // 鏁版嵁鏍� name
+ size_t stacknamel;
+ int type; // 鏁版嵁鏍堢被鍨� video picture
+ int shmkey; // 鏁版嵁鏍堜娇鐢ㄧ殑鍏变韩鍐呭瓨key
+ int width; // 鍒嗚鲸鐜�
int height;
- int fps;
- struct cstackfile* files;
+ int fps; // fps 閲囨牱 fps/s
+ struct cstackfile* files; // 鏁版嵁鏍堟枃浠跺垪琛�
size_t filescnt;
};
// reply msg
+// 瀵瑰簲 bhome_msg.MsgRequestTopicReply
struct crepmsg{
- int errcode;
- struct cstr errmsg;
- struct cstr data;
+ int errcode; // 鐩稿簲request璇锋眰鐨勬秷鎭紝閿欒鐮�
+ char* errmsg; // 閿欒娑堟伅
+ size_t errmsgl;
+ char* data; // 娑堟伅浣�
+ size_t datal;
};
#ifdef __cplusplus
extern "C"{
#endif
-struct cstr cstr_new(const char* str, const size_t len);
-void cstr_free(struct cstr str);
-struct cstrarr cstr_arr_new(const size_t count);
-void cstr_arr_add(struct cstrarr* arr, const char* data, const size_t len, const size_t idx);
-void cstr_arr_free(struct cstrarr arr);
+/*
+ 鍐呴儴浣跨敤锛屾繁鎷疯礉 cproc
+*/
+cproc* internal_clone_cproc(const cproc* proc);
+void internal_cproc_free(cproc* proc);
+/*
+ 杩斿洖涓�涓� cproc 缁撴瀯锛屼粎鎷疯礉杈撳叆鍙傛暟
+ 鐢熷懡鍛ㄦ湡 cproc < name[id]
+*/
+cproc* make_cproc(const char* name, const char* id);
+/*
+ 浠庡凡瀛樺湪鐨� cproc 涓幏鍙� name 鍜� id锛屼粎浠呮槸 cproc 鍐呴儴鐨勫紩鐢紝鏃犻渶閲婃斁
+ 鐢熷懡鍛ㄦ湡 name[id] < cproc
+*/
+char* cproc_name(const cproc* proc);
+char* cproc_id(const cproc* proc);
+/*
+ 閲婃斁 cproc 鎸囬拡
+*/
+void cproc_free(cproc* proc);
-void free_creg(struct creg* reg);
-
-struct cproc* clone_proc_info(struct cproc* pi);
-void free_proc_info(struct cproc* pi);
+/*
+ 杩斿洖涓�涓� creg 缁撴瀯锛屼粎鎷疯礉杈撳叆鍙傛暟
+ 杈撳叆鍙傛暟鐢熷懡鍛ㄦ湡闇�瑕嗙洊杩斿洖鍊肩敓鍛藉懆鏈�
+*/
+creg* make_creg(const cproc* proc, const char** rep, const size_t repcnt,
+ const char** pub, const size_t pubcnt,
+ const char** sub, const size_t subcnt,
+ const char** subnet, const size_t subnetcnt);
+creg* make_creg_from_cproc(const cproc* proc);
+void creg_add_topic_reply(creg* reg, const char** topic, const size_t count);
+void creg_add_topic_pub(creg* reg, const char** topic, const size_t count);
+void creg_add_topic_sub(creg* reg, const char** topic, const size_t count);
+void creg_add_topic_subnet(creg* reg, const char** topic, const size_t count);
+/*
+ 鑾峰彇宸插瓨鍦ㄧ殑 creg 涓殑 cproc 鎴栬�呮敞鍐岀殑涓婚锛屾棤闇�閲婃斁
+ 鐢熷懡鍛ㄦ湡 < creg
+*/
+const cproc* creg_proc(const creg* reg);
+char** creg_reply_topic(const creg* reg, size_t* count);
+char** creg_pub_topic(const creg* reg, size_t* count);
+char** creg_sub_topic(const creg* reg, size_t* count);
+char** creg_subnet_topic(const creg* reg, size_t* count);
+/*
+ 閲婃斁 creg 鎸囬拡
+*/
+void creg_free(creg* reg);
// 璁㈤槄娑堟伅鐩稿叧锛岃闃呮暟鎹簱db娑堟伅鍜岃繘绋嬪垪琛╬roclist娑堟伅
+/*
+ cbhomeclient.cpp涓娇鐢紝灏嗘帴鏀跺埌鐨剆ubmsg瑙e寘鎴恈submsg
+ 鍖呮嫭topic鍜宮sg鏁版嵁锛宮sg鏁版嵁骞舵湭鍙嶅簭鍒楀寲
+ 蹇呴』浣跨敤free_submsg閲婃斁
+*/
struct csubmsg* to_submsg(const char* data, const size_t size);
void free_submsg(struct csubmsg* msg);
// db msg
+/*
+ 鎺ユ敹鍒扮殑submsg鍦╬ollcontrol涓彲鑳戒负鏁版嵁搴撴洿鏂扮殑閫氱煡
+ 灏哻submsg涓湭鍙嶅簭鍒楀寲鐨勬暟鎹В鍖呮垚db鐨勬暟鎹牸寮�
+ 蹇呴』鐢╢ree_submsg_db閲婃斁
+*/
struct DbChangeMsg* get_submsg_db(struct csubmsg* msg);
void free_submsg_db(struct DbChangeMsg* msg);
// proclist msg
+/*
+ 鎺ユ敹鍒扮殑submsg鍦╬ollcontrol涓彲鑳戒负鍏冲績鐨勫叾浠栬繘绋嬬殑鍒楄〃
+ 灏哻submsg涓湭鍙嶅簭鍒楀寲鐨勬暟鎹В鍖呮垚杩涚▼鐨勫垪琛�
+ 蹇呴』鐢╢ree_submsg_proclist閲婃斁
+*/
struct cproclist* get_submsg_proclist(struct csubmsg* msg);
void free_submsg_proclist(struct cproclist* ppl);
// request msg
+/*
+ cbhomeclient.cpp涓娇鐢紝灏嗘帴鏀跺埌鐨剅equest璇锋眰鏁版嵁瑙e寘鎴恈reqmsg
+ 鍖呮嫭request杩涚▼鐨刾rocid鍜宮sg鏁版嵁锛宮sg鏁版嵁骞舵湭鍙嶅簭鍒楀寲
+ 蹇呴』浣跨敤free_reqmsg閲婃斁
+*/
struct creqmsg* to_reqmsg(const char* pid,const size_t pids,const char* data,const size_t size);
-struct creqmsg* make_req_msg(const char* topic, const size_t topics,
+void free_reqmsg(struct creqmsg* msg);
+/*
+ 鏈繘绋嬪悜鍏朵粬杩涚▼璇锋眰鏁版嵁鏋勫缓
+ 鍖呮嫭璇锋眰鐨勪富棰榯opic鍜岃姹傜殑鏁版嵁body[data]
+ 蹇呴』浣跨敤free_reqmsg閲婃斁
+*/
+struct creqmsg* make_req_msg(const char* topic, const size_t topicl,
const char* data, const size_t datal);
-void free_reqmsg(struct creqmsg* msg);
// decode err msg
+/*
+ 鎺ユ敹鍒扮殑creqmsg鍦╬ollcontrol涓彲鑳戒负鏁版嵁鏍堣В鐮侀敊璇俊鎭�
+ 灏哻reqmsg涓湭鍙嶅簭鍒楀寲鐨勬暟鎹В鍖呮垚cstackmsgerr锛屽寘鎷暟鎹爤id stackid鍜屾枃浠秈d fileid
+ 蹇呴』鐢╢ree_reqmsg_stackerr閲婃斁
+*/
struct cstackmsgerr* get_reqmsg_stackerr(struct creqmsg* msg);
void free_reqmsg_stackerr(struct cstackmsgerr* msg);
// decode success msg
+/*
+ 鎺ユ敹鍒扮殑creqmsg鍦╬ollcontrol涓彲鑳戒负鏁版嵁鏍堣В鐮佸畬鎴愪俊鎭�
+ 灏哻reqmsg涓湭鍙嶅簭鍒楀寲鐨勬暟鎹В鍖呮垚cstackmsg
+ 鍖呮嫭
+ int procnum; // 鍚姩鐨刣ecoder杩涚▼num
+ struct cstr stackid;
+ struct cstr stackname;
+ int type; // video picture
+ int shmkey;
+ int width;
+ int height;
+ int fps;
+ struct cstackfile* files; // 鏂囦欢鍒楄〃
+ size_t filescnt; // 鏂囦欢鏁伴噺
+ 蹇呴』鐢╢ree_reqmsg_stackerr閲婃斁
+*/
struct cstackmsg* get_reqmsg_stack(struct creqmsg* msg);
void free_reqmsg_stack(struct cstackmsg* msg);
// reply msg
-struct cstr make_reply_msg_json(const int success, const char* msg, const size_t msgl,
- const char* data, const size_t datal);
+/*
+ 鍒涘缓 creqmsg 鍖呮嫭errcode銆乪rrmsg鍜屾秷鎭綋data
+ 蹇呴』浣跨敤 free_reply_msg 閲婃斁
+*/
struct crepmsg* make_reply_msg(const int errcode, const char* errmsg, const size_t emsgl,
const char* data, const size_t datal);
-
void free_reply_msg(struct crepmsg* msg);
#ifdef __cplusplus
--
Gitblit v1.8.0