fujuntang
2021-10-25 08f25e576c34f447cb60870d037d9146b2113d66
src/bh_api.cpp
@@ -7,6 +7,7 @@
#include "bh_api.h"
#include <pthread.h>
#include <getopt.h>
#include "msg_mgr.h"
#include "../proto/source/error_msg.pb.h"
#include "../proto/source/bhome_msg.pb.h"
#include "../proto/source/bhome_msg_api.pb.h"
@@ -17,7 +18,6 @@
static int gRun_stat = 0;
static void *gNetmod_socket = NULL;
static std::map<std::string, int> gRecvbuf;
static pthread_mutex_t mutex;
@@ -102,6 +102,10 @@
  memset(&pData, 0x00, sizeof(ProcInfo));
  if (gRun_stat == 0) {
    pthread_mutex_init(&mutex, NULL);
#if defined(MSG_HANDLER)
    msg_init();
#endif
  } else {
    logger->error("the process has already registered!\n");
@@ -1197,7 +1201,6 @@
  std::string str;
  std::string MsgID;
  int timeout_ms = 3000;
  std::map<std::string, int>::iterator recvIter;
  char data_buf[MAX_STR_LEN] = { 0x00 };
  char buf_temp[MAX_STR_LEN] = { 0x00 };
  char *topics_buf = NULL;
@@ -1260,11 +1263,10 @@
#endif 
 
  str = buf_temp;
  recvIter = gRecvbuf.find(str);
  if(recvIter != gRecvbuf.end()) {
  val = net_mod_socket_buf_data_get(gNetmod_socket, str);
  if(val > 0) {
    
    rv = 0;
    val = recvIter->second;
  } else {
    rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
@@ -1275,7 +1277,7 @@
      val = atoi((char *)data_buf);
      if (val > 0) {
        str = buf_temp;
        gRecvbuf.insert({str, val});
        net_mod_socket_buf_data_set(gNetmod_socket, str, val);
      }
      free(buf);
@@ -1376,7 +1378,6 @@
  net_mod_err_t *errarr;
  int errarr_size = 0;
  char *errString = NULL;
  std::map<std::string, int>::iterator recvIter;
  char buf_temp[MAX_STR_LEN] = { 0x00 };
  char *topics_buf = NULL;
  
@@ -1445,11 +1446,10 @@
#endif 
 
  str = buf_temp;
  recvIter = gRecvbuf.find(str);
  if(recvIter != gRecvbuf.end()) {
  val = net_mod_socket_buf_data_get(gNetmod_socket, str);
  if(val > 0) {
    
    rv = 0;
    val = recvIter->second;
  } else {
    rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
@@ -1460,7 +1460,7 @@
      val = atoi((char *)data_buf);
      if (val > 0) {
        str = buf_temp;
        gRecvbuf.insert({str, val});
        net_mod_socket_buf_data_set(gNetmod_socket, str, val);
      }
      free(buf);
@@ -1814,9 +1814,13 @@
}
#if defined(MSG_HANDLER)
int inter_key_get(void)
{
  return net_mod_socket_get_key(gNetmod_socket);
}
  if (gNetmod_socket != NULL)
    return net_mod_socket_get_key(gNetmod_socket);
  return 0;
}
#endif