From 16935f4aebffdd1b6580b844391a0aa0f4f3012b Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 22 四月 2024 10:29:12 +0800
Subject: [PATCH] bug fixed

---
 src/interface_bus_api.cpp |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index ccb75c8..13bc08e 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -31,6 +31,7 @@
         bus *b = new bus;
         bhome_msg::ProcInfo pi;
         if (pi.ParseFromArray(proc_info, proc_info_len)) get<8>(*b) = pi.proc_id();
+        std::move(pi);
 
         const auto& url_hb = get_url(URLHeartBeat);
         respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&get<5>(*b));
@@ -89,6 +90,11 @@
         PRNTVITAG("topics is null");
         return false;
     }
+    const auto& url = get_url(URLRegTopic);
+    if (!url) {
+        set_last_error("bus_register_topics url empty");
+        return false;
+    }
 
     if (get<8>(*b).empty()) {
         PRNTVITAG("proc_id is null");
@@ -106,13 +112,11 @@
     for(int i = 0; i < mtl.topic_list_size(); i++){
         mtl2.add_topic_list(mtl.topic_list(i));
     }
+    std::move(mtl);
 
     string msg(mtl2.SerializeAsString());
-    const auto& url = get_url(URLRegTopic);
-    if (url.empty()) {
-        set_last_error("bus_register_topics url empty");
-        return false;
-    }
+    std::move(mtl2);
+
     return simple_request(url, msg.data(), msg.size(), reply, reply_len, timeout_ms);
 }
 
@@ -135,8 +139,8 @@
         return false;
     }
 
-    auto url(get_url(URLQueryTopic));
-    if (url.empty()) {
+    const auto& url = get_url(URLQueryTopic);
+    if (!url) {
         set_last_error("bus_query_topic_address url empty");
         return false;
     }
@@ -168,13 +172,13 @@
         PRNTVITAG("handle is null");
         return false;
     }
-    if (!query || query_len <= 0) {
-        PRNTVITAG("query is null");
-        return false;
-    }
+    // if (!query || query_len <= 0) {
+    //     PRNTVITAG("query is null");
+    //     return false;
+    // }
 
-    auto url(get_url(URLQueryProcs));
-    if (url.empty()) {
+    const auto& url = get_url(URLQueryProcs);
+    if (!url) {
         set_last_error("bus_query_procs url empty");
         return false;
     }
@@ -221,6 +225,7 @@
     for(int i = 0; i < mtl.topic_list_size(); i ++){
         subscribe_topic(mtl.topic_list(i), &get<2>(*b));
     }
+    std::move(mtl);
 
 ///////////////////////////////////////////////////
     auto ret = simple_request(url, topics, topics_len, reply, reply_len, timeout_ms);
@@ -283,6 +288,8 @@
     newPub.set_data(string{(const char*)msgpub, (const size_t)msgpub_len});
 
     string msg(newPub.SerializeAsString());
+    std::move(newPub);
+
     auto ret = publish(pub.topic(), msg.data(), msg.size(), &get<1>(*b));
     if (ret > 0) return true;
     return false;
@@ -300,6 +307,8 @@
         PRNTVITAG("handle is null");
         return false;
     }
+    if (!proc_id && !proc_id_len && !msgpub && !msgpub_len)
+        return subscribe_read(NULL, NULL, timeout_ms, &get<2>(*b)) == 0;
 
     string topic, msg;
     auto ret = subscribe_read(&topic, &msg, timeout_ms, &get<2>(*b));
@@ -380,6 +389,8 @@
         PRNTVITAG("handle is null");
         return false;
     }
+    if (!proc_id && !proc_id_len && !request && !request_len && !src)
+        return read_request(NULL, NULL, timeout_ms, &get<6>(*b)) == 0;
 
     string msg;
     auto ret = read_request(src, &msg, timeout_ms, &get<6>(*b));

--
Gitblit v1.8.0