Line |
Branch |
Exec |
Source |
1 |
|
|
/************************************************************************ |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2009-2024 IRCAD France |
4 |
|
|
* Copyright (C) 2012-2020 IHU Strasbourg |
5 |
|
|
* |
6 |
|
|
* This file is part of Sight. |
7 |
|
|
* |
8 |
|
|
* Sight is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the GNU Lesser General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* Sight is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU Lesser General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU Lesser General Public |
19 |
|
|
* License along with Sight. If not, see <https://www.gnu.org/licenses/>. |
20 |
|
|
* |
21 |
|
|
***********************************************************************/ |
22 |
|
|
|
23 |
|
|
#include "core/runtime/detail/profile/activater.hpp" |
24 |
|
|
|
25 |
|
|
#include "core/runtime/detail/extension_point.hpp" |
26 |
|
|
#include "core/runtime/detail/module.hpp" |
27 |
|
|
#include "core/runtime/extension.hpp" |
28 |
|
|
|
29 |
|
|
#include <boost/algorithm/string/replace.hpp> |
30 |
|
|
|
31 |
|
|
#include <utility> |
32 |
|
|
|
33 |
|
|
namespace sight::core::runtime::detail::profile |
34 |
|
|
{ |
35 |
|
|
|
36 |
|
|
//------------------------------------------------------------------------------ |
37 |
|
|
|
38 |
|
365 |
activater::activater(std::string _identifier, const std::string& /*unused*/) : |
39 |
|
365 |
m_identifier(std::move(_identifier)) |
40 |
|
|
{ |
41 |
|
365 |
} |
42 |
|
|
|
43 |
|
|
//------------------------------------------------------------------------------ |
44 |
|
|
|
45 |
|
66 |
void activater::add_parameter(const std::string& _identifier, const std::string& _value) |
46 |
|
|
{ |
47 |
|
66 |
m_parameters[_identifier] = _value; |
48 |
|
66 |
} |
49 |
|
|
|
50 |
|
|
//------------------------------------------------------------------------------ |
51 |
|
|
|
52 |
|
✗ |
void activater::add_disable_extension_point(const std::string& _identifier) |
53 |
|
|
{ |
54 |
|
✗ |
m_disable_extension_points.push_back(_identifier); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
//------------------------------------------------------------------------------ |
58 |
|
|
|
59 |
|
✗ |
void activater::add_disable_extension(const std::string& _identifier) |
60 |
|
|
{ |
61 |
|
✗ |
m_disable_extensions.push_back(_identifier); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
//------------------------------------------------------------------------------ |
65 |
|
|
|
66 |
|
362 |
void activater::apply() |
67 |
|
|
{ |
68 |
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 362 times.
|
362 |
auto module = std::dynamic_pointer_cast<detail::module>(runtime::get().find_module(m_identifier)); |
69 |
|
|
|
70 |
|
|
// TEMP_FB: until I refactor the profile.xml |
71 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 |
if(module == nullptr) |
72 |
|
|
{ |
73 |
|
✗ |
const auto identifier = boost::algorithm::replace_first_copy(m_identifier, "sight_", ""); |
74 |
|
✗ |
module = std::dynamic_pointer_cast<detail::module>(runtime::get().find_module(identifier)); |
75 |
|
✗ |
SIGHT_FATAL_IF("Unable to activate Module " + identifier + ". Not found.", module == nullptr); |
76 |
|
|
} |
77 |
|
|
|
78 |
1/12
✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
362 |
SIGHT_FATAL_IF("Unable to activate Module " + m_identifier + ". Not found.", module == nullptr); |
79 |
1/2
✓ Branch 1 taken 362 times.
✗ Branch 2 not taken.
|
362 |
module->set_enable(true); |
80 |
|
|
|
81 |
|
|
// Management of parameter configuration |
82 |
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 362 times.
|
427 |
for(auto& m_parameter : m_parameters) |
83 |
|
|
{ |
84 |
1/2
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 |
module->add_parameter(m_parameter.first, m_parameter.second); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
// Disable extension point for this module |
88 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 |
for(auto& m_disable_extension_point : m_disable_extension_points) |
89 |
|
|
{ |
90 |
|
✗ |
if(module->has_extension_point(m_disable_extension_point)) |
91 |
|
|
{ |
92 |
|
✗ |
module->set_enable_extension_point(m_disable_extension_point, false); |
93 |
|
|
} |
94 |
|
|
else |
95 |
|
|
{ |
96 |
|
✗ |
SIGHT_ERROR( |
97 |
|
|
"Unable to disable Extension Point " << m_disable_extension_point << " defined in the Module " |
98 |
|
|
<< m_identifier |
99 |
|
|
<< ". Not found." |
100 |
|
✗ |
); |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
// Disable extension for this module |
105 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 |
for(auto& m_disable_extension : m_disable_extensions) |
106 |
|
|
{ |
107 |
|
✗ |
if(module->has_extension(m_disable_extension)) |
108 |
|
|
{ |
109 |
|
✗ |
module->set_enable_extension(m_disable_extension, false); |
110 |
|
|
} |
111 |
|
|
else |
112 |
|
|
{ |
113 |
|
✗ |
SIGHT_ERROR( |
114 |
|
|
"Unable to disable Extension " << m_disable_extension << " defined in the Module " << m_identifier |
115 |
|
|
<< ". Not found." |
116 |
|
✗ |
); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
362 |
} |
120 |
|
|
|
121 |
|
|
//------------------------------------------------------------------------------ |
122 |
|
|
|
123 |
|
|
} // namespace sight::core::runtime::detail::profile |
124 |
|
|
|