From aac0fe50f0ae9d13ff8ff7db2288a877b2fb2c53 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期五, 17 十二月 2021 14:13:55 +0800
Subject: [PATCH] bug fixed

---
 src/interface_bus_api.cpp |   38 ++++++++++++++++----------------------
 1 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index 20a4659..a23dd79 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -3,20 +3,14 @@
 using namespace nng_wrap;
 
 #include "common.h"
+#include <tuple>
 using namespace std;
 
 #include "bhome_msg.pb.h"
 #include "bhome_msg_api.pb.h"
 using namespace bhome_msg;
 
-struct bus{
-    _ps         pub{};
-    _ps_sub     sub{};
-    _sv         sv{};
-    _rr         rr{};
-    string      proc_id{};
-};
-
+using bus = tuple<_ps, _ps_sub, _sv, _rr, string>;
 void* bus_register(const void *proc_info,
                const int proc_info_len,
                void **reply,
@@ -36,19 +30,19 @@
 /////////////////////////////////////////////////////////////////////////
         bus *b = new bus;
         bhome_msg::ProcInfo pi;
-        if (pi.ParseFromArray(proc_info, proc_info_len)) b->proc_id = pi.proc_id();
+        if (pi.ParseFromArray(proc_info, proc_info_len)) get<4>(*b) = pi.proc_id();
 
         const auto& url_hb = get_url(URLHeartBeat);
-        respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&b->sv);
+        respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&get<2>(*b));
 
         const auto& url_pub_proxy = get_url(URLPubProxy);
-        publish(url_pub_proxy, NULL, 0, &b->pub);
+        publish(url_pub_proxy, NULL, 0, &get<0>(*b));
         const auto& url_sub_queue = get_url(URLSubQueue);
-        subscribe_center(url_sub_queue, &b->sub);
+        subscribe_center(url_sub_queue, &get<1>(*b));
 
         // temporary
         port = 0;
-        start_reply(b->proc_id, port, &b->rr);
+        start_reply(get<4>(*b), port, &get<3>(*b));
 
         return b;
     }
@@ -96,7 +90,7 @@
         return false;
     }
 
-    if (b->proc_id.empty()) {
+    if (get<4>(*b).empty()) {
         PRNTVITAG("proc_id is null");
         return false;
     }
@@ -108,7 +102,7 @@
     }
 
     bhome_msg::MsgTopicList mtl2;
-    mtl2.add_topic_list(b->proc_id);
+    mtl2.add_topic_list(get<4>(*b));
     for(int i = 0; i < mtl.topic_list_size(); i++){
         mtl2.add_topic_list(mtl.topic_list(i));
     }
@@ -214,7 +208,7 @@
     }
 
     for(int i = 0; i < mtl.topic_list_size(); i ++){
-        subscribe_topic(mtl.topic_list(i), &b->sub);
+        subscribe_topic(mtl.topic_list(i), &get<1>(*b));
     }
 
     return true;
@@ -250,7 +244,7 @@
         PRNTVITAG("handle is null");
         return false;
     }
-    if (b->proc_id.empty()){
+    if (get<4>(*b).empty()){
         PRNTVITAG("proc_id is null");
         return false;
     }
@@ -266,11 +260,11 @@
     }
 
     MsgPublish newPub;
-    newPub.set_topic(b->proc_id);
+    newPub.set_topic(get<4>(*b));
     newPub.set_data(string{(const char*)msgpub, (const size_t)msgpub_len});
 
     string msg(newPub.SerializeAsString());
-    auto ret = publish(pub.topic(), msg.data(), msg.size(), &b->pub);
+    auto ret = publish(pub.topic(), msg.data(), msg.size(), &get<0>(*b));
     if (ret > 0) return true;
     return false;
 }
@@ -289,7 +283,7 @@
     }
 
     string topic, msg;
-    auto ret = subscribe_read(&topic, &msg, timeout_ms, &b->sub);
+    auto ret = subscribe_read(&topic, &msg, timeout_ms, &get<1>(*b));
     if (ret < 0) return false;
 
     MsgPublish newPub;
@@ -366,7 +360,7 @@
     }
 
     string msg;
-    auto ret = read_request(src, &msg, timeout_ms, &b->rr);
+    auto ret = read_request(src, &msg, timeout_ms, &get<3>(*b));
     if (ret != 0) return false;
 
     string procid{};
@@ -397,7 +391,7 @@
         return false;
     }
 
-    auto ret = send_reply(src, reply, reply_len, &b->rr);
+    auto ret = send_reply(src, reply, reply_len, &get<3>(*b));
 
     if (ret < 0) return false;
     return true;

--
Gitblit v1.8.0