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
|
/************************************************************************
*
* Copyright (C) 2009-2025 IRCAD France
* Copyright (C) 2012-2020 IHU Strasbourg
*
* 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 "core/runtime/extension.hpp"
#include "core/runtime/detail/extension_point.hpp"
#include "core/runtime/detail/io/validator.hpp"
#include "core/runtime/detail/runtime.hpp"
#include "core/runtime/module.hpp"
#include <libxml/xmlstring.h>
namespace sight::core::runtime::detail
{
//------------------------------------------------------------------------------
extension::extension(
std::shared_ptr<core::runtime::module> _module,
const std::string& _id,
const std::string& _point,
xmlNodePtr _xml_node
) :
sight::core::runtime::extension(_module, _id, _point),
m_xml_doc(xmlNewDoc(reinterpret_cast<const xmlChar*>("1.0"))),
m_xml_node(xmlCopyNode(_xml_node, 1))
{
xmlDocSetRootElement(m_xml_doc, m_xml_node);
}
//------------------------------------------------------------------------------
extension::~extension()
{
xmlFreeDoc(m_xml_doc);
}
//------------------------------------------------------------------------------
xmlNodePtr extension::get_xml_node() const
{
return m_xml_node;
}
//------------------------------------------------------------------------------
extension::validity extension::validate()
{
// Skips the validation if already done.
if(m_validity != unknown_validity)
{
return m_validity;
}
// Retrieves the extension point.
const auto& runtime = detail::runtime::get();
std::shared_ptr<detail::extension_point> ext_point(runtime.find_extension_point(point()));
// Checks that the point exists.
if(!ext_point)
{
throw runtime_exception(point() + " : invalid point reference.");
}
// Validates the extension.
std::shared_ptr<detail::io::validator> validator(ext_point->get_extension_validator());
SIGHT_ASSERT("The validator creation failed for the extension point " << ext_point->identifier(), validator);
// Check extension XML Node <extension id="xxx" implements="yyy" >...</extension>
validator->clear_error_log();
if(validator->validate(m_xml_node))
{
m_validity = valid;
}
else
{
m_validity = invalid;
const auto id = this->identifier();
const std::string identifier = id.empty() ? "anonymous" : id;
const std::string error_msg = "In bundle " + get_module()->identifier() + ". " + identifier
+
": invalid extension XML element node does not respect schema. Verification error log is : \n"
+ validator->get_error_log();
SIGHT_ASSERT(error_msg, false);
SIGHT_ERROR(error_msg);
}
return m_validity;
}
//------------------------------------------------------------------------------
void extension::set_config(const core::runtime::config_t& _config)
{
m_config = _config;
}
//------------------------------------------------------------------------------
const core::runtime::config_t& extension::get_config() const
{
return m_config;
}
//------------------------------------------------------------------------------
} // namespace sight::core::runtime::detail
|