From ba9e213d3f01555d823aaf453798a148dade45a4 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 13 十二月 2022 09:56:18 +0800 Subject: [PATCH] 添加注释 --- message.h | 192 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 140 insertions(+), 52 deletions(-) diff --git a/message.h b/message.h index 6024a7b..e22be44 100644 --- a/message.h +++ b/message.h @@ -4,38 +4,38 @@ #include <stddef.h> struct cstr{ - char* str; - size_t size; + char* str; // 瀛楃涓插唴瀹� + size_t size; // 瀛楃涓查暱搴� }; // 杩涚▼淇℃伅 struct cproc{ - struct cstr name; - struct cstr id; - struct cstr info; + struct cstr name; // 杩涚▼鍚嶅瓧 + struct cstr id; // 杩涚▼id + struct cstr info; // 杩涚▼鍏朵粬淇℃伅锛岀洰鍓嶆病鐢� }; struct cstrarr{ - struct cstr* arr; - size_t count; + struct cstr* arr; // 瀛楃涓叉暟缁� + size_t count; // 瀛楃涓叉暟缁勯暱搴� }; // 杩涚▼娉ㄥ唽淇℃伅 struct creg{ - struct cproc* pinfo; + struct cproc* pinfo; // 闇�瑕佹敞鍐岀殑杩涚▼淇℃伅 - cstrarr channel; - cstrarr topic_pub; - cstrarr topic_sub; - cstrarr topic_sub_net; + cstrarr channel; // 杩涚▼鎻愪緵鐨勮姹傚搷搴旀湇鍔$殑涓婚 + cstrarr topic_pub; // 杩涚▼鎻愪緵鐨勫彂甯冭闃呯殑鍙戝竷涓婚 + cstrarr topic_sub; // 杩涚▼闇�瑕佽闃呯殑涓婚 + cstrarr topic_sub_net; // 杩涚▼闇�瑕佽闃呯殑缃戠粶涓婚锛岀洰鍓嶆病鐢� }; // 鍏朵粬杩涚▼淇℃伅 struct cclient{ - struct creg* rinfo; + struct creg* rinfo; // 浠h〃鍏朵粬杩涚▼鐨勮繘绋嬩俊鎭� - int replykey; - int hbcnt; - int dcnt; - int status; + int replykey; // 娌$敤锛屼笂涓�涓増鏈敤鍏变韩鍐呭瓨锛屾涓簁ey + int hbcnt; // 蹇冭烦娆℃暟锛熷彲鑳芥病鐢� + int dcnt; // deadcount锛屽彲鑳芥病鐢紵 + int status; // 杩涚▼鐘舵�侊紝鍙兘娌$敤锛� }; //TableChanged enum @@ -59,118 +59,206 @@ T_Voice = 16, //鎶ヨ澹伴煶鍙戠敓鍙樺寲 }; 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 + DbAction action; //action/ DbAction[Insert/Update/Delete] struct cstr info; //鍙樺寲鍐呭 }; // 璁㈤槄娑堟伅 struct csubmsg{ - struct cstr topic; + struct cstr topic; // 鏀跺埌鐨勮闃呮秷鎭殑涓婚锛屽尯鍒嗛偅绉嶈闃呮秷鎭� // private // enum MsgT {NONE=0, DB, PROCLIST} type; - struct cstr msg; + struct cstr msg; // 鏀跺埌鐨勮闃呮秷鎭殑body }; // 鍏朵粬娉ㄥ唽杩涚▼鍒楄〃锛屽鏁版嵁搴撹繘绋嬮渶瑕佸惎鍔ㄥ啀杩愯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; + struct cstr procid; // 鍙戦�乺equest娑堟伅鐨勮繘绋媔d + struct cstr msg; // request娑堟伅浣� }; // decode stack err msg +/* + pollcontrol浼氭帴鏀舵暟鎹爤瑙g爜鍙戦�佺殑瑙g爜澶辫触娑堟伅锛岀敤浜庣疆缃戦〉鐘舵�� +*/ struct cstackmsgerr{ - struct cstr stackid; - struct cstr fileid; + struct cstr stackid; // 瑙g爜澶辫触鐨勬暟鎹爤id + struct cstr fileid; // 瑙g爜澶辫触鐨勬枃浠秈d }; // stack file +/* + 鏁版嵁鏍堢殑鏂囦欢鍒楄〃锛屽搴� protomsg.FileAnalysis 浣嗘槸姝ょ粨鏋勪綋闈炲父闀� + 鐪嬩唬鐮佸簲璇ュ彧闇�瑕佽В鏋愬嚭鐨勫嚑涓� +*/ struct cstackfile{ - struct cstr id; - struct cstr name; - struct cstr path; - int type; - void* noused; + struct cstr id; // 鏂囦欢id + struct cstr name; // 鏂囦欢name + struct cstr path; // 鏂囦欢璺緞 + 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鍚屾椂杩愯 + struct cstr stackid; // 鏁版嵁鏍� id + struct cstr stackname; // 鏁版嵁鏍� name + 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璇锋眰鐨勬秷鎭紝閿欒鐮� + struct cstr errmsg; // 閿欒娑堟伅 + struct cstr data; // 娑堟伅浣� }; #ifdef __cplusplus extern "C"{ #endif - +/* + 灏佽浜咰鎺ュ彛鐨剆tring + cstr_new 鍒涘缓涓�涓猻tring锛屽寘鎷唴瀛樺湴鍧�鍜岄暱搴︼紝浼氭嫹璐濆弬鏁� + 蹇呴』浣跨敤cstr_free閲婃斁 +*/ struct cstr cstr_new(const char* str, const size_t len); void cstr_free(struct cstr str); +/* + 灏佽瀛楃涓叉暟缁勶紝鍏朵腑鏄竴涓猻truct cstr鏁扮粍锛屽寘鎷寚鍚戞暟缁勭殑鎸囬拡鍜宑ount + 閫氳繃cstr_arr_add娣诲姞瀛楃涓诧紝鍐呴儴浼氭嫹璐濆瓧绗︿覆 + 蹇呴』浣跨敤cstr_arr_free閲婃斁 +*/ 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); -void free_creg(struct creg* reg); - -struct cproc* clone_proc_info(struct cproc* pi); +/* + 鍒涘缓struct cproc 缁撴瀯锛屽搴攑rocinfo锛屼繚瀛榩roc鐨刵ame锛宨d锛宨nfo[褰撳墠娌℃湁浣跨敤] + 蹇呴』浣跨敤free_proc_info閲婃斁 +*/ +struct cproc* make_proc_info(const struct cstr name, const struct cstr id, const struct cstr info); +/* + 浠庡凡瀛樺湪鐨刾roc鍏嬮殕锛屼細鎷疯礉锛屼娇鐢╢ree_proc_info閲婃斁 +*/ +struct cproc* clone_proc_info(const struct cproc* pi); void free_proc_info(struct cproc* pi); +/* + 閲婃斁creg缁撴瀯鎸囬拡 + creg缁撴瀯鍙互浣跨敤涓婅堪make_proc_info銆乧str_arr_new銆乧str_new鍑芥暟鍒涘缓 +*/ +void free_creg(struct 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 +/* + no use 灏唕eply娑堟伅搴忓垪鍖栦负json锛岀洰鍓嶆病鏈変娇鐢� + 浣跨敤 cstr_free 閲婃斁 +*/ 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