| | |
| | | int BHRegisterTopics(const void *topics, const int topics_len, void **reply, int *reply_len, const int timeout_ms) |
| | | { |
| | | int rv; |
| | | int min, i; |
| | | int len, i; |
| | | void *buf = NULL; |
| | | int total = 0; |
| | | int count = 0; |
| | | char topics_buf[MAX_STR_LEN * MAX_TOPICS_NUN] = { 0x00 }; |
| | | char *topics_buf = NULL; |
| | | |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | struct _MsgTopicList |
| | |
| | | |
| | | for(int i = 0; i < _input.amount; i++) { |
| | | _input.topics[i] = input.topic_list(i).c_str(); |
| | | |
| | | total += strlen(_input.topics[i]) + 1; |
| | | } |
| | | #else |
| | | if ((topics == NULL) || (topics_len == 0)) { |
| | |
| | | |
| | | goto exit_entry; |
| | | } |
| | | |
| | | total = topics_len; |
| | | #endif |
| | | |
| | | if (gRun_stat == 0) { |
| | |
| | | |
| | | rv = pthread_mutex_trylock(&mutex); |
| | | if (rv == 0) { |
| | | |
| | | topics_buf = (char *)malloc(total); |
| | | if (topics_buf == NULL) { |
| | | |
| | | rv = EBUS_RES_NO; |
| | | memset(errString, 0x00, sizeof(errString)); |
| | | strncpy(errString, bus_strerror(rv), sizeof(errString)); |
| | | |
| | | logger->error("in BHRegisterTopics: Out of memory!\n"); |
| | | |
| | | goto exit_entry; |
| | | } |
| | | memset(topics_buf, 0x00, total); |
| | | |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | total = sizeof(topics_buf) / sizeof(char); |
| | | for (i = 0; i < _input.amount; i++) { |
| | | min = (strlen(_input.topics[i]) > (total - 1) ? (total - 1) : strlen(_input.topics[i])); |
| | | if (min > 0) { |
| | | strncpy(topics_buf + count, _input.topics[i], min); |
| | | count += min; |
| | | |
| | | len = strlen(_input.topics[i]); |
| | | strncpy(topics_buf + count, _input.topics[i], len); |
| | | |
| | | count += len; |
| | | |
| | | total -= min; |
| | | |
| | | if ((total > 1) && (_input.amount > 1) && (i < (_input.amount - 1))) { |
| | | strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC)); |
| | | total -= 1; |
| | | count++; |
| | | } |
| | | } else { |
| | | topics_buf[strlen(topics_buf) - 1] = '\0'; |
| | | if ((_input.amount > 1) && (i < (_input.amount - 1))) { |
| | | strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC)); |
| | | |
| | | count++; |
| | | } |
| | | } |
| | | |
| | | //logger->debug("the parsed compound register topics: %s!\n", topics_buf); |
| | | |
| | | #else |
| | | memcpy(topics_buf, topics, topics_len > (sizeof(topics_buf) - 1) ? (sizeof(topics_buf) - 1) : topics_len); |
| | | memcpy(topics_buf, topics, topics_len); |
| | | #endif |
| | | |
| | | rv = net_mod_socket_reg(gNetmod_socket, topics_buf, strlen(topics_buf) + 1, NULL, 0, timeout_ms, PROC_REG_TCS); |
| | |
| | | memset(errString, 0x00, sizeof(errString)); |
| | | strncpy(errString, bus_strerror(rv), sizeof(errString)); |
| | | |
| | | free(topics_buf); |
| | | pthread_mutex_unlock(&mutex); |
| | | |
| | | } else { |
| | |
| | | *reply = malloc(*reply_len); |
| | | mcr.SerializePartialToArray(*reply, *reply_len); |
| | | #else |
| | | min = strlen(errString) + 1; |
| | | buf = malloc(min) ; |
| | | len = strlen(errString) + 1; |
| | | buf = malloc(len) ; |
| | | memcpy(buf, errString, strlen(errString)); |
| | | *((char *)buf + min - 1) = '\0'; |
| | | *((char *)buf + len - 1) = '\0'; |
| | | |
| | | *reply = buf; |
| | | *reply_len = min; |
| | | *reply_len = len; |
| | | #endif |
| | | |
| | | if (rv == 0) |
| | |
| | | int sec, nsec; |
| | | int total = 0; |
| | | int count = 0; |
| | | int min, i; |
| | | int len, i; |
| | | void *buf = NULL; |
| | | char topics_buf[MAX_STR_LEN * MAX_TOPICS_NUN] = { 0x00 }; |
| | | char *topics_buf = NULL; |
| | | |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | struct _MsgTopicList |
| | |
| | | _input.amount = MAX_STR_LEN; |
| | | } |
| | | |
| | | for(int i = 0; i < _input.amount; i++) |
| | | for(int i = 0; i < _input.amount; i++) { |
| | | _input.topics[i] = input.topic_list(i).c_str(); |
| | | |
| | | total += strlen(_input.topics[i]) + 1; |
| | | } |
| | | |
| | | #else |
| | | if ((topics == NULL) || (topics_len == 0)) { |
| | |
| | | |
| | | rv = pthread_mutex_trylock(&mutex); |
| | | if (rv == 0) { |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | total = sizeof(topics_buf) / sizeof(char); |
| | | for (i = 0; i < _input.amount; i++) { |
| | | min = (strlen(_input.topics[i]) > (total - 1) ? (total - 1) : strlen(_input.topics[i])); |
| | | if (min > 0) { |
| | | strncpy(topics_buf + count, _input.topics[i], min); |
| | | count += min; |
| | | |
| | | total -= min; |
| | | |
| | | if ((total > 1) && (_input.amount > 1) && (i < (_input.amount - 1))) { |
| | | strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC)); |
| | | total -= 1; |
| | | count++; |
| | | } |
| | | } else { |
| | | topics_buf[strlen(topics_buf) - 1] = '\0'; |
| | | } |
| | | topics_buf = (char *)malloc(total); |
| | | if (topics_buf == NULL) { |
| | | |
| | | rv = EBUS_RES_NO; |
| | | memset(errString, 0x00, sizeof(errString)); |
| | | strncpy(errString, bus_strerror(rv), sizeof(errString)); |
| | | |
| | | logger->error("in BHSubscribeTopics: Out of memory!\n"); |
| | | |
| | | goto exit_entry; |
| | | } |
| | | //logger->debug("the parsed compound sub topics: %s!\n", topics_buf); |
| | | memset(topics_buf, 0x00, total); |
| | | |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | for (i = 0; i < _input.amount; i++) { |
| | | len = strlen(_input.topics[i]); |
| | | strncpy(topics_buf + count, _input.topics[i], min); |
| | | |
| | | count += len; |
| | | |
| | | if ((_input.amount > 1) && (i < (_input.amount - 1))) { |
| | | strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC)); |
| | | |
| | | count++; |
| | | } |
| | | } |
| | | |
| | | #else |
| | | memcpy(topics_buf, topics, topics_len > (sizeof(topics_buf) - 1) ? (sizeof(topics_buf) - 1) : topics_len); |
| | | memcpy(topics_buf, topics, topics_len); |
| | | #endif |
| | | |
| | | if (timeout_ms > 0) { |
| | |
| | | memset(errString, 0x00, sizeof(errString)); |
| | | strncpy(errString, bus_strerror(rv), sizeof(errString)); |
| | | |
| | | free(topics_buf); |
| | | pthread_mutex_unlock(&mutex); |
| | | |
| | | } else { |
| | |
| | | *reply=malloc(*reply_len); |
| | | mcr.SerializePartialToArray(*reply,*reply_len); |
| | | #else |
| | | min = strlen(errString) + 1; |
| | | buf = malloc(min) ; |
| | | len = strlen(errString) + 1; |
| | | buf = malloc(len) ; |
| | | memcpy(buf, errString, strlen(errString)); |
| | | *((char *)buf + min - 1) = '\0'; |
| | | *((char *)buf + len - 1) = '\0'; |
| | | |
| | | *reply = buf; |
| | | *reply_len = min; |
| | | *reply_len = len; |
| | | #endif |
| | | |
| | | if (rv == 0) |