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 OHOS_DP_SUBSCRIBE_DEVICE_PROFILE_MANAGER_H 17 #define OHOS_DP_SUBSCRIBE_DEVICE_PROFILE_MANAGER_H 18 19 #include <string> 20 #include <map> 21 #include <mutex> 22 #include "single_instance.h" 23 #include "distributed_device_profile_enums.h" 24 #include "device_profile.h" 25 #include "dp_subscribe_info.h" 26 #include "service_profile.h" 27 #include "characteristic_profile.h" 28 29 namespace OHOS { 30 namespace DistributedDeviceProfile { 31 class SubscribeProfileManager { 32 DECLARE_SINGLE_INSTANCE(SubscribeProfileManager); 33 public: 34 int32_t Init(); 35 int32_t UnInit(); 36 int32_t NotifyProfileChange(ProfileType profileType, ChangeType changeType, const std::string& dbKey, 37 const std::string& dbValue); 38 int32_t NotifyTrustDeviceProfileAdd(const TrustDeviceProfile& trustDeviceProfile); 39 int32_t NotifyTrustDeviceProfileUpdate(const TrustDeviceProfile& oldDeviceProfile, 40 const TrustDeviceProfile& newDeviceProfile); 41 int32_t NotifyTrustDeviceProfileDelete(const TrustDeviceProfile& trustDeviceProfile); 42 int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); 43 int32_t SubscribeDeviceProfile(std::map<std::string, SubscribeInfo> subscribeInfos); 44 int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); 45 46 private: 47 int32_t NotifyDeviceProfileAdd(const std::string& dbKey, const std::string& dbValue); 48 int32_t NotifyDeviceProfileUpdate(const std::string& dbKey, const std::string& dbValue); 49 int32_t NotifyDeviceProfileDelete(const std::string& dbKey, const std::string& dbValue); 50 int32_t NotifyServiceProfileAdd(const std::string& dbKey, const std::string& dbValue); 51 int32_t NotifyServiceProfileUpdate(const std::string& dbKey, const std::string& dbValue); 52 int32_t NotifyServiceProfileDelete(const std::string& dbKey, const std::string& dbValue); 53 int32_t NotifyCharProfileAdd(const std::string& dbKey, const std::string& dbValue); 54 int32_t NotifyCharProfileUpdate(const std::string& dbKey, const std::string& dbValue); 55 int32_t NotifyCharProfileDelete(const std::string& dbKey, const std::string& dbValue); 56 std::unordered_set<SubscribeInfo, SubscribeHash, SubscribeCompare> GetSubscribeInfos(const std::string& dbKey); 57 std::string DBKeyToSubcribeKey(const std::string& dbkey); 58 59 private: 60 using Func = int32_t(SubscribeProfileManager::*)(const std::string& profileKey, const std::string& profileValue); 61 std::mutex funcsMutex_; 62 std::map<uint32_t, Func> funcsMap_; 63 std::mutex subscribeMutex_; 64 std::map<std::string, std::unordered_set<SubscribeInfo, SubscribeHash, SubscribeCompare>> subscribeInfoMap_; 65 }; 66 } // namespace DistributedDeviceProfile 67 } // namespace OHOS 68 #endif // OHOS_DP_SUBSCRIBE_DEVICE_PROFILE_MANAGER_H 69