fw4spl
Bundles/core/appXml/src/appXml/Plugin.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 #include "appXml/Plugin.hpp"
8 
9 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp>
10 
11 #include <fwServices/registry/AppConfig.hpp>
12 #include <fwServices/registry/AppConfigParameters.hpp>
13 
14 namespace appXml
15 {
16 
17 static ::fwRuntime::utils::GenericExecutableFactoryRegistrar<Plugin> registrar("::appXml::Plugin");
18 
19 //------------------------------------------------------------------------------
20 
21 Plugin::Plugin() noexcept :
22  m_configurationName(""),
23  m_parametersName("")
24 {
25 }
26 
27 //------------------------------------------------------------------------------
28 
29 Plugin::~Plugin() noexcept
30 {
31 }
32 
33 //------------------------------------------------------------------------------
34 
36 {
37  SLM_FATAL_IF("Bundle appXml, missing param config in profile", !this->getBundle()->hasParameter("config"));
38  m_configurationName = this->getBundle()->getParameterValue("config");
39  if( this->getBundle()->hasParameter("parameters") )
40  {
41  m_parametersName = this->getBundle()->getParameterValue("parameters");
42  }
43 }
44 
45 //------------------------------------------------------------------------------
46 
48 {
49  SLM_ASSERT("The OSR is already initialized.", !m_appConfigMng );
50  SLM_ASSERT("The configuration name parameter is not initialized.", !m_configurationName.empty());
51 
52  m_appConfigMng = ::fwServices::AppConfigManager::New();
53 
54  if( m_parametersName.empty() )
55  {
56  const ::fwServices::registry::FieldAdaptorType fields;
57  m_appConfigMng->setConfig( m_configurationName, fields );
58  }
59  else
60  {
61  const ::fwServices::registry::FieldAdaptorType& fields =
62  ::fwServices::registry::AppConfigParameters::getDefault()->getParameters( m_parametersName );
63  m_appConfigMng->setConfig( m_configurationName, fields );
64  }
65 
66  m_appConfigMng->launch();
67 }
68 
69 //------------------------------------------------------------------------------
70 
71 void Plugin::stop() noexcept
72 {
73 }
74 
75 //------------------------------------------------------------------------------
76 
77 void Plugin::uninitialize() noexcept
78 {
79  SLM_ASSERT("The OSR is not initialized.", m_appConfigMng );
80  m_appConfigMng->stopAndDestroy();
81  m_appConfigMng.reset();
82 }
83 
84 //------------------------------------------------------------------------------
85 
86 } // namespace appXml
APPXML_API Plugin() noexcept
Constructor.
APPXML_API void stop() noexcept
Overrides stop method. Do nothing.
The bundle appXml allows to parse xml configuration of an application. See AppConfig for more details...
APPXML_API void initialize()
Notifies the plugin about its initialisation.
APPXML_API void uninitialize() noexcept
Notifies the plugin about its uninitialisation.
APPXML_API ~Plugin() noexcept
Destructor. Do nothing.
APPXML_API void start()
Overrides start method. .
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
static FWSERVICES_API AppConfigParameters::sptr getDefault()
Return the default global instance of AppConfigParameters.
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
FWRUNTIME_API std::shared_ptr< Bundle > getBundle() const noexcept override
Retrieves the bundle the executable originates from.
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()