1 /* 2 * Copyright (c) 2024 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_SERVICES_ACCOUNTMGR_INCLUDE_DISTRIBUTED_ACCOUNT_SUBSCRIBE_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_DISTRIBUTED_ACCOUNT_SUBSCRIBE_MANAGER_H 18 19 #include <map> 20 #include <set> 21 #include "idistributed_account_event.h" 22 #include "idistributed_account_subscribe.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class DistributedAccountSubscribeManager : public IDistributedAccountSubscribe { 28 public: 29 static DistributedAccountSubscribeManager &GetInstance(); 30 ErrCode SubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type, 31 const sptr<IRemoteObject> &eventListener) override; 32 ErrCode UnsubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type, 33 const sptr<IRemoteObject> &eventListener) override; 34 ErrCode UnsubscribeDistributedAccountEvent(const sptr<IRemoteObject> &eventListener) override; 35 ErrCode Publish(const int id, DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE subscribeType) override; 36 37 private: 38 DistributedAccountSubscribeManager(); 39 ~DistributedAccountSubscribeManager() = default; 40 DISALLOW_COPY_AND_MOVE(DistributedAccountSubscribeManager); 41 bool OnAccountsChanged(const sptr<IDistributedAccountEvent> &eventProxy, 42 const int id, DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE subscribeType); 43 44 private: 45 sptr<IRemoteObject::DeathRecipient> subscribeDeathRecipient_; 46 std::mutex subscribeRecordMutex_; 47 std::vector<DistributedSubscribeRecordPtr> subscribeRecords_; 48 }; 49 } // namespace AccountSA 50 } // namespace OHOS 51 52 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_DISTRIBUTED_ACCOUNT_SUBSCRIBE_MANAGER_H 53