From 2eebf13462324b2a0d1b5db884d8dafc4c3345af Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 31 八月 2021 10:13:56 +0800 Subject: [PATCH] change proto path and import in bhome_node.go --- src/bh_api.cpp | 50 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/bh_api.cpp b/src/bh_api.cpp index 9875cfa..a5c1985 100644 --- a/src/bh_api.cpp +++ b/src/bh_api.cpp @@ -10,8 +10,8 @@ #include "bhome_msg_api.pb.h" #include "bhome_msg.pb.h" #include "error_msg.pb.h" -#include "proto/bhome_msg.pb.h" -#include "proto/bhome_msg_api.pb.h" +#include "../proto/bhome_msg.pb.h" +#include "../proto/bhome_msg_api.pb.h" static Logger *logger = LoggerFactory::getLogger(); @@ -906,7 +906,7 @@ } #if defined(PRO_DE_SERIALIZE) -int BHPublish(const char *msgpub, const char msgpub_len, const int timeout_ms) +int BHPublish(const char *msgpub, const int msgpub_len, const int timeout_ms) #else int BHPublish(const char *topic, const char *content, const int timeout_ms) #endif @@ -1275,6 +1275,12 @@ int sec, nsec; char topics_buf[MAX_STR_LEN] = { 0x00 }; + struct _RequestReply + { + std::string proc_id; + std::string data; + }rr; + #if defined(PRO_DE_SERIALIZE) struct _BHAddress { @@ -1289,7 +1295,7 @@ const char *topic; const char *data; }_input1; - + ::bhome_msg::BHAddress input0; ::bhome_msg::MsgRequestTopic input1; if (!input0.ParseFromArray(remote, remote_len) || !input1.ParseFromArray(request, request_len)) { @@ -1389,12 +1395,6 @@ memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); - - struct _RequestReply - { - std::string proc_id; - std::string data; - }rr; if (rv == 0) { memset(topics_buf, 0x00, sizeof(topics_buf)); @@ -1408,16 +1408,6 @@ memset(topics_buf, 0x00, sizeof(topics_buf)); memcpy(topics_buf, buf, size); rr.data = topics_buf; - -#if defined(PRO_DE_SERIALIZE) - ::bhome_msg::MsgRequestTopicReply mrt; - mrt.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); - mrt.mutable_errmsg()->set_errstring(errString); - mrt.set_data(rr.data.data()); - *reply_len = mrt.ByteSizeLong(); - *reply = malloc(*reply_len); - mrt.SerializePartialToArray(*reply, *reply_len); -#endif } pthread_mutex_unlock(&mutex); @@ -1429,6 +1419,26 @@ strncpy(errString, bus_strerror(rv), sizeof(errString)); } +#if defined(PRO_DE_SERIALIZE) + ::bhome_msg::MsgRequestTopicReply mrt; + mrt.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); + mrt.mutable_errmsg()->set_errstring(errString); + mrt.set_data(rr.data.data()); + *reply_len = mrt.ByteSizeLong(); + *reply = malloc(*reply_len); + mrt.SerializePartialToArray(*reply, *reply_len); +#else + if (rv > 0) { + min = strlen(errString) + 1; + buf = malloc(min); + memcpy(buf, errString, strlen(errString)); + *((char *)buf + min - 1) = '\0'; + + *reply = buf; + *reply_len = min; + } +#endif + if (rv == 0) return true; -- Gitblit v1.8.0