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_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_dumper.h" 36 #include "devicestatus_msdp_interface.h" 37 38 namespace OHOS { 39 namespace Msdp { 40 class DevicestatusMsdpClientImpl : public DevicestatusMsdpInterface::MsdpAlgorithmCallback { 41 public: 42 using CallbackManager = std::function<int32_t(const DevicestatusDataUtils::DevicestatusData&)>; 43 44 ErrCode InitMsdpImpl(DevicestatusDataUtils::DevicestatusType type); 45 ErrCode DisableMsdpImpl(DevicestatusDataUtils::DevicestatusType type); 46 ErrCode RegisterImpl(const CallbackManager& callback); 47 ErrCode UnregisterImpl(); 48 std::map<DevicestatusDataUtils::DevicestatusType, DevicestatusDataUtils::DevicestatusValue> GetObserverData() const; 49 int32_t LoadAlgorithmLibrary(); 50 int32_t UnloadAlgorithmLibrary(); 51 int32_t LoadAlgoLib(); 52 int32_t UnloadAlgoLib(); 53 private: 54 using CreateFunc = DevicestatusMsdpInterface* (*)(); 55 using DestroyFunc = void *(*)(DevicestatusMsdpInterface*); 56 57 ErrCode ImplCallback(const DevicestatusDataUtils::DevicestatusData& data); 58 int32_t MsdpCallback(const DevicestatusDataUtils::DevicestatusData& data); 59 ErrCode RegisterMsdp(); 60 ErrCode UnregisterMsdp(void); 61 DevicestatusDataUtils::DevicestatusData SaveObserverData(const DevicestatusDataUtils::DevicestatusData& data); 62 DevicestatusMsdpInterface* GetAlgorithmInst(); 63 DevicestatusMsdpInterface* GetAlgoObj(); 64 MsdpAlgorithmHandle mAlgorithm_; 65 MsdpAlgorithmHandle algoHandler_; 66 std::mutex mutex_; 67 bool notifyManagerFlag_ = false; 68 void OnResult(const DevicestatusDataUtils::DevicestatusData& data) override; 69 }; 70 } // Msdp 71 } // OHOS 72 #endif // DEVICESTATUS_MSDP_CLIENT_IMPL_H 73