diff --git a/bundle.json b/bundle.json index 6f0d0ce0f8fa30d46e824221a4cad1411ff44f18..cdf2edd62d7b5f86a27279b9109f18e557ff7eef 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 ea34d1f308cf07b7de974696e87eb8f2a913f91f..ce3c973a2e79f4bb0717fe04aa93af16a23a5e23 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -16,10 +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/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/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", @@ -43,17 +42,11 @@ 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/adapter/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 +55,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/direct_connection/include/direct_connection.h b/services/sensor/hdi_connection/adapter/direct_connection/include/direct_connection.h deleted file mode 100644 index 1bfc5c86746b7637c604a391c0288946f72231bc..0000000000000000000000000000000000000000 --- 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 e82ca8255f12f27ac721972b467b79b748074fbf..0000000000000000000000000000000000000000 --- 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/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 95% rename from services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp rename to services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index dc09e145d02e300da158abdc448d5f3c26ff2ffc..25d5d0250a04027ce384288306060b825052f0a6 100644 --- a/services/sensor/hdi_connection/adapter/compatible_connection/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/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/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 99% 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 index fd705680ec15c0efe6964f60b27321ec74db2c45..ce7036e7e7b399eb32e1240d8a9355111ae23dc1 100644 --- 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 @@ -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 787d250a271520e0c26d3ef69a1f52a7ecfcc33d..a4a30a4dafb368b1206704f3a33cc2947d2a08b9 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 0a22d925a3836fd6b5f4f4a2d77641b17bb9e79c..2b9e59ae7efb7b5d2e3cabc186d9e37556bf8989 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 5a2c120a16388141f13c234f7f0bc69b1d5f82a6..2ccffc75aed23a5135d968f17329c3abd7ffcbf9 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",