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