zhangmeng
2022-01-17 b4bda4a8e6aa1acf5e161a95642e944e08c72646
src/interface_bus_api.cpp
@@ -41,7 +41,7 @@
        subscribe_center(url_sub_queue, &get<2>(*b));
        // temporary
        port = 0;
        // port = 0;
        start_reply(get<8>(*b), port, &get<6>(*b));
        return b;
@@ -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);
}
@@ -259,6 +259,7 @@
        return false;
    }
    // msgpublish(msgpublish(msg))
    MsgPublish newPub;
    newPub.set_topic(get<8>(*b));
    newPub.set_data(string{(const char*)msgpub, (const size_t)msgpub_len});
@@ -319,20 +320,19 @@
        return false;
    }
    string url{};
    // BHQueryTopicAddress获取proc_id
    string procid{};
    if (!get_proc_id_from_MsgRequestTopic(request, request_len, timeout_ms, &procid)){
        PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
        return false;
    if (get_proc_id_from_MsgRequestTopic(request, request_len, timeout_ms, &procid)){
        // PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
        // return false;
        url = "ipc:///tmp/" + procid;
    }
    auto url("ipc:///tmp/" + procid);
    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());
                url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
                printf("======>> BHRequest use remote address %s\n", url.c_str());
            }
        }
@@ -361,15 +361,16 @@
    string msg;
    auto ret = read_request(src, &msg, timeout_ms, &get<6>(*b));
    // printf("bus_recv_request read_request ret %d msg %s\n", ret, msg.c_str());
    if (ret != 0) return false;
    string procid{};
    if (!get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
        PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
        return false;
    if (get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
        // PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
        // return false;
        copy_memory(proc_id, proc_id_len, procid.data(), procid.size());
    }
    copy_memory(proc_id, proc_id_len, procid.data(), procid.size());
    copy_memory(request, request_len, msg.data(), msg.size());
    return true;