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 16 #ifndef DISTRIBUTED_RDB_KNOWLEDGE_SCHEMA_HELPER_H 17 #define DISTRIBUTED_RDB_KNOWLEDGE_SCHEMA_HELPER_H 18 19 #include <memory> 20 #include <vector> 21 #include <shared_mutex> 22 #include <string> 23 24 #include "knowledge_types.h" 25 #include "rdb_types.h" 26 27 namespace OHOS::NativeRdb { 28 class KnowledgeSchemaHelper : public std::enable_shared_from_this<KnowledgeSchemaHelper> { 29 public: 30 KnowledgeSchemaHelper() = default; 31 ~KnowledgeSchemaHelper(); 32 33 void Init(const RdbStoreConfig &config, const DistributedRdb::RdbKnowledgeSchema &schema); 34 std::pair<int, DistributedRdb::RdbKnowledgeSchema> GetRdbKnowledgeSchema(const std::string &dbName); 35 void DonateKnowledgeData(); 36 void Close(); 37 private: 38 void LoadKnowledgeLib(); 39 void LoadKnowledgeSchemaManager(void *handle); 40 bool IsLoadLib() const; 41 void StartTask(); 42 43 mutable std::shared_mutex libMutex_; 44 DistributedRdb::IKnowledgeSchemaManager *schemaManager_ = nullptr; 45 bool inited_ = false; 46 #ifndef CROSS_PLATFORM 47 void *dlHandle_ = nullptr; 48 #endif 49 std::string bundleName_ = ""; 50 std::string dbName_ = ""; 51 }; 52 } 53 #endif // DISTRIBUTED_RDB_KNOWLEDGE_SCHEMA_HELPER_H 54