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