1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/************************************************************************
*
* Copyright (C) 2025 IRCAD France
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "config.hpp"
#include <core/runtime/runtime.hpp>
namespace sight::data::extension
{
config::sptr config::s_data_config = std::make_shared<config>();
//-----------------------------------------------------------------------------
config::sptr config::get()
{
return s_data_config;
}
//-----------------------------------------------------------------------------
void config::parse_plugin_infos()
{
using extension_t = std::shared_ptr<core::runtime::extension>;
const auto ext_elements = core::runtime::get_all_extensions_for_point("sight::data::extension::config");
for(const extension_t& ext : ext_elements)
{
const auto& cfg = ext->get_config();
const auto config_id = cfg.get<std::string>("id");
const auto desc = cfg.get<std::string>("desc", "No description available");
const auto object = cfg.get<std::string>("object", "");
// Get config
const auto config = cfg.get_child("config");
// Add data config info
this->add_data_config_info(config_id, object, desc, config);
}
}
//-----------------------------------------------------------------------------
void config::add_data_config_info
(
const std::string& _config_id,
const std::string& _data,
const std::string& _desc,
const boost::property_tree::ptree& _config
)
{
std::unique_lock lock(m_registry_mutex);
SIGHT_DEBUG(
"New data config registering : "
<< " configId = " << _config_id
<< " data = " << _data
<< " desc = " << _desc
);
SIGHT_ASSERT(
"The data config with the id " << _config_id << " already exists.",
m_registry.find(_config_id) == m_registry.end()
);
data_config_info info {
.data = sight::core::runtime::filter_id(_data),
.desc = _desc,
.config = _config,
};
m_registry[_config_id] = info;
}
//-----------------------------------------------------------------------------
void config::clear_registry()
{
std::unique_lock lock(m_registry_mutex);
m_registry.clear();
}
//-----------------------------------------------------------------------------
boost::property_tree::ptree config::get_data_config(
const std::string& _config_id,
const std::string& _data_impl
) const
{
#ifndef _DEBUG
SIGHT_NOT_USED(_data_impl);
#else
const std::string data_impl = core::runtime::filter_id(_data_impl);
#endif
std::shared_lock lock(m_registry_mutex);
auto iter = m_registry.find(_config_id);
SIGHT_ASSERT(
"The id " << _config_id << " is not found in the application configuration registry",
iter != m_registry.end()
);
SIGHT_ASSERT(
"The id " << _config_id << " is not allowed for this data " << data_impl,
data_impl.empty() || iter->second.data.empty() || iter->second.data == data_impl
);
return iter->second.config;
}
//-----------------------------------------------------------------------------
const std::string& config::get_config_desc(const std::string& _config_id) const
{
std::shared_lock lock(m_registry_mutex);
auto iter = m_registry.find(_config_id);
SIGHT_ASSERT(
"The id " << _config_id << " is not found in the application configuration registry",
iter != m_registry.end()
);
return iter->second.desc;
}
//-----------------------------------------------------------------------------
std::vector<std::string> config::get_all_config_for_data(std::string _data_impl, bool _matching_only) const
{
const std::string data_impl = core::runtime::filter_id(_data_impl);
std::shared_lock lock(m_registry_mutex);
std::vector<std::string> configs;
for(const auto& srv_cfg : m_registry)
{
const data_config_info& info = srv_cfg.second;
if((info.data.empty() && !_matching_only) || info.data == data_impl)
{
configs.push_back(srv_cfg.first);
}
}
return configs;
}
} // namespace sight::data::extension
|