fw4spl
Activater.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #if defined(__GNUC__)
8 #pragma GCC visibility push(default)
9 #endif
10 #include <iostream>
11 #if defined(__GNUC__)
12 #pragma GCC visibility pop
13 #endif
14 
15 #include <fwCore/base.hpp>
16 
17 #include "fwRuntime/Runtime.hpp"
18 #include "fwRuntime/Bundle.hpp"
19 #include "fwRuntime/ExtensionPoint.hpp"
20 #include "fwRuntime/Extension.hpp"
21 #include "fwRuntime/profile/Activater.hpp"
22 
23 namespace fwRuntime
24 {
25 
26 namespace profile
27 {
28 
29 //------------------------------------------------------------------------------
30 
31 Activater::Activater( const std::string& identifier, const std::string& version ) :
32  m_identifier( identifier ),
33  m_version( version )
34 {
35 }
36 
37 //------------------------------------------------------------------------------
38 
39 void Activater::addParameter( const std::string& identifier, const std::string& value )
40 {
41  m_parameters[identifier] = value;
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 void Activater::addDisableExtensionPoint( const std::string& identifier )
47 {
48  m_disableExtensionPoints.push_back(identifier);
49 }
50 
51 //------------------------------------------------------------------------------
52 
53 void Activater::addDisableExtension( const std::string& identifier )
54 {
55  m_disableExtensions.push_back(identifier);
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  std::shared_ptr< Bundle > bundle = Runtime::getDefault()->findBundle(m_identifier, m_version);
63  SLM_FATAL_IF("Unable to activate Bundle " + m_identifier + "-" + m_version.string() + ". Not found.", bundle == 0);
64 
65  bundle->setEnable( true );
66 
67  // Managment of parameter configuration
68  for( ParameterContainer::const_iterator i = m_parameters.begin();
69  i != m_parameters.end();
70  ++i )
71  {
72  bundle->addParameter( i->first, i->second );
73  }
74 
75  // Disable extension point for this bundle
76  for( DisableExtensionPointContainer::const_iterator id = m_disableExtensionPoints.begin();
77  id != m_disableExtensionPoints.end();
78  ++id )
79  {
80  if( bundle->hasExtensionPoint(*id) )
81  {
82  bundle->setEnableExtensionPoint( *id, false );
83  }
84  else
85  {
86  OSLM_ERROR(
87  "Unable to disable Extension Point " << *id << " defined in the Bundle " << m_identifier <<
88  ". Not found.");
89  }
90  }
91 
92  // Disable extension for this bundle
93  for( DisableExtensionContainer::const_iterator id = m_disableExtensions.begin();
94  id != m_disableExtensions.end();
95  ++id )
96  {
97  if( bundle->hasExtension(*id) )
98  {
99  bundle->setEnableExtension( *id, false );
100  }
101  else
102  {
103  OSLM_ERROR(
104  "Unable to disable Extension " << *id << " defined in the Bundle " << m_identifier <<
105  ". Not found.");
106  }
107  }
108 }
109 
110 //------------------------------------------------------------------------------
111 
112 } // namespace profile
113 
114 } // namespace fwRuntime
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Definition: Runtime.cpp:286
void apply()
Applies the activater on the system.
Definition: Activater.cpp:60
FWRUNTIME_API void addParameter(const std::string &identifier, const std::string &value)
Adds a new parameter to the activater.
Definition: Activater.cpp:39
FWRUNTIME_API void addDisableExtensionPoint(const std::string &identifier)
Adds a new disable extension point to the activater.
Definition: Activater.cpp:46
FWRUNTIME_API std::shared_ptr< Bundle > findBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the bundle for the specified idenfier.
Definition: Runtime.cpp:254
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
FWRUNTIME_API void addDisableExtension(const std::string &identifier)
Adds a new disable extension to the activater.
Definition: Activater.cpp:53
FWRUNTIME_API const std::string string() const
String converter.
FWRUNTIME_API Activater(const std::string &identifier, const std::string &version)
Constructor.
Definition: Activater.cpp:31