fujuntang
2021-11-10 c479ef57baaaa28964fc3ec8d80ff99dffa7d49f
src/bh_api.cpp
@@ -23,6 +23,7 @@
static pthread_t gTids;
static void *client_run_check(void *skptr) { 
  pthread_detach(pthread_self());
 
@@ -36,7 +37,7 @@
  sec = TIME_WAIT;
  nsec = 0;
  sprintf(buf, "%s", "Success");
  sprintf(buf, "%s", STR_EXEC);
  data = net_mod_socket_int_get(gNetmod_socket);
  while(true) {
    
@@ -45,9 +46,13 @@
      
      BHFree(buf_temp, size);
      if ((gNetmod_socket != NULL) && (gRun_stat != 0)) {
      rv = net_mod_socket_sendto_timeout(gNetmod_socket, buf, strlen(buf), key, sec, nsec, SVR_STR, data);
      if (rv != 0) {
        logger->error("the process check response failed with error: %s!\n", bus_strerror(rv));
        }
      } else {
        break;
      }
      
    } else {
@@ -123,25 +128,25 @@
    shm_mm_wrapper_init(SHM_RES_SIZE);
    
#if defined(PRO_DE_SERIALIZE)
    if (_input.proc_id != NULL) {
    if (strlen(_input.proc_id) > 0) {
      count = strlen(_input.proc_id) + 1;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
      strncpy(pData.proc_id, _input.proc_id, min);
    }
    if (_input.name != NULL) {
    if (strlen(_input.name) > 0) {
      count = strlen(_input.name) + 1;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN -1) : count;
      strncpy(pData.name, _input.name, min); 
    }
    if (_input.public_info != NULL) {
    if (strlen(_input.public_info) > 0) {
      count = strlen(_input.public_info) + 1;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1) : count;
      strncpy(pData.public_info, _input.public_info, min);
    }
 
    if (_input.private_info != NULL) {
    if (strlen(_input.private_info) > 0) {
      count = strlen(_input.private_info) + 1;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1): count;
      strncpy(pData.private_info, _input.private_info, min);
@@ -172,11 +177,12 @@
    }
#endif 
    if (pData.proc_id == NULL) {
    if (strlen(pData.proc_id) == 0) {
      rv = EBUS_INVALID_PARA;
      bus_errorset(rv);
      gRun_stat = 0;
      pthread_mutex_unlock(&mutex);
      
      goto exit_entry;
@@ -185,13 +191,13 @@
    gNetmod_socket = net_mod_socket_open();
    hashtable_t *hashtable = mm_get_hashtable();
    key = hashtable_alloc_key(hashtable);
    net_mod_socket_bind(gNetmod_socket, key);
    count = hashtable_alloc_key(hashtable);
    rv = hashtable_alloc_key(hashtable);
    net_mod_socket_int_set(gNetmod_socket, count);
    net_mod_socket_svr_set(gNetmod_socket, rv);
    sprintf(pData.int_info, "%d", count);
    sprintf(pData.svr_info, "%d", rv);
    net_mod_socket_bind(gNetmod_socket, key);
  
    rv = net_mod_socket_reg(gNetmod_socket, &pData, sizeof(ProcInfo), NULL, 0, timeout_ms, PROC_REG);
@@ -539,6 +545,8 @@
  if (rv == 0) {
    
    min = *(int *)buf;
    if (min > 0) {
    ptr = (ProcInfo_query *)((char *)buf + sizeof(int));
    mtr_list_num = ptr->num;
    
@@ -554,6 +562,11 @@
      mtr_list[i].ip = "127.0.0.1";
      mtr_list[i].port = 5000;
    }
    } else {
      mtr_list_num = 0;
    }
    free(buf);
  }
  
exit_entry:
@@ -685,6 +698,7 @@
      mpr_list_num = sizeof(mpr_list) / sizeof(mpr_list[0]);
    }
    
    if (mpr_list_num > 0) {
    Proc_ptr = (ProcInfo_sum *)((char *)buf + sizeof(int));
    for(int i = 0; i < mpr_list_num; i++) {
      mpr_list[i].proc_id = (Proc_ptr + i)->procData.proc_id;
@@ -705,6 +719,9 @@
        }
      }
    }
    }
    free(buf);
  }
    
  errString = bus_strerror(0, 1);
@@ -1583,6 +1600,13 @@
exit_entry:
  errString = bus_strerror(0, 1);
  
  if (rv != 0) {
    if ((proc_id != NULL) && (proc_id_len != NULL)) {
      *proc_id_len = 0;
      *proc_id = NULL;
    }
  }
#if defined(PRO_DE_SERIALIZE) 
  ::bhome_msg::MsgRequestTopicReply mrt; 
  mrt.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv));
@@ -1707,6 +1731,12 @@
  if (rv != 0) { 
    rrr.topic = STR_RSV;
    rrr.data = STR_RSV;   
    if ((proc_id != NULL) && (proc_id_len != NULL)) {
      *proc_id_len = 0;
      *proc_id = NULL;
    }
  }
#if defined(PRO_DE_SERIALIZE)
@@ -1814,13 +1844,21 @@
}
#if defined(MSG_HANDLER)
int inter_key_get(void)
{
  if (gNetmod_socket != NULL)
    return net_mod_socket_get_key(gNetmod_socket);
  return 0;
  return SHM_BUS_KEY;
}
#endif
void *socket_data_get(void)
{
  return gNetmod_socket;
}
void inter_key_set(int key)
{
  net_mod_socket_bind(gNetmod_socket, key);
}