#include "bus_server_socket.h" #include "shm_mod_socket.h" #include "shm_mm_wrapper.h" #include "usg_common.h" #include "mm.h" #include "logger_factory.h" #include #include #include #include #include "bus_error.h" #include "bh_api.h" #include "proc_def.h" static ProcInfo proc_desc; int main(int argc, char *argv[]) { int ret; void *buf_temp = NULL; void *errBuf = NULL; void *proc_id = NULL; void *src = NULL; void *data_buf = NULL; char topics_buf[200] = { 0x00 }; int size; int id_len; int count = 0; const int timeout_ms = 3000; memset(&proc_desc, 0x00, sizeof(ProcInfo)); strncpy(proc_desc.proc_id, "Hello", strlen("Hello")); strncpy(proc_desc.name, "World", strlen("World")); strncpy(proc_desc.public_info, "Good", strlen("Good") + 1); const char *topics_server_specific_reg_buf1 = "Server Specific topics demo1"; const char *topics_server_specific_reg_buf2 = "Server Specific Hello World"; ret = BHRegister(&proc_desc, (const int)sizeof(ProcInfo), &buf_temp, &size, timeout_ms); if (ret == true) { printf("the process registered OKay\n"); BHFree(buf_temp, size); } else { BHGetLastError(&errBuf, &size); printf("the process registered fail with error: %s\n", (char *)errBuf); BHFree(errBuf, size); }; ret = BHRegisterTopics(topics_server_specific_reg_buf1, strlen(topics_server_specific_reg_buf1), &buf_temp, &size, timeout_ms); if (ret == true) { printf("the process registered topics OKay\n"); BHFree(buf_temp, size); } else { BHGetLastError(&errBuf, &size); printf("the process registered1 fail with errorL %s\n", (char *)errBuf); BHFree(errBuf, size); }; ret = BHRegisterTopics(topics_server_specific_reg_buf2, strlen(topics_server_specific_reg_buf2), &buf_temp, &size, timeout_ms); if (ret == true) { printf("the process registered topics OKay\n"); BHFree(buf_temp, size); } else { BHGetLastError(&errBuf, &size); printf("the process registered1 fail with errorL %s\n", (char *)errBuf); BHFree(errBuf, size); }; while(true) { ret = BHReadRequest(&proc_id, &id_len, &buf_temp, &size, &src, -1); if (ret == true) { strncpy(topics_buf, (char *)buf_temp, (sizeof(topics_buf) - 1) > size ? size : (sizeof(topics_buf) - 1)); printf("Get data(%s)", topics_buf); memset(topics_buf, 0x00, sizeof(topics_buf)); strncpy(topics_buf, (char *)proc_id, (sizeof(topics_buf) - 1) > id_len ? id_len : (sizeof(topics_buf) - 1)); printf("proc id(%s)", topics_buf); BHFree(buf_temp, size); BHFree(proc_id, id_len); memset(topics_buf, 0x00, sizeof(topics_buf)); sprintf(topics_buf, "Get data count: %d", ++count); ret = BHSendReply(src, topics_buf, strlen(topics_buf)); if (ret == true) { printf("the process send reply OKay\n"); } else { BHGetLastError(&errBuf, &size); printf("the process send reply fail with errorL %s\n", (char *)errBuf); BHFree(errBuf, size); }; BHFree(src, size); } else { BHGetLastError(&errBuf, &size); printf("BHReadRequest fail with error(%s)\n", (char *)errBuf); BHFree(errBuf, size); }; } return 0; }