zhangmeng
2022-12-27 7a77e0a80e633bdb5cb3f2b633eebdbf70f6a430
restruct
6 文件已重命名
7个文件已修改
70 ■■■■■ 已修改文件
3rdparty/bus_nng/aarch64/libbus_nng.so 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/bus_nng/bn_api.h 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/bus_nng/interface_bus_api.h 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/bus_nng/x86_64/libbus_nng.so 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/yyjson/yyjson.c 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/yyjson/yyjson.h 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cbhomeclient.cpp 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cbhomeclient.h 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
exported_symbols 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
message.cpp 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
message.h 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
3rdparty/bus_nng/aarch64/libbus_nng.so
Binary files differ
3rdparty/bus_nng/bn_api.h
3rdparty/bus_nng/interface_bus_api.h
3rdparty/bus_nng/x86_64/libbus_nng.so
Binary files differ
3rdparty/yyjson/yyjson.c
3rdparty/yyjson/yyjson.h
CMakeLists.txt
@@ -25,7 +25,7 @@
##########################################################]
include_directories(
    ${CMAKE_SOURCE_DIR}/3dparty/bus_nng
    ${CMAKE_SOURCE_DIR}/3rdparty/bus_nng
    ${CMAKE_SOURCE_DIR}/proto/${ARCH}
    ${PROTO_LIB_PATH}/include
    )
@@ -33,7 +33,7 @@
set(src
    ${CMAKE_SOURCE_DIR}/cbhomeclient.cpp
    ${CMAKE_SOURCE_DIR}/message.cpp
    ${CMAKE_SOURCE_DIR}/3dparty/yyjson/yyjson.c
    ${CMAKE_SOURCE_DIR}/3rdparty/yyjson/yyjson.c
    )
add_library(objs OBJECT ${src})
@@ -50,5 +50,5 @@
# test
add_executable(test main.cpp $<TARGET_OBJECTS:objs>)
target_link_libraries(test ${Target}
    ${CMAKE_SOURCE_DIR}/3dparty/bus_nng/x86_64/libbus_nng.so
    ${CMAKE_SOURCE_DIR}/3rdparty/bus_nng/x86_64/libbus_nng.so
    bhome_msg pthread rt)
cbhomeclient.cpp
@@ -9,7 +9,7 @@
#include "cbhomeclient.h"
#include "fixed_q.h"
#include "3dparty/bus_nng/interface_bus_api.h"
#include "3rdparty/bus_nng/interface_bus_api.h"
#include "bhome_msg.pb.h"
@@ -74,7 +74,7 @@
}
template <class T> Msg msg(T&& t){
    Msg m;
    msg_helper(make_index_sequence<tuple_size<T>::value>{}, std::forward<T>(t), m);
    msg_helper(make_index_sequence<tuple_size<typename decay<T>::type>::value>{}, std::forward<T>(t), m);
    return m;
}
@@ -325,6 +325,33 @@
    return bus_send_reply(cli->bus, src, pbstr.data(), pbstr.size());
}
struct cqueryprocs* bus_client_query_procs(void* handle, size_t* count){
    BHAddress addr;
    const auto& pbaddr = addr.SerializeAsString();
    MsgQueryProc topic;
    const auto& pbtopic = topic.SerializeAsString();
    void* rep = NULL;
    int repl = 0;
    auto msg = to_bus<4,5>(ptr(handle), bus_query_procs, pbaddr.data(), pbaddr.size(),
        pbtopic.data(), pbtopic.size(), &rep, &repl, sndto);
    MsgQueryProcReply msgR;
    msgR.ParseFromArray(rep, repl);
    bus_free(rep, repl);
    *count = msgR.proc_list_size();
    auto procs = (struct cqueryprocs*)calloc(*count, sizeof(struct cqueryprocs));
    for(size_t i = 0; i < *count; i++){
        const auto& p = msgR.proc_list(i);
        size_t idl = p.proc().proc_id().size();
        char* id = (char*)calloc(idl+1, 1);
        memcpy(id, p.proc().proc_id().data(), idl);
        procs[i] = cqueryprocs{ .id = id, .idl = idl, .online = p.online() };
    }
    return procs;
}
////////////////////////////////////////////////////
int bus_client_publish(void* handle, const char* topic, const size_t topicl, const char* data, const size_t size){
    MsgPublish pbmsg;
cbhomeclient.h
@@ -61,6 +61,11 @@
*/
int bus_client_request(void* handle, struct creqmsg* msg, struct crepmsg** repmsg);
/*
    queryprocs 获取bhnng_center 注册的所有进程
*/
struct cqueryprocs* bus_client_query_procs(void* handle, size_t* count);
#ifdef __cplusplus
}
#endif
exported_symbols
@@ -45,6 +45,9 @@
    make_reply_msg;
    free_reply_msg;
    free_query_procs;
    bus_client_query_procs;
local:
    *;
};
main.cpp
@@ -9,7 +9,7 @@
#include "cbhomeclient.h"
#include "message.h"
// #include "3dparty/bus_nng/bn_api.h"
// #include "3rdparty/bus_nng/bn_api.h"
#include "bhome_msg_api.pb.h"
using namespace bhome_msg;
message.cpp
@@ -13,7 +13,7 @@
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/compiler/importer.h"
#include "3dparty/yyjson/yyjson.h"
#include "3rdparty/yyjson/yyjson.h"
#include "bhome_msg_api.pb.h"
using namespace bhome_msg;
@@ -635,3 +635,10 @@
    yyjson_mut_doc_free(doc);
    return cstr_ref(json, jsonl);
}
void free_query_procs(struct cqueryprocs* procs, const size_t count){
    for(size_t i = 0; i < count; i++){
        free(procs[i].id);
    }
    free(procs);
}
message.h
@@ -147,6 +147,15 @@
    size_t datal;
};
/*
    对应 bhome_msg.MsgQueryProcReply_Info query procs 返回值
*/
struct cqueryprocs{
    char* id;
    size_t idl;
    int online;
};
#ifdef __cplusplus
extern "C"{
#endif
@@ -277,6 +286,11 @@
                                const char* data, const size_t datal);
void free_reply_msg(struct crepmsg* msg);
/*
    释放 query procs 从center获取所有的procs信息
*/
void free_query_procs(struct cqueryprocs* procs, const size_t count);
#ifdef __cplusplus
}
#endif