fw4spl
Initializer.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 "fwRuntime/profile/Initializer.hpp"
8 
9 #include "fwRuntime/Bundle.hpp"
10 #include "fwRuntime/profile/Profile.hpp"
11 #include "fwRuntime/profile/Uninitializer.hpp"
12 #include "fwRuntime/Runtime.hpp"
13 
14 #include <fwCore/base.hpp>
15 
16 namespace fwRuntime
17 {
18 
19 namespace profile
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 Initializer::Initializer( const std::string& identifier, const Version& version) :
25  m_identifier( identifier ),
26  m_version( version )
27 {
28 }
29 
30 //------------------------------------------------------------------------------
31 
33 {
35  SLM_FATAL_IF("Unable to initialize bundle " + Bundle::getBundleStr(m_identifier, m_version) + ". Not found.",
36  bundle == 0);
37  try
38  {
39  if (!bundle->isInitialized())
40  {
41  bundle->initialize();
42  ::fwRuntime::profile::getCurrentProfile()->add( SPTR(Uninitializer) (new Uninitializer(m_identifier,
43  m_version)));
44  }
45  }
46  catch( const std::exception& e )
47  {
48  SLM_FATAL("Unable to initialize bundle " + Bundle::getBundleStr(m_identifier, m_version) + ". " + e.what());
49  }
50 }
51 
52 //------------------------------------------------------------------------------
53 
54 } // namespace profile
55 
56 } // namespace fwRuntime
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Definition: Runtime.cpp:286
#define SPTR(_cls_)
FWRUNTIME_API std::shared_ptr< Bundle > findEnabledBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the enabled bundle for the specified idenfier.
Definition: Runtime.cpp:270
const std::string m_identifier
the bundle identifier
Definition: Initializer.hpp:47
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
FWRUNTIME_API Initializer(const std::string &identifier, const Version &version=Version())
Constructor.
Definition: Initializer.cpp:24
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
void apply()
Applies the initializer on the bundle.
Definition: Initializer.cpp:32
const Version m_version
the bundle version
Definition: Initializer.hpp:48
Defines the bundle class.
Definition: Bundle.hpp:45
Holds version information for libraries and bundles.