From f5bc1f553793f73243b97224a9e7c25414df2b1a Mon Sep 17 00:00:00 2001 From: h00514358 Date: Tue, 25 Jan 2022 16:25:02 +0800 Subject: [PATCH 1/2] Signed-off-by:hellohyh001 Signed-off-by: h00514358 --- bundle.json | 2 +- services/sensor/BUILD.gn | 9 +- .../src/compatible_connection.cpp | 3 +- .../include/direct_connection.h | 61 ------ .../src/direct_connection.cpp | 195 ------------------ .../src/sensor_event_callback.cpp | 1 - .../interface/include/sensor_hdi_connection.h | 1 + .../interface/src/sensor_hdi_connection.cpp | 26 +-- utils/BUILD.gn | 1 - 9 files changed, 20 insertions(+), 279 deletions(-) delete mode 100644 services/sensor/hdi_connection/adapter/direct_connection/include/direct_connection.h delete mode 100644 services/sensor/hdi_connection/adapter/direct_connection/src/direct_connection.cpp diff --git a/bundle.json b/bundle.json index 6f0d0ce0..cdf2edd6 100644 --- a/bundle.json +++ b/bundle.json @@ -25,7 +25,7 @@ "permission_standard", "napi", "hisysevent_native", - "hdi_sensor" + "sensor_device_driver" ], "third_party": [] }, diff --git a/services/sensor/BUILD.gn b/services/sensor/BUILD.gn index ea34d1f3..a651d00b 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -17,7 +17,6 @@ SUBSYSTEM_DIR = "//base/sensors" ohos_shared_library("libsensor_service") { sources = [ "hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp", - "hdi_connection/adapter/direct_connection/src/direct_connection.cpp", "hdi_connection/adapter/v1_0_connection/src/hdi_connection.cpp", "hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp", "hdi_connection/hardware/src/hdi_service_impl.cpp", @@ -43,17 +42,12 @@ ohos_shared_library("libsensor_service") { "$SUBSYSTEM_DIR/sensor/services/sensor/include", "//drivers/peripheral/sensor/interfaces/include", "hdi_connection/interface/include", - "hdi_connection/adapter/direct_connection/include", "hdi_connection/adapter/v1_0_connection/include", "hdi_connection/hardware/include", "hdi_connection/adapter/compatible_connection/include", ] - deps = [ - "$SUBSYSTEM_DIR/sensor/utils:libsensor_utils", - "//drivers/peripheral/sensor/hal:hdi_sensor", - "//drivers/peripheral/sensor/interfaces/hdi/sensor/v1_0:libsensor_proxy_1.0", - ] + deps = [ "$SUBSYSTEM_DIR/sensor/utils:libsensor_utils" ] external_deps = [ "hisysevent_native:libhisysevent", @@ -62,6 +56,7 @@ ohos_shared_library("libsensor_service") { "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", + "sensor_device_driver:libsensor_proxy_1.0", "utils_base:utils", ] part_name = "sensor" diff --git a/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp index dc09e145..25d5d025 100644 --- a/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp @@ -29,7 +29,8 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "Comp ZReportDataCb CompatibleConnection::reportDataCb_ = nullptr; sptr CompatibleConnection::reportDataCallback_ = nullptr; - +std::mutex ISensorHdiConnection::dataMutex_; +std::condition_variable ISensorHdiConnection::dataCondition_; int32_t CompatibleConnection::ConnectHdi() { return ERR_OK; diff --git a/services/sensor/hdi_connection/adapter/direct_connection/include/direct_connection.h b/services/sensor/hdi_connection/adapter/direct_connection/include/direct_connection.h deleted file mode 100644 index 1bfc5c86..00000000 --- a/services/sensor/hdi_connection/adapter/direct_connection/include/direct_connection.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DIRECT_CONNECTION_H -#define DIRECT_CONNECTION_H - -#include "i_sensor_hdi_connection.h" -#include "sensor_agent_type.h" -#include "sensor_if.h" - -namespace OHOS { -namespace Sensors { -class DirectConnection : public ISensorHdiConnection { -public: - DirectConnection() = default; - - virtual ~DirectConnection() {} - - int32_t ConnectHdi() override; - - int32_t GetSensorList(std::vector& sensorList) override; - - int32_t EnableSensor(uint32_t sensorId) override; - - int32_t DisableSensor(uint32_t sensorId) override; - - int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; - - int32_t SetMode(int32_t sensorId, int32_t mode) override; - - int32_t SetOption(int32_t sensorId, uint32_t option) override; - - int32_t RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) override; - - int32_t RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) override; - - int32_t DestroyHdiConnection() override; - -private: - DISALLOW_COPY_AND_MOVE(DirectConnection); - const struct SensorInterface *sensorInterface_ = nullptr; - int32_t Register(RecordDataCallback cb) const; - static int32_t SensorDataCallback(const struct SensorEvents *event); - static ZReportDataCb reportDataCb_; - static sptr reportDataCallback_; -}; -} // namespace Sensors -} // namespace OHOS -#endif // DIRECT_CONNECTION_H \ No newline at end of file diff --git a/services/sensor/hdi_connection/adapter/direct_connection/src/direct_connection.cpp b/services/sensor/hdi_connection/adapter/direct_connection/src/direct_connection.cpp deleted file mode 100644 index e82ca825..00000000 --- a/services/sensor/hdi_connection/adapter/direct_connection/src/direct_connection.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "direct_connection.h" - -#include "sensors_errors.h" -#include "sensors_log_domain.h" -#include "securec.h" - -namespace OHOS { -namespace Sensors { -using namespace OHOS::HiviewDFX; - -namespace { -constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "DirectConnection" }; -} - -ZReportDataCb DirectConnection::reportDataCb_ = nullptr; -sptr DirectConnection::reportDataCallback_ = nullptr; -std::mutex ISensorHdiConnection::dataMutex_; -std::condition_variable ISensorHdiConnection::dataCondition_; - -int32_t DirectConnection::ConnectHdi() -{ - sensorInterface_ = NewSensorInterfaceInstance(); - if (sensorInterface_ == nullptr) { - HiLog::Error(LABEL, "%{public}s connect hdi failed", __func__); - return ERR_NO_INIT; - } - return ERR_OK; -} - -int32_t DirectConnection::GetSensorList(std::vector& sensorList) -{ - HiLog::Info(LABEL, "%{public}s begin", __func__); - struct SensorInformation *sensorInfo = nullptr; - int32_t count = 0; - int32_t ret = sensorInterface_->GetAllSensors(&sensorInfo, &count); - if (ret != 0) { - HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); - return ret; - } - for (int32_t i = 0; i < count; i++) { - const std::string sensorName(sensorInfo->sensorName); - const std::string vendorName(sensorInfo->vendorName); - const int32_t sensorId = sensorInfo->sensorId; - const float maxRange = sensorInfo->maxRange; - Sensor sensor; - sensor.SetSensorId(sensorId); - sensor.SetMaxRange(maxRange); - sensor.SetName(sensorName.c_str()); - sensor.SetVendor(vendorName.c_str()); - sensorList.push_back(sensor); - sensorInfo++; - } - return ERR_OK; -} - -int32_t DirectConnection::EnableSensor(uint32_t sensorId) -{ - int32_t ret = sensorInterface_->Enable(sensorId); - if (ret < 0) { - HiLog::Error(LABEL, "%{public}s is failed", __func__); - return ret; - } - return ERR_OK; -}; - -int32_t DirectConnection::DisableSensor(uint32_t sensorId) -{ - int32_t ret = sensorInterface_->Disable(sensorId); - if (ret < 0) { - HiLog::Error(LABEL, "%{public}s is failed", __func__); - return ret; - } - return ERR_OK; -} - -int32_t DirectConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) -{ - int32_t ret = sensorInterface_->SetBatch(sensorId, samplingInterval, reportInterval); - if (ret != 0) { - HiLog::Info(LABEL, "%{public}s set batch failed, sensorId: %{public}d", __func__, sensorId); - return ret; - } - return ERR_OK; -} - -int32_t DirectConnection::SetMode(int32_t sensorId, int32_t mode) -{ - int32_t ret = sensorInterface_->SetMode(sensorId, mode); - if (ret != 0) { - HiLog::Info(LABEL, "%{public}s set mode failed, sensorId: %{public}d", __func__, sensorId); - return ret; - } - return ERR_OK; -} - -int32_t DirectConnection::RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) -{ - return ERR_OK; -} - -int32_t DirectConnection::SetOption(int32_t sensorId, uint32_t option) -{ - int32_t ret = sensorInterface_->SetOption(sensorId, option); - if (ret != 0) { - HiLog::Info(LABEL, "%{public}s set option failed, sensorId: %{public}d", __func__, sensorId); - return ret; - } - return ERR_OK; -} - -int32_t DirectConnection::SensorDataCallback(const struct SensorEvents *event) -{ - HiLog::Debug(LABEL, "%{public}s begin", __func__); - if ((event == nullptr) || (event->dataLen == 0)) { - HiLog::Error(LABEL, "%{public}s event is NULL", __func__); - return ERR_INVALID_VALUE; - } - - if (reportDataCb_ == nullptr) { - HiLog::Error(LABEL, "%{public}s reportDataCb_ cannot be null", __func__); - return ERR_NO_INIT; - } - struct SensorEvent sensorEvent = { - .sensorTypeId = event->sensorId, - .version = event->version, - .timestamp = event->timestamp, - .option = event->option, - .mode = event->mode, - .dataLen = event->dataLen - }; - sensorEvent.data = new uint8_t[SENSOR_DATA_LENGHT]; - if (memcpy_s(sensorEvent.data, event->dataLen, event->data, event->dataLen) != EOK) { - HiLog::Error(LABEL, "%{public}s copy data failed", __func__); - return COPY_ERR; - } - (void)(reportDataCallback_->*reportDataCb_)(&sensorEvent, reportDataCallback_); - ISensorHdiConnection::dataCondition_.notify_one(); - return ERR_OK; -} - -int32_t DirectConnection::Register(RecordDataCallback cb) const -{ - if (sensorInterface_ == nullptr) { - HiLog::Error(LABEL, " %{public}s,", "test sensorHdi get Module instance failed\n\r"); - return ERR_INVALID_VALUE; - } - int32_t ret = sensorInterface_->Register(0, cb); - if (ret < 0) { - HiLog::Error(LABEL, "%{public}s failed", __func__); - return ret; - } - return ERR_OK; -} - -int32_t DirectConnection::RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) -{ - if (reportDataCallback == nullptr) { - HiLog::Error(LABEL, "%{public}s failed, reportDataCallback cannot be null", __func__); - return ERR_NO_INIT; - } - int32_t ret = Register(SensorDataCallback); - if (ret < 0) { - HiLog::Error(LABEL, "%{public}s failed", __func__); - return ret; - } - reportDataCb_ = cb; - reportDataCallback_ = reportDataCallback; - return ERR_OK; -} - -int32_t DirectConnection::DestroyHdiConnection() -{ - int32_t ret = sensorInterface_->Unregister(0, SensorDataCallback); - if (ret < 0) { - HiLog::Error(LABEL, "%{public}s failed", __func__); - return ret; - } - return ERR_OK; -} -} // namespace Sensors -} // namespace OHOS \ No newline at end of file diff --git a/services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp b/services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp index fd705680..ce7036e7 100644 --- a/services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp +++ b/services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp @@ -25,7 +25,6 @@ namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "HdiConnection" }; std::unique_ptr HdiConnection_ = std::make_unique(); } - int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents& event) { HiLog::Debug(LABEL, "%{public}s begin", __func__); diff --git a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h index 787d250a..a4a30a4d 100644 --- a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h +++ b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h @@ -51,6 +51,7 @@ private: DISALLOW_COPY_AND_MOVE(SensorHdiConnection); std::unique_ptr iSensorHdiConnection_; std::vector sensorList_; + int32_t connectHdiService(); }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0a22d925..2b9e59ae 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -15,7 +15,6 @@ #include "sensor_hdi_connection.h" #include "compatible_connection.h" -#include "direct_connection.h" #include "hdi_connection.h" #include "sensors_errors.h" #include "sensors_log_domain.h" @@ -31,21 +30,24 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "Sens int32_t SensorHdiConnection::ConnectHdi() { iSensorHdiConnection_ = std::make_unique(); - int32_t ret = iSensorHdiConnection_->ConnectHdi(); - if (ret != 0) { - HiLog::Error(LABEL, "%{public}s connect hdi v1_0 failed", __func__); - iSensorHdiConnection_ = std::make_unique(); - ret = iSensorHdiConnection_->ConnectHdi(); - } - - if (ret != 0) { - HiLog::Error(LABEL, "%{public}s hdi direct connection failed", __func__); + int32_t ret = connectHdiService(); + if (ret != ERR_OK) { + HiLog::Error(LABEL, "%{public}s connect hdi service failed, try to connect compatible connection", + __func__); iSensorHdiConnection_ = std::make_unique(); - ret = iSensorHdiConnection_->ConnectHdi(); + ret = connectHdiService(); } + if (ret != ERR_OK) { + HiLog::Error(LABEL, "%{public}s connect hdi failed", __func__); + } + return ERR_OK; +} +int32_t SensorHdiConnection::connectHdiService() +{ + int32_t ret = iSensorHdiConnection_->ConnectHdi(); if (ret != 0) { - HiLog::Error(LABEL, "%{public}s hdi connection failed", __func__); + HiLog::Error(LABEL, "%{public}s connect hdi service failed", __func__); return CONNECT_SENSOR_HDF_ERR; } ret = iSensorHdiConnection_->GetSensorList(sensorList_); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 5a2c120a..2ccffc75 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -33,7 +33,6 @@ ohos_shared_library("libsensor_utils") { "$SUBSYSTEM_DIR/sensor/interfaces/native/include", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include/message_parcel.h", ] - deps = [ "//drivers/peripheral/sensor/hal:hdi_sensor" ] external_deps = [ "hisysevent_native:libhisysevent", -- Gitee From d6a235fd24a5b4008e21d9755a8b5e07b73158e6 Mon Sep 17 00:00:00 2001 From: h00514358 Date: Tue, 25 Jan 2022 17:20:15 +0800 Subject: [PATCH 2/2] Signed-off-by:hellohyh001 Signed-off-by: h00514358 --- services/sensor/BUILD.gn | 9 ++++----- .../include/compatible_connection.h | 0 .../{v1_0_connection => }/include/hdi_connection.h | 0 .../include/sensor_event_callback.h | 0 .../src/compatible_connection.cpp | 0 .../adapter/{v1_0_connection => }/src/hdi_connection.cpp | 0 .../{v1_0_connection => }/src/sensor_event_callback.cpp | 0 7 files changed, 4 insertions(+), 5 deletions(-) rename services/sensor/hdi_connection/adapter/{compatible_connection => }/include/compatible_connection.h (100%) rename services/sensor/hdi_connection/adapter/{v1_0_connection => }/include/hdi_connection.h (100%) rename services/sensor/hdi_connection/adapter/{v1_0_connection => }/include/sensor_event_callback.h (100%) rename services/sensor/hdi_connection/adapter/{compatible_connection => }/src/compatible_connection.cpp (100%) rename services/sensor/hdi_connection/adapter/{v1_0_connection => }/src/hdi_connection.cpp (100%) rename services/sensor/hdi_connection/adapter/{v1_0_connection => }/src/sensor_event_callback.cpp (100%) diff --git a/services/sensor/BUILD.gn b/services/sensor/BUILD.gn index a651d00b..ce3c973a 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -16,9 +16,9 @@ import("//build/ohos.gni") SUBSYSTEM_DIR = "//base/sensors" ohos_shared_library("libsensor_service") { sources = [ - "hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp", - "hdi_connection/adapter/v1_0_connection/src/hdi_connection.cpp", - "hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp", + "hdi_connection/adapter/src/compatible_connection.cpp", + "hdi_connection/adapter/src/hdi_connection.cpp", + "hdi_connection/adapter/src/sensor_event_callback.cpp", "hdi_connection/hardware/src/hdi_service_impl.cpp", "hdi_connection/interface/src/sensor_hdi_connection.cpp", "src/client_info.cpp", @@ -42,9 +42,8 @@ ohos_shared_library("libsensor_service") { "$SUBSYSTEM_DIR/sensor/services/sensor/include", "//drivers/peripheral/sensor/interfaces/include", "hdi_connection/interface/include", - "hdi_connection/adapter/v1_0_connection/include", + "hdi_connection/adapter/include", "hdi_connection/hardware/include", - "hdi_connection/adapter/compatible_connection/include", ] deps = [ "$SUBSYSTEM_DIR/sensor/utils:libsensor_utils" ] diff --git a/services/sensor/hdi_connection/adapter/compatible_connection/include/compatible_connection.h b/services/sensor/hdi_connection/adapter/include/compatible_connection.h similarity index 100% rename from services/sensor/hdi_connection/adapter/compatible_connection/include/compatible_connection.h rename to services/sensor/hdi_connection/adapter/include/compatible_connection.h diff --git a/services/sensor/hdi_connection/adapter/v1_0_connection/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h similarity index 100% rename from services/sensor/hdi_connection/adapter/v1_0_connection/include/hdi_connection.h rename to services/sensor/hdi_connection/adapter/include/hdi_connection.h diff --git a/services/sensor/hdi_connection/adapter/v1_0_connection/include/sensor_event_callback.h b/services/sensor/hdi_connection/adapter/include/sensor_event_callback.h similarity index 100% rename from services/sensor/hdi_connection/adapter/v1_0_connection/include/sensor_event_callback.h rename to services/sensor/hdi_connection/adapter/include/sensor_event_callback.h diff --git a/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp similarity index 100% rename from services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp rename to services/sensor/hdi_connection/adapter/src/compatible_connection.cpp diff --git a/services/sensor/hdi_connection/adapter/v1_0_connection/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp similarity index 100% rename from services/sensor/hdi_connection/adapter/v1_0_connection/src/hdi_connection.cpp rename to services/sensor/hdi_connection/adapter/src/hdi_connection.cpp diff --git a/services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp similarity index 100% rename from services/sensor/hdi_connection/adapter/v1_0_connection/src/sensor_event_callback.cpp rename to services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp -- Gitee