• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICES_ACCOUNTMGR_INCLUDE_OS_ACCOUNT_STATIC_SUBSCRIBER_MANAGER_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OS_ACCOUNT_STATIC_SUBSCRIBER_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 #include "account_error_no.h"
22 #include "os_account_subscribe_info.h"
23 
24 namespace OHOS {
25 namespace AccountSA {
26 struct StaticSubscriber {
27     ~StaticSubscriber();
28     std::string path;
29     void *handle = nullptr;
30     void *callback = nullptr;
31 };
32 
33 class OsAccountStaticSubscriberManager {
34 public:
35     static OsAccountStaticSubscriberManager& GetInstance();
36     ErrCode Publish(int32_t fromId, OsAccountState state, int32_t toId);
37 
38 private:
39     OsAccountStaticSubscriberManager();
40     ~OsAccountStaticSubscriberManager() = default;
41     void Init(const std::map<OsAccountState, std::set<std::string>> &staticSubscriberConfig);
42     std::shared_ptr<StaticSubscriber> ParseStaticSubscriber(const std::string &path);
43     static ErrCode PublishToSubscriber(
44         const std::shared_ptr<StaticSubscriber> &subscriber, const COsAccountStateData &data);
45     DISALLOW_COPY_AND_MOVE(OsAccountStaticSubscriberManager);
46 
47 private:
48     std::mutex mutex_;
49     std::map<std::string, std::shared_ptr<StaticSubscriber>> staticSubscribers_;
50     std::map<OsAccountState, std::set<std::shared_ptr<StaticSubscriber>>> state2Subscribers_;
51 };
52 } // AccountSA
53 } // OHOS
54 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OS_ACCOUNT_STATIC_SUBSCRIBER_MANAGER_H
55