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 #define LOG_TAG "KvStoreAccountObserver"
17
18 #include "kvstore_account_observer.h"
19
20 #include <atomic>
21
22 #include "kvstore_data_service.h"
23 #include "log_print.h"
24 #include "xcollie.h"
25
26 namespace OHOS {
27 namespace DistributedKv {
28 std::atomic<int> g_kvStoreAccountEventStatus {0};
OnAccountChanged(const AccountEventInfo & eventInfo,int32_t timeout)29 void KvStoreAccountObserver::OnAccountChanged(const AccountEventInfo &eventInfo, int32_t timeout)
30 {
31 ZLOGI("account event %{public}d, begin.", eventInfo.status);
32 if (timeout > 0) {
33 XCollie xcollie(__FUNCTION__, XCollie::XCOLLIE_LOG | XCollie::XCOLLIE_RECOVERY, timeout);
34 kvStoreDataService_.AccountEventChanged(eventInfo);
35 } else {
36 ExecutorPool::Task task([this, eventInfo]() {
37 ZLOGI("account event processing in thread");
38 kvStoreDataService_.AccountEventChanged(eventInfo);
39 });
40 executors_->Execute(std::move(task));
41 }
42 ZLOGI("account event %{public}d, end.", eventInfo.status);
43 }
44 } // namespace DistributedKv
45 } // namespace OHOS
46