1 /* 2 * Copyright (c) 2021-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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 18 19 #include <map> 20 #include <set> 21 22 #include "ios_account_subscribe.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class OsAccountSubscribeManager : public IOsAccountSubscribe, public DelayedSingleton<OsAccountSubscribeManager> { 28 public: 29 OsAccountSubscribeManager(); 30 virtual ~OsAccountSubscribeManager(); 31 32 ErrCode SubscribeOsAccount(const std::shared_ptr<OsAccountSubscribeInfo> &subscribeInfoPtr, 33 const sptr<IRemoteObject> &eventListener) override; 34 ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override; 35 ErrCode PublishActivatedOsAccount(const int id) override; 36 ErrCode PublishActivatingOsAccount(const int id) override; 37 ErrCode GetEventHandler(void) override; 38 bool OnAccountsChanged(const OsSubscribeRecordPtr &osSubscribeRecordPtr, const int id); 39 40 private: 41 ErrCode InsertSubscribeRecord(const OsSubscribeRecordPtr &subscribeRecordPtr); 42 ErrCode RemoveSubscribeRecord(const sptr<IRemoteObject> &eventListener); 43 ErrCode Publish(const int id, OS_ACCOUNT_SUBSCRIBE_TYPE subscribeType, uint32_t& sendCnt); 44 45 private: 46 std::mutex mutex_; 47 sptr<IRemoteObject::DeathRecipient> subscribeDeathRecipient_; 48 std::mutex subscribeRecordMutex_; 49 std::vector<OsSubscribeRecordPtr> subscribeRecords_; 50 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_; 51 }; 52 } // namespace AccountSA 53 } // namespace OHOS 54 55 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 56