• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MSDP_CLIENT_IMPL_H
17 #define DEVICESTATUS_MSDP_CLIENT_IMPL_H
18 
19 #include <string>
20 #include <memory>
21 #include <mutex>
22 #include <vector>
23 #include <thread>
24 #include <map>
25 #include <errors.h>
26 
27 #include "rdb_store.h"
28 #include "rdb_helper.h"
29 #include "rdb_open_callback.h"
30 #include "rdb_store_config.h"
31 #include "values_bucket.h"
32 #include "result_set.h"
33 #include "devicestatus_data_utils.h"
34 #include "devicestatus_delayed_sp_singleton.h"
35 #include "devicestatus_msdp_interface.h"
36 #include "devicestatus_sensor_interface.h"
37 
38 namespace OHOS {
39 namespace Msdp {
40 class DevicestatusMsdpClientImpl :
41     public DevicestatusMsdpInterface::MsdpAlgorithmCallback,
42     public DevicestatusSensorInterface::DevicestatusSensorHdiCallback {
43 public:
44     using CallbackManager = std::function<int32_t(const DevicestatusDataUtils::DevicestatusData&)>;
45 
46     ErrCode InitMsdpImpl();
47     ErrCode DisableMsdpImpl();
48     ErrCode RegisterImpl(const CallbackManager& callback);
49     ErrCode UnregisterImpl();
50     int32_t MsdpCallback(const DevicestatusDataUtils::DevicestatusData& data);
51     ErrCode RegisterMsdp();
52     ErrCode UnregisterMsdp(void);
53     ErrCode RegisterSensor();
54     ErrCode UnregisterSensor(void);
55     DevicestatusDataUtils::DevicestatusData SaveObserverData(const DevicestatusDataUtils::DevicestatusData& data);
56     std::map<DevicestatusDataUtils::DevicestatusType, DevicestatusDataUtils::DevicestatusValue> GetObserverData() const;
57     void GetDevicestatusTimestamp();
58     void GetLongtitude();
59     void GetLatitude();
60     int32_t LoadAlgorithmLibrary(bool bCreate);
61     int32_t UnloadAlgorithmLibrary(bool bCreate);
62     int32_t LoadSensorHdiLibrary(bool bCreate);
63     int32_t UnloadSensorHdiLibrary(bool bCreate);
64 private:
65     ErrCode ImplCallback(const DevicestatusDataUtils::DevicestatusData& data);
66     DevicestatusSensorInterface* GetSensorHdiInst();
67     DevicestatusMsdpInterface* GetAlgorithmInst();
68     MsdpAlgorithmHandle mAlgorithm_;
69     SensorHdiHandle sensorHdi_;
70     std::mutex mMutex_;
71     bool notifyManagerFlag_ = false;
72     void OnResult(const DevicestatusDataUtils::DevicestatusData& data) override;
73     void OnSensorHdiResult(const DevicestatusDataUtils::DevicestatusData& data) override;
74 };
75 }
76 }
77 #endif // DEVICESTATUS_MSDP_CLIENT_IMPL_H
78