| | |
| | | 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)); |
| | |
| | | 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()); |
| | | std::move(mtl2); |
| | | |
| | | return simple_request(get_url(URLRegTopic), msg.data(), msg.size(), reply, reply_len, timeout_ms); |
| | | const auto& url = get_url(URLRegTopic); |
| | | if (url.empty()) { |
| | | set_last_error("bus_register_topics url empty"); |
| | | return false; |
| | | } |
| | | return simple_request(url, msg.data(), msg.size(), reply, reply_len, timeout_ms); |
| | | } |
| | | |
| | | int bus_query_topic_address(void* handle, const void *remote, |
| | |
| | | return false; |
| | | } |
| | | |
| | | auto url(get_url(URLQueryTopic)); |
| | | const auto& url = get_url(URLQueryTopic); |
| | | if (url.empty()) { |
| | | set_last_error("bus_query_topic_address url empty"); |
| | | return false; |
| | | } |
| | | |
| | | // if (remote && remote_len > 0){ |
| | | // BHAddress addr; |
| | |
| | | PRNTVITAG("handle is null"); |
| | | return false; |
| | | } |
| | | if (!query || query_len <= 0) { |
| | | PRNTVITAG("query is null"); |
| | | // if (!query || query_len <= 0) { |
| | | // PRNTVITAG("query is null"); |
| | | // return false; |
| | | // } |
| | | |
| | | const auto& url = get_url(URLQueryProcs); |
| | | if (url.empty()) { |
| | | set_last_error("bus_query_procs url empty"); |
| | | return false; |
| | | } |
| | | |
| | | auto url(get_url(URLQueryProcs)); |
| | | |
| | | // if (remote && remote_len > 0){ |
| | | // BHAddress addr; |
| | | // if (addr.ParseFromArray(remote, remote_len)){ |
| | |
| | | return simple_request(url, query, query_len, reply, reply_len, timeout_ms); |
| | | } |
| | | |
| | | int bus_subscribe_topics(void* handle, const void *topics, |
| | | static int sub(const string& url,void* handle, const void *topics, |
| | | const int topics_len, |
| | | void **reply, |
| | | int *reply_len, |
| | | const int timeout_ms) |
| | | { |
| | | const int timeout_ms){ |
| | | |
| | | TAG; |
| | | bus* b = get(handle); |
| | | if (!b){ |
| | |
| | | for(int i = 0; i < mtl.topic_list_size(); i ++){ |
| | | subscribe_topic(mtl.topic_list(i), &get<2>(*b)); |
| | | } |
| | | |
| | | return true; |
| | | std::move(mtl); |
| | | |
| | | /////////////////////////////////////////////////// |
| | | auto ret = simple_request(get_url(URLSubLocal), topics, topics_len, reply, reply_len, timeout_ms); |
| | | auto ret = simple_request(url, topics, topics_len, reply, reply_len, timeout_ms); |
| | | if (!ret){ |
| | | printf("bus_subscribe_topics simple_request failed\n"); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | int bus_subscribe_topics(void* handle, const void *topics, |
| | | const int topics_len, |
| | | void **reply, |
| | | int *reply_len, |
| | | const int timeout_ms) |
| | | { |
| | | return sub(get_url(URLSubLocal), handle, topics, topics_len, reply, reply_len, timeout_ms); |
| | | } |
| | | int bus_subscribe_topics_net(void* handle, const void *topics, |
| | | const int topics_len, |
| | | void **reply, |
| | | int *reply_len, |
| | | const int timeout_ms) |
| | | { |
| | | return bus_subscribe_topics(handle, topics, topics_len, reply, reply_len, timeout_ms); |
| | | return sub(get_url(URLSubNet), handle, topics, topics_len, reply, reply_len, timeout_ms); |
| | | } |
| | | |
| | | int bus_heartbeat_easy(void* handle, const int timeout_ms){ return 1; } |
| | |
| | | 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}); |
| | | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | | |
| | | 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()); |
| | | printf("======>> BHRequest use remote address %s\n", url.c_str()); |
| | | url = "tcp://" + addr.ip() + ":" + to_string(addr.port()); |
| | | // printf("======>> BHRequest use remote address %s\n", url.c_str()); |
| | | } |
| | | } |
| | | } else 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; |
| | | } |
| | | |
| | | if (url.empty()) { |
| | | set_last_error("bus_request url empty"); |
| | | return false; |
| | | } |
| | | int rc = request2(url, request, request_len, reply, reply_len, timeout_ms); |
| | | if (rc < 0) return false; |
| | | copy_memory(proc_id, proc_id_len, procid.data(), procid.size()); |
| | |
| | | |
| | | string msg; |
| | | auto ret = read_request(src, &msg, timeout_ms, &get<6>(*b)); |
| | | if (ret != 0) return false; |
| | | // 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 (ret == REPLY_IPC){ |
| | | string procid{}; |
| | | 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; |