1 /* 2 * Copyright (c) 2021 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 KVSTORE_ACCOUNT_OBSERVER_H 17 #define KVSTORE_ACCOUNT_OBSERVER_H 18 19 #include <atomic> 20 21 #include "account_delegate.h" 22 #include "executor_pool.h" 23 24 namespace OHOS { 25 namespace DistributedKv { 26 // KvStore account event proc controller. 27 extern std::atomic<int> g_kvStoreAccountEventStatus; 28 #define KVSTORE_ACCOUNT_EVENT_PROCESSING_CHECKER(result) \ 29 do { \ 30 if (g_kvStoreAccountEventStatus == 1) { \ 31 ZLOGW("system is busy with processing account event."); \ 32 } \ 33 } while (0) 34 class KvStoreDataService; 35 class KvStoreAccountObserver : public AccountDelegate::Observer { 36 public: KvStoreAccountObserver(KvStoreDataService & kvStoreDataService,std::shared_ptr<ExecutorPool> executors)37 explicit KvStoreAccountObserver(KvStoreDataService &kvStoreDataService, 38 std::shared_ptr<ExecutorPool> executors) 39 : kvStoreDataService_(kvStoreDataService), executors_(executors) 40 { 41 } 42 ~KvStoreAccountObserver() override = default; 43 44 void OnAccountChanged(const AccountEventInfo &eventInfo) override; 45 // must specify unique name for observer Name()46 std::string Name() override 47 { 48 return "DistributedDataService"; 49 } 50 GetLevel()51 LevelType GetLevel() override 52 { 53 return LevelType::LOW; 54 } 55 56 private: 57 KvStoreDataService &kvStoreDataService_; 58 std::shared_ptr<ExecutorPool> executors_; 59 }; 60 } // namespace DistributedKv 61 } // namespace OHOS 62 #endif // KVSTORE_ACCOUNT_OBSERVER_H 63