| | |
| | | #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; // 代表其他进程的进程信息 |
| | | |
| | | int replykey; |
| | | int hbcnt; |
| | | int dcnt; |
| | | int status; |
| | | int replykey; // 没用,上一个版本用共享内存,此为key |
| | | int hbcnt; // 心跳次数?可能没用 |
| | | int dcnt; // deadcount,可能没用? |
| | | int status; // 进程状态,可能没用? |
| | | }; |
| | | |
| | | //TableChanged enum |
| | |
| | | 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 |
| | | /* |
| | | 此消息既作为接收的request msg的结构,也作为发送request 消息的结构 |
| | | 接收request消息会带有发出request消息的进程的id,procid |
| | | */ |
| | | struct creqmsg{ |
| | | struct cstr procid; |
| | | struct cstr msg; |
| | | struct cstr procid; // 发送request消息的进程id |
| | | struct cstr msg; // request消息体 |
| | | }; |
| | | // decode stack err msg |
| | | /* |
| | | pollcontrol会接收数据栈解码发送的解码失败消息,用于置网页状态 |
| | | */ |
| | | struct cstackmsgerr{ |
| | | struct cstr stackid; |
| | | struct cstr fileid; |
| | | struct cstr stackid; // 解码失败的数据栈id |
| | | struct cstr fileid; // 解码失败的文件id |
| | | }; |
| | | // 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:video,2:picture |
| | | void* noused; // 未使用 |
| | | }; |
| | | // decode stack success msg |
| | | /* |
| | | pollcontrol会接收数据栈解码完成的消息,然后下发新的数据栈任务 |
| | | */ |
| | | 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 |
| | | |
| | | /* |
| | | 封装了C接口的string |
| | | cstr_new 创建一个string,包括内存地址和长度,会拷贝参数 |
| | | 必须使用cstr_free释放 |
| | | */ |
| | | struct cstr cstr_new(const char* str, const size_t len); |
| | | void cstr_free(struct cstr str); |
| | | /* |
| | | 封装字符串数组,其中是一个struct cstr数组,包括指向数组的指针和count |
| | | 通过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 结构,对应procinfo,保存proc的name,id,info[当前没有使用] |
| | | 必须使用free_proc_info释放 |
| | | */ |
| | | struct cproc* make_proc_info(const struct cstr name, const struct cstr id, const struct cstr info); |
| | | /* |
| | | 从已存在的proc克隆,会拷贝,使用free_proc_info释放 |
| | | */ |
| | | struct cproc* clone_proc_info(const struct cproc* pi); |
| | | void free_proc_info(struct cproc* pi); |
| | | |
| | | /* |
| | | 释放creg结构指针 |
| | | creg结构可以使用上述make_proc_info、cstr_arr_new、cstr_new函数创建 |
| | | */ |
| | | void free_creg(struct creg* reg); |
| | | // 订阅消息相关,订阅数据库db消息和进程列表proclist消息 |
| | | /* |
| | | cbhomeclient.cpp中使用,将接收到的submsg解包成csubmsg |
| | | 包括topic和msg数据,msg数据并未反序列化 |
| | | 必须使用free_submsg释放 |
| | | */ |
| | | struct csubmsg* to_submsg(const char* data, const size_t size); |
| | | void free_submsg(struct csubmsg* msg); |
| | | // db msg |
| | | /* |
| | | 接收到的submsg在pollcontrol中可能为数据库更新的通知 |
| | | 将csubmsg中未反序列化的数据解包成db的数据格式 |
| | | 必须用free_submsg_db释放 |
| | | */ |
| | | struct DbChangeMsg* get_submsg_db(struct csubmsg* msg); |
| | | void free_submsg_db(struct DbChangeMsg* msg); |
| | | // proclist msg |
| | | /* |
| | | 接收到的submsg在pollcontrol中可能为关心的其他进程的列表 |
| | | 将csubmsg中未反序列化的数据解包成进程的列表 |
| | | 必须用free_submsg_proclist释放 |
| | | */ |
| | | struct cproclist* get_submsg_proclist(struct csubmsg* msg); |
| | | void free_submsg_proclist(struct cproclist* ppl); |
| | | |
| | | // request msg |
| | | /* |
| | | cbhomeclient.cpp中使用,将接收到的request请求数据解包成creqmsg |
| | | 包括request进程的procid和msg数据,msg数据并未反序列化 |
| | | 必须使用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); |
| | | /* |
| | | 本进程向其他进程请求数据构建 |
| | | 包括请求的主题topic和请求的数据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在pollcontrol中可能为数据栈解码错误信息 |
| | | 将creqmsg中未反序列化的数据解包成cstackmsgerr,包括数据栈id stackid和文件id fileid |
| | | 必须用free_reqmsg_stackerr释放 |
| | | */ |
| | | struct cstackmsgerr* get_reqmsg_stackerr(struct creqmsg* msg); |
| | | void free_reqmsg_stackerr(struct cstackmsgerr* msg); |
| | | // decode success msg |
| | | /* |
| | | 接收到的creqmsg在pollcontrol中可能为数据栈解码完成信息 |
| | | 将creqmsg中未反序列化的数据解包成cstackmsg |
| | | 包括 |
| | | int procnum; // 启动的decoder进程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; // 文件数量 |
| | | 必须用free_reqmsg_stackerr释放 |
| | | */ |
| | | struct cstackmsg* get_reqmsg_stack(struct creqmsg* msg); |
| | | void free_reqmsg_stack(struct cstackmsg* msg); |
| | | |
| | | // reply msg |
| | | /* |
| | | no use 将reply消息序列化为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、errmsg和消息体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 |