zhangmeng
2022-01-14 f7c4658c884629e79a9ce98052e19f8a68abdf22
src/interface_bus_api.cpp
@@ -10,7 +10,7 @@
#include "bhome_msg_api.pb.h"
using namespace bhome_msg;
using bus = tuple<_ps, _ps_sub, _sv, _rr, string>;
using bus = tuple<array<thread, 0>, _ps, _ps_sub, vector<tuple<float>>, deque<map<string, void*>>, _sv, _rr, unordered_map<void*, unordered_set<string*>>, string>;
void* bus_register(const void *proc_info,
               const int proc_info_len,
               void **reply,
@@ -30,19 +30,19 @@
/////////////////////////////////////////////////////////////////////////
        bus *b = new bus;
        bhome_msg::ProcInfo pi;
        if (pi.ParseFromArray(proc_info, proc_info_len)) get<4>(*b) = pi.proc_id();
        if (pi.ParseFromArray(proc_info, proc_info_len)) get<8>(*b) = pi.proc_id();
        const auto& url_hb = get_url(URLHeartBeat);
        respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&get<2>(*b));
        respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&get<5>(*b));
        const auto& url_pub_proxy = get_url(URLPubProxy);
        publish(url_pub_proxy, NULL, 0, &get<0>(*b));
        publish(url_pub_proxy, NULL, 0, &get<1>(*b));
        const auto& url_sub_queue = get_url(URLSubQueue);
        subscribe_center(url_sub_queue, &get<1>(*b));
        subscribe_center(url_sub_queue, &get<2>(*b));
        // temporary
        port = 0;
        start_reply(get<4>(*b), port, &get<3>(*b));
        // port = 0;
        start_reply(get<8>(*b), port, &get<6>(*b));
        return b;
    }
@@ -90,7 +90,7 @@
        return false;
    }
    if (get<4>(*b).empty()) {
    if (get<8>(*b).empty()) {
        PRNTVITAG("proc_id is null");
        return false;
    }
@@ -102,7 +102,7 @@
    }
    bhome_msg::MsgTopicList mtl2;
    mtl2.add_topic_list(get<4>(*b));
    mtl2.add_topic_list(get<8>(*b));
    for(int i = 0; i < mtl.topic_list_size(); i++){
        mtl2.add_topic_list(mtl.topic_list(i));
    }
@@ -133,15 +133,15 @@
    auto url(get_url(URLQueryTopic));
    if (remote && remote_len > 0){
        BHAddress addr;
        if (addr.ParseFromArray(remote, remote_len)){
            if (!addr.ip().empty() && addr.port() > 0){
                // url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
                printf("======>> bus_query_topic_address use remote address %s\n", url.c_str());
            }
        }
    }
    // if (remote && remote_len > 0){
    //     BHAddress addr;
    //     if (addr.ParseFromArray(remote, remote_len)){
    //         if (!addr.ip().empty() && addr.port() > 0){
    //             // url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
    //             printf("======>> bus_query_topic_address use remote address %s\n", url.c_str());
    //         }
    //     }
    // }
    return simple_request(url, topics, topics_len, reply, reply_len, timeout_ms);
}
@@ -167,15 +167,15 @@
    auto url(get_url(URLQueryProcs));
    if (remote && remote_len > 0){
        BHAddress addr;
        if (addr.ParseFromArray(remote, remote_len)){
            if (!addr.ip().empty() && addr.port() > 0){
                // url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
                printf("======>> bus_query_procs use remote address %s\n", url.c_str());
            }
        }
    }
    // if (remote && remote_len > 0){
    //     BHAddress addr;
    //     if (addr.ParseFromArray(remote, remote_len)){
    //         if (!addr.ip().empty() && addr.port() > 0){
    //             // url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
    //             printf("======>> bus_query_procs use remote address %s\n", url.c_str());
    //         }
    //     }
    // }
    return simple_request(url, query, query_len, reply, reply_len, timeout_ms);
}
@@ -208,7 +208,7 @@
    }
    for(int i = 0; i < mtl.topic_list_size(); i ++){
        subscribe_topic(mtl.topic_list(i), &get<1>(*b));
        subscribe_topic(mtl.topic_list(i), &get<2>(*b));
    }
    return true;
@@ -244,7 +244,7 @@
        PRNTVITAG("handle is null");
        return false;
    }
    if (get<4>(*b).empty()){
    if (get<8>(*b).empty()){
        PRNTVITAG("proc_id is null");
        return false;
    }
@@ -260,11 +260,11 @@
    }
    MsgPublish newPub;
    newPub.set_topic(get<4>(*b));
    newPub.set_topic(get<8>(*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(), &get<0>(*b));
    auto ret = publish(pub.topic(), msg.data(), msg.size(), &get<1>(*b));
    if (ret > 0) return true;
    return false;
}
@@ -283,7 +283,7 @@
    }
    string topic, msg;
    auto ret = subscribe_read(&topic, &msg, timeout_ms, &get<1>(*b));
    auto ret = subscribe_read(&topic, &msg, timeout_ms, &get<2>(*b));
    if (ret < 0) return false;
    MsgPublish newPub;
@@ -360,7 +360,7 @@
    }
    string msg;
    auto ret = read_request(src, &msg, timeout_ms, &get<3>(*b));
    auto ret = read_request(src, &msg, timeout_ms, &get<6>(*b));
    if (ret != 0) return false;
    string procid{};
@@ -391,7 +391,7 @@
        return false;
    }
    auto ret = send_reply(src, reply, reply_len, &get<3>(*b));
    auto ret = send_reply(src, reply, reply_len, &get<6>(*b));
    if (ret < 0) return false;
    return true;