| | |
| | | #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" |
| | |
| | | |
| | | static int gRun_stat = 0; |
| | | static void *gNetmod_socket = NULL; |
| | | static std::map<std::string, int> gRecvbuf; |
| | | |
| | | static pthread_mutex_t mutex; |
| | | |
| | |
| | | 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"); |
| | |
| | | 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; |
| | |
| | | #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); |
| | |
| | | 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); |
| | |
| | | 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; |
| | | |
| | |
| | | #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); |
| | |
| | | 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); |
| | |
| | | |
| | | } |
| | | |
| | | #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 |
| | | |