fw4spl
Starter.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/Starter.hpp"
8 
9 #include "fwRuntime/Bundle.hpp"
10 #include "fwRuntime/Runtime.hpp"
11 
12 #include <fwCore/base.hpp>
13 
14 #include <iostream>
15 #include <sstream>
16 
17 namespace fwRuntime
18 {
19 
20 namespace profile
21 {
22 
23 //------------------------------------------------------------------------------
24 
25 Starter::Starter( const std::string& identifier, const Version& version) :
26  m_identifier( identifier ),
27  m_version( version )
28 {
29 }
30 
31 //------------------------------------------------------------------------------
32 
34 {
35  std::shared_ptr< Bundle > bundle = Runtime::getDefault()->findEnabledBundle(m_identifier, m_version);
37  "Unable to start bundle " + m_identifier + Bundle::s_VERSION_DELIMITER + m_version.string() + ". Not found.",
38  bundle == 0);
39  try
40  {
41  if(!bundle->isStarted())
42  {
43  bundle->start();
44  }
45  else
46  {
47  SLM_WARN("bundle " + Bundle::getBundleStr(m_identifier, m_version) + " already started");
48  }
49  }
50  catch( const std::exception& e )
51  {
52  SLM_FATAL(
53  "Unable to start bundle " + m_identifier + Bundle::s_VERSION_DELIMITER + m_version.string() + ". " +
54  e.what());
55  }
56 }
57 
58 //------------------------------------------------------------------------------
59 
60 } // namespace profile
61 
62 } // namespace fwRuntime
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Definition: Runtime.cpp:286
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
void apply()
Applies the starter on the system.
Definition: Starter.cpp:33
const Version m_version
the bundle version
Definition: Starter.hpp:48
#define SLM_WARN(message)
Definition: spyLog.hpp:261
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
FWRUNTIME_API Starter(const std::string &identifier, const Version &version=Version())
Constructor.
Definition: Starter.cpp:25
Holds version information for libraries and bundles.
FWRUNTIME_API const std::string string() const
String converter.
const std::string m_identifier
the bundle identifier
Definition: Starter.hpp:47