• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 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 {
28 public:
29     static OsAccountSubscribeManager &GetInstance();
30     ErrCode SubscribeOsAccount(const std::shared_ptr<OsAccountSubscribeInfo> &subscribeInfoPtr,
31         const sptr<IRemoteObject> &eventListener) override;
32     ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override;
33     ErrCode PublishActivatedOsAccount(const int id) override;
34     ErrCode PublishActivatingOsAccount(const int id) override;
35     bool OnAccountsChanged(const OsSubscribeRecordPtr &osSubscribeRecordPtr, const int id);
36 
37 private:
38     OsAccountSubscribeManager();
39     ~OsAccountSubscribeManager() = default;
40     DISALLOW_COPY_AND_MOVE(OsAccountSubscribeManager);
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 };
51 }  // namespace AccountSA
52 }  // namespace OHOS
53 
54 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APP_ACCOUNT_SUBSCRIBE_MANAGER_H
55