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 #include "kvdb_observer_handle.h" 16 #include "db_errno.h" 17 #include "log_print.h" 18 19 namespace DistributedDB { KvDBObserverHandle(uint32_t mode)20KvDBObserverHandle::KvDBObserverHandle(uint32_t mode) 21 : mode_(mode) 22 {} 23 ~KvDBObserverHandle()24KvDBObserverHandle::~KvDBObserverHandle() 25 { 26 for (auto &listener : listeners_) { 27 int errCode = listener->Drop(true); 28 if (errCode != E_OK) { 29 LOGE("Drop listener failed!"); 30 } 31 listener = nullptr; 32 } 33 } 34 InsertListener(NotificationChain::Listener * listener)35void KvDBObserverHandle::InsertListener(NotificationChain::Listener *listener) 36 { 37 listeners_.push_back(listener); 38 } 39 GetObserverMode() const40uint32_t KvDBObserverHandle::GetObserverMode() const 41 { 42 return mode_; 43 } 44 } // namespace DistributedDB 45