1 /*
2  * Copyright (c) 2023-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 BASE_NOTIFICATION_COMMON_EVENT_SERVICE_INCLUDE_STATIC_SUBSCRIBER_DATA_MANAGER_H
17 #define BASE_NOTIFICATION_COMMON_EVENT_SERVICE_INCLUDE_STATIC_SUBSCRIBER_DATA_MANAGER_H
18 
19 #include <mutex>
20 #include <set>
21 #include <string>
22 
23 #include "distributed_kv_data_manager.h"
24 #include "singleton.h"
25 
26 namespace OHOS {
27 namespace EventFwk {
28 class StaticSubscriberDataManager : public DelayedSingleton<StaticSubscriberDataManager> {
29 public:
30     StaticSubscriberDataManager();
31 
32     virtual ~StaticSubscriberDataManager();
33 
34     int32_t UpdateStaticSubscriberState(const std::map<std::string, std::vector<std::string>> &disableEvents);
35 
36     int32_t QueryStaticSubscriberStateData(
37         std::map<std::string, std::vector<std::string>> &disableEvents, std::set<std::string> &bundleList);
38 
39     int32_t DeleteDisableEventElementByBundleName(const std::string &bundleName);
40 
41 private:
42     DistributedKv::Status GetKvStore();
43     bool CheckKvStore();
44     DistributedKv::Value ConvertEventsToValue(const std::vector<std::string> &events);
45     bool ConvertValueToEvents(const DistributedKv::Value &value, std::vector<std::string> &events);
46 
47     const DistributedKv::AppId appId_ { "static_subscriber_storage" };
48     const DistributedKv::StoreId storeId_ { "static_subscriber_infos" };
49     DistributedKv::DistributedKvDataManager dataManager_;
50     std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
51     mutable std::mutex kvStorePtrMutex_;
52 };
53 } // namespace EventFwk
54 } // namespace OHOS
55 #endif // BASE_NOTIFICATION_COMMON_EVENT_SERVICE_INCLUDE_STATIC_SUBSCRIBER_DATA_MANAGER_H