diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index af655e306f86e2e263fa3de925350d0ae40688fe..50b1f9266e65865f0e06a126e49f4fb4f93ee529 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -79,21 +79,15 @@ int32_t HdiConnection::GetSensorList(std::vector& sensorList) HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); return ret; } - for (int32_t i = 0; i < static_cast(sensorInfos.size()); i++) { - const std::string sensorName(sensorInfos[i].sensorName); - const std::string vendorName(sensorInfos[i].vendorName); - const std::string firmwareVersion(sensorInfos[i].firmwareVersion); - const std::string hardwareVersion(sensorInfos[i].hardwareVersion); - const int32_t sensorId = sensorInfos[i].sensorId; - const float maxRange = sensorInfos[i].maxRange; + for (size_t i = 0; i < sensorInfos.size(); i++) { Sensor sensor; - sensor.SetSensorId(sensorId); - sensor.SetSensorTypeId(sensorId); - sensor.SetFirmwareVersion(firmwareVersion.c_str()); - sensor.SetHardwareVersion(hardwareVersion.c_str()); - sensor.SetMaxRange(maxRange); - sensor.SetSensorName(sensorName.c_str()); - sensor.SetVendorName(vendorName.c_str()); + sensor.SetSensorId(sensorInfos[i].sensorId); + sensor.SetSensorTypeId(sensorInfos[i].sensorId); + sensor.SetFirmwareVersion(sensorInfos[i].firmwareVersion.c_str()); + sensor.SetHardwareVersion(sensorInfos[i].hardwareVersion.c_str()); + sensor.SetMaxRange(sensorInfos[i].maxRange); + sensor.SetSensorName(sensorInfos[i].sensorName.c_str()); + sensor.SetVendorName(sensorInfos[i].vendorName.c_str()); sensor.SetResolution(sensorInfos[i].accuracy); sensor.SetPower(sensorInfos[i].power); sensorList.push_back(sensor); diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index dd02a4c820ad9f25ff57c350e8e49c5b4f304045..748bef5f5c67fb143ada3138fd0a8ba88c525892 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -308,10 +308,10 @@ int32_t SensorDataProcesser::CacheSensorEvent(const struct SensorEvent &event, s void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) { uint32_t realSensorId = 0; - uint32_t sensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPosition].sensorTypeId); + uint32_t sensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPos].sensorTypeId); std::vector> channelList; if (sensorId == FLUSH_COMPLETE_ID) { - realSensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPosition].sensorTypeId); + realSensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPos].sensorTypeId); channelList = clientInfo_.GetSensorChannel(realSensorId); } else { channelList = clientInfo_.GetSensorChannel(sensorId); @@ -325,7 +325,7 @@ void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) flushVec = it->second; for (auto &channel : flushVec) { if (flushInfo_.IsFlushChannelValid(channelList, channel.flushChannel)) { - SendEvents(channel.flushChannel, eventsBuf.circularBuf[eventsBuf.readPosition]); + SendEvents(channel.flushChannel, eventsBuf.circularBuf[eventsBuf.readPos]); flushInfo_.ClearFlushInfoItem(realSensorId); break; } else { @@ -347,7 +347,7 @@ void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) /* if has some suspend flush, but this flush come from the flush function rather than enable, so we need to calling GetSensorStatus to decided whether send this event. */ if (channel->GetSensorStatus()) { - SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPosition]); + SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPos]); } } } @@ -369,10 +369,10 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback int32_t eventNum = eventsBuf.eventNum; for (int32_t i = 0; i < eventNum; i++) { EventFilter(eventsBuf); - delete[] eventsBuf.circularBuf[eventsBuf.readPosition].data; - eventsBuf.readPosition++; - if (eventsBuf.readPosition == CIRCULAR_BUF_LEN) { - eventsBuf.readPosition = 0; + delete[] eventsBuf.circularBuf[eventsBuf.readPos].data; + eventsBuf.readPos++; + if (eventsBuf.readPos == CIRCULAR_BUF_LEN) { + eventsBuf.readPos = 0; } eventsBuf.eventNum--; } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 774ae79cbf284b3e53759e141e87da0facb40c39..212b46b0f27ad5e4a678f0cd29091e51a699e964 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -111,7 +111,7 @@ bool SensorService::InitDataCallback() HiLog::Error(LABEL, "%{public}s failed, reportDataCallback_ cannot be null", __func__); return false; } - ZReportDataCb cb = &ReportDataCallback::ZReportDataCallback; + ZReportDataCb cb = &ReportDataCallback::ReportEventCallback; auto ret = sensorHdiConnection_.RegisteDataReport(cb, reportDataCallback_); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s RegisterDataReport failed", __func__); diff --git a/utils/include/report_data_callback.h b/utils/include/report_data_callback.h index a1b7a2970dc5b855948f9e7ba728ea74b292803b..1bd9bb706ac461be6cd44dcabbfc2969618cbe75 100644 --- a/utils/include/report_data_callback.h +++ b/utils/include/report_data_callback.h @@ -29,7 +29,7 @@ constexpr int32_t SENSOR_DATA_LENGHT = 64; struct CircularEventBuf { struct SensorEvent *circularBuf; - int32_t readPosition; + int32_t readPos; int32_t writePosition; int32_t eventNum; }; @@ -38,7 +38,7 @@ class ReportDataCallback : public RefBase { public: ReportDataCallback(); ~ReportDataCallback(); - int32_t ZReportDataCallback(const struct SensorEvent *event, sptr cb); + int32_t ReportEventCallback(const struct SensorEvent *event, sptr cb); struct CircularEventBuf &GetEventData(); struct CircularEventBuf eventsBuf_; }; diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 4317c7cd395001dbd9d56b2a6340b1c170e37d57..702fd0e7edbeb7f38ae99c18090b2edabb72e3da 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -35,7 +35,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { ReportDataCallback::ReportDataCallback() { eventsBuf_.circularBuf = new struct SensorEvent[CIRCULAR_BUF_LEN]; - eventsBuf_.readPosition = 0; + eventsBuf_.readPos = 0; eventsBuf_.writePosition = 0; eventsBuf_.eventNum = 0; } @@ -46,12 +46,12 @@ ReportDataCallback::~ReportDataCallback() delete[] eventsBuf_.circularBuf; } eventsBuf_.circularBuf = nullptr; - eventsBuf_.readPosition = 0; + eventsBuf_.readPos = 0; eventsBuf_.writePosition = 0; eventsBuf_.eventNum = 0; } -int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, sptr cb) +int32_t ReportDataCallback::ReportEventCallback(const struct SensorEvent* event, sptr cb) { if (event == nullptr) { HiLog::Error(LABEL, "%{public}s sensor data is null", __func__); @@ -74,7 +74,7 @@ int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, cb->eventsBuf_.writePosition += 1; } if (leftSize < 1) { - cb->eventsBuf_.readPosition = cb->eventsBuf_.writePosition; + cb->eventsBuf_.readPos = cb->eventsBuf_.writePosition; } cb->eventsBuf_.eventNum += 1; if (cb->eventsBuf_.eventNum >= CIRCULAR_BUF_LEN) {