1.增加获取系统授权接口
2.完善相机相关函数实现
3.优化内存释放
| | |
| | | ) |
| | | |
| | | set(src |
| | | ${CMAKE_SOURCE_DIR}/versionctrlapi.cpp |
| | | ${CMAKE_SOURCE_DIR}/camera.cpp |
| | | ${CMAKE_SOURCE_DIR}/polygon.cpp |
| | | ${CMAKE_SOURCE_DIR}/rule.cpp |
| | |
| | | /****************************************************************************** |
| | | |
| | | 版权所有 (C), 2001-2011, 北京贝思科技术有限公司 |
| | | |
| | | ****************************************************************************** |
| | | 文 件 名 : camera.cpp |
| | | 版 本 号 : 初稿 |
| | | 作 者 : cheliequan |
| | | 生成日期 : 2023年1月13日 |
| | | 最近修改 : |
| | | 功能描述 : 获取相机相关信息 |
| | | 函数列表 : |
| | | dbapi_get_cameras_by_runtype |
| | | dbapi_get_gb28181_cameras_by_runtype |
| | | 修改历史 : |
| | | 1.日 期 : 2023年1月13日 |
| | | 作 者 : cheliequan |
| | | 修改内容 : 创建文件 |
| | | |
| | | ******************************************************************************/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 包含头文件 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 外部变量说明 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 外部函数原型说明 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 内部函数原型说明 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 全局变量 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 模块级变量 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 常量定义 * |
| | | *----------------------------------------------*/ |
| | | |
| | | /*----------------------------------------------* |
| | | * 宏定义 * |
| | | *----------------------------------------------*/ |
| | | |
| | | #include "dbapi.h" |
| | | #include "util.h" |
| | | |
| | | using namespace protomsg; |
| | | |
| | | // 加get参数 runType 1: 实时 0 轮询 |
| | | bool dbapi_get_cameras_by_runtype(void *handle, std::vector<protomsg::Camera> & list) { |
| | | const char *topic = DATA_URL_PREFIX("/camera/getCamerasByRunType"); |
| | | |
| | | return true; |
| | | bool ret = bus_dbapi_get_list(handle, topic, list); |
| | | return ret; |
| | | } |
| | | |
| | | // 加get参数 runType 1: 实时 0 轮询 |
| | | bool dbapi_get_gb28181_cameras_by_runtype(void *handle, std::vector<protomsg::Camera> & list) { |
| | | const char *topic = DATA_URL_PREFIX("/gb28181/camera/getCamerasByRunType"); |
| | | |
| | | return true; |
| | | bool ret = bus_dbapi_get_list(handle, topic, list); |
| | | return ret; |
| | | } |
| | | |
| | |
| | | bool dbapi_get_doing_stacks(void *handle, std::vector<protomsg::FileStack> & list); |
| | | bool dbapi_get_polygons(void *handle, std::vector<protomsg::CameraPolygon> & list); |
| | | bool dbapi_get_polygon_relations(void *handle, std::vector<protomsg::CameraPolygonRelation> & list); |
| | | |
| | | bool dbapi_get_server_get_is_sys_expired(void *handle); |
| | | #endif |
| | |
| | | printf("CameraTimerule:\n"); |
| | | } |
| | | |
| | | //系统授权信息 |
| | | |
| | | printf("isExpired:%d\n", dbapi_get_server_get_is_sys_expired(handle)); |
| | | |
| | | return 0; |
| | | } |
| | |
| | | if (bus_client_request(handle, reqmsg, pptr_repmsg)) { |
| | | printf("======>> bus_client_reqest [%s] get [%s]\n", topic, (*pptr_repmsg)->data); |
| | | } else { |
| | | free(reqData); |
| | | return false; |
| | | } |
| | | |
| | | len = strlen((*pptr_repmsg)->data) + 1; |
| | | |
| | | free(reqData); |
| | | free(reqData); |
| | | return true; |
| | | } |
| | | |
| | | |
| | |
| | | yyjson_type type = YYJSON_TYPE_OBJ; |
| | | crepmsg *repmsg = NULL; |
| | | size_t len = 0; |
| | | bool bRet = false; |
| | | |
| | | bus_dbapi_get_topic_data(handle, topic, &repmsg, len); |
| | | |
| | |
| | | } |
| | | |
| | | std::string jsonString = msgdata; |
| | | if (json_to_proto(jsonString, message)) |
| | | bRet = json_to_proto(jsonString, message); |
| | | if (bRet) |
| | | { |
| | | printf("======>> json_to_proto done\n"); |
| | | } |
| | | else |
| | | { |
| | | printf("======>> json_to_proto fail\n"); |
| | | return false; |
| | | } |
| | | |
| | | free(msgdata); |
| | | free_reply_msg(repmsg); |
| | | |
| | | return true; |
| | | return bRet; |
| | | } |
| | | |
| | | /***************************************************************************** |
| | | 函 数 名 : bus_dbapi_get_str |
| | | 功能描述 : 获取订阅主题消息字符串,返回的内存调用者需要手工调用free函数释放 |
| | | 输入参数 : void *handle |
| | | const char* topic |
| | | char **pptr_str |
| | | 输出参数 : 无 |
| | | 返 回 值 : |
| | | 调用函数 : |
| | | 被调函数 : |
| | | |
| | | 修改历史 : |
| | | 1.日 期 : 2023年1月13日 |
| | | 作 者 : cheliequan |
| | | 修改内容 : 新生成函数 |
| | | |
| | | *****************************************************************************/ |
| | | bool bus_dbapi_get_str(void *handle, const char* topic, char **pptr_str) { |
| | | yyjson_type type = YYJSON_TYPE_OBJ; |
| | | crepmsg *repmsg = NULL; |
| | | size_t len = 0; |
| | | int iRet = 0; |
| | | bool bRet = false; |
| | | |
| | | bus_dbapi_get_topic_data(handle, topic, &repmsg, len); |
| | | |
| | | int msglen = strlen(repmsg->data); |
| | | char* msgdata = (char *)malloc(msglen); |
| | | memset(msgdata, 0 , msglen); |
| | | |
| | | iRet = bus_dbapi_get_json_data((const char *)repmsg->data, &msgdata, &type); |
| | | if(0 == iRet) |
| | | { |
| | | printf("======>> protomsg: %s\n", msgdata); |
| | | bRet = true; |
| | | } |
| | | |
| | | *pptr_str = msgdata; |
| | | |
| | | free(msgdata); |
| | | free_reply_msg(repmsg); |
| | | |
| | | return bRet; |
| | | } |
| | |
| | | using namespace std; |
| | | using google::protobuf::util::JsonStringToMessage; |
| | | |
| | | |
| | | bool json_to_proto(const std::string &json, google::protobuf::Message& message); |
| | | bool proto_to_json(const google::protobuf::Message& message, std::string& json); |
| | | char *make_get_request(const char *topic); |
| | | bool bus_dbapi_get(void *handle, const char* topic, google::protobuf::Message& message); |
| | | bool bus_dbapi_get_topic_data(void *handle, const char* topic, crepmsg **pptr_repmsg, size_t len); |
| | | extern "C" int bus_dbapi_get_json_data(const char * json, char ** pptr_data, uint8_t *ptr_type); |
| | | bool bus_dbapi_get_str(void *handle, const char* topic, char **pptr_str); |
| | | template <class T> bool bus_dbapi_get_list (void *handle, const char* topic, T & list) |
| | | |
| | | { |
New file |
| | |
| | | #include "dbapi.h" |
| | | #include "util.h" |
| | | |
| | | using namespace protomsg; |
| | | |
| | | //获取服务器本机配置信息 |
| | | bool dbapi_get_server_get_sn(void *handle, char * reply_msg){ |
| | | const char *topic = DATA_URL_PREFIX("/version/snBus"); |
| | | return bus_dbapi_get_str(handle, topic, &reply_msg); |
| | | } |
| | | |
| | | bool dbapi_get_server_get_is_sys_expired(void *handle) { |
| | | char * reply_msg = NULL; |
| | | bool is_expired = false; |
| | | bool ret = false; |
| | | bool expire_val = false; |
| | | |
| | | ret = dbapi_get_server_get_sn(handle, reply_msg); |
| | | if(ret && reply_msg != NULL) |
| | | { |
| | | // Read JSON and get root |
| | | yyjson_doc *doc = yyjson_read(reply_msg, strlen(reply_msg), 0); |
| | | yyjson_val *root = yyjson_doc_get_root(doc); |
| | | |
| | | yyjson_val *data = yyjson_obj_get(root, "expire"); |
| | | expire_val = yyjson_get_bool(data); |
| | | printf("expire: %d\n", expire_val); |
| | | yyjson_doc_free(doc); |
| | | } |
| | | |
| | | free(reply_msg); |
| | | return expire_val; |
| | | } |