Branch data Line data Source code
1 : : /* 2 : : * Copyright (C) 2026 by Thun Lu. All rights reserved. 3 : : * Author: Thun Lu <thun.lu@zohomail.cn> 4 : : * Repo: https://github.com/thun-res/vlink 5 : : * _ __ __ _ __ 6 : : * | | / / / / (_) ____ / /__ 7 : : * | | / / / / / / / __ \ / //_/ 8 : : * | |/ / / /___ / / / / / / / ,< 9 : : * |___/ /_____/ /_/ /_/ /_/ /_/|_| 10 : : * 11 : : * Licensed under the Apache License, Version 2.0 (the "License"); 12 : : * you may not use this file except in compliance with the License. 13 : : * You may obtain a copy of the License at 14 : : * 15 : : * http://www.apache.org/licenses/LICENSE-2.0 16 : : * 17 : : * Unless required by applicable law or agreed to in writing, software 18 : : * distributed under the License is distributed on an "AS IS" BASIS, 19 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 : : * See the License for the specific language governing permissions and 21 : : * limitations under the License. 22 : : */ 23 : : 24 : : #include "./extension/schema_plugin_manager.h" 25 : : 26 : : #include <memory> 27 : : #include <string> 28 : : 29 : : #include "./base/utils.h" 30 : : 31 : : namespace vlink { 32 : : 33 : : // SchemaPluginManager 34 : : struct SchemaPluginManager::Impl { 35 : : Plugin plugin; 36 : : std::shared_ptr<SchemaPluginInterface> interface; 37 : : }; 38 : : 39 : 162 : SchemaPluginManager& SchemaPluginManager::get(const std::string& schema_plugin_path) { 40 [ + + + - : 162 : static SchemaPluginManager global_schema_plugin(schema_plugin_path); + - + - - - ] 41 : 162 : return global_schema_plugin; 42 : : } 43 : : 44 : 5 : bool SchemaPluginManager::is_valid() const { return impl_->interface != nullptr; } 45 : : 46 : 159 : std::shared_ptr<SchemaPluginInterface> SchemaPluginManager::get_interface() const { return impl_->interface; } 47 : : 48 : 6 : SchemaPluginManager::SchemaPluginManager(std::string schema_plugin_path) : impl_(std::make_unique<Impl>()) { 49 [ + + ]: 6 : if (schema_plugin_path.empty()) { 50 [ + - + - ]: 5 : schema_plugin_path = Utils::get_env("VLINK_SCHEMA_PLUGIN"); 51 : : 52 [ + + ]: 5 : if (schema_plugin_path.empty()) { 53 : 4 : return; 54 : : } 55 : : } 56 : : 57 [ + - + - : 2 : impl_->interface = impl_->plugin.load<SchemaPluginInterface>(schema_plugin_path, 1, 0); + - + - ] 58 : : 59 [ - + ]: 2 : if VLIKELY (impl_->interface) { 60 : : // LCOV_EXCL_START GCOVR_EXCL_START 61 : : auto version_info = impl_->interface->get_version_info(); 62 : : 63 : : VLOG_D(""); 64 : : VLOG_D("##########################################################"); 65 : : VLOG_D("# Plugin Name: ", version_info.name); 66 : : VLOG_D("# Version: ", version_info.version); 67 : : VLOG_D("# Timestamp: ", version_info.timestamp); 68 : : VLOG_D("# Tag: ", version_info.tag); 69 : : VLOG_D("# Commit: ", version_info.commit_id); 70 : : VLOG_D("##########################################################"); 71 : : VLOG_D(""); 72 : : } 73 : : } 74 : : // LCOV_EXCL_STOP GCOVR_EXCL_STOP 75 : : 76 : 6 : SchemaPluginManager::~SchemaPluginManager() { 77 : 6 : impl_->interface.reset(); 78 : 6 : impl_->plugin.clear(); 79 : 6 : } 80 : : 81 : : } // namespace vlink