1 /* 2 * Copyright (c) 2025 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 OS_ACCOUNT_CONSTRAINT_SUBSCRIBE_MANAGER_H 17 #define OS_ACCOUNT_CONSTRAINT_SUBSCRIBE_MANAGER_H 18 19 #include <map> 20 #include <set> 21 #include "ios_account_subscribe.h" 22 23 namespace OHOS { 24 namespace AccountSA { 25 class OsAccountConstraintSubscribeManager { 26 public: 27 static OsAccountConstraintSubscribeManager &GetInstance(); 28 ErrCode SubscribeOsAccountConstraints(const std::set<std::string> &constraints, 29 const sptr<IRemoteObject> &eventListener); 30 ErrCode UnsubscribeOsAccountConstraints(const std::set<std::string> &constraints, 31 const sptr<IRemoteObject> &eventListener); 32 ErrCode UnsubscribeOsAccountConstraints(const sptr<IRemoteObject> &eventListener); 33 void Publish(int32_t localId, const std::set<std::string> &constraints, const bool isEnabled); 34 35 private: 36 OsAccountConstraintSubscribeManager(); 37 ~OsAccountConstraintSubscribeManager() = default; 38 DISALLOW_COPY_AND_MOVE(OsAccountConstraintSubscribeManager); 39 void RemoveConstraintFromSubscribeRecord(const OsAccountConstraintSubscribeRecordPtr &recordPtr, 40 const std::set<std::string> &constraints); 41 void InsertSubscribeRecord(const OsAccountConstraintSubscribeRecordPtr &recordPtr); 42 void PublishToSubscriber(const OsAccountConstraintSubscribeRecordPtr &recordPtr, int32_t localId, 43 const std::set<std::string> &constraints, bool isEnabled); 44 45 private: 46 std::mutex mutex_; 47 sptr<IRemoteObject::DeathRecipient> subscribeDeathRecipient_; 48 std::set<OsAccountConstraintSubscribeRecordPtr> constraintRecords_; 49 std::map<std::string, std::set<OsAccountConstraintSubscribeRecordPtr>> constraint2RecordMap_; 50 }; 51 } // AccountSA 52 } // OHOS 53 #endif //OS_ACCOUNT_CONSTRAINT_SUBSCRIBE_MANAGER_H