mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
modify msg batch too long then CAN NOT send
Signed-off-by: hwzhangchuang <zhangchuang.zhang@huawei.com>
This commit is contained in:
@@ -95,6 +95,8 @@ private:
|
||||
|
||||
void RecordEventLog(const std::string &dhId, int32_t type, int32_t code, int32_t value);
|
||||
void RecordEventLog(const std::vector<struct RawEvent> &events);
|
||||
|
||||
void DoSendMsgBatch(const int32_t sessionId, const std::vector<struct RawEvent> &events);
|
||||
private:
|
||||
std::string mySessionName_;
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> eventHandler_;
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
// each time, we send msg batch with MAX 20 events.
|
||||
constexpr int32_t MSG_BTACH_MAX_SIZE =20;
|
||||
}
|
||||
DistributedInputSinkTransport::DistributedInputSinkTransport() : mySessionName_("")
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
|
||||
@@ -230,6 +234,22 @@ void DistributedInputSinkTransport::SendKeyStateNodeMsgBatch(const int32_t sessi
|
||||
}
|
||||
DHLOGI("SendKeyStateNodeMsgBatch sessionId: %d, event size: %d ", sessionId, events.size());
|
||||
|
||||
std::vector<struct RawEvent> eventBatch;
|
||||
for (int32_t i = 0; i < events.size(); i++) {
|
||||
eventBatch.push_back(events[i]);
|
||||
if (i == MSG_BTACH_MAX_SIZE) {
|
||||
DoSendMsgBatch(sessionId, eventBatch);
|
||||
eventBatch.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!eventBatch.empty()) {
|
||||
DoSendMsgBatch(sessionId, eventBatch);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::DoSendMsgBatch(const int32_t sessionId, const std::vector<struct RawEvent> &events)
|
||||
{
|
||||
int64_t currentTimeNs = GetCurrentTimeUs() * 1000LL;
|
||||
std::shared_ptr<nlohmann::json> eventsJsonArr = std::make_shared<nlohmann::json>();
|
||||
for (const auto &ev : events) {
|
||||
|
||||
@@ -521,7 +521,7 @@ void DistributedInputTransportBase::HandleSession(int32_t sessionId, const std::
|
||||
int32_t DistributedInputTransportBase::SendMsg(int32_t sessionId, std::string &message)
|
||||
{
|
||||
if (message.size() > MSG_MAX_SIZE) {
|
||||
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
|
||||
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE, msg size: %d", message.size());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
|
||||
}
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(calloc((MSG_MAX_SIZE), sizeof(uint8_t)));
|
||||
|
||||
Reference in New Issue
Block a user