From 7a77e0a80e633bdb5cb3f2b633eebdbf70f6a430 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 27 十二月 2022 10:16:51 +0800
Subject: [PATCH] restruct

---
 3rdparty/yyjson/yyjson.c               |    0 
 main.cpp                               |    2 
 3rdparty/bus_nng/interface_bus_api.h   |    0 
 3rdparty/bus_nng/x86_64/libbus_nng.so  |    0 
 message.h                              |   14 +++++++
 3rdparty/yyjson/yyjson.h               |    0 
 CMakeLists.txt                         |    6 +-
 cbhomeclient.cpp                       |   31 ++++++++++++++-
 cbhomeclient.h                         |    5 ++
 message.cpp                            |    9 ++++
 3rdparty/bus_nng/bn_api.h              |    0 
 exported_symbols                       |    3 +
 3rdparty/bus_nng/aarch64/libbus_nng.so |    0 
 13 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/3dparty/bus_nng/aarch64/libbus_nng.so b/3rdparty/bus_nng/aarch64/libbus_nng.so
similarity index 100%
rename from 3dparty/bus_nng/aarch64/libbus_nng.so
rename to 3rdparty/bus_nng/aarch64/libbus_nng.so
Binary files differ
diff --git a/3dparty/bus_nng/bn_api.h b/3rdparty/bus_nng/bn_api.h
similarity index 100%
rename from 3dparty/bus_nng/bn_api.h
rename to 3rdparty/bus_nng/bn_api.h
diff --git a/3dparty/bus_nng/interface_bus_api.h b/3rdparty/bus_nng/interface_bus_api.h
similarity index 100%
rename from 3dparty/bus_nng/interface_bus_api.h
rename to 3rdparty/bus_nng/interface_bus_api.h
diff --git a/3dparty/bus_nng/x86_64/libbus_nng.so b/3rdparty/bus_nng/x86_64/libbus_nng.so
similarity index 100%
rename from 3dparty/bus_nng/x86_64/libbus_nng.so
rename to 3rdparty/bus_nng/x86_64/libbus_nng.so
Binary files differ
diff --git a/3dparty/yyjson/yyjson.c b/3rdparty/yyjson/yyjson.c
similarity index 100%
rename from 3dparty/yyjson/yyjson.c
rename to 3rdparty/yyjson/yyjson.c
diff --git a/3dparty/yyjson/yyjson.h b/3rdparty/yyjson/yyjson.h
similarity index 100%
rename from 3dparty/yyjson/yyjson.h
rename to 3rdparty/yyjson/yyjson.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 29d8e34..344aedd 100644
--- a/CMakeLists.txt
+++ b/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)
diff --git a/cbhomeclient.cpp b/cbhomeclient.cpp
index 1dac84e..c101e66 100644
--- a/cbhomeclient.cpp
+++ b/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;
diff --git a/cbhomeclient.h b/cbhomeclient.h
index 94ac29f..9d24e6c 100644
--- a/cbhomeclient.h
+++ b/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
diff --git a/exported_symbols b/exported_symbols
index 653901c..be3995b 100644
--- a/exported_symbols
+++ b/exported_symbols
@@ -45,6 +45,9 @@
     make_reply_msg;
     free_reply_msg;
 
+    free_query_procs;
+    bus_client_query_procs;
+
 local:
     *;
 };
diff --git a/main.cpp b/main.cpp
index 8811cf0..9f400b8 100644
--- a/main.cpp
+++ b/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;
 
diff --git a/message.cpp b/message.cpp
index 5c15f6c..f7f42f3 100644
--- a/message.cpp
+++ b/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);
+}
diff --git a/message.h b/message.h
index 258c135..88ac25f 100644
--- a/message.h
+++ b/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 浠巆enter鑾峰彇鎵�鏈夌殑procs淇℃伅
+*/
+void free_query_procs(struct cqueryprocs* procs, const size_t count);
+
 #ifdef __cplusplus
 }
 #endif

--
Gitblit v1.8.0