1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_OBS_MANAGER_H 16 #define OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_OBS_MANAGER_H 17 #include <list> 18 #include <memory> 19 #include <string> 20 21 #include "concurrent_map.h" 22 #include "rdb_types.h" 23 24 namespace OHOS::NativeRdb { 25 class RdbObsManager { 26 public: 27 RdbObsManager() = default; 28 virtual ~RdbObsManager(); 29 int32_t Register(const std::string &uri, std::shared_ptr<DistributedRdb::RdbStoreObserver> rdbStoreObserver); 30 int32_t Unregister(const std::string &uri, std::shared_ptr<DistributedRdb::RdbStoreObserver> rdbStoreObserver); 31 int32_t Notify(const std::string &uri); 32 33 private: 34 using RegisterFunc = int32_t (*)(const std::string &, std::shared_ptr<DistributedRdb::RdbStoreObserver>); 35 using UnregisterFunc = int32_t (*)(const std::string &, std::shared_ptr<DistributedRdb::RdbStoreObserver>); 36 using NotifyFunc = int32_t (*)(const std::string &); 37 using CleanFunc = bool (*)(); 38 struct ObsAPIInfo { 39 RegisterFunc registerFunc = nullptr; 40 UnregisterFunc unregisterFunc = nullptr; 41 NotifyFunc notifyFunc = nullptr; 42 CleanFunc cleanFunc = nullptr; 43 }; 44 static ObsAPIInfo GetApiInfo(); 45 static int32_t CleanUp(); 46 static std::mutex mutex_; 47 static ObsAPIInfo apiInfo_; 48 static void *handle_; 49 ConcurrentMap<std::string, std::list<std::shared_ptr<DistributedRdb::RdbStoreObserver>>> obs_; 50 }; 51 } // namespace OHOS::NativeRdb 52 #endif //OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_OBS_MANAGER_H 53