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

---
 cbhomeclient.cpp |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

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;

--
Gitblit v1.8.0