• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifdef DEVICE_STATUS_SENSOR_ENABLE
20 #include <map>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <thread>
25 #include <vector>
26 
27 #include "algo_absolute_still.h"
28 #include "algo_horizontal.h"
29 #include "algo_vertical.h"
30 #include "devicestatus_data_define.h"
31 #include "devicestatus_msdp_interface.h"
32 #include "sensor_data_callback.h"
33 #include "stationary_data.h"
34 
35 namespace OHOS {
36 namespace Msdp {
37 namespace DeviceStatus {
38 class AlgoMgr final : public IMsdp {
39 public:
40     AlgoMgr() = default;
41     virtual ~AlgoMgr() = default;
42 
43     bool Init();
44     ErrCode RegisterCallback(std::shared_ptr<MsdpAlgoCallback> callback) override;
45     ErrCode UnregisterCallback() override;
46     ErrCode Enable(Type type) override;
47     ErrCode Disable(Type type) override;
48     ErrCode DisableCount(Type type) override;
49     ErrCode UnregisterSensor(Type type);
GetCallbackImpl()50     std::shared_ptr<MsdpAlgoCallback> GetCallbackImpl()
51     {
52         std::unique_lock lock(mutex_);
53         return callback_;
54     }
55     bool CheckSensorTypeId(int32_t sensorTypeId);
56     bool StartSensor(Type type);
57     int32_t GetSensorTypeId(Type type);
58 private:
59     int32_t type_[Type::TYPE_MAX] { 0 };
60     std::shared_ptr<MsdpAlgoCallback> callback_ { nullptr };
61     std::mutex mutex_;
62     std::shared_ptr<AlgoAbsoluteStill> still_ { nullptr };
63     std::shared_ptr<AlgoHorizontal> horizontalPosition_ { nullptr };
64     std::shared_ptr<AlgoVertical> verticalPosition_ { nullptr };
65     std::map<Type, int32_t> callAlgoNums_ {};
66     Type algoType_ { TYPE_INVALID };
67 };
68 } // namespace DeviceStatus
69 } // namespace Msdp
70 } // namespace OHOS
71 #endif // DEVICE_STATUS_SENSOR_ENABLE
72 #endif // DEVICESTATUS_ALGORITHM_MANAGER_H