1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DEVICESTATUS_ALGORITHM_MANAGER_H 17 #define DEVICESTATUS_ALGORITHM_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <optional> 23 #include <string> 24 #include <thread> 25 #include <vector> 26 27 #include "algo_absolute_still.h" 28 #include "algo_relative_still.h" 29 #include "devicestatus_data_define.h" 30 #include "devicestatus_data_utils.h" 31 #include "devicestatus_msdp_interface.h" 32 #include "sensor_data_callback.h" 33 34 namespace OHOS { 35 namespace Msdp { 36 class AlgoMgr final : public DevicestatusMsdpInterface { 37 public: 38 AlgoMgr() = default; 39 virtual ~AlgoMgr() = default; 40 41 ErrCode RegisterCallback(std::shared_ptr<MsdpAlgorithmCallback> callback) override; 42 ErrCode UnregisterCallback() override; 43 ErrCode Enable(DevicestatusDataUtils::DevicestatusType type) override; 44 ErrCode Disable(DevicestatusDataUtils::DevicestatusType type) override; 45 46 bool Init(); 47 ErrCode UnregisterSensor(DevicestatusDataUtils::DevicestatusType type); 48 bool CheckSensorTypeId(int32_t sensorTypeId); 49 bool StartSensor(DevicestatusDataUtils::DevicestatusType type); 50 std::optional<int32_t> GetSensorTypeId(DevicestatusDataUtils::DevicestatusType type); 51 private: 52 int32_t type_[DevicestatusDataUtils::TYPE_MAX] = { 0 }; 53 std::mutex mutex_; 54 std::shared_ptr<AlgoAbsoluteStill> still_ { nullptr }; 55 std::shared_ptr<AlgoRelativeStill> relativeStill_ { nullptr }; 56 DevicestatusDataUtils::DevicestatusType algoType_; 57 }; 58 } // namespace Msdp 59 } // namespace OHOS 60 #endif // DEVICESTATUS_ALGORITHM_MANAGER_H 61