lichao
2021-04-23 65a230ec6ccb61c3ce6816730da2106f07f40b4a
src/bh_api.cpp
@@ -10,6 +10,7 @@
{
TopicNode &ProcNode()
{
   static bool init_bind_msg_shm = MsgI::BindShm(BHomeShm());
   static TopicNode node(BHomeShm());
   return node;
}
@@ -103,6 +104,10 @@
{
   return BHApiIn1Out1<ProcInfo>(&TopicNode::Register, proc_info, proc_info_len, reply, reply_len, timeout_ms);
}
int BHUnregister(const void *proc_info, const int proc_info_len, void **reply, int *reply_len, const int timeout_ms)
{
   return BHApiIn1Out1<ProcInfo>(&TopicNode::Unregister, proc_info, proc_info_len, reply, reply_len, timeout_ms);
}
int BHHeartbeatEasy(const int timeout_ms)
{
@@ -119,6 +124,10 @@
   return BHApiIn1Out1<MsgTopicList>(&TopicNode::ServerRegisterRPC, topics, topics_len, reply, reply_len, timeout_ms);
}
int BHQueryTopicAddress(const void *topics, const int topics_len, void **reply, int *reply_len, const int timeout_ms)
{
   return BHApiIn1Out1<MsgQueryTopic, MsgQueryTopicReply>(&TopicNode::QueryTopicAddress, topics, topics_len, reply, reply_len, timeout_ms);
}
int BHSubscribeTopics(const void *topics, const int topics_len, void **reply, int *reply_len, const int timeout_ms)
{
   return BHApiIn1Out1<MsgTopicList>(&TopicNode::Subscribe, topics, topics_len, reply, reply_len, timeout_ms);
@@ -157,19 +166,23 @@
   return false;
}
int BHAsyncRequest(const void *request,
int BHAsyncRequest(const void *remote,
                   const int remote_len,
                   const void *request,
                   const int request_len,
                   void **msg_id,
                   int *msg_id_len)
{
   BHAddress dest;
   MsgRequestTopic req;
   if (!req.ParseFromArray(request, request_len)) {
   if (!dest.ParseFromArray(remote, remote_len) ||
       !req.ParseFromArray(request, request_len)) {
      SetLastError(eInvalidInput, "invalid input.");
      return false;
   }
   std::string str_msg_id;
   MsgRequestTopicReply out_msg;
   if (ProcNode().ClientAsyncRequest(req, str_msg_id)) {
   if (ProcNode().ClientAsyncRequest(dest, req, str_msg_id)) {
      if (!msg_id || !msg_id_len) {
         return true;
      }
@@ -184,7 +197,9 @@
   return false;
}
int BHRequest(const void *request,
int BHRequest(const void *remote,
              const int remote_len,
              const void *request,
              const int request_len,
              void **proc_id,
              int *proc_id_len,
@@ -192,14 +207,16 @@
              int *reply_len,
              const int timeout_ms)
{
   BHAddress dest;
   MsgRequestTopic req;
   if (!req.ParseFromArray(request, request_len)) {
   if (!dest.ParseFromArray(remote, remote_len) ||
       !req.ParseFromArray(request, request_len)) {
      SetLastError(eInvalidInput, "invalid input.");
      return false;
   }
   std::string proc;
   MsgRequestTopicReply out_msg;
   if (ProcNode().ClientSyncRequest(req, proc, out_msg, timeout_ms)) {
   if (ProcNode().ClientSyncRequest(dest, req, proc, out_msg, timeout_ms)) {
      TmpPtr pproc(proc);
      if (pproc && PackOutput(out_msg, reply, reply_len)) {
         pproc.ReleaseTo(proc_id, proc_id_len);